Skip to content
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

Introduce GetKeyValuesStretchCluster for Accurate Label Matching in StretchCluster #2965

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions api/v1/topologymap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package v1

import (
"strings"
corev1 "k8s.io/api/core/v1"
)

// NewNodeTopologyMap returns an initialized NodeTopologyMap
Expand Down Expand Up @@ -61,18 +61,31 @@ func (m *NodeTopologyMap) Add(topologyKey string, value string) {
m.Labels[topologyKey] = append(m.Labels[topologyKey], value)
}

// GetKeyValues returns a node label matching the topologyKey and all values
// for that label across all storage nodes
// GetKeyValues returns a node label matching the supported topologyKey and all values
// for that label across all storage nodes.
func (m *NodeTopologyMap) GetKeyValues(topologyKey string) (string, []string) {
values := []string{}

// Supported failure domain labels
supportedLabels := map[string]string{
"rack": "topology.rook.io/rack",
"hostname": corev1.LabelHostname,
"zone": corev1.LabelZoneFailureDomainStable,
}

// Get the specific label based on the topologyKey
expectedLabel, exists := supportedLabels[topologyKey]
if !exists {
return "", values // Return empty if the topologyKey is unsupported
}

// Match the expected label and fetch the values
for label, labelValues := range m.Labels {
if strings.Contains(label, topologyKey) {
topologyKey = label
if label == expectedLabel {
values = labelValues
break
return label, values
}
}

return topologyKey, values
return "", values // Return empty if no match is found
}
10 changes: 6 additions & 4 deletions controllers/storagecluster/placement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func TestGetPlacement(t *testing.T) {
},
},
},
TopologyKey: zoneTopologyLabel,
TopologyKey: corev1.LabelZoneFailureDomainStable,
},
},
},
Expand All @@ -402,15 +402,15 @@ func TestGetPlacement(t *testing.T) {
},
},
},
TopologyKey: zoneTopologyLabel,
TopologyKey: corev1.LabelZoneFailureDomainStable,
},
},
},
},
},
topologyMap: &ocsv1.NodeTopologyMap{
Labels: map[string]ocsv1.TopologyLabelValues{
zoneTopologyLabel: []string{
corev1.LabelZoneFailureDomainStable: []string{
"zone1",
"zone2",
"zone3",
Expand Down Expand Up @@ -497,7 +497,9 @@ func TestGetPlacement(t *testing.T) {
sc.Spec.Placement = c.placements
sc.Spec.LabelSelector = c.labelSelector
sc.Status.NodeTopologies = c.topologyMap

if c.topologyMap != nil {
setFailureDomain(sc)
}
expectedPlacement := c.expectedPlacements["all"]
actualPlacement = getPlacement(sc, "all")
assert.Equal(t, expectedPlacement, actualPlacement, c.label)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading