Home  >  Article  >  Backend Development  >  Controller coordinates object changes

Controller coordinates object changes

WBOY
WBOYforward
2024-02-10 14:15:091120browse

Controller coordinates object changes

php editor Yuzai will introduce to you the relevant content of controller coordination object changes in this article. During the development process, the controller plays an important role, responsible for receiving user requests and scheduling corresponding business logic. However, sometimes we may need to change the controller's coordination object to meet specific needs. This article will explain in detail how to make changes to controller coordination objects, helping developers better understand and apply this concept. Whether you are a beginner or an experienced developer, you will gain useful knowledge and tips from this article. Let’s get started!

Question content

I'm trying to use the operator sdk to listen for secret changes The problem is that when I apply the secret using the label I defined in the operator, I don't receive the reconciliation event

I did the following things

mgr, err := ctrl.newmanager(ctrl.getconfigordie(), ctrl.options{
    scheme:                 scheme,
        …
    newcache: cache.builderwithoptions(cache.options{
        selectorsbyobject: cache.selectorsbyobject{
            &corev1.secret{}: {
                label: labels.selectorfromset(labels.set{"foo": "bar"}),
            },
        },
    }),

I run the operator and apply the following secret, but coordination is not called, any idea?

apiVersion: v1
kind: Secret
metadata:
  labels:
    foo: bar
  name: mysecret
  namespace: dev
type: Opaque
data:
  USER_NAME: YWRtaW4=
  PASSWORD: dGVzdBo=

Workaround

Looks like you are using the cache.options.selectorsbyobject field to specify the tags that should trigger the coordination event. However, this field is used to specify the tag that should be used to select the object from the cache, not the tag that should trigger the reconciliation event.

To specify the tags that should trigger the coordination event, you can use the ctrl.watch function as follows:

mgr.Watch(&source.Kind{Type: &corev1.Secret{}},
    &handler.EnqueueRequestForObject{},
    predicate.Funcs{
        UpdateFunc: func(e event.UpdateEvent) bool {
            return labels.Set(e.MetaNew.GetLabels()).Has("foo", "bar")
        },
    })

The above is the detailed content of Controller coordinates object changes. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete