func createNamespace(clientset *kubernetes.Clientset) { namespace := &corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ Name: "example", }, } _, err := clientset.CoreV1().Namespaces().Create(namespace) if err != nil { panic(err.Error()) } fmt.Printf("Namespace %s created successfully\n", namespace.Name) }
func getPodByName(clientset *kubernetes.Clientset, name string) (*corev1.Pod, error) { pod, err := clientset.CoreV1().Pods("default").Get(name, metav1.GetOptions{}) if err != nil { return nil, err } return pod, nil }This example gets a Pod by its name using the Get() method provided by the clientset interface. It takes the name of the Pod and returns a pointer to a Pod object and an error.