@@ -167,12 +167,11 @@ func (ts *tester) createASG() error {
167167 ts .cfg .EKSConfig .AddOnManagedNodeGroups .RequestHeaderValue != "" ) {
168168
169169 for mngName , cur := range ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs {
170- vv , ok := ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [mngName ]
171- if ok && (vv .CreateRequested || vv .CFNStackID != "" ) {
170+ if cur .CreateRequested || cur .CFNStackID != "" {
172171 ts .cfg .Logger .Warn ("no need to create a new one, skipping" ,
173172 zap .String ("mng-name" , mngName ),
174- zap .Bool ("create-requested" , vv .CreateRequested ),
175- zap .String ("cfn-stack-id" , vv .CFNStackID ),
173+ zap .Bool ("create-requested" , cur .CreateRequested ),
174+ zap .String ("cfn-stack-id" , cur .CFNStackID ),
176175 )
177176 continue
178177 }
@@ -247,12 +246,11 @@ func (ts *tester) createASG() error {
247246 } else {
248247
249248 for mngName , cur := range ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs {
250- vv , ok := ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [mngName ]
251- if ok && (vv .CreateRequested || vv .CFNStackID != "" ) {
249+ if cur .CreateRequested || cur .CFNStackID != "" {
252250 ts .cfg .Logger .Warn ("no need to create a new one, skipping" ,
253251 zap .String ("mng-name" , mngName ),
254- zap .Bool ("create-requested" , vv .CreateRequested ),
255- zap .String ("cfn-stack-id" , vv .CFNStackID ),
252+ zap .Bool ("create-requested" , cur .CreateRequested ),
253+ zap .String ("cfn-stack-id" , cur .CFNStackID ),
256254 )
257255 continue
258256 }
@@ -391,6 +389,11 @@ func (ts *tester) createASG() error {
391389 var st cfn.StackStatus
392390 for st = range ch {
393391 if st .Error != nil {
392+ cur , ok = ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [mngName ]
393+ if ! ok {
394+ cancel ()
395+ return fmt .Errorf ("MNG name %q not found after creation" , mngName )
396+ }
394397 timeEnd := time .Now ()
395398 cur .TimeFrameCreate = timeutil .NewTimeFrame (cur .TimeFrameCreate .StartUTC , cur .TimeFrameCreate .EndUTC .Add (timeEnd .Sub (timeStart )))
396399 cur .Status = fmt .Sprintf ("failed to create managed node group (%v)" , st .Error )
@@ -402,6 +405,10 @@ func (ts *tester) createASG() error {
402405 for _ , o := range st .Stack .Outputs {
403406 switch k := aws .StringValue (o .OutputKey ); k {
404407 case "MNGID" :
408+ cur , ok = ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [mngName ]
409+ if ! ok {
410+ return fmt .Errorf ("MNG name %q not found after creation" , mngName )
411+ }
405412 timeEnd := time .Now ()
406413 cur .TimeFrameCreate = timeutil .NewTimeFrame (cur .TimeFrameCreate .StartUTC , cur .TimeFrameCreate .EndUTC .Add (timeEnd .Sub (timeStart )))
407414 cur .PhysicalID = aws .StringValue (o .OutputValue )
@@ -443,6 +450,10 @@ func (ts *tester) createASG() error {
443450 }
444451 }
445452 cancel ()
453+ cur , ok = ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [mngName ]
454+ if ! ok {
455+ return fmt .Errorf ("MNG name %q not found after creation" , mngName )
456+ }
446457 timeEnd := time .Now ()
447458 cur .TimeFrameCreate = timeutil .NewTimeFrame (cur .TimeFrameCreate .StartUTC , cur .TimeFrameCreate .EndUTC .Add (timeEnd .Sub (timeStart )))
448459 ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [mngName ] = cur
@@ -452,6 +463,10 @@ func (ts *tester) createASG() error {
452463 if err := ts .waitForNodes (cur .Name , 3 ); err != nil {
453464 return err
454465 }
466+ cur , ok = ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [mngName ]
467+ if ! ok {
468+ return fmt .Errorf ("MNG name %q not found after creation" , mngName )
469+ }
455470 timeEnd = time .Now ()
456471 cur .TimeFrameCreate = timeutil .NewTimeFrame (cur .TimeFrameCreate .StartUTC , cur .TimeFrameCreate .EndUTC .Add (timeEnd .Sub (timeStart )))
457472 ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [mngName ] = cur
@@ -543,7 +558,12 @@ func (ts *tester) deleteASG() error {
543558 var st cfn.StackStatus
544559 for st = range ch {
545560 if st .Error != nil {
546- cancel ()
561+ var ok bool
562+ cur , ok = ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [mngName ]
563+ if ! ok {
564+ cancel ()
565+ return fmt .Errorf ("MNG name %q not found after creation" , mngName )
566+ }
547567 timeEnd := time .Now ()
548568 cur .TimeFrameDelete = timeutil .NewTimeFrame (timeStart , timeEnd )
549569 cur .Status = fmt .Sprintf ("failed to delete a managed node group (%v)" , st .Error )
@@ -585,6 +605,11 @@ func (ts *tester) deleteASG() error {
585605 cancel ()
586606 }
587607
608+ var ok bool
609+ cur , ok = ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [mngName ]
610+ if ! ok {
611+ return fmt .Errorf ("MNG name %q not found after creation" , mngName )
612+ }
588613 timeEnd := time .Now ()
589614 cur .TimeFrameDelete = timeutil .NewTimeFrame (timeStart , timeEnd )
590615 cur .Status = ManagedNodeGroupStatusDELETEDORNOTEXIST
@@ -754,25 +779,25 @@ func (ts *tester) setStatus(sv ManagedNodeGroupStatus) error {
754779 if name == "" {
755780 return errors .New ("EKS Managed Node Group empty name" )
756781 }
757- mv , ok := ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [name ]
782+ cur , ok := ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [name ]
758783 if ! ok {
759784 return fmt .Errorf ("EKS Managed Node Group %q not found" , name )
760785 }
761786
762787 if sv .NodeGroup == nil {
763788 if sv .Error != nil {
764- mv .Status = fmt .Sprintf ("%q failed with error %v" , sv .NodeGroupName , sv .Error )
789+ cur .Status = fmt .Sprintf ("%q failed with error %v" , sv .NodeGroupName , sv .Error )
765790 } else {
766- mv .Status = ManagedNodeGroupStatusDELETEDORNOTEXIST
791+ cur .Status = ManagedNodeGroupStatusDELETEDORNOTEXIST
767792 }
768793 } else {
769- mv .Status = aws .StringValue (sv .NodeGroup .Status )
770- if sv .NodeGroup .Resources != nil && mv .RemoteAccessSecurityGroupID == "" {
771- mv .RemoteAccessSecurityGroupID = aws .StringValue (sv .NodeGroup .Resources .RemoteAccessSecurityGroup )
794+ cur .Status = aws .StringValue (sv .NodeGroup .Status )
795+ if sv .NodeGroup .Resources != nil && cur .RemoteAccessSecurityGroupID == "" {
796+ cur .RemoteAccessSecurityGroupID = aws .StringValue (sv .NodeGroup .Resources .RemoteAccessSecurityGroup )
772797 }
773798 }
774799
775- ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [name ] = mv
800+ ts .cfg .EKSConfig .AddOnManagedNodeGroups .MNGs [name ] = cur
776801 return ts .cfg .EKSConfig .Sync ()
777802}
778803
0 commit comments