MOHIT KUMAR AGRAWAL
MOHIT KUMAR AGRAWAL

Reputation: 1

Invalid label selector for kubernetes.core.k8s_info ansible inside operator

I am trying to filter out the the deployments which are not of my current version using ansible.

- name: Filter and get old deployment
  kubernetes.core.k8s_info:
    api_version: v1
    kind: Deployment
    namespace: "my_namespace"
    label_selectors:
      - curr_version notin (1.1.0)
  register: old_deployments

Expected the output to give the list of deployments not having curr_version equal to 1.1.0

But I am getting this error

{"level":"error","ts":1665557104.5018141,"logger":"proxy","msg":"Unable to convert label selectors for the client","error":"invalid selector: [curr_version notin (1.1.0)]","stacktrace":"net/http.serverHandler.ServeHTTP\n\t/usr/lib/golang/src/net/http/server.go:2879\nnet/http.(*conn).serve\n\t/usr/lib/golang/src/net/http/server.go:1930"}

I referenced the pattern matching from here - https://github.com/abikouo/kubernetes.core/blob/08596fd05ba7190a04e7112270a38a0ce32095dd/plugins/module_utils/selector.py#L39

According to the pattern the above selector looks fine.

Even I tried to change the selector line as this (for testing purpose) -

      - curr_version notin ("1.1.0")

But getting error as below.

{"level":"error","ts":1665555657.2939646,"logger":"requestfactory","msg":"Could not parse request","error":"unable to parse requirement: values[0][curr_version]: Invalid value: \"\\\"1.1.0\\\"\": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')","stacktrace":"net/http.serverHandler.ServeHTTP\n\t/usr/lib/golang/src/net/http/server.go:2879\nnet/http.(*conn).serve\n\t/usr/lib/golang/src/net/http/server.go:1930"}
{"level":"error","ts":1665555657.2940943,"logger":"proxy","msg":"Unable to convert label selectors for the client","error":"invalid selector: [curr_version notin (\"1.1.0\")]","stacktrace":"net/http.serverHandler.ServeHTTP\n\t/usr/lib/golang/src/net/http/server.go:2879\nnet/http.(*conn).serve\n\t/usr/lib/golang/src/net/http/server.go:1930"}

I am not sure where am I wrong. I tried to find out the possible workaround but was not able to find it anywhere.

Although I am guessing second issue is just because the label selector is a string and the pattern doesn't allows to have quotes in the string. Which is understood.

Other information which might be useful

kubernetes.core.k8s version - 2.2.3
operator-sdk version - 1.23.0
ansible version - 2.9.27
python - 3.6.8

EDIT

I am using ose-ansible-operator image v4.10 to build an operator. I am unable to see the same error in local. But I am able to when going to operator.

Upvotes: 0

Views: 816

Answers (0)

Related Questions