tokers commented on a change in pull request #715: URL: https://github.com/apache/apisix-ingress-controller/pull/715#discussion_r737030050
########## File path: pkg/config/config.go ########## @@ -56,6 +58,8 @@ const ( ApisixRouteV2beta2 = "apisix.apache.org/v2beta2" _minimalResyncInterval = 30 * time.Second + + LabelNameInvalidMsg = "a qualified name must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyName', or 'my.name', or '123-abc', regex used for validation is '([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]') with an optional DNS subdomain prefix and '/' (e.g. 'example.com/MyName')" Review comment: Where is this variable used? ########## File path: pkg/config/config.go ########## @@ -191,3 +200,54 @@ func purifyAppNamespaces(namespaces []string) []string { } return ultimate } + +func (cfg *Config) verifyNamespaceSelector() (bool, error) { + labels := cfg.Kubernetes.NamespaceSelector + // default is [""] + if len(labels) == 1 && labels[0] == "" { + cfg.Kubernetes.NamespaceSelector = []string{} + } + + for _, s := range cfg.Kubernetes.NamespaceSelector { + parts := strings.Split(s, "=") + if len(parts) != 2 { + return false, fmt.Errorf("Illegal namespaceSelector: %s, should be key-value pairs divided by = ", s) + } else { + if err := cfg.validateLabelKey(parts[0]); err != nil { + return false, err + } + if err := cfg.validateLabelValue(parts[1]); err != nil { + return false, err + } + } + } + return true, nil +} + +// validateLabelKey validate the key part of label +// ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set +func (cfg *Config) validateLabelKey(key string) error { + errorMsg := validation.IsQualifiedName(key) + msg := "" Review comment: Use the `multierror` package to handle this will be more elegant. ########## File path: pkg/config/config.go ########## @@ -191,3 +200,54 @@ func purifyAppNamespaces(namespaces []string) []string { } return ultimate } + +func (cfg *Config) verifyNamespaceSelector() (bool, error) { + labels := cfg.Kubernetes.NamespaceSelector + // default is [""] + if len(labels) == 1 && labels[0] == "" { + cfg.Kubernetes.NamespaceSelector = []string{} + } + + for _, s := range cfg.Kubernetes.NamespaceSelector { + parts := strings.Split(s, "=") + if len(parts) != 2 { + return false, fmt.Errorf("Illegal namespaceSelector: %s, should be key-value pairs divided by = ", s) + } else { + if err := cfg.validateLabelKey(parts[0]); err != nil { + return false, err + } + if err := cfg.validateLabelValue(parts[1]); err != nil { + return false, err + } + } + } + return true, nil +} + +// validateLabelKey validate the key part of label +// ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set +func (cfg *Config) validateLabelKey(key string) error { + errorMsg := validation.IsQualifiedName(key) + msg := "" + for _, err := range errorMsg { + msg = msg + err + " . " + } + if msg == "" { + return nil + } + return fmt.Errorf("Illegal namespaceSelector: %s, "+msg, key) +} + +// validateLabelValue validate the value part of label +// ref: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set +func (cfg *Config) validateLabelValue(value string) error { + errorMsg := validation.IsValidLabelValue(value) + msg := "" + for _, err := range errorMsg { + msg = msg + err + " . " Review comment: Ditto. -- 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-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org