Skip to content

Commit

Permalink
Enhance checks for potential nil references (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
aattuluri committed Jul 6, 2022
1 parent 0e07ab3 commit f488367
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions admiral/pkg/clusters/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,22 @@ func (sh *ServiceHandler) Deleted(obj *k8sV1.Service) {

func HandleEventForService(svc *k8sV1.Service, remoteRegistry *RemoteRegistry, clusterName string) error {
if svc.Spec.Selector == nil {
return errors.New("selector missing on service");
return fmt.Errorf("selector missing on service=%s in namespace=%s cluster=%s", svc.Name, svc.Namespace, clusterName);
}
matchingDeployements := remoteRegistry.RemoteControllers[clusterName].DeploymentController.GetDeploymentBySelectorInNamespace(svc.Spec.Selector, svc.Namespace)
if len(matchingDeployements) > 0 {
for _, deployment := range matchingDeployements {
HandleEventForDeployment(admiral.Update, &deployment, remoteRegistry, clusterName)
if remoteRegistry.RemoteControllers[clusterName] == nil {
return fmt.Errorf("could not find the remote controller for cluster=%s", clusterName);
}
deploymentController := remoteRegistry.RemoteControllers[clusterName].DeploymentController
rolloutController := remoteRegistry.RemoteControllers[clusterName].RolloutController
if deploymentController != nil {
matchingDeployements := remoteRegistry.RemoteControllers[clusterName].DeploymentController.GetDeploymentBySelectorInNamespace(svc.Spec.Selector, svc.Namespace)
if len(matchingDeployements) > 0 {
for _, deployment := range matchingDeployements {
HandleEventForDeployment(admiral.Update, &deployment, remoteRegistry, clusterName)
}
}
}
if common.GetAdmiralParams().ArgoRolloutsEnabled {
if common.GetAdmiralParams().ArgoRolloutsEnabled && rolloutController != nil {
matchingRollouts := remoteRegistry.RemoteControllers[clusterName].RolloutController.GetRolloutBySelectorInNamespace(svc.Spec.Selector, svc.Namespace)

if len(matchingRollouts) > 0 {
Expand Down

0 comments on commit f488367

Please sign in to comment.