Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go 告密者中的kubernetes过滤对象_Go_Filter_Kubernetes - Fatal编程技术网

Go 告密者中的kubernetes过滤对象

Go 告密者中的kubernetes过滤对象,go,filter,kubernetes,Go,Filter,Kubernetes,我正在为kubernetes编写自定义控制器。 我正在创建共享的告密者 cache.NewSharedIndexInformer( &cache.ListWatch{ ListFunc: func(options meta_v1.ListOptions) (k8sruntime.Object, error) { return client.CoreV1().ConfigMaps(nameSp

我正在为kubernetes编写自定义控制器。 我正在创建共享的告密者

cache.NewSharedIndexInformer(
            &cache.ListWatch{
                ListFunc: func(options meta_v1.ListOptions) (k8sruntime.Object, error) {

                    return client.CoreV1().ConfigMaps(nameSpace).List(options)
                },
                WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {

                    return client.CoreV1().ConfigMaps(nameSpace).Watch(options)
                },
            },
            &api_v1.ConfigMap{},
            0, //Skip resyncr
            cache.Indexers{},
        )
我可以选择在回调函数中添加过滤函数,以进一步减少我处理的对象数量。 诸如此类

options.FieldSelector := fields.OneTermEqualSelector("metadata.name", nodeName).String()
我想用正则表达式过滤掉对象。或者至少用某种标签。不幸的是,文档没有帮助。除了代码本身的测试之外,找不到任何内容。 如何在过滤机制上应用正则表达式?
关于这个问题,我从哪里可以得到一些示例?

不可能通过正则表达式过滤对象。 可以通过标签对对象进行文件管理

这是将按标签过滤的代码

labelSelector := labels.Set(map[string]string{"mylabel": "ourdaomain1"}).AsSelector()

informer := cache.NewSharedIndexInformer(
    &cache.ListWatch{
        ListFunc: func(options meta_v1.ListOptions) (k8sruntime.Object, error) {

            options.LabelSelector = labelSelector.String()
            return client.CoreV1().ConfigMaps(nameSpace).List(options)
        },
        WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {

            options.LabelSelector = labelSelector.String()
            return client.CoreV1().ConfigMaps(nameSpace).Watch(options)
        },
    },
    &api_v1.ConfigMap{},
    0, //Skip resyncr
    cache.Indexers{},
)
另一件需要记住的重要事情是如何向k8s添加新对象 我在做类似的事情

kubectl --namespace==ourdomain1 create configmap config4 -f ./config1.yaml
这不好。它覆盖配置映射中的所有字段,并将整个文件内容放入新对象的数据中。 正确的方法是

kubectl create  -f ./config1.yam