Skip to content

Commit

Permalink
eks/mng: fix mng status update
Browse files Browse the repository at this point in the history
do not overwrite

Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
  • Loading branch information
gyuho committed May 26, 2020
1 parent 1151d5b commit 3aa3b65
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions eks/mng/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ func (ts *tester) createASG() error {
ts.cfg.EKSConfig.AddOnManagedNodeGroups.RequestHeaderValue != "") {

for mngName, cur := range ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs {
vv, ok := ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[mngName]
if ok && (vv.CreateRequested || vv.CFNStackID != "") {
if cur.CreateRequested || cur.CFNStackID != "" {
ts.cfg.Logger.Warn("no need to create a new one, skipping",
zap.String("mng-name", mngName),
zap.Bool("create-requested", vv.CreateRequested),
zap.String("cfn-stack-id", vv.CFNStackID),
zap.Bool("create-requested", cur.CreateRequested),
zap.String("cfn-stack-id", cur.CFNStackID),
)
continue
}
Expand Down Expand Up @@ -247,12 +246,11 @@ func (ts *tester) createASG() error {
} else {

for mngName, cur := range ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs {
vv, ok := ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[mngName]
if ok && (vv.CreateRequested || vv.CFNStackID != "") {
if cur.CreateRequested || cur.CFNStackID != "" {
ts.cfg.Logger.Warn("no need to create a new one, skipping",
zap.String("mng-name", mngName),
zap.Bool("create-requested", vv.CreateRequested),
zap.String("cfn-stack-id", vv.CFNStackID),
zap.Bool("create-requested", cur.CreateRequested),
zap.String("cfn-stack-id", cur.CFNStackID),
)
continue
}
Expand Down Expand Up @@ -391,6 +389,11 @@ func (ts *tester) createASG() error {
var st cfn.StackStatus
for st = range ch {
if st.Error != nil {
cur, ok = ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[mngName]
if !ok {
cancel()
return fmt.Errorf("MNG name %q not found after creation", mngName)
}
timeEnd := time.Now()
cur.TimeFrameCreate = timeutil.NewTimeFrame(cur.TimeFrameCreate.StartUTC, cur.TimeFrameCreate.EndUTC.Add(timeEnd.Sub(timeStart)))
cur.Status = fmt.Sprintf("failed to create managed node group (%v)", st.Error)
Expand All @@ -402,6 +405,10 @@ func (ts *tester) createASG() error {
for _, o := range st.Stack.Outputs {
switch k := aws.StringValue(o.OutputKey); k {
case "MNGID":
cur, ok = ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[mngName]
if !ok {
return fmt.Errorf("MNG name %q not found after creation", mngName)
}
timeEnd := time.Now()
cur.TimeFrameCreate = timeutil.NewTimeFrame(cur.TimeFrameCreate.StartUTC, cur.TimeFrameCreate.EndUTC.Add(timeEnd.Sub(timeStart)))
cur.PhysicalID = aws.StringValue(o.OutputValue)
Expand Down Expand Up @@ -443,6 +450,10 @@ func (ts *tester) createASG() error {
}
}
cancel()
cur, ok = ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[mngName]
if !ok {
return fmt.Errorf("MNG name %q not found after creation", mngName)
}
timeEnd := time.Now()
cur.TimeFrameCreate = timeutil.NewTimeFrame(cur.TimeFrameCreate.StartUTC, cur.TimeFrameCreate.EndUTC.Add(timeEnd.Sub(timeStart)))
ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[mngName] = cur
Expand All @@ -452,6 +463,10 @@ func (ts *tester) createASG() error {
if err := ts.waitForNodes(cur.Name, 3); err != nil {
return err
}
cur, ok = ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[mngName]
if !ok {
return fmt.Errorf("MNG name %q not found after creation", mngName)
}
timeEnd = time.Now()
cur.TimeFrameCreate = timeutil.NewTimeFrame(cur.TimeFrameCreate.StartUTC, cur.TimeFrameCreate.EndUTC.Add(timeEnd.Sub(timeStart)))
ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[mngName] = cur
Expand Down Expand Up @@ -543,7 +558,12 @@ func (ts *tester) deleteASG() error {
var st cfn.StackStatus
for st = range ch {
if st.Error != nil {
cancel()
var ok bool
cur, ok = ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[mngName]
if !ok {
cancel()
return fmt.Errorf("MNG name %q not found after creation", mngName)
}
timeEnd := time.Now()
cur.TimeFrameDelete = timeutil.NewTimeFrame(timeStart, timeEnd)
cur.Status = fmt.Sprintf("failed to delete a managed node group (%v)", st.Error)
Expand Down Expand Up @@ -585,6 +605,11 @@ func (ts *tester) deleteASG() error {
cancel()
}

var ok bool
cur, ok = ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[mngName]
if !ok {
return fmt.Errorf("MNG name %q not found after creation", mngName)
}
timeEnd := time.Now()
cur.TimeFrameDelete = timeutil.NewTimeFrame(timeStart, timeEnd)
cur.Status = ManagedNodeGroupStatusDELETEDORNOTEXIST
Expand Down Expand Up @@ -754,25 +779,25 @@ func (ts *tester) setStatus(sv ManagedNodeGroupStatus) error {
if name == "" {
return errors.New("EKS Managed Node Group empty name")
}
mv, ok := ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[name]
cur, ok := ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[name]
if !ok {
return fmt.Errorf("EKS Managed Node Group %q not found", name)
}

if sv.NodeGroup == nil {
if sv.Error != nil {
mv.Status = fmt.Sprintf("%q failed with error %v", sv.NodeGroupName, sv.Error)
cur.Status = fmt.Sprintf("%q failed with error %v", sv.NodeGroupName, sv.Error)
} else {
mv.Status = ManagedNodeGroupStatusDELETEDORNOTEXIST
cur.Status = ManagedNodeGroupStatusDELETEDORNOTEXIST
}
} else {
mv.Status = aws.StringValue(sv.NodeGroup.Status)
if sv.NodeGroup.Resources != nil && mv.RemoteAccessSecurityGroupID == "" {
mv.RemoteAccessSecurityGroupID = aws.StringValue(sv.NodeGroup.Resources.RemoteAccessSecurityGroup)
cur.Status = aws.StringValue(sv.NodeGroup.Status)
if sv.NodeGroup.Resources != nil && cur.RemoteAccessSecurityGroupID == "" {
cur.RemoteAccessSecurityGroupID = aws.StringValue(sv.NodeGroup.Resources.RemoteAccessSecurityGroup)
}
}

ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[name] = mv
ts.cfg.EKSConfig.AddOnManagedNodeGroups.MNGs[name] = cur
return ts.cfg.EKSConfig.Sync()
}

Expand Down

0 comments on commit 3aa3b65

Please sign in to comment.