mirror of https://github.com/kubernetes/kops.git
Fix suspend proccesst to also resume
Also fixed internal consistency error by switching from []*string to *[]string.
This commit is contained in:
parent
31f9984bad
commit
84d63cbe60
|
@ -230,11 +230,11 @@ func (b *AutoscalingGroupModelBuilder) Build(c *fi.ModelBuilderContext) error {
|
||||||
}
|
}
|
||||||
t.Tags = tags
|
t.Tags = tags
|
||||||
|
|
||||||
if ig.Spec.SuspendProcesses != nil {
|
processes := []string{}
|
||||||
for _, p := range ig.Spec.SuspendProcesses {
|
for _, p := range ig.Spec.SuspendProcesses {
|
||||||
t.SuspendProcesses = append(t.SuspendProcesses, p)
|
processes = append(processes, p)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
t.SuspendProcesses = &processes
|
||||||
|
|
||||||
c.AddTask(t)
|
c.AddTask(t)
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ type AutoscalingGroup struct {
|
||||||
|
|
||||||
LaunchConfiguration *LaunchConfiguration
|
LaunchConfiguration *LaunchConfiguration
|
||||||
|
|
||||||
SuspendProcesses []string
|
SuspendProcesses *[]string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ fi.CompareWithID = &AutoscalingGroup{}
|
var _ fi.CompareWithID = &AutoscalingGroup{}
|
||||||
|
@ -146,6 +146,13 @@ func (e *AutoscalingGroup) Find(c *fi.Context) (*AutoscalingGroup, error) {
|
||||||
actual.Subnets = e.Subnets
|
actual.Subnets = e.Subnets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processes := []string{}
|
||||||
|
for _, p := range g.SuspendedProcesses {
|
||||||
|
processes = append(processes, *p.ProcessName)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual.SuspendProcesses = &processes
|
||||||
|
|
||||||
// Avoid spurious changes
|
// Avoid spurious changes
|
||||||
actual.Lifecycle = e.Lifecycle
|
actual.Lifecycle = e.Lifecycle
|
||||||
|
|
||||||
|
@ -227,6 +234,21 @@ func (_ *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
|
||||||
return fmt.Errorf("error enabling metrics collection for AutoscalingGroup: %v", err)
|
return fmt.Errorf("error enabling metrics collection for AutoscalingGroup: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(*e.SuspendProcesses) > 0 {
|
||||||
|
toSuspend := []*string{}
|
||||||
|
for _, p := range *e.SuspendProcesses {
|
||||||
|
toSuspend = append(toSuspend, &p)
|
||||||
|
}
|
||||||
|
|
||||||
|
processQuery := &autoscaling.ScalingProcessQuery{}
|
||||||
|
processQuery.AutoScalingGroupName = e.Name
|
||||||
|
processQuery.ScalingProcesses = toSuspend
|
||||||
|
|
||||||
|
_, err := t.Cloud.Autoscaling().SuspendProcesses(processQuery)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error suspending processes: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
request := &autoscaling.UpdateAutoScalingGroupInput{
|
request := &autoscaling.UpdateAutoScalingGroupInput{
|
||||||
AutoScalingGroupName: e.Name,
|
AutoScalingGroupName: e.Name,
|
||||||
|
@ -282,6 +304,33 @@ func (_ *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if changes.SuspendProcesses != nil {
|
||||||
|
toSuspend := processCompare(e.SuspendProcesses, a.SuspendProcesses)
|
||||||
|
toResume := processCompare(a.SuspendProcesses, e.SuspendProcesses)
|
||||||
|
|
||||||
|
if len(toSuspend) > 0 {
|
||||||
|
suspendProcessQuery := &autoscaling.ScalingProcessQuery{}
|
||||||
|
suspendProcessQuery.AutoScalingGroupName = e.Name
|
||||||
|
suspendProcessQuery.ScalingProcesses = toSuspend
|
||||||
|
|
||||||
|
_, err := t.Cloud.Autoscaling().SuspendProcesses(suspendProcessQuery)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error suspending processes: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(toResume) > 0 {
|
||||||
|
resumeProcessQuery := &autoscaling.ScalingProcessQuery{}
|
||||||
|
resumeProcessQuery.AutoScalingGroupName = e.Name
|
||||||
|
resumeProcessQuery.ScalingProcesses = toResume
|
||||||
|
|
||||||
|
_, err := t.Cloud.Autoscaling().ResumeProcesses(resumeProcessQuery)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error resuming processes: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
changes.SuspendProcesses = nil
|
||||||
|
}
|
||||||
|
|
||||||
empty := &AutoscalingGroup{}
|
empty := &AutoscalingGroup{}
|
||||||
if !reflect.DeepEqual(empty, changes) {
|
if !reflect.DeepEqual(empty, changes) {
|
||||||
glog.Warningf("cannot apply changes to AutoScalingGroup: %v", changes)
|
glog.Warningf("cannot apply changes to AutoScalingGroup: %v", changes)
|
||||||
|
@ -306,26 +355,30 @@ func (_ *AutoscalingGroup) RenderAWS(t *awsup.AWSAPITarget, a, e, changes *Autos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if e.SuspendProcesses != nil {
|
|
||||||
processQuery := &autoscaling.ScalingProcessQuery{}
|
|
||||||
processQuery.AutoScalingGroupName = e.Name
|
|
||||||
processQuery.ScalingProcesses = []*string{}
|
|
||||||
|
|
||||||
for _, p := range e.SuspendProcesses {
|
|
||||||
processQuery.ScalingProcesses = append(processQuery.ScalingProcesses, &p)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := t.Cloud.Autoscaling().SuspendProcesses(processQuery)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error suspending processes: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Use PropagateAtLaunch = false for tagging?
|
// TODO: Use PropagateAtLaunch = false for tagging?
|
||||||
|
|
||||||
return nil // We have
|
return nil // We have
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// processCompare returns processes that exist in a but not in b
|
||||||
|
func processCompare(a *[]string, b *[]string) []*string {
|
||||||
|
notInB := []*string{}
|
||||||
|
for _, ap := range *a {
|
||||||
|
found := false
|
||||||
|
for _, bp := range *b {
|
||||||
|
if ap == bp {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
notFound := ap
|
||||||
|
notInB = append(notInB, ¬Found)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return notInB
|
||||||
|
}
|
||||||
|
|
||||||
// getASGTagsToDelete loops through the currently set tags and builds a list of
|
// getASGTagsToDelete loops through the currently set tags and builds a list of
|
||||||
// tags to be deleted from the Autoscaling Group
|
// tags to be deleted from the Autoscaling Group
|
||||||
func (e *AutoscalingGroup) getASGTagsToDelete(currentTags map[string]string) []*autoscaling.Tag {
|
func (e *AutoscalingGroup) getASGTagsToDelete(currentTags map[string]string) []*autoscaling.Tag {
|
||||||
|
@ -429,7 +482,7 @@ func (_ *AutoscalingGroup) RenderTerraform(t *terraform.TerraformTarget, a, e, c
|
||||||
|
|
||||||
var processes []*string
|
var processes []*string
|
||||||
if e.SuspendProcesses != nil {
|
if e.SuspendProcesses != nil {
|
||||||
for _, p := range e.SuspendProcesses {
|
for _, p := range *e.SuspendProcesses {
|
||||||
processes = append(processes, fi.String(p))
|
processes = append(processes, fi.String(p))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue