Skip to content

Commit

Permalink
handle ocp 311 case when adding major-minor label (stolostron#530)
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Le <[email protected]>

Signed-off-by: Yang Le <[email protected]>
  • Loading branch information
elgnay authored Oct 21, 2022
1 parent 84e76f4 commit 0e952ef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
22 changes: 18 additions & 4 deletions pkg/controllers/clusterinfo/autodetect_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func (r *AutoDetectReconciler) Reconcile(ctx context.Context, req ctrl.Request)
needUpdate = true
}

if len(minor) == 0 {
// no clusterinfov1beta1.OCPVersionMajorMinor label for OCP 311
continue
}

ocpVersionMajorMinor := fmt.Sprintf("%s.%s", major, minor)
if labels[clusterinfov1beta1.OCPVersionMajorMinor] != ocpVersionMajorMinor {
labels[clusterinfov1beta1.OCPVersionMajorMinor] = ocpVersionMajorMinor
Expand Down Expand Up @@ -134,10 +139,19 @@ func (r *AutoDetectReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// parseOCPVersion pasrses the full version of OCP and returns major, minor and patch.
func parseOCPVersion(version string) (string, string, string, error) {
parts := strings.Split(version, ".")
if len(parts) != 3 {
return "", "", "", fmt.Errorf("invalid Openshift version: %s", version)
if len(version) == 0 {
return "", "", "", fmt.Errorf("invalid OpenShift version: %s", version)
}

return parts[0], parts[1], parts[2], nil
parts := strings.Split(version, ".")
switch {
case len(parts) == 1:
// handle OCP 311 case
// only major version is avaiable, like "3"
return parts[0], "", "", nil
case len(parts) == 3:
return parts[0], parts[1], parts[2], nil
default:
return "", "", "", fmt.Errorf("invalid OpenShift version: %s", version)
}
}
14 changes: 13 additions & 1 deletion pkg/controllers/clusterinfo/autodetect_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,22 @@ func TestParseOCPVersion(t *testing.T) {
minor: "11",
patch: "3",
},
{
name: "ocp 311 version",
ocpVersion: "3",
major: "3",
minor: "",
patch: "",
},
{
name: "empty version",
ocpVersion: "",
expectedError: "invalid OpenShift version: ",
},
{
name: "invalid ocp version",
ocpVersion: "4.11",
expectedError: "invalid Openshift version: 4.11",
expectedError: "invalid OpenShift version: 4.11",
},
}

Expand Down

0 comments on commit 0e952ef

Please sign in to comment.