Skip to content

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

Open
@mwohlmutherebc

Description

@mwohlmutherebc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions