Skip to content

Commit

Permalink
Enhance checks for potential nil references (istio-ecosystem#241) (is…
Browse files Browse the repository at this point in the history
…tio-ecosystem#140)

Co-authored-by: aattuluri <[email protected]>
  • Loading branch information
2 people authored and GitHub Enterprise committed Jul 6, 2022
1 parent a9a4356 commit de341d6
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 @@ -183,15 +183,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 de341d6

Please sign in to comment.