Skip to content

Commit

Permalink
Add validation for label selectors
Browse files Browse the repository at this point in the history
- Reject deployment if the pod label selector doesn't match 'app: <DEPLOYMENT_NAME>'
  • Loading branch information
stefanprodan committed Feb 11, 2019
1 parent 217ef06 commit 97fc4a9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/controller/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ func (c *CanaryDeployer) createPrimaryDeployment(cd *flaggerv1.Canary) error {
return err
}

if appSel, ok := canaryDep.Spec.Selector.MatchLabels["app"]; !ok || appSel != canaryDep.Name {
return fmt.Errorf("invalid label selector! Deployment %s.%s spec.selector.matchLabels must contain selector 'app: %s'",
targetName, cd.Namespace, targetName)
}

primaryDep, err := c.kubeClient.AppsV1().Deployments(cd.Namespace).Get(primaryName, metav1.GetOptions{})
if errors.IsNotFound(err) {
// create primary secrets and config maps
Expand Down

0 comments on commit 97fc4a9

Please sign in to comment.