<p>Im writing custom controller for kubernetes.
Im creating shared informer</p>

<pre><code>cache.NewSharedIndexInformer(
            &amp;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)
                },
            },
            &amp;api_v1.ConfigMap{},
            0, //Skip resyncr
            cache.Indexers{},
        )
</code></pre>

<p>I have option to add filtering function into call back functions to further decrease number of objects im working with.
Something like that</p>

<pre><code>options.FieldSelector := fields.OneTermEqualSelector("metadata.name", nodeName).String()
</code></pre>

<p>I would like to filter out objects by regular expression. Or by some label at least. Unfortunately documentation is not helping. Could not find anything except for tests for code itself.
Ho do i apply regular expression on filtering mechanism?
Where do i get some examples on this issue?</p>

<p>Its not possible to filter objects by regular expression.
It is possible to filer object by lable</p>

<p>This is the code that will filter by label</p>

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

informer := cache.NewSharedIndexInformer(
    &amp;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)
        },
    },
    &amp;api_v1.ConfigMap{},
    0, //Skip resyncr
    cache.Indexers{},
)
</code></pre>

<p>Another thing that is important to remember is how do you add new objects to k8s
I was doing something like </p>

<pre><code>kubectl --namespace==ourdomain1 create configmap config4 -f ./config1.yaml
</code></pre>

<p>This is not good. It overwrites all the fields in config map and puts whole file content into data of the new object.
Proper way is </p>

<pre><code>kubectl create  -f ./config1.yam
</code></pre>
