Skip to content

Commit

Permalink
Merge pull request #51 from wunderio/feature/frontend-postinstall-rem…
Browse files Browse the repository at this point in the history
…oval

remove postinstall jobs based on release label instead of hardcoded name
  • Loading branch information
Rade333 authored Jan 16, 2024
2 parents 61d7ddc + 01bb0cd commit eca09a6
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions cmd/ciReleaseDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

helmclient "github.com/mittwald/go-helm-client"
"github.com/spf13/cobra"
errs "k8s.io/apimachinery/pkg/api/errors" // k8s errors and handling
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp" // gcp auth provider
Expand Down Expand Up @@ -67,13 +66,24 @@ var ciReleaseDeleteCmd = &cobra.Command{
log.Fatalf("Error removing a release:%s", uninstallErr)
}

propagationPolicy := v1.DeletePropagationBackground
deleteErr := clientset.BatchV1().Jobs(namespace).Delete(context.TODO(), releaseName+"-post-release", v1.DeleteOptions{PropagationPolicy: &propagationPolicy})
if deleteErr != nil {
if errs.IsNotFound(deleteErr) {
//Resource doesnt exist, lets skip printing a message
} else {
log.Println("Cannot delete post-release job: %s", deleteErr)
//Delete pre-release jobs
selectorLabels := []string{
"release",
"app.kubernetes.io/instance",
}

for _, l := range selectorLabels {
selector := l + "=" + releaseName
list, err := clientset.BatchV1().Jobs(namespace).List(context.TODO(), v1.ListOptions{
LabelSelector: selector,
})
if err != nil {
log.Fatalf("Error getting the list of jobs: %s", err)
}
for _, v := range list.Items {
log.Printf("Deleting job: %s", v.Name)
propagationPolicy := v1.DeletePropagationBackground
clientset.BatchV1().Jobs(namespace).Delete(context.TODO(), v.Name, v1.DeleteOptions{PropagationPolicy: &propagationPolicy})
}
}

Expand Down

0 comments on commit eca09a6

Please sign in to comment.