Skip to content

Commit

Permalink
fix: correct service owner references (#2691)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Sep 16, 2024
1 parent d5c6a82 commit 9a33881
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion backend/controller/scaling/k8sscaling/deployment_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (r *DeploymentProvisioner) handleNewDeployment(ctx context.Context, dep *sc

service.Name = name
service.Labels["app"] = name
deployment.OwnerReferences = []v1.OwnerReference{{APIVersion: "apps/v1", Kind: "deployment", Name: thisDeploymentName, UID: deployment.UID}}
service.OwnerReferences = []v1.OwnerReference{{APIVersion: "apps/v1", Kind: "deployment", Name: thisDeploymentName, UID: deployment.UID}}
service.Spec.Selector = map[string]string{"app": name}
_, err = r.Client.CoreV1().Services(r.Namespace).Create(ctx, service, v1.CreateOptions{})
if err != nil {
Expand Down Expand Up @@ -369,6 +369,15 @@ func (r *DeploymentProvisioner) deleteMissingDeployments(ctx context.Context) {
logger.Errorf(err, "failed to delete deployment %s", deployment.Name)
}

// With owner references the service should be deleted automatically
// However there was a bug so we need this in prod for a bit to clean up
logger.Infof("deleting service %s", deployment.Name)
err = r.Client.CoreV1().Services(r.Namespace).Delete(ctx, deployment.Name, v1.DeleteOptions{})
if err != nil {
if !errors.IsNotFound(err) {
logger.Errorf(err, "failed to delete service %s", deployment.Name)
}
}
}
}
}
Expand Down

0 comments on commit 9a33881

Please sign in to comment.