0

We have a little internal tool listing our Kubernetes services using Go client for Kubernetes.

Now we have added Traefik to map our services to meaningful dns names using ingress controllers. We see that there is an ingress lister extension in Go client for Kubernetes that can be used to list ingress controllers. However, we could not make it work.

Are there any Go client code snippets listing ingress controllers?

Maksim Sorokin
  • 2,334
  • 3
  • 34
  • 61
  • 1
    "However, we could not make it work." – please provide samples of the code you have already tried, so we have some of your prior art to work with. – Cosmic Ossifrage Sep 06 '18 at 09:36

1 Answers1

2

What have you tried so far? Posting examples helps. Try the following arbitrary example to get you started:

    // imports
    // metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    // "k8s.io/client-go/kubernetes"
    // "k8s.io/client-go/tools/clientcmd"

    // create the clientset
    clientset, err := kubernetes.NewForConfig(config)
    if err != nil {
            panic(err.Error())
    }
    for {
            ingressList, err := clientset.ExtensionsV1beta1().Ingresses("").List(metav1.ListOptions{})
            if err != nil {
                    // handle err
            }
            ingressCtrls := ingressList.Items
            if len(ingressCtrls) > 0 {
                    for _, ingress := range ingressCtrls {
                            fmt.Printf("ingress %s exists in namespace %s\n", ingress.Name, ingress.Namespace)
                    }
            } else {
                    fmt.Println("no ingress found")
            }
            time.Sleep(10 * time.Second)
    }
PhilipGough
  • 1,709
  • 1
  • 13
  • 18