Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-324: ELB priority check added (for manually assigned priority) #373

Merged
merged 6 commits into from
Oct 24, 2018
32 changes: 30 additions & 2 deletions workflows/service_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ func getMaxPriority(elbRuleLister common.ElbRuleLister, listenerArn string) int
return maxPriority
}

func checkPriorityNotInUse(elbRuleLister common.ElbRuleLister, listenerArn string, priorities []int) error {
rules, err := elbRuleLister.ListRules(listenerArn)
if err != nil {
return fmt.Errorf("Error checking priorities for listener '%s': %v", listenerArn, err)
}
res := []string{}
for _, rule := range rules {
priority, _ := strconv.Atoi(common.StringValue(rule.Priority))
for _, p := range priorities {
if priority == p {
res = append(res, strconv.Itoa(p))
}
}
}
if len(res) > 0 {
return fmt.Errorf("ELB priority already in use: %s\nChange or remove the priority definition in mu.yml", strings.Join(res, ","))
}
return nil
}

func (workflow *serviceWorkflow) serviceEnvironmentLoader(namespace string, environmentName string, stackWaiter common.StackWaiter) Executor {
return func() error {
lbStackName := common.CreateStackName(namespace, common.StackTypeLoadBalancer, environmentName)
Expand Down Expand Up @@ -266,11 +286,13 @@ func (workflow *serviceWorkflow) serviceApplyCommonParams(namespace string, serv
if workflow.lbStack != nil {
if workflow.lbStack.Outputs["ElbHttpListenerArn"] != "" {
params["ElbHttpListenerArn"] = fmt.Sprintf("%s-ElbHttpListenerArn", workflow.lbStack.Name)
nextAvailablePriority = 1 + getMaxPriority(elbRuleLister, workflow.lbStack.Outputs["ElbHttpListenerArn"])
if workflow.priority < 1 {
nextAvailablePriority = 1 + getMaxPriority(elbRuleLister, workflow.lbStack.Outputs["ElbHttpListenerArn"])
}
}
if workflow.lbStack.Outputs["ElbHttpsListenerArn"] != "" {
params["ElbHttpsListenerArn"] = fmt.Sprintf("%s-ElbHttpsListenerArn", workflow.lbStack.Name)
if nextAvailablePriority == 0 {
if workflow.priority < 1 && nextAvailablePriority == 0 {
nextAvailablePriority = 1 + getMaxPriority(elbRuleLister, workflow.lbStack.Outputs["ElbHttpsListenerArn"])
}
}
Expand All @@ -297,6 +319,12 @@ func (workflow *serviceWorkflow) serviceApplyCommonParams(namespace string, serv
svcStack := stackWaiter.AwaitFinalStatus(svcStackName)

if workflow.priority > 0 {
// make sure manually specified priority is not already in use
err := checkPriorityNotInUse(elbRuleLister, workflow.lbStack.Outputs["ElbHttpListenerArn"], []int{workflow.priority, workflow.priority + 1})
if err != nil {
return err
}

params["PathListenerRulePriority"] = strconv.Itoa(workflow.priority)
params["HostListenerRulePriority"] = strconv.Itoa(workflow.priority + 1)
} else if svcStack != nil && svcStack.Status != "ROLLBACK_COMPLETE" {
Expand Down