import ( "context" "fmt" batchv1 "k8s.io/kubernetes/pkg/apis/batch/v1" clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" ) func ListCronJobs(namespace string) { client, _ := clientset.NewForConfig() cronJobList, _ := client.BatchV1().CronJobs(namespace).List(context.Background(), metav1.ListOptions{}) for _, cronJob := range cronJobList.Items { fmt.Println(cronJob.Name) } }
import ( "context" batchv1 "k8s.io/kubernetes/pkg/apis/batch/v1" clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset" ) func CreateJob(namespace string, job *batchv1.Job) error { client, _ := clientset.NewForConfig() _, err := client.BatchV1().Jobs(namespace).Create(context.Background(), job, metav1.CreateOptions{}) return err }In the first example, the ListCronJobs function uses the BatchV1 interface to list all the cronjobs in the specified namespace. In the second example, the CreateJob function uses the same interface to create a new job in the specified namespace. Both examples demonstrate the use of the clientset_generated/internalclientset interface to interact with Kubernetes batch operations.