Controller coordinates object changes

WBOY
Release: 2024-02-10 14:15:09
forward
1117 people have browsed it

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"}),
            },
        },
    }),
Copy after login

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=
Copy after login

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")
        },
    })
Copy after login

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

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!