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"}
@zeusng-fast: 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/99):
>## 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](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.
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.
When the same playbook is executed inside ansible-operator, I get the following error.
This happens to ansible shell as well.
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?
Environment
Operator type:
/language ansible
Kubernetes cluster type:
OpenShift 4.14
$ operator-sdk version
$ kubectl version
$ ansible-operator version
Possible Solution
Additional context