You can use the following client-go method to remove k8s Jobs and their associated pods:
import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
config, err := rest.InClusterConfig()
if err != nil {
panic(err.Error())
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
jobClient := clientset.BatchV1().Jobs(namespace)
err = jobClient.Delete(jobName, &metav1.DeleteOptions{})
if err != nil {
panic(err.Error())
}
podClient := clientset.CoreV1().Pods(namespace)
selector := fmt.Sprintf("job-name=%s", jobName)
err = podClient.DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{
LabelSelector: selector,
})
if err != nil {
panic(err.Error())
}
With the above client-go methods, you can easily remove k8s Jobs and their associated pods.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-19 14:42:49 +0000
Seen: 8 times
Last updated: Jun 19 '23
What is the method for altering the color of the input text in a TextFormField in Flutter?
What is the procedure for utilizing the node-rdpjs library?
What is the method to change a PDF file to an Excel file using C#?
What is the method to make a TextButton inactive when the text field has no text?
What is the method to alter the background image in HTML?
What is the method for saving an entity with @EmbeddedId as its primary key in Hibernate?
What is the method to superimpose two seaborn density plots?