简体   繁体   中英

K8s operator listen to specific config map

I've an operator which run a reconcile for some object changes, now I want to add ability to reconcile when specific configmap is changing, (my operator doesn't responsible on this CM just needs to listen to it and read on changes...) from the docs I think I need to use the Owns(&corev1.Configmap{}) but not sure how to do it and provide specific configmap name to watch,

How should I refer to specific configmap name: foo in namespace=bar

https://sdk.operatorframework.io/docs/building-operators/golang/references/event-filtering/#using-predicates

I haven't used this specific operator framework, but the concepts are familiar. Create a predicate function like this and use it when you are creating a controller by passing it into the SDK's WithEventFilter function:

func specificConfigMap(name, namespace string) predicate.Predicate {
    return predicate.Funcs{
        UpdateFunc: func(e event.UpdateEvent) bool {
            configmap := e.NewObject.(*corev1.ConfigMap)
            if configmap.Name == name && configmap.Namespace == namespace {
                return true
            }
            return false
        },
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM