@@ -367,6 +367,28 @@ func TestHandleV1Alpha1MemberCluster(t *testing.T) {
367367 },
368368 wantResponse : admission .Denied (fmt .Sprintf (validation .ResourceDeniedFormat , "test-user" , utils .GenerateGroupString ([]string {"test-group" }), admissionv1 .Update , & utils .MCV1Alpha1MetaGVK , "" , types.NamespacedName {Name : "test-mc" })),
369369 },
370+ // added as UT since testing this case as an E2E requires
371+ // creating a new user called aks-support in our test environment.
372+ "allow delete of member cluster by aks-support user" : {
373+ req : admission.Request {
374+ AdmissionRequest : admissionv1.AdmissionRequest {
375+ Name : "test-mc" ,
376+ OldObject : runtime.RawExtension {
377+ Raw : MCObjectBytes ,
378+ },
379+ UserInfo : authenticationv1.UserInfo {
380+ Username : "aks-support" ,
381+ Groups : []string {"system:authenticated" },
382+ },
383+ RequestKind : & utils .MCV1Alpha1MetaGVK ,
384+ Operation : admissionv1 .Delete ,
385+ },
386+ },
387+ resourceValidator : fleetResourceValidator {
388+ decoder : decoder ,
389+ },
390+ wantResponse : admission .Allowed (fmt .Sprintf (validation .ResourceAllowedFormat , "aks-support" , utils .GenerateGroupString ([]string {"system:authenticated" }), admissionv1 .Delete , & utils .MCV1Alpha1MetaGVK , "" , types.NamespacedName {Name : "test-mc" })),
391+ },
370392 }
371393
372394 for testName , testCase := range testCases {
@@ -570,6 +592,28 @@ func TestHandleMemberCluster(t *testing.T) {
570592 },
571593 wantResponse : admission .Allowed (fmt .Sprintf (validation .ResourceAllowedFormat , "test-user" , utils .GenerateGroupString ([]string {"test-group" }), admissionv1 .Update , & utils .MCMetaGVK , "status" , types.NamespacedName {Name : "test-mc" })),
572594 },
595+ // added as UT since testing this case as an E2E requires
596+ // creating a new user called aks-support in our test environment.
597+ "allow delete for fleet MC by aks-support user" : {
598+ req : admission.Request {
599+ AdmissionRequest : admissionv1.AdmissionRequest {
600+ Name : "test-mc" ,
601+ OldObject : runtime.RawExtension {
602+ Raw : fleetMCObjectBytes ,
603+ },
604+ UserInfo : authenticationv1.UserInfo {
605+ Username : "aks-support" ,
606+ Groups : []string {"system:authenticated" },
607+ },
608+ RequestKind : & utils .MCMetaGVK ,
609+ Operation : admissionv1 .Delete ,
610+ },
611+ },
612+ resourceValidator : fleetResourceValidator {
613+ decoder : decoder ,
614+ },
615+ wantResponse : admission .Allowed (fmt .Sprintf (validation .ResourceAllowedFormat , "aks-support" , utils .GenerateGroupString ([]string {"system:authenticated" }), admissionv1 .Delete , & utils .MCMetaGVK , "" , types.NamespacedName {Name : "test-mc" })),
616+ },
573617 }
574618
575619 for testName , testCase := range testCases {
@@ -873,6 +917,27 @@ func TestHandleFleetReservedNamespacedResource(t *testing.T) {
873917 },
874918 wantResponse : admission .Denied (fmt .Sprintf (validation .ResourceDeniedFormat , "testUser" , utils .GenerateGroupString ([]string {"testGroup" }), admissionv1 .Create , & utils .EndpointSliceExportMetaGVK , "" , types.NamespacedName {Name : "test-net-eps" , Namespace : "fleet-system" })),
875919 },
920+ // added as UT since testing this case as an E2E requires
921+ // creating a new user called aks-support in our test environment.
922+ "allow delete on v1beta1 IMC in fleet-member namespace" : {
923+ req : admission.Request {
924+ AdmissionRequest : admissionv1.AdmissionRequest {
925+ Name : "test-mc" ,
926+ Namespace : "fleet-member-test-mc" ,
927+ RequestKind : & utils .IMCMetaGVK ,
928+ UserInfo : authenticationv1.UserInfo {
929+ Username : "aks-support" ,
930+ Groups : []string {"system:authenticated" },
931+ },
932+ Operation : admissionv1 .Delete ,
933+ },
934+ },
935+ resourceValidator : fleetResourceValidator {
936+ client : mockClient ,
937+ isFleetV1Beta1API : true ,
938+ },
939+ wantResponse : admission .Allowed (fmt .Sprintf (validation .ResourceAllowedFormat , "aks-support" , utils .GenerateGroupString ([]string {"system:authenticated" }), admissionv1 .Delete , & utils .IMCMetaGVK , "" , types.NamespacedName {Name : "test-mc" , Namespace : "fleet-member-test-mc" })),
940+ },
876941 }
877942 for testName , testCase := range testCases {
878943 t .Run (testName , func (t * testing.T ) {
0 commit comments