diff --git a/apis/hive/v1/clusterdeployment_types.go b/apis/hive/v1/clusterdeployment_types.go index ffae7c21197..214ace3fca5 100644 --- a/apis/hive/v1/clusterdeployment_types.go +++ b/apis/hive/v1/clusterdeployment_types.go @@ -592,7 +592,7 @@ const InitializedConditionReason = "Initialized" // +kubebuilder:printcolumn:name="InfraID",type="string",JSONPath=".spec.clusterMetadata.infraID" // +kubebuilder:printcolumn:name="Platform",type="string",JSONPath=".metadata.labels.hive\\.openshift\\.io/cluster-platform" // +kubebuilder:printcolumn:name="Region",type="string",JSONPath=".metadata.labels.hive\\.openshift\\.io/cluster-region" -// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".metadata.labels.hive\\.openshift\\.io/version-major-minor-patch" +// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".metadata.labels.hive\\.openshift\\.io/version" // +kubebuilder:printcolumn:name="ClusterType",type="string",JSONPath=".metadata.labels.hive\\.openshift\\.io/cluster-type" // +kubebuilder:printcolumn:name="ProvisionStatus",type="string",JSONPath=".status.conditions[?(@.type=='Provisioned')].reason" // +kubebuilder:printcolumn:name="PowerState",type="string",JSONPath=".status.powerState" diff --git a/config/crds/hive.openshift.io_clusterdeployments.yaml b/config/crds/hive.openshift.io_clusterdeployments.yaml index 4ca96b5efc0..eafd40f823c 100644 --- a/config/crds/hive.openshift.io_clusterdeployments.yaml +++ b/config/crds/hive.openshift.io_clusterdeployments.yaml @@ -26,7 +26,7 @@ spec: - jsonPath: .metadata.labels.hive\.openshift\.io/cluster-region name: Region type: string - - jsonPath: .metadata.labels.hive\.openshift\.io/version-major-minor-patch + - jsonPath: .metadata.labels.hive\.openshift\.io/version name: Version type: string - jsonPath: .metadata.labels.hive\.openshift\.io/cluster-type diff --git a/hack/app-sre/saas-template.yaml b/hack/app-sre/saas-template.yaml index 5f1fa00faf4..9aa00fe0c0e 100644 --- a/hack/app-sre/saas-template.yaml +++ b/hack/app-sre/saas-template.yaml @@ -400,7 +400,7 @@ objects: - jsonPath: .metadata.labels.hive\.openshift\.io/cluster-region name: Region type: string - - jsonPath: .metadata.labels.hive\.openshift\.io/version-major-minor-patch + - jsonPath: .metadata.labels.hive\.openshift\.io/version name: Version type: string - jsonPath: .metadata.labels.hive\.openshift\.io/cluster-type diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index ba4abf5223a..73ea9bfbd1f 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -335,6 +335,11 @@ const ( // VSphereCertificatesDir is the directory containing VSphere certificate files. VSphereCertificatesDir = "/vsphere-certificates" + // VersionLabel is a label applied to ClusterDeployments to show the full version of the cluster + // per ClusterVersion.status.desired.version. This should differ from VersionMajorMinorPatchLabel + // only for pre-release versions. + VersionLabel = "hive.openshift.io/version" + // VersionMajorLabel is a label applied to ClusterDeployments to show the version of the cluster // in the form "[MAJOR]". VersionMajorLabel = "hive.openshift.io/version-major" diff --git a/pkg/controller/clusterversion/clusterversion_controller.go b/pkg/controller/clusterversion/clusterversion_controller.go index 63a76484a82..2be144820b0 100644 --- a/pkg/controller/clusterversion/clusterversion_controller.go +++ b/pkg/controller/clusterversion/clusterversion_controller.go @@ -161,26 +161,32 @@ func (r *ReconcileClusterVersion) Reconcile(ctx context.Context, request reconci func (r *ReconcileClusterVersion) updateClusterVersionLabels(cd *hivev1.ClusterDeployment, clusterVersion *openshiftapiv1.ClusterVersion, cdLog log.FieldLogger) error { changed := false - if version, err := semver.ParseTolerant(clusterVersion.Status.Desired.Version); err == nil { - if cd.Labels == nil { - cd.Labels = make(map[string]string, 3) - } + cvoVersion := clusterVersion.Status.Desired.Version + if cd.Labels == nil { + cd.Labels = map[string]string{} + } + if cd.Labels[constants.VersionLabel] != cvoVersion { + cd.Labels[constants.VersionLabel] = cvoVersion + changed = true + } + if version, err := semver.ParseTolerant(cvoVersion); err == nil { major := fmt.Sprintf("%d", version.Major) majorMinor := fmt.Sprintf("%s.%d", major, version.Minor) majorMinorPatch := fmt.Sprintf("%s.%d", majorMinor, version.Patch) - changed = cd.Labels[constants.VersionMajorLabel] != major || + changed = changed || + cd.Labels[constants.VersionMajorLabel] != major || cd.Labels[constants.VersionMajorMinorLabel] != majorMinor || cd.Labels[constants.VersionMajorMinorPatchLabel] != majorMinorPatch cd.Labels[constants.VersionMajorLabel] = major cd.Labels[constants.VersionMajorMinorLabel] = majorMinor cd.Labels[constants.VersionMajorMinorPatchLabel] = majorMinorPatch } else { - cdLog.WithField("version", clusterVersion.Status.Desired.Version).WithError(err).Warn("could not parse the cluster version") + cdLog.WithField("version", cvoVersion).WithError(err).Warn("could not parse the cluster version") origLen := len(cd.Labels) delete(cd.Labels, constants.VersionMajorLabel) delete(cd.Labels, constants.VersionMajorMinorLabel) delete(cd.Labels, constants.VersionMajorMinorPatchLabel) - changed = origLen != len(cd.Labels) + changed = changed || origLen != len(cd.Labels) } if !changed { diff --git a/pkg/controller/clusterversion/clusterversion_controller_test.go b/pkg/controller/clusterversion/clusterversion_controller_test.go index e21d5787463..00b7f52e3e1 100644 --- a/pkg/controller/clusterversion/clusterversion_controller_test.go +++ b/pkg/controller/clusterversion/clusterversion_controller_test.go @@ -73,6 +73,7 @@ func TestClusterVersionReconcile(t *testing.T) { testKubeconfigSecret(), }, validate: func(t *testing.T, cd *hivev1.ClusterDeployment) { + assert.Equal(t, "2.3.4+somebuild", cd.Labels[constants.VersionLabel], "unexpected version label") assert.Equal(t, "2", cd.Labels[constants.VersionMajorLabel], "unexpected version major label") assert.Equal(t, "2.3", cd.Labels[constants.VersionMajorMinorLabel], "unexpected version major-minor label") assert.Equal(t, "2.3.4", cd.Labels[constants.VersionMajorMinorPatchLabel], "unexpected version major-minor-patch label") diff --git a/pkg/controller/hibernation/hibernation_controller.go b/pkg/controller/hibernation/hibernation_controller.go index ff3ee28c051..60a756763c9 100644 --- a/pkg/controller/hibernation/hibernation_controller.go +++ b/pkg/controller/hibernation/hibernation_controller.go @@ -651,7 +651,7 @@ func deleteTransitionMetric(metric *prometheus.HistogramVec, cd *hivev1.ClusterD "cluster_deployment_namespace": cd.Namespace, "cluster_deployment": cd.Name, "platform": cd.Labels[hivev1.HiveClusterPlatformLabel], - "cluster_version": cd.Labels[constants.VersionMajorMinorPatchLabel], + "cluster_version": cd.Labels[constants.VersionLabel], "cluster_pool_namespace": poolNS, }) } @@ -675,7 +675,7 @@ func logCumulativeMetric(metric *prometheus.HistogramVec, cd *hivev1.ClusterDepl poolNS = cd.Spec.ClusterPoolRef.Namespace poolName = cd.Spec.ClusterPoolRef.PoolName } - metric.WithLabelValues(cd.Labels[constants.VersionMajorMinorPatchLabel], + metric.WithLabelValues(cd.Labels[constants.VersionLabel], cd.Labels[hivev1.HiveClusterPlatformLabel], poolNS, poolName).Observe(time) diff --git a/pkg/controller/machinepool/azureactuator_test.go b/pkg/controller/machinepool/azureactuator_test.go index ff0057d3de8..08892a9e884 100644 --- a/pkg/controller/machinepool/azureactuator_test.go +++ b/pkg/controller/machinepool/azureactuator_test.go @@ -88,7 +88,7 @@ func TestAzureActuator(t *testing.T) { clusterDeployment: testAzureClusterDeployment(), pool: func() *hivev1.MachinePool { p := testAzurePool() - p.Spec.Replicas = pointer.Int64Ptr(5) + p.Spec.Replicas = pointer.Int64(5) return p }(), mockAzureClient: func(mockCtrl *gomock.Controller, client *mockazure.MockClient) { @@ -311,7 +311,7 @@ func TestAzureActuator(t *testing.T) { clusterDeployment: testAzureClusterDeployment412(), pool: func() *hivev1.MachinePool { p := testAzurePool() - p.Spec.Replicas = pointer.Int64Ptr(5) + p.Spec.Replicas = pointer.Int64(5) return p }(), mockAzureClient: func(mockCtrl *gomock.Controller, client *mockazure.MockClient) { @@ -595,7 +595,7 @@ func testAzureClusterDeployment() *hivev1.ClusterDeployment { func testAzureClusterDeployment412() *hivev1.ClusterDeployment { cd := testAzureClusterDeployment() - cd.Labels[constants.VersionMajorMinorPatchLabel] = "4.12.0" + cd.Labels[constants.VersionLabel] = "4.12.0" return cd } diff --git a/pkg/controller/machinepool/machinepool_controller.go b/pkg/controller/machinepool/machinepool_controller.go index d9d199c5187..a5cbc8fc144 100644 --- a/pkg/controller/machinepool/machinepool_controller.go +++ b/pkg/controller/machinepool/machinepool_controller.go @@ -1139,7 +1139,7 @@ func getMinMaxReplicasForMachineSet(pool *hivev1.MachinePool, machineSets []*mac } func getClusterVersion(cd *hivev1.ClusterDeployment) (string, error) { - version, versionPresent := cd.Labels[constants.VersionMajorMinorPatchLabel] + version, versionPresent := cd.Labels[constants.VersionLabel] if !versionPresent { return "", errors.New("cluster version not set in clusterdeployment") } @@ -1154,13 +1154,13 @@ func platformAllowsZeroAutoscalingMinReplicas(cd *hivev1.ClusterDeployment) bool // Since 4.7, OpenStack allows zero-sized minReplicas for autoscaling if cd.Spec.Platform.OpenStack != nil { - majorMinorPatch, ok := cd.Labels[constants.VersionMajorMinorPatchLabel] + version, ok := cd.Labels[constants.VersionLabel] if !ok { // can't determine whether to allow zero minReplicas return false } - currentVersion, err := semver.Make(majorMinorPatch) + currentVersion, err := semver.Make(version) if err != nil { // assume we can't set minReplicas to zero return false diff --git a/pkg/controller/machinepool/machinepool_controller_test.go b/pkg/controller/machinepool/machinepool_controller_test.go index 942b309cf18..d7a79bdb5bf 100644 --- a/pkg/controller/machinepool/machinepool_controller_test.go +++ b/pkg/controller/machinepool/machinepool_controller_test.go @@ -1439,7 +1439,7 @@ func testClusterDeployment() *hivev1.ClusterDeployment { Finalizers: []string{hivev1.FinalizerDeprovision}, UID: types.UID("1234"), Labels: map[string]string{ - constants.VersionMajorMinorPatchLabel: "4.4.0", + constants.VersionLabel: "4.4.0", }, }, Spec: hivev1.ClusterDeploymentSpec{ @@ -1480,6 +1480,6 @@ func withClusterVersion(cd *hivev1.ClusterDeployment, version string) *hivev1.Cl if cd.Labels == nil { cd.Labels = make(map[string]string, 1) } - cd.Labels[constants.VersionMajorMinorPatchLabel] = version + cd.Labels[constants.VersionLabel] = version return cd } diff --git a/pkg/controller/metrics/metrics.go b/pkg/controller/metrics/metrics.go index 452be2c86a5..6c69670802f 100644 --- a/pkg/controller/metrics/metrics.go +++ b/pkg/controller/metrics/metrics.go @@ -769,7 +769,7 @@ func logHistogramDurationMetric(metric *prometheus.HistogramVec, cd *hivev1.Clus cd.Namespace, cd.Name, cd.Labels[hivev1.HiveClusterPlatformLabel], - cd.Labels[constants.VersionMajorMinorPatchLabel], + cd.Labels[constants.VersionLabel], poolNS).Observe(time) } diff --git a/pkg/test/clusterdeployment/clusterdeployment.go b/pkg/test/clusterdeployment/clusterdeployment.go index 247fa2235ce..b2cef6b5d9f 100644 --- a/pkg/test/clusterdeployment/clusterdeployment.go +++ b/pkg/test/clusterdeployment/clusterdeployment.go @@ -183,7 +183,7 @@ func InstallRestarts(restarts int) Option { } func WithClusterVersion(version string) Option { - return Generic(generic.WithLabel(constants.VersionMajorMinorPatchLabel, version)) + return Generic(generic.WithLabel(constants.VersionLabel, version)) } func WithPowerState(powerState hivev1.ClusterPowerState) Option { diff --git a/vendor/github.com/openshift/hive/apis/hive/v1/clusterdeployment_types.go b/vendor/github.com/openshift/hive/apis/hive/v1/clusterdeployment_types.go index ffae7c21197..214ace3fca5 100644 --- a/vendor/github.com/openshift/hive/apis/hive/v1/clusterdeployment_types.go +++ b/vendor/github.com/openshift/hive/apis/hive/v1/clusterdeployment_types.go @@ -592,7 +592,7 @@ const InitializedConditionReason = "Initialized" // +kubebuilder:printcolumn:name="InfraID",type="string",JSONPath=".spec.clusterMetadata.infraID" // +kubebuilder:printcolumn:name="Platform",type="string",JSONPath=".metadata.labels.hive\\.openshift\\.io/cluster-platform" // +kubebuilder:printcolumn:name="Region",type="string",JSONPath=".metadata.labels.hive\\.openshift\\.io/cluster-region" -// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".metadata.labels.hive\\.openshift\\.io/version-major-minor-patch" +// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".metadata.labels.hive\\.openshift\\.io/version" // +kubebuilder:printcolumn:name="ClusterType",type="string",JSONPath=".metadata.labels.hive\\.openshift\\.io/cluster-type" // +kubebuilder:printcolumn:name="ProvisionStatus",type="string",JSONPath=".status.conditions[?(@.type=='Provisioned')].reason" // +kubebuilder:printcolumn:name="PowerState",type="string",JSONPath=".status.powerState"