From 2bf7271f1b2eb3240182ca8b134f49a21aafa821 Mon Sep 17 00:00:00 2001 From: Oded Viner Date: Sun, 12 Jan 2025 14:51:21 +0200 Subject: [PATCH] Adjust Node Label Conditions Based on Full Label Name on strechcluster Signed-off-by: Oded Viner --- api/v1/topologymap.go | 19 +++++++++++++++++++ controllers/storagecluster/cephcluster.go | 2 +- .../ocs-operator/api/v4/v1/topologymap.go | 19 +++++++++++++++++++ .../ocs-operator/api/v4/v1/topologymap.go | 19 +++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/api/v1/topologymap.go b/api/v1/topologymap.go index 63c008d2f5..a6543f08d6 100644 --- a/api/v1/topologymap.go +++ b/api/v1/topologymap.go @@ -17,9 +17,12 @@ limitations under the License. package v1 import ( + corev1 "k8s.io/api/core/v1" "strings" ) +const labelZoneFailureDomainWithoutBeta = "failure-domain.kubernetes.io/zone" + // NewNodeTopologyMap returns an initialized NodeTopologyMap func NewNodeTopologyMap() *NodeTopologyMap { return &NodeTopologyMap{ @@ -76,3 +79,19 @@ func (m *NodeTopologyMap) GetKeyValues(topologyKey string) (string, []string) { return topologyKey, values } + +// GetKeyValues returns a node label matching the topologyKey and all values for StrechCluster +// for that label across all storage nodes +func (m *NodeTopologyMap) GetKeyValuesStrechCluster() (string, []string) { + values := []string{} + topologyKey := "" + for label, labelValues := range m.Labels { + if label == corev1.LabelZoneFailureDomainStable || label == labelZoneFailureDomainWithoutBeta { + topologyKey = label + values = labelValues + break + } + } + + return topologyKey, values +} diff --git a/controllers/storagecluster/cephcluster.go b/controllers/storagecluster/cephcluster.go index 1cfaad2717..414bc7c606 100644 --- a/controllers/storagecluster/cephcluster.go +++ b/controllers/storagecluster/cephcluster.go @@ -1068,7 +1068,7 @@ func allowUnsupportedCephVersion() bool { func generateStretchClusterSpec(sc *ocsv1.StorageCluster) *rookCephv1.StretchClusterSpec { var zones []string stretchClusterSpec := rookCephv1.StretchClusterSpec{} - stretchClusterSpec.FailureDomainLabel, zones = sc.Status.NodeTopologies.GetKeyValues(getFailureDomain(sc)) + stretchClusterSpec.FailureDomainLabel, zones = sc.Status.NodeTopologies.GetKeyValuesStrechCluster() for _, zone := range zones { if zone == sc.Spec.NodeTopologies.ArbiterLocation { diff --git a/metrics/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/topologymap.go b/metrics/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/topologymap.go index 63c008d2f5..a6543f08d6 100644 --- a/metrics/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/topologymap.go +++ b/metrics/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/topologymap.go @@ -17,9 +17,12 @@ limitations under the License. package v1 import ( + corev1 "k8s.io/api/core/v1" "strings" ) +const labelZoneFailureDomainWithoutBeta = "failure-domain.kubernetes.io/zone" + // NewNodeTopologyMap returns an initialized NodeTopologyMap func NewNodeTopologyMap() *NodeTopologyMap { return &NodeTopologyMap{ @@ -76,3 +79,19 @@ func (m *NodeTopologyMap) GetKeyValues(topologyKey string) (string, []string) { return topologyKey, values } + +// GetKeyValues returns a node label matching the topologyKey and all values for StrechCluster +// for that label across all storage nodes +func (m *NodeTopologyMap) GetKeyValuesStrechCluster() (string, []string) { + values := []string{} + topologyKey := "" + for label, labelValues := range m.Labels { + if label == corev1.LabelZoneFailureDomainStable || label == labelZoneFailureDomainWithoutBeta { + topologyKey = label + values = labelValues + break + } + } + + return topologyKey, values +} diff --git a/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/topologymap.go b/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/topologymap.go index 63c008d2f5..a6543f08d6 100644 --- a/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/topologymap.go +++ b/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/topologymap.go @@ -17,9 +17,12 @@ limitations under the License. package v1 import ( + corev1 "k8s.io/api/core/v1" "strings" ) +const labelZoneFailureDomainWithoutBeta = "failure-domain.kubernetes.io/zone" + // NewNodeTopologyMap returns an initialized NodeTopologyMap func NewNodeTopologyMap() *NodeTopologyMap { return &NodeTopologyMap{ @@ -76,3 +79,19 @@ func (m *NodeTopologyMap) GetKeyValues(topologyKey string) (string, []string) { return topologyKey, values } + +// GetKeyValues returns a node label matching the topologyKey and all values for StrechCluster +// for that label across all storage nodes +func (m *NodeTopologyMap) GetKeyValuesStrechCluster() (string, []string) { + values := []string{} + topologyKey := "" + for label, labelValues := range m.Labels { + if label == corev1.LabelZoneFailureDomainStable || label == labelZoneFailureDomainWithoutBeta { + topologyKey = label + values = labelValues + break + } + } + + return topologyKey, values +}