Search code examples
kubernetesfabric8

Watch a secret using annotation


I want to watch secrets for a specific service account. How can I do it using fabric8 k8s-client ? I can create watch using a field ( like below ) but how can I do for annotation as service account detail is available as annotation .

kubernetesClient.inAnyNamespace().secrets().withField("type", "kubernetes.io/service-account-token")


kind: Secret
metadata:
  annotations:
    kubernetes.io/service-account.name: test-admin
    kubernetes.io/service-account.uid: e65430b6-819b-11ea-b7cd-025000000001
  creationTimestamp: "2020-04-18T17:41:57Z"
  name: test-admin-token-6jfqq
  namespace: demo
  resourceVersion: "4298298"
  selfLink: /api/v1/namespaces/demo/secrets/test-admin-token-6jfqq
  uid: e655da50-819b-11ea-b7cd-025000000001
type: kubernetes.io/service-account-token

Solution

  • You cannot, annotations are not indexed. Only labels are. You’ll have to do that filtering client side.