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

Selecting Kubernetes resources with "do not match" label selector causes an error #84

Open
mwohlmutherebc opened this issue Jul 11, 2024 · 2 comments

Comments

@mwohlmutherebc
Copy link

mwohlmutherebc commented Jul 11, 2024

Bug Report

What did you do?

Trying to get specific resources from an OpenShift cluster using an Ansible Operator with the following ansible code:

- name: Fetch Objects
  kubernetes.core.k8s_info:
    api_version: v1
    kind: VirtualServer
    namespace: mynamespace
    label_selectors:
      - "app = {{ application }}"
      - "my-value != {{ value_variable }}"
  register: selection_result

What did you expect to see?

The expectation is to get all objects in "mynamespace" with kind "VirtualServer" which do match the label app=application AND do NOT MATCH the label my-value=value_variable.

What did you see instead? Under which circumstances?

An error occured in the operator, which can be seen in the logs:

{"level":"error","ts":"2024-07-03T15:21:55Z","logger":"proxy","msg":"Unable to convert label selectors for the client","error":"<nil>: Invalid value: \"my-value !\": name part 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]')","stacktrace":"github.com/operator-framework/ansible-operator-plugins/internal/ansible/proxy.
(*cacheResponseHandler).getListFromCache\n\tansible-operator-plugins/internal/ansible/proxy/cache_response.go:259\ngithub.com/operator-framework/ansible-operator-plugins/internal/ansible/proxy.(*cacheResponseHandler).ServeHTTP\n\tansible-operator-plugins/internal/ansible/proxy/cache_response.go:112
\nnet/http.serverHandler.ServeHTTP\n\t/opt/hostedtoolcache/go/1.20.14/x64/src/net/http/server.go:2936\nnet/http.(*conn).serve\n\t/opt/hostedtoolcache/go/1.20.14/x64/src/net/http/server.go:1995"}

Environment

Operator type:

ansible

Kubernetes cluster type:

OpenShift

$ operator-sdk version

1.34.1

$ kubectl version

1.23.0

Additional context

The same ansible code can be executed without any error on a linux machine targeting the same cluster to manage the cluster resources on.

Further tries to mitigate the issue (but did not solve it):

Changing quotes to single / double quotes
Not quoting the label name but only the value doesn't solve the issue.
Conclusion

Since no ansible syntax changes seem to change the behavior and the stacktrace in the error message states that the error happens in some ansible-operator-plugin library it is likely that the error has to do with the operator framework but not the ansible code.

Copy link

openshift-ci bot commented Jul 11, 2024

@mwohlmutherebc: The label(s) language/ansible cannot be applied, because the repository doesn't have them.

In response to this:

Bug Report

What did you do?

Trying to get specific resources from an OpenShift cluster using an Ansible Operator with the following ansible code:

- name: Fetch Objects
 kubernetes.core.k8s_info:
   api_version: v1
   kind: VirtualServer
   namespace: mynamespace
   label_selectors:
     - "app = {{ application }}"
     - "my-value != {{ value_variable }}"
 register: selection_result

What did you expect to see?

The expectation is to get all objects in "mynamespace" with kind "VirtualServer" which do match the label app=application AND do NOT MATCH the label my-value=value_variable.

What did you see instead? Under which circumstances?

An error occured in the operator, which can be seen in the logs:

{"level":"error","ts":"2024-07-03T15:21:55Z","logger":"proxy","msg":"Unable to convert label selectors for the client","error":"<nil>: Invalid value: \"my-value !\": name part 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]')","stacktrace":"github.com/operator-framework/ansible-operator-plugins/internal/ansible/proxy.
(*cacheResponseHandler).getListFromCache\n\tansible-operator-plugins/internal/ansible/proxy/cache_response.go:259\ngithub.com/operator-framework/ansible-operator-plugins/internal/ansible/proxy.(*cacheResponseHandler).ServeHTTP\n\tansible-operator-plugins/internal/ansible/proxy/cache_response.go:112
\nnet/http.serverHandler.ServeHTTP\n\t/opt/hostedtoolcache/go/1.20.14/x64/src/net/http/server.go:2936\nnet/http.(*conn).serve\n\t/opt/hostedtoolcache/go/1.20.14/x64/src/net/http/server.go:1995"}

Environment

Operator type:

/language ansible

Kubernetes cluster type:

OpenShift

$ operator-sdk version

1.34.1

$ kubectl version

1.23.0

Additional context

The same ansible code can be executed without any error on a linux machine targeting the same cluster to manage the cluster resources on.

Further tries to mitigate the issue (but did not solve it):

Changing quotes to single / double quotes
Not quoting the label name but only the value doesn't solve the issue.
Conclusion

Since no ansible syntax changes seem to change the behavior and the stacktrace in the error message states that the error happens in some ansible-operator-plugin library it is likely that the error has to do with the operator framework but not the ansible code.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@mwohlmutherebc
Copy link
Author

@mwohlmutherebc: The label(s) language/ansible cannot be applied, because the repository doesn't have them.

The label is suggested in the template for the bug report - now changed it to a "normal" string - because it's indeed an ansible operator.

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

No branches or pull requests

1 participant