operator-framework / ansible-operator-plugins

Experimental extraction/refactoring of the Operator SDK's ansible operator plugin
Apache License 2.0
9 stars 23 forks source link

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

Open mwohlmutherebc opened 4 months ago

mwohlmutherebc commented 4 months ago

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.

openshift-ci[bot] commented 4 months ago

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

In response to [this](https://github.com/operator-framework/ansible-operator-plugins/issues/84): >## 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":": 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](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
mwohlmutherebc commented 3 months ago

@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.