@@ -591,6 +591,121 @@ func TestReconcileAccessConfig(t *testing.T) {
591591 }
592592}
593593
594+ func TestReconcileAccessConfig (t * testing.T ) {
595+ clusterName := "default.cluster"
596+ tests := []struct {
597+ name string
598+ expect func (m * mock_eksiface.MockEKSAPIMockRecorder )
599+ expectError bool
600+ }{
601+ {
602+ name : "no upgrade necessary" ,
603+ expect : func (m * mock_eksiface.MockEKSAPIMockRecorder ) {
604+ m .
605+ DescribeCluster (gomock .AssignableToTypeOf (& eks.DescribeClusterInput {})).
606+ Return (& eks.DescribeClusterOutput {
607+ Cluster : & eks.Cluster {
608+ Name : aws .String ("default.cluster" ),
609+ AccessConfig : & eks.AccessConfigResponse {
610+ AuthenticationMode : aws .String (eks .AuthenticationModeApiAndConfigMap ),
611+ },
612+ },
613+ }, nil )
614+ },
615+ expectError : false ,
616+ },
617+ {
618+ name : "needs upgrade" ,
619+ expect : func (m * mock_eksiface.MockEKSAPIMockRecorder ) {
620+ m .
621+ DescribeCluster (gomock .AssignableToTypeOf (& eks.DescribeClusterInput {})).
622+ Return (& eks.DescribeClusterOutput {
623+ Cluster : & eks.Cluster {
624+ Name : aws .String ("default.cluster" ),
625+ AccessConfig : & eks.AccessConfigResponse {
626+ AuthenticationMode : aws .String (eks .AuthenticationModeConfigMap ),
627+ },
628+ },
629+ }, nil )
630+ m .WaitUntilClusterUpdating (
631+ gomock .AssignableToTypeOf (& eks.DescribeClusterInput {}), gomock .Any (),
632+ ).Return (nil )
633+ m .
634+ UpdateClusterConfig (gomock .AssignableToTypeOf (& eks.UpdateClusterConfigInput {})).
635+ Return (& eks.UpdateClusterConfigOutput {}, nil )
636+ },
637+ expectError : false ,
638+ },
639+ {
640+ name : "api error" ,
641+ expect : func (m * mock_eksiface.MockEKSAPIMockRecorder ) {
642+ m .
643+ DescribeCluster (gomock .AssignableToTypeOf (& eks.DescribeClusterInput {})).
644+ Return (& eks.DescribeClusterOutput {
645+ Cluster : & eks.Cluster {
646+ Name : aws .String ("default.cluster" ),
647+ AccessConfig : & eks.AccessConfigResponse {
648+ AuthenticationMode : aws .String (eks .AuthenticationModeApi ),
649+ },
650+ },
651+ }, nil )
652+ m .
653+ UpdateClusterConfig (gomock .AssignableToTypeOf (& eks.UpdateClusterConfigInput {})).
654+ Return (& eks.UpdateClusterConfigOutput {}, awserr .New (eks .ErrCodeInvalidParameterException , "Unsupported authentication mode update" , nil ))
655+ },
656+ expectError : true ,
657+ },
658+ }
659+
660+ for _ , tc := range tests {
661+ t .Run (tc .name , func (t * testing.T ) {
662+ g := NewWithT (t )
663+
664+ mockControl := gomock .NewController (t )
665+ defer mockControl .Finish ()
666+
667+ eksMock := mock_eksiface .NewMockEKSAPI (mockControl )
668+
669+ scheme := runtime .NewScheme ()
670+ _ = infrav1 .AddToScheme (scheme )
671+ _ = ekscontrolplanev1 .AddToScheme (scheme )
672+ client := fake .NewClientBuilder ().WithScheme (scheme ).Build ()
673+ scope , err := scope .NewManagedControlPlaneScope (scope.ManagedControlPlaneScopeParams {
674+ Client : client ,
675+ Cluster : & clusterv1.Cluster {
676+ ObjectMeta : metav1.ObjectMeta {
677+ Namespace : "ns" ,
678+ Name : clusterName ,
679+ },
680+ },
681+ ControlPlane : & ekscontrolplanev1.AWSManagedControlPlane {
682+ Spec : ekscontrolplanev1.AWSManagedControlPlaneSpec {
683+ EKSClusterName : clusterName ,
684+ AccessConfig : & ekscontrolplanev1.AccessConfig {
685+ AuthenticationMode : eks .AuthenticationModeApiAndConfigMap ,
686+ },
687+ },
688+ },
689+ })
690+ g .Expect (err ).To (BeNil ())
691+
692+ tc .expect (eksMock .EXPECT ())
693+ s := NewService (scope )
694+ s .EKSClient = eksMock
695+
696+ cluster , err := s .describeEKSCluster (clusterName )
697+ g .Expect (err ).To (BeNil ())
698+
699+ err = s .reconcileAccessConfig (cluster .AccessConfig )
700+ if tc .expectError {
701+ g .Expect (err ).To (HaveOccurred ())
702+ return
703+ }
704+ g .Expect (err ).To (BeNil ())
705+ })
706+ }
707+ }
708+
594709func TestCreateCluster (t * testing.T ) {
595710 clusterName := "cluster.default"
596711 version := aws .String ("1.24" )
0 commit comments