Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the check for frontend image before cache bust #152

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions controllers/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,33 +485,24 @@ func (r *FrontendReconciliation) getExistingJob() (*batchv1.Job, bool, error) {

}

func (r *FrontendReconciliation) isJobFromCurrentFrontendImage(j *batchv1.Job) bool {
return j.Spec.Template.ObjectMeta.Annotations["frontend-image"] == r.Frontend.Spec.Image
}

// manageExistingJob will delete the existing job if it exists and is not from the current frontend image
// It will return true if the job exists and is from the current frontend image
func (r *FrontendReconciliation) manageExistingJob() (bool, error) {
// manageExistingJob will delete the existing job if it exists
func (r *FrontendReconciliation) deleteExistingJob() error {
j, exists, err := r.getExistingJob()
if err != nil {
return false, err
return err
}

// If it doesn't exist we can return false and no error
if !exists {
return false, nil
return nil
}

// If it exists but is not from the current frontend image we delete it
if !r.isJobFromCurrentFrontendImage(j) {
backgroundDeletion := metav1.DeletePropagationBackground
return false, r.Client.Delete(r.Ctx, j, &client.DeleteOptions{
PropagationPolicy: &backgroundDeletion,
})
}
//
backgroundDeletion := metav1.DeletePropagationBackground
return r.Client.Delete(r.Ctx, j, &client.DeleteOptions{
PropagationPolicy: &backgroundDeletion,
})

// If it exists and is from the current frontend image we return true and no error
return true, nil
}

// createOrUpdateCacheBustJob will create a new job if it doesn't exist
Expand All @@ -526,13 +517,10 @@ func (r *FrontendReconciliation) createOrUpdateCacheBustJob() error {
// If the job exists and is from the current frontend image we can return
// If the job exists and is not from the current frontend image we delete it
// If the job doesn't exist we create it
existsAndMatchesCurrentFrontendImage, err := r.manageExistingJob()
err := r.deleteExistingJob()
if err != nil {
return err
}
if existsAndMatchesCurrentFrontendImage {
return nil
}

// Create job
j := &batchv1.Job{}
Expand Down Expand Up @@ -567,7 +555,6 @@ func (r *FrontendReconciliation) createOrUpdateCacheBustJob() error {
if annotations == nil {
annotations = make(map[string]string)
}
annotations["frontend-image"] = r.Frontend.Spec.Image
annotations["kube-linter.io/ignore-all"] = "we don't need no any checking"

j.Spec.Template.ObjectMeta.SetAnnotations(annotations)
Expand Down
Loading