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

Ansible Operator proxy/cache not supporting set-based label selectors #99

Open
zeusng-fast opened this issue Oct 2, 2024 · 1 comment
Labels
language/ansible Issue is related to an Ansible operator project

Comments

@zeusng-fast
Copy link

zeusng-fast commented Oct 2, 2024

Bug Report

What did you do?

I have an Ansible Operator that needs to query resources with set-based label selector but seems the proxy/caching is not supporting this.

# cat play.yaml
---
- hosts: localhost
  gather_facts: no
  collections:
    - kubernetes.core
    - operator_sdk.util
  tasks:
  - name: "Get pod name with labels role: king or role: leader"
    kubernetes.core.k8s_info:
      kind: Pod
      api_version: v1
      namespace: my-namespace
      label_selectors:
        - "role in (king,leader)"
    register: k8s_get_pod

  - name: "pod name"
    debug:
      msg: "{{ k8s_get_pod.resources[0].metadata,name }}"

Run the above playbook directly from ansible-playbook

# ansible-playbook play.yaml
PLAY [localhost] *******************************************************************************************************

TASK [Get pod name with labels role: king or role: leader] *************************************************************
ok: [localhost]

TASK [pod name] ********************************************************************************************************
ok: [localhost] => {
    "msg": "app-0"
}

PLAY RECAP *************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

When the same playbook is executed inside ansible-operator, I get the following error.

{"level":"error","ts":"2024-10-02T05:35:11Z","logger":"proxy","msg":"Unable to convert label selectors for the client","error":"invalid selector: [role in (king]","stacktrace":"github.com/operator-framework/operator-sdk/internal/ansible/proxy.(*cacheResponseHandler).getListFromCache
\t/workspace/internal/ansible/proxy/cache_response.go:257
github.com/operator-framework/operator-sdk/internal/ansible/proxy.(*cacheResponseHandler).ServeHTTP
\t/workspace/internal/ansible/proxy/cache_response.go:110
net/http.serverHandler.ServeHTTP
\t/usr/lib/golang/src/net/http/server.go:2938
net/http.(*conn).serve
\t/usr/lib/golang/src/net/http/server.go:2009"}

This happens to ansible shell as well.

  tasks:
  - name: "Get pod name with labels role: king or role: leader"
    shell: kubectl -n my-namespace get pod -l "role in (king,leader)"

What did you expect to see?

Expect ansible-operator proxy to support set-base label selectors. Or a way to disable proxy/caching.

What did you see instead? Under which circumstances?

{"level":"error","ts":"2024-10-02T05:35:11Z","logger":"proxy","msg":"Unable to convert label selectors for the client","error":"invalid selector: [role in (king]","stacktrace":"github.com/operator-framework/operator-sdk/internal/ansible/proxy.(*cacheResponseHandler).getListFromCache
\t/workspace/internal/ansible/proxy/cache_response.go:257
github.com/operator-framework/operator-sdk/internal/ansible/proxy.(*cacheResponseHandler).ServeHTTP
\t/workspace/internal/ansible/proxy/cache_response.go:110
net/http.serverHandler.ServeHTTP
\t/usr/lib/golang/src/net/http/server.go:2938
net/http.(*conn).serve
\t/usr/lib/golang/src/net/http/server.go:2009"}

Environment

Operator type:

/language ansible

Kubernetes cluster type:

OpenShift 4.14

$ operator-sdk version

operator-sdk version: "v1.31.0", commit: "e67da35ef4fff3e471a208904b2a142b27ae32b1", kubernetes version: "1.26.0", go version: "go1.19.11", GOOS: "linux", GOARCH: "amd64"

$ kubectl version

Client Version: v1.28.11
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.27.16+03a907c

$ ansible-operator version

ansible-operator version: "v1.31.0-dirty", commit: "e67da35ef4fff3e471a208904b2a142b27ae32b1", kubernetes version: "v1.26.0", go version: "go1.21.9 (Red Hat 1.21.9-2.el9_4)", GOOS: "linux", GOARCH: "amd64"

Possible Solution

Additional context

@acornett21 acornett21 transferred this issue from operator-framework/operator-sdk Oct 2, 2024
Copy link

openshift-ci bot commented Oct 2, 2024

@zeusng-fast: 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?

I have an Ansible Operator that needs to query resources with set-based label selector but seems the proxy/caching is not supporting this.

# cat play.yaml
---
- hosts: localhost
 gather_facts: no
 collections:
   - kubernetes.core
   - operator_sdk.util
 tasks:
 - name: "Get pod name with labels role: king or role: leader"
   kubernetes.core.k8s_info:
     kind: Pod
     api_version: v1
     namespace: my-namespace
     label_selectors:
       - "role in (king,leader)"
   register: k8s_get_pod

 - name: "pod name"
   debug:
     msg: "{{ k8s_get_pod.resources[0].metadata,name }}"

Run the above playbook directly from ansible-playbook

# ansible-playbook play.yaml
PLAY [localhost] *******************************************************************************************************

TASK [Get pod name with labels role: king or role: leader] *************************************************************
ok: [localhost]

TASK [pod name] ********************************************************************************************************
ok: [localhost] => {
   "msg": "app-0"
}

PLAY RECAP *************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

When the same playbook is executed inside ansible-operator, I get the following error.

{"level":"error","ts":"2024-10-02T05:35:11Z","logger":"proxy","msg":"Unable to convert label selectors for the client","error":"invalid selector: [role in (king]","stacktrace":"github.com/operator-framework/operator-sdk/internal/ansible/proxy.(*cacheResponseHandler).getListFromCache
\t/workspace/internal/ansible/proxy/cache_response.go:257
github.com/operator-framework/operator-sdk/internal/ansible/proxy.(*cacheResponseHandler).ServeHTTP
\t/workspace/internal/ansible/proxy/cache_response.go:110
net/http.serverHandler.ServeHTTP
\t/usr/lib/golang/src/net/http/server.go:2938
net/http.(*conn).serve
\t/usr/lib/golang/src/net/http/server.go:2009"}

This happens to ansible shell as well.

 tasks:
 - name: "Get pod name with labels role: king or role: leader"
   shell: kubectl -n my-namespace get pod -l "role in (king,leader)"

What did you expect to see?

Expect ansible-operator proxy to support set-base label selectors. Or a way to disable proxy/caching.

What did you see instead? Under which circumstances?

{"level":"error","ts":"2024-10-02T05:35:11Z","logger":"proxy","msg":"Unable to convert label selectors for the client","error":"invalid selector: [role in (king]","stacktrace":"github.com/operator-framework/operator-sdk/internal/ansible/proxy.(*cacheResponseHandler).getListFromCache
\t/workspace/internal/ansible/proxy/cache_response.go:257
github.com/operator-framework/operator-sdk/internal/ansible/proxy.(*cacheResponseHandler).ServeHTTP
\t/workspace/internal/ansible/proxy/cache_response.go:110
net/http.serverHandler.ServeHTTP
\t/usr/lib/golang/src/net/http/server.go:2938
net/http.(*conn).serve
\t/usr/lib/golang/src/net/http/server.go:2009"}

Environment

Operator type:

/language ansible

Kubernetes cluster type:

OpenShift 4.14

$ operator-sdk version

operator-sdk version: "v1.31.0", commit: "e67da35ef4fff3e471a208904b2a142b27ae32b1", kubernetes version: "1.26.0", go version: "go1.19.11", GOOS: "linux", GOARCH: "amd64"

$ kubectl version

Client Version: v1.28.11
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.27.16+03a907c

$ ansible-operator version

ansible-operator version: "v1.31.0-dirty", commit: "e67da35ef4fff3e471a208904b2a142b27ae32b1", kubernetes version: "v1.26.0", go version: "go1.21.9 (Red Hat 1.21.9-2.el9_4)", GOOS: "linux", GOARCH: "amd64"

Possible Solution

Additional context

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.

@acornett21 acornett21 added the language/ansible Issue is related to an Ansible operator project label Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language/ansible Issue is related to an Ansible operator project
Projects
None yet
Development

No branches or pull requests

2 participants