diff --git a/cmd/prepNode.go b/cmd/prepNode.go index 1e7f7cd..552cefd 100644 --- a/cmd/prepNode.go +++ b/cmd/prepNode.go @@ -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" @@ -45,6 +46,7 @@ var ( password string sshKey string ips []string + skipOSChecks bool skipChecks bool disableSwapOff bool ) @@ -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") @@ -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) diff --git a/pkg/platform/centos/centos.go b/pkg/platform/centos/centos.go index d7be927..012fe8d 100644 --- a/pkg/platform/centos/centos.go +++ b/pkg/platform/centos/centos.go @@ -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)) + } for _, p := range packages { if !centos && (rhel8 || rocky9) { switch p { @@ -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)) + } output, err := c.exec.RunWithStdout("bash", "-c", "yum repolist") if err != nil { diff --git a/pkg/platform/platform.go b/pkg/platform/platform.go index 75837db..9c0deea 100644 --- a/pkg/platform/platform.go +++ b/pkg/platform/platform.go @@ -1,5 +1,7 @@ package platform +var SkipOSChecks bool + type Platform interface { Check() []Check Version() (string, error) diff --git a/pkg/pmk/node.go b/pkg/pmk/node.go index 3538b02..8ffc122 100644 --- a/pkg/pmk/node.go +++ b/pkg/pmk/node.go @@ -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()) }