go - K8s operator 监听特定的 config map
问题描述
我有一个操作员为某些对象更改运行协调,现在我想添加在特定configmap
更改时进行协调的能力,(我的操作员对此 CM不负责,只需要听它并阅读更改... ) 从文档中我认为我需要使用Owns(&corev1.Configmap{})
但不确定如何使用并提供特定的 configmap 名称以供观看,
我应该如何参考特定name: foo
的configmapnamespace=bar
解决方案
这个具体的算子框架我没用过,但是概念很熟悉。创建一个这样的谓词函数,并在创建控制器时通过将其传递给 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
},
}
}
推荐阅读
- python - Python(熊猫)从SQL Server数据库错误查询数据框
- r - 保存脚本文件后发生错误
- angular - 如何在应用程序初始化时启动一个长时间运行的进程(API 请求)而不阻塞 Angular 应用程序的加载?
- kubernetes - kubeflow 卡在管道启动中:无法附加或安装卷:未安装的卷 = [mlpipeline-minio-artifact]
- sql - PostgreSQL 汇总特征查询
- azure-devops - 业力单元测试结果未推送到声纳
- microservices - 当一个聚合上的大多数操作时,如何将单体应用程序拆分为微服务?
- python - 如何使在子进程中运行的命令保存到对象而不是文件之类的文件中?
- c# - 使用 Entity Framework Core 的 OnModelCreating 上的空引用异常
- javascript - 如何使用 JS 设置 .env