Skip to content

[topology] Add optional default for topologyConstraint LabelSelector#597

Merged
fmount merged 3 commits intoopenstack-k8s-operators:mainfrom
olliewalsh:topo_default
Feb 5, 2025
Merged

[topology] Add optional default for topologyConstraint LabelSelector#597
fmount merged 3 commits intoopenstack-k8s-operators:mainfrom
olliewalsh:topo_default

Conversation

@olliewalsh
Copy link
Contributor

Replicate the defaulting behaviour used in cluster-level default constraints https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/#cluster-level-default-constraints

@olliewalsh olliewalsh requested a review from fmount February 4, 2025 21:30
@fmount
Copy link
Contributor

fmount commented Feb 5, 2025

@olliewalsh tested and works as expected (no regressions in the previous code that we tested). If you can take a look at openstack-k8s-operators/glance-operator#670 (comment) I was wondering if similarly to what we did for DistributePods [1], we can make the following:

// GetGlanceAPILabelSelector - Returns a metav1.LabelSelector for a given GlanceAPI
func GetGlanceAPILabelSelector(instance *glancev1.GlanceAPI) metav1.LabelSelector {
	return metav1.LabelSelector{
		MatchExpressions: []metav1.LabelSelectorRequirement{
			{
				Key:      glance.GlanceAPIName,
				Operator: metav1.LabelSelectorOpIn,
				Values: []string{
					fmt.Sprintf("%s-%s-%s", glance.ServiceName, instance.APIName(), instance.Spec.APIType),
				},
			},
		},
	}
}

a generic one, that can be called from this module.
This way we can avoid duplicating it across the operators, and we can provide

common.AppSelector, []string{<service>.ServiceName`}

as input for that function.
You could then call it with something like topology.GetDefaultTopologySelector(common.AppSelector, []string{<service>.ServiceName}) and pass it down to topology.EnsureTopologyRef(.

Do you want to push an update for this before we land it?

[1] https://github.com/openstack-k8s-operators/glance-operator/blob/main/pkg/glanceapi/statefulset.go#L296
[2] olliewalsh/glance-operator@8386bff

@olliewalsh olliewalsh requested a review from stuggi February 5, 2025 13:40
Copy link
Contributor

@fmount fmount left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@fmount fmount merged commit 43504d7 into openstack-k8s-operators:main Feb 5, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants