-
Notifications
You must be signed in to change notification settings - Fork 490
MCO-2208: MCO-2125: Migrate mco_units and mco_registry TCs from private-repo #6027
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,3 +152,43 @@ func createMcAndVerifyMCValue(oc *exutil.CLI, stepText, mcName string, node *Nod | |
| o.Expect(podOut).Should(o.MatchRegexp(textToVerify.textToVerifyForNode)) | ||
| logger.Infof("%s is verified in the machine config daemon!", stepText) | ||
| } | ||
|
|
||
| func getClusterVersion(oc *exutil.CLI) (string, error) { | ||
| clusterBuild, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("clusterversion", "-o", "jsonpath={..desired.version}").Output() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| splitValues := strings.Split(clusterBuild, ".") | ||
| return splitValues[0] + "." + splitValues[1], nil | ||
| } | ||
|
|
||
| func skipTestIfClusterVersion(oc *exutil.CLI, operator, constraintVersion string) { | ||
| clusterVersion, err := getClusterVersion(oc) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
|
|
||
| if CompareVersions(clusterVersion, operator, constraintVersion) { | ||
| g.Skip(fmt.Sprintf("Test case skipped because current cluster version %s %s %s", | ||
| clusterVersion, operator, constraintVersion)) | ||
| } | ||
| } | ||
|
|
||
| func skipTestIfExtensionsAreUsed(oc *exutil.CLI) { | ||
| wMcp := NewMachineConfigPool(oc.AsAdmin(), MachineConfigPoolWorker) | ||
| mMcp := NewMachineConfigPool(oc.AsAdmin(), MachineConfigPoolMaster) | ||
|
|
||
| wCurrentMC, err := wMcp.GetConfiguredMachineConfig() | ||
| o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error trying to get the current MC configured in worker pool") | ||
|
|
||
| mCurrentMC, err := mMcp.GetConfiguredMachineConfig() | ||
| o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error trying to get the current MC configured in master pool") | ||
|
|
||
| wExtensions, err := wCurrentMC.Get(`{.spec.extensions}`) | ||
| o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error trying to get the extensions configured in MC: %s", wCurrentMC.GetName()) | ||
|
|
||
| mExtensions, err := mCurrentMC.Get(`{.spec.extensions}`) | ||
| o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error trying to get the extensions configured in MC: %s", mCurrentMC.GetName()) | ||
|
|
||
| if wExtensions != "[]" || mExtensions != "[]" { | ||
| g.Skip("Current cluster is using extensions. This test cannot be execute in a cluster using extensions") | ||
| } | ||
|
Comment on lines
+191
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extension detection is too strict for raw jsonpath output. Comparing to exactly Suggested fix- if wExtensions != "[]" || mExtensions != "[]" {
+ wExt := strings.TrimSpace(wExtensions)
+ mExt := strings.TrimSpace(mExtensions)
+ hasWorkerExt := wExt != "" && wExt != "[]" && wExt != "<no value>"
+ hasMasterExt := mExt != "" && mExt != "[]" && mExt != "<no value>"
+ if hasWorkerExt || hasMasterExt {
g.Skip("Current cluster is using extensions. This test cannot be execute in a cluster using extensions")
}🤖 Prompt for AI Agents |
||
| } | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||
| g "github.com/onsi/ginkgo/v2" | ||||||||||||||||||||||||||||||||||||||||
| o "github.com/onsi/gomega" | ||||||||||||||||||||||||||||||||||||||||
| exutil "github.com/openshift/machine-config-operator/test/extended-priv/util" | ||||||||||||||||||||||||||||||||||||||||
| bootstrap "github.com/openshift/machine-config-operator/test/extended-priv/util/bootstrap" | ||||||||||||||||||||||||||||||||||||||||
| logger "github.com/openshift/machine-config-operator/test/extended-priv/util/logext" | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -359,4 +360,34 @@ var _ = g.Describe("[sig-mco][Suite:openshift/machine-config-operator/longdurati | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| behaviourValidatorRemove.Validate() | ||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| g.It("[PolarionID:53960][OTP] No failed units in the bootstrap machine", func() { | ||||||||||||||||||||||||||||||||||||||||
| skipTestIfSupportedPlatformNotMatched(oc, AWSPlatform, AzurePlatform) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| failedUnitsCommand := "sudo systemctl list-units --failed --all" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // If no bootstrap is found, we skip the case. | ||||||||||||||||||||||||||||||||||||||||
| // The test can only be executed in deployments that didn't remove the bootstrap machine | ||||||||||||||||||||||||||||||||||||||||
| bs, err := bootstrap.GetBootstrap(oc) | ||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||
| if _, notFound := err.(*bootstrap.InstanceNotFound); notFound { | ||||||||||||||||||||||||||||||||||||||||
| g.Skip("skip test because bootstrap machine does not exist in the current cluster") | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| exutil.By("Verify that there is no failed units in the bootstrap machine") | ||||||||||||||||||||||||||||||||||||||||
| // ssh client is a bit unstable, and it can return an empty string for no apparent reason every now and then. | ||||||||||||||||||||||||||||||||||||||||
| // Hence we use 'Eventually' to verify the command to make the test robust. | ||||||||||||||||||||||||||||||||||||||||
| o.Eventually(func() string { | ||||||||||||||||||||||||||||||||||||||||
| logger.Infof("Executing command in bootstrap: %s", failedUnitsCommand) | ||||||||||||||||||||||||||||||||||||||||
| failedUnits, err := bs.SSH.RunOutput(failedUnitsCommand) | ||||||||||||||||||||||||||||||||||||||||
| logger.Infof("Command output:\n%s", failedUnits) | ||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||
| logger.Errorf("Command Error:\n%s", err) | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| return failedUnits | ||||||||||||||||||||||||||||||||||||||||
| }).Should(o.ContainSubstring("0 loaded units listed"), | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+382
to
+390
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: head -400 test/extended-priv/mco_units.go | tail -50Repository: openshift/machine-config-operator Length of output: 1941 🏁 Script executed: sed -n '370,400p' test/extended-priv/mco_units.goRepository: openshift/machine-config-operator Length of output: 1124 🏁 Script executed: rg -n "Eventually.*SSH|RunOutput.*Eventually" test/extended-priv/ -A 3 -B 1Repository: openshift/machine-config-operator Length of output: 59 🏁 Script executed: rg -n "Eventually" test/extended-priv/mco_units.go | head -20Repository: openshift/machine-config-operator Length of output: 194 🏁 Script executed: head -50 test/extended-priv/mco_units.goRepository: openshift/machine-config-operator Length of output: 1844 🏁 Script executed: rg "Eventually.*\)\.Should|Eventually.*\)\.WithPolling" test/extended-priv/ -A 1 | head -40Repository: openshift/machine-config-operator Length of output: 3002 🏁 Script executed: rg 'Eventually\(.*["\d]+[ms]' test/extended-priv/ -A 2 -B 1Repository: openshift/machine-config-operator Length of output: 50389 Set explicit timeout/polling for the SSH The SSH client instability is acknowledged in the code comment, and relying on implicit Suggested fix- o.Eventually(func() string {
+ o.Eventually(func() string {
logger.Infof("Executing command in bootstrap: %s", failedUnitsCommand)
failedUnits, err := bs.SSH.RunOutput(failedUnitsCommand)
logger.Infof("Command output:\n%s", failedUnits)
if err != nil {
logger.Errorf("Command Error:\n%s", err)
}
return failedUnits
- }).Should(o.ContainSubstring("0 loaded units listed"),
+ }, "3m", "15s").Should(o.ContainSubstring("0 loaded units listed"),
"There are failed units in the bootstrap machine")📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||
| "There are failed units in the bootstrap machine") | ||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| apiVersion: template.openshift.io/v1 | ||
| kind: Template | ||
| metadata: | ||
| name: imaa-tag-mirror-set | ||
| objects: | ||
| - kind: ImageTagMirrorSet | ||
| apiVersion: config.openshift.io/v1 | ||
| metadata: | ||
| name: "${NAME}" | ||
| spec: | ||
| imageTagMirrors: | ||
| - mirrors: | ||
| - mirror.example.com/redhat | ||
| source: registry.redhat.io/openshift4 | ||
| mirrorSourcePolicy: AllowContactingSource | ||
| parameters: | ||
| - name: NAME |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| apiVersion: template.openshift.io/v1 | ||
| kind: Template | ||
| metadata: | ||
| name: repository-mirror | ||
| objects: | ||
| - kind: ImageContentSourcePolicy | ||
| apiVersion: operator.openshift.io/v1alpha1 | ||
| metadata: | ||
| name: "${NAME}" | ||
| spec: | ||
| repositoryDigestMirrors: | ||
| - mirrors: | ||
| - example.io/example/ubi-minimal | ||
| source: registry.access.redhat.com/ubi8/ubi-minimal | ||
| - mirrors: | ||
| - example.com/example/ubi-minimal | ||
| source: registry.access.redhat.com/ubi8/ubi-minimal | ||
| parameters: | ||
| - name: NAME |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package bootstrap | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "strings" | ||
|
|
||
| util "github.com/openshift/machine-config-operator/test/extended-priv/util" | ||
| logger "github.com/openshift/machine-config-operator/test/extended-priv/util/logext" | ||
| ) | ||
|
|
||
| const ( | ||
| // EnvVarSSHCloudPrivAWSUser stores the environment variable for the AWS ssh user | ||
| EnvVarSSHCloudPrivAWSUser = "SSH_CLOUD_PRIV_AWS_USER" | ||
| ) | ||
|
|
||
| // AWSBSInfoProvider implements interface BSInfoProvider for AWS | ||
| type AWSBSInfoProvider struct{} | ||
|
|
||
| // GetIPs returns the IPs of the bootstrap machine if this machine exists in AWS | ||
| func (a AWSBSInfoProvider) GetIPs(oc *util.CLI) (*Ips, error) { | ||
| infraName, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.status.infrastructureName}").Output() | ||
| if err != nil { | ||
| logger.Errorf("Could not get bootstrap's IP in AWS. Unable to get infrastructure's name. Error: %s", err) | ||
| return nil, err | ||
| } | ||
|
|
||
| bootstrapName := infraName + "-bootstrap" | ||
|
|
||
| publicIP, err := awsCLIGetInstancePublicIP(bootstrapName) | ||
| if err != nil { | ||
| return nil, &InstanceNotFound{bootstrapName} | ||
| } | ||
| if publicIP == "" || publicIP == "None" { | ||
| logger.Infof("Bootstrap instance '%s' has no public IP or is terminated", bootstrapName) | ||
| return nil, &InstanceNotFound{bootstrapName} | ||
| } | ||
|
|
||
| privateIP, _ := awsCLIGetInstancePrivateIP(bootstrapName) | ||
| logger.Infof("Bootstrap instance '%s': publicIP=%s, privateIP=%s", bootstrapName, publicIP, privateIP) | ||
| return &Ips{PublicIPAddress: publicIP, PrivateIPAddress: privateIP}, nil | ||
| } | ||
|
|
||
| // GetSSHUser returns the user needed to connect to the bootstrap machine via ssh | ||
| func (a AWSBSInfoProvider) GetSSHUser() string { | ||
| if user, exists := os.LookupEnv(EnvVarSSHCloudPrivAWSUser); exists { | ||
| return user | ||
| } | ||
| return DefaultSSHUser | ||
| } | ||
|
|
||
| func awsCLIGetInstancePublicIP(instanceName string) (string, error) { | ||
| out, err := exec.Command("aws", "ec2", "describe-instances", | ||
| "--filters", fmt.Sprintf("Name=tag:Name,Values=%s", instanceName), | ||
| "--query", "Reservations[0].Instances[0].PublicIpAddress", | ||
| "--output", "text", | ||
| ).Output() | ||
|
Comment on lines
+54
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AWS CLI query assumes instance exists at array position [0]. The JMESPath query Consider adding error handling to distinguish between "instance not found" (empty results) and "instance exists but has no public IP" (empty/None value). 🔍 Suggested improvement for robustness func awsCLIGetInstancePublicIP(instanceName string) (string, error) {
out, err := exec.Command("aws", "ec2", "describe-instances",
"--filters", fmt.Sprintf("Name=tag:Name,Values=%s", instanceName),
"--query", "Reservations[0].Instances[0].PublicIpAddress",
"--output", "text",
).Output()
if err != nil {
return "", err
}
- return strings.TrimSpace(string(out)), nil
+ result := strings.TrimSpace(string(out))
+ if result == "null" {
+ return "", fmt.Errorf("no instance found with name %s", instanceName)
+ }
+ return result, nil
}🤖 Prompt for AI Agents |
||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return strings.TrimSpace(string(out)), nil | ||
| } | ||
|
Comment on lines
+53
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add timeout and context to AWS CLI command execution. The ⏱️ Proposed fix to add timeout context+import (
+ "context"
+ "time"
+)
+
func awsCLIGetInstancePublicIP(instanceName string) (string, error) {
+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+ defer cancel()
+
- out, err := exec.Command("aws", "ec2", "describe-instances",
+ out, err := exec.CommandContext(ctx, "aws", "ec2", "describe-instances",
"--filters", fmt.Sprintf("Name=tag:Name,Values=%s", instanceName),
"--query", "Reservations[0].Instances[0].PublicIpAddress",
"--output", "text",
).Output()Apply the same pattern to 🤖 Prompt for AI Agents |
||
|
|
||
| func awsCLIGetInstancePrivateIP(instanceName string) (string, error) { | ||
| out, err := exec.Command("aws", "ec2", "describe-instances", | ||
| "--filters", fmt.Sprintf("Name=tag:Name,Values=%s", instanceName), | ||
| "--query", "Reservations[0].Instances[0].PrivateIpAddress", | ||
| "--output", "text", | ||
| ).Output() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return strings.TrimSpace(string(out)), nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,28 @@ | ||||||||||||||||
| package bootstrap | ||||||||||||||||
|
|
||||||||||||||||
| import ( | ||||||||||||||||
| util "github.com/openshift/machine-config-operator/test/extended-priv/util" | ||||||||||||||||
| logger "github.com/openshift/machine-config-operator/test/extended-priv/util/logext" | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| const ( | ||||||||||||||||
| // EnvVarSSHCloudPrivAzureUser stores the environment variable for the Azure ssh user | ||||||||||||||||
| EnvVarSSHCloudPrivAzureUser = "SSH_CLOUD_PRIV_AZURE_USER" | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| // AzureBSInfoProvider implements interface BSInfoProvider for Azure | ||||||||||||||||
| type AzureBSInfoProvider struct{} | ||||||||||||||||
|
|
||||||||||||||||
| // GetIPs returns the IPs of the bootstrap machine if this machine exists in Azure. | ||||||||||||||||
| // Azure bootstrap discovery is not yet implemented; returns InstanceNotFound so the test skips. | ||||||||||||||||
| func (a AzureBSInfoProvider) GetIPs(oc *util.CLI) (*Ips, error) { | ||||||||||||||||
| infraName, _ := oc.WithoutNamespace().AsAdmin().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.status.infrastructureName}").Output() | ||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle the error from the oc command. The error returned by 🛡️ Proposed fix to handle the error- infraName, _ := oc.WithoutNamespace().AsAdmin().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.status.infrastructureName}").Output()
+ infraName, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.status.infrastructureName}").Output()
+ if err != nil {
+ logger.Errorf("Could not get infrastructure name for Azure bootstrap discovery. Error: %s", err)
+ return nil, err
+ }
bootstrapName := infraName + "-bootstrap"📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| bootstrapName := infraName + "-bootstrap" | ||||||||||||||||
| logger.Infof("Azure bootstrap discovery is not yet implemented, skipping bootstrap machine: %s", bootstrapName) | ||||||||||||||||
| return nil, &InstanceNotFound{bootstrapName} | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // GetSSHUser returns the user needed to connect to the bootstrap machine via ssh | ||||||||||||||||
| func (a AzureBSInfoProvider) GetSSHUser() string { | ||||||||||||||||
| return DefaultSSHUser | ||||||||||||||||
| } | ||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package bootstrap | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| util "github.com/openshift/machine-config-operator/test/extended-priv/util" | ||
| logger "github.com/openshift/machine-config-operator/test/extended-priv/util/logext" | ||
| ) | ||
|
|
||
| const ( | ||
| // EnvVarSSHCloudPrivKey stores the environment variable for the ssh private key path | ||
| EnvVarSSHCloudPrivKey = "SSH_CLOUD_PRIV_KEY" | ||
| // DefaultSSHUser is the default ssh user for bootstrap machines | ||
| DefaultSSHUser = "core" | ||
| ) | ||
|
|
||
| // InstanceNotFound reports an error because the bootstrap instance is not found. It can be used to skip the test case. | ||
| type InstanceNotFound struct{ InstanceName string } | ||
|
|
||
| // Error implements the error interface | ||
| func (inferr *InstanceNotFound) Error() string { | ||
| return fmt.Sprintf("Instance %s has 'terminated' status", inferr.InstanceName) | ||
| } | ||
|
|
||
| // BSInfoProvider any struct implementing this interface can be used to create a Bootstrap object. | ||
| type BSInfoProvider interface { | ||
| GetIPs(*util.CLI) (*Ips, error) | ||
| GetSSHUser() string | ||
| } | ||
|
|
||
| // Bootstrap contains the functionality regarding the bootstrap machine | ||
| type Bootstrap struct { | ||
| SSH util.SshClient | ||
| IPs Ips | ||
| } | ||
|
|
||
| // Ips struct to store the public and the private IPs of the bootstrap machine | ||
| type Ips struct { | ||
| PrivateIPAddress string | ||
| PublicIPAddress string | ||
| } | ||
|
|
||
| // GetBootstrap returns a bootstrap struct pointing to the bootstrap machine if it exists | ||
| func GetBootstrap(oc *util.CLI) (*Bootstrap, error) { | ||
| bsInfoProvider, err := GetBSInfoProvider(oc) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| bootstrapIPs, err := bsInfoProvider.GetIPs(oc.AsAdmin()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| user := bsInfoProvider.GetSSHUser() | ||
| return buildBootstrap(user, *bootstrapIPs, 22), nil | ||
| } | ||
|
|
||
| // GetBSInfoProvider returns a struct implementing BSInfoProvider for the current platform | ||
| func GetBSInfoProvider(oc *util.CLI) (BSInfoProvider, error) { | ||
| platform := util.CheckPlatform(oc) | ||
| switch platform { | ||
| case "aws": | ||
| return AWSBSInfoProvider{}, nil | ||
| case "azure": | ||
| return AzureBSInfoProvider{}, nil | ||
| default: | ||
| return nil, fmt.Errorf("platform not supported. Cannot get bootstrap information for platform: %s", platform) | ||
| } | ||
| } | ||
|
|
||
| func buildBootstrap(user string, bootstrapIPs Ips, port int) *Bootstrap { | ||
| privateKey := util.GetSSHPrivateKey() | ||
| publicIP := bootstrapIPs.PublicIPAddress | ||
| logger.Infof("Creating bootstrap with ip '%s', user: '%s', private key: '%s', port '%d'", | ||
| publicIP, user, privateKey, port) | ||
| return &Bootstrap{ | ||
| SSH: util.SshClient{User: user, Host: publicIP, Port: port, PrivateKey: privateKey}, | ||
| IPs: bootstrapIPs, | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard cluster version parsing before indexing.
splitValues[0]/splitValues[1]can panic whendesired.versionis empty or malformed.Suggested fix
func getClusterVersion(oc *exutil.CLI) (string, error) { clusterBuild, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("clusterversion", "-o", "jsonpath={..desired.version}").Output() if err != nil { return "", err } - splitValues := strings.Split(clusterBuild, ".") - return splitValues[0] + "." + splitValues[1], nil + clusterBuild = strings.TrimSpace(clusterBuild) + splitValues := strings.Split(clusterBuild, ".") + if len(splitValues) < 2 { + return "", fmt.Errorf("unexpected cluster version format: %q", clusterBuild) + } + return splitValues[0] + "." + splitValues[1], nil }🤖 Prompt for AI Agents