<p>So Kubernetes events seems to have options for watch for all kinds of things like pod up/down creation/deletion etc.. - but I want to watch for a namespace creation/deletion itself - and I can't find an option to do that.</p>
<p>I want to know if someone created a namespace or deleted one. Is this possible?</p>
<p>Rgds,
Gopa.</p>

gopa
<p>So I got it working, pasting the entire code below for anyone's future reference</p>
<pre class="lang-golang prettyprint-override"><code>package main

import (
    &quot;os&quot;
    &quot;os/exec&quot;
    &quot;os/signal&quot;
    &quot;strings&quot;
    &quot;syscall&quot;
    &quot;time&quot;

    &quot;github.com/golang/glog&quot;
    v1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;
    &quot;k8s.io/apimachinery/pkg/util/runtime&quot;
    &quot;k8s.io/client-go/informers&quot;
    &quot;k8s.io/client-go/kubernetes&quot;
    &quot;k8s.io/client-go/rest&quot;
    &quot;k8s.io/client-go/tools/cache&quot;
    &quot;k8s.io/client-go/tools/clientcmd&quot;
)

func newNamespace(obj interface{}) {
    ns := obj.(v1.Object)
    glog.Error(&quot;New Namespace &quot;, ns.GetName())
}

func modNamespace(objOld interface{}, objNew interface{}) {
}

func delNamespace(obj interface{}) {
    ns := obj.(v1.Object)
    glog.Error(&quot;Del Namespace &quot;, ns.GetName())
}

func watchNamespace(k8s *kubernetes.Clientset) {
    // Add watcher for the Namespace.
    factory := informers.NewSharedInformerFactory(k8s, 5*time.Second)
    nsInformer := factory.Core().V1().Namespaces().Informer()
    nsInformerChan := make(chan struct{})
    //defer close(nsInformerChan)
    defer runtime.HandleCrash()

    // Namespace informer state change handler
    nsInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
        // When a new namespace gets created
        AddFunc: func(obj interface{}) {
            newNamespace(obj)
        },
        // When a namespace gets updated
        UpdateFunc: func(oldObj interface{}, newObj interface{}) {
            modNamespace(oldObj, newObj)
        },
        // When a namespace gets deleted
        DeleteFunc: func(obj interface{}) {
            delNamespace(obj)
        },
    })
    factory.Start(nsInformerChan)
    //go nsInformer.GetController().Run(nsInformerChan)
    go nsInformer.Run(nsInformerChan)
}

func main() {
    kconfig := os.Getenv(&quot;KUBECONFIG&quot;)
    glog.Error(&quot;KCONFIG&quot;, kconfig)
    var config *rest.Config
    var clientset *kubernetes.Clientset
    var err error
    for {
        if config == nil {
            config, err = clientcmd.BuildConfigFromFlags(&quot;&quot;, kconfig)
            if err != nil {
                glog.Error(&quot;Cant create  kubernetes config&quot;)
                time.Sleep(time.Second)
                continue
            }
        }
        // creates the clientset
        clientset, err = kubernetes.NewForConfig(config)
        if err != nil {
            glog.Error(&quot;Cannot create kubernetes client&quot;)
            time.Sleep(time.Second)
            continue
        }
        break
    }
    watchNamespace(clientset)
    glog.Error(&quot;Watch started&quot;)

    term := make(chan os.Signal, 1)
    signal.Notify(term, os.Interrupt)
    signal.Notify(term, syscall.SIGTERM)
    select {
    case &lt;-term:
    }
}
</code></pre>
