Skip to content

Instantly share code, notes, and snippets.

@pathcl
Created October 9, 2019 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pathcl/212300d2bd8d183b8dcb47149b59ce52 to your computer and use it in GitHub Desktop.
Save pathcl/212300d2bd8d183b8dcb47149b59ce52 to your computer and use it in GitHub Desktop.
Get ingress using tls from k8s
// Problem
// - we simply want to check ssl certs on ingress on kubernetes
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
func main() {
var kubeconfig *string
if home := homeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.Parse()
// use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
if err != nil {
panic(err.Error())
}
// create the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
ingress, err := clientset.ExtensionsV1beta1().Ingresses("").List(metav1.ListOptions{})
if err != nil {
panic(err.Error())
}
// maybe there's a better way
for _, s := range ingress.Items {
// log.Println(reflect.TypeOf(host.Spec.TLS))
for p := range s.Spec.TLS {
// fmt.Println("Ingress:", s.Spec.TLS[p].Hosts)
for _, h := range s.Spec.TLS[p].Hosts {
fmt.Println(h)
}
}
}
// services, err := clientset.CoreV1().Services("").List(v1.ListOptions{})
// if err != nil {
// panic(err.Error())
// }
// fmt.Printf("There are %d pods in the cluster\n", len(services.Items))
// for _, s := range services.Items {
// for p, _ := range s.Spec.Ports {
// fmt.Println("Port:", s.Spec.Ports[p].Port)
// fmt.Println("NodePort:", s.Spec.Ports[p].NodePort)
// }
// }
}
func homeDir() string {
if h := os.Getenv("HOME"); h != "" {
return h
}
return os.Getenv("USERPROFILE") // windows
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment