Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a flag to prep-node to bypass initial OS check #376

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/prepNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/platform9/pf9ctl/pkg/config"
"github.com/platform9/pf9ctl/pkg/log"
"github.com/platform9/pf9ctl/pkg/objects"
"github.com/platform9/pf9ctl/pkg/platform"
"github.com/platform9/pf9ctl/pkg/pmk"
"github.com/platform9/pf9ctl/pkg/ssh"
"github.com/platform9/pf9ctl/pkg/supportBundle"
Expand Down Expand Up @@ -45,6 +46,7 @@ var (
password string
sshKey string
ips []string
skipOSChecks bool
skipChecks bool
disableSwapOff bool
)
Expand All @@ -56,6 +58,7 @@ func init() {
prepNodeCmd.Flags().StringVarP(&nodeConfig.Password, "password", "p", "", "ssh password for the nodes (use 'single quotes' to pass password)")
prepNodeCmd.Flags().StringVarP(&nodeConfig.SshKey, "ssh-key", "s", "", "ssh key file for connecting to the nodes")
prepNodeCmd.Flags().StringSliceVarP(&nodeConfig.IPs, "ip", "i", []string{}, "IP address of host to be prepared")
prepNodeCmd.Flags().BoolVarP(&skipOSChecks, "skip-os-checks", "o", false, "Will continue prep-node even if os version checks fail")
prepNodeCmd.Flags().BoolVarP(&skipChecks, "skip-checks", "c", false, "Will skip optional checks if true")
prepNodeCmd.Flags().BoolVarP(&disableSwapOff, "disable-swapoff", "d", false, "Will skip swapoff")
prepNodeCmd.Flags().MarkHidden("disable-swapoff")
Expand All @@ -78,6 +81,9 @@ func prepNodeRun(cmd *cobra.Command, args []string) {
if skipChecks {
pmk.WarningOptionalChecks = true
}
if skipOSChecks {
platform.SkipOSChecks = true
}

detachedMode := cmd.Flags().Changed("no-prompt")
isRemote := cmdexec.CheckRemote(nodeConfig)
Expand Down
20 changes: 16 additions & 4 deletions pkg/platform/centos/centos.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,17 @@ func (c *CentOS) CheckExistingInstallation() (bool, error) {

func (c *CentOS) checkOSPackages() (bool, error) {

var rhel8, rocky9 bool
errLines := []string{packageInstallError}
zap.S().Debug("Checking OS Packages")

rhel8, _ := regexp.MatchString(`.*8\.[5-9]\.*`, string(version))
rocky9, _ := regexp.MatchString(`.*9\.[1-2]\.*`, string(version))
rhel8, _ = regexp.MatchString(`.*8\.[5-9]\.*`, string(version))
rocky9, _ = regexp.MatchString(`.*9\.[1-2]\.*`, string(version))

if platform.SkipOSChecks {
rhel8, _ = regexp.MatchString(`8\.\d{1,2}`, string(version))
rocky9, _ = regexp.MatchString(`9\.\d{1,2}`, string(version))
manasabsv26 marked this conversation as resolved.
Show resolved Hide resolved
}
for _, p := range packages {
if !centos && (rhel8 || rocky9) {
switch p {
Expand Down Expand Up @@ -173,8 +179,14 @@ func (c *CentOS) checkOSPackages() (bool, error) {

func (c *CentOS) checkEnabledRepos() (bool, error) {

centos, _ := regexp.MatchString(`.*7\.[3-9]\.*`, string(version))
rhel8, _ := regexp.MatchString(`.*8\.[5-9]\.*`, string(version))
var centos, rhel8 bool
centos, _ = regexp.MatchString(`.*7\.[3-9]\.*`, string(version))
rhel8, _ = regexp.MatchString(`.*8\.[5-9]\.*`, string(version))

if platform.SkipOSChecks {
centos, _ = regexp.MatchString(`7\.\d{1,2}`, string(version))
rhel8, _ = regexp.MatchString(`8\.\d{1,2}`, string(version))
manasabsv26 marked this conversation as resolved.
Show resolved Hide resolved
}

output, err := c.exec.RunWithStdout("bash", "-c", "yum repolist")
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/platform/platform.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package platform

var SkipOSChecks bool

type Platform interface {
Check() []Check
Version() (string, error)
Expand Down
18 changes: 13 additions & 5 deletions pkg/pmk/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,21 +374,29 @@ func ValidatePlatform(exec cmdexec.Executor) (string, error) {
if err != nil {
return "", fmt.Errorf("failed reading data from file: %s", err)
}
var platform platform.Platform
var osplatform platform.Platform
switch {
case strings.Contains(strData, util.Centos) || strings.Contains(strData, util.Redhat) || strings.Contains(strData, util.Rocky):
platform = centos.NewCentOS(exec)
osVersion, err := platform.Version()
osplatform = centos.NewCentOS(exec)
osVersion, err := osplatform.Version()
if err == nil {
return osVersion, nil
} else if platform.SkipOSChecks && strings.Contains(err.Error(), "Unable to determine OS type") {
zap.S().Info(err.Error())
zap.S().Info("This OS version is not supported. Continuing as --skip-os-checks flag was used")
return "redhat", nil
} else {
return "", fmt.Errorf("error in fetching OS version: %s", err.Error())
}
case strings.Contains(strData, util.Ubuntu):
platform = debian.NewDebian(exec)
osVersion, err := platform.Version()
osplatform = debian.NewDebian(exec)
osVersion, err := osplatform.Version()
if err == nil {
return osVersion, nil
} else if platform.SkipOSChecks && strings.Contains(err.Error(), "Unable to determine OS type") {
zap.S().Info(err.Error())
zap.S().Info("This OS version is not supported. Continuing as --skip-os-checks flag was used")
return "debian", nil
} else {
return "", fmt.Errorf("error in fetching OS version: %s", err.Error())
}
Expand Down
Loading