Skip to content

Commit

Permalink
ingress: Avoid potential nil pointer during cleanup
Browse files Browse the repository at this point in the history
As part of garbage collected steps in default Ingress class changes, the
garbage collection process kicks off based on our translation logic.
However, depending on which load-balancer mode is used, the translated
service or endpoint might be nil. This commit is to make sure that we
only performs GC if applicable. Ideally, only Service and Endpoint objs
should be checked, but for readability, nil check for CEC object is also
done.

Fixes: 85671ad
Fixes: #24347
Signed-off-by: Tam Mach <tam.mach@cilium.io>
  • Loading branch information
sayboras committed Mar 22, 2023
1 parent cf0eae1 commit a17f306
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions operator/pkg/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,16 +654,22 @@ func (ic *Controller) garbageCollectOwnedResources(ing *slim_networkingv1.Ingres
return err
}

if err := deleteObjectIfExists(cec, ic.envoyConfigManager.getByKey, ic.clientset.CiliumV2().CiliumEnvoyConfigs(cec.GetNamespace()).Delete); err != nil {
return err
if cec != nil {
if err := deleteObjectIfExists(cec, ic.envoyConfigManager.getByKey, ic.clientset.CiliumV2().CiliumEnvoyConfigs(cec.GetNamespace()).Delete); err != nil {
return err
}
}

if err := deleteObjectIfExists(svc, ic.serviceManager.getByKey, ic.clientset.CoreV1().Services(svc.GetNamespace()).Delete); err != nil {
return err
if svc != nil {
if err := deleteObjectIfExists(svc, ic.serviceManager.getByKey, ic.clientset.CoreV1().Services(svc.GetNamespace()).Delete); err != nil {
return err
}
}

if err := deleteObjectIfExists(ep, ic.endpointManager.getByKey, ic.clientset.CoreV1().Endpoints(ep.GetNamespace()).Delete); err != nil {
return err
if ep != nil {
if err := deleteObjectIfExists(ep, ic.endpointManager.getByKey, ic.clientset.CoreV1().Endpoints(ep.GetNamespace()).Delete); err != nil {
return err
}
}

return nil
Expand Down

0 comments on commit a17f306

Please sign in to comment.