Skip to content

Commit

Permalink
MESH-000 Add check for selector existence for Rollouts/Deployments (i…
Browse files Browse the repository at this point in the history
  • Loading branch information
aattuluri authored and GitHub Enterprise committed Mar 2, 2022
1 parent 1ea431b commit 7cda6c3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion admiral/pkg/clusters/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@ func createDestinationRuleForLocal(remoteController *RemoteController, localDrNa
syncNamespace := common.GetSyncNamespace()
serviceInstance := getServiceForDeployment(remoteController, deploymentInstance)

serviceInstance = getServiceForDeployment(remoteController, deploymentInstance)
if serviceInstance == nil {
log.Warnf(LogFormatAdv, "Get", "Service", deploymentInstance.Name, deploymentInstance.Namespace, remoteController.ClusterID, "No matching service instance found")
return
}

cname := common.GetCname(deploymentInstance, common.GetHostnameSuffix(), common.GetWorkloadIdentifier())
if cname == destinationRule.Host {
destinationRule.Host = serviceInstance.Name + common.Sep + serviceInstance.Namespace + common.DotLocalDomainSuffix
Expand Down Expand Up @@ -688,6 +694,11 @@ func getServiceForDeployment(rc *RemoteController, deployment *k8sAppsV1.Deploym
return nil
}

if deployment.Spec.Selector == nil || deployment.Spec.Selector.MatchLabels == nil {
log.Infof("No selector for deployment=%s in namespace=%s and cluster=%s", deployment.Name, deployment.Namespace, rc.ClusterID)
return nil
}

cachedService := rc.ServiceController.Cache.Get(deployment.Namespace)

if cachedService == nil {
Expand Down Expand Up @@ -751,6 +762,12 @@ func getServiceForRollout(rc *RemoteController, rollout *argo.Rollout) map[strin
if rollout == nil {
return nil
}

if rollout.Spec.Selector == nil || rollout.Spec.Selector.MatchLabels == nil {
log.Infof("No selector for rollout=%s in namespace=%s and cluster=%s", rollout.Name, rollout.Namespace, rc.ClusterID)
return nil
}

cachedService := rc.ServiceController.Cache.Get(rollout.Namespace)

if cachedService == nil {
Expand Down Expand Up @@ -828,7 +845,6 @@ func getServiceForRollout(rc *RemoteController, rollout *argo.Rollout) map[strin

var matchedServices = make(map[string]*WeightedService)


//if we have more than one matching service we will pick the first one, for this to be deterministic we sort services
var servicesInNamespace = cachedService.Service[rollout.Namespace]

Expand Down

0 comments on commit 7cda6c3

Please sign in to comment.