英文:
K8s operator listen to specific config map
问题
我有一个运算符,用于对一些对象的更改进行调和,现在我想在特定的configmap
更改时添加调和的能力(我的运算符不负责这个CM,只需要监听它并读取更改...)根据文档,我认为我需要使用Owns(&corev1.Configmap{})
,但不确定如何做以及如何提供要监视的特定configmap名称。
在namespace=bar
中,我应该如何引用特定的configmap名称name: foo
?
英文:
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
答案1
得分: 3
我还没有使用过这个特定的操作符框架,但是这些概念我很熟悉。创建一个像这样的谓词函数,并在创建控制器时使用它,通过将其传递给SDK的WithEventFilter
函数:
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
},
}
}
希望对你有帮助!
英文:
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
},
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论