You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "vortegatorres (via GitHub)" <gi...@apache.org> on 2023/09/30 14:45:22 UTC
[GitHub] [apisix-ingress-controller] vortegatorres commented on a diff in pull request #1994: Feature: namespace_selector support for having multiple values for the same label
vortegatorres commented on code in PR #1994:
URL: https://github.com/apache/apisix-ingress-controller/pull/1994#discussion_r1341970199
##########
pkg/providers/k8s/namespace/namespace_provider.go:
##########
@@ -103,7 +103,21 @@ func (c *watchingProvider) Init(ctx context.Context) error {
}
func (c *watchingProvider) initWatchingNamespacesByLabels(ctx context.Context) error {
- labelSelector := metav1.LabelSelector{MatchLabels: c.watchingLabels}
+ valuesByKey := make(map[string][]string)
+ for key, value := range c.watchingLabels {
+ valuesByKey[key] = append(valuesByKey[key], value)
+ }
+ var matchExpressions []metav1.LabelSelectorRequirement
+ for key, values := range valuesByKey {
+ requirement := metav1.LabelSelectorRequirement{
+ Key: key,
+ Operator: metav1.LabelSelectorOpIn,
+ Values: values,
+ }
+ matchExpressions = append(matchExpressions, requirement)
+ }
+
+ labelSelector := metav1.LabelSelector{MatchExpressions: matchExpressions}
Review Comment:
I opted for `MatchLabels` over `MatchExpressions` in the LabelSelector criteria. This choice enables us to select multiple label values and facilitates support for a `namespace_selector` with multiple values for the same label: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#resources-that-support-set-based-requirements
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org