@@ -48,13 +48,31 @@ func TestReconcileIstioCSRDeployment(t *testing.T) {
4848 }
4949 return nil
5050 })
51+ // SSA-migrated resources (Service, ServiceAccount, Certificate, Role, RoleBinding) use Patch
52+ m .PatchCalls (func (ctx context.Context , obj client.Object , patch client.Patch , opts ... client.PatchOption ) error {
53+ switch o := obj .(type ) {
54+ case * corev1.Service , * corev1.ServiceAccount :
55+ if ! reflect .DeepEqual (o .GetLabels (), labels ) {
56+ return fmt .Errorf ("labels mismatch in %v resource; got: %v, want: %v" , o , o .GetLabels (), labels )
57+ }
58+ case * certmanagerv1.Certificate , * rbacv1.Role , * rbacv1.RoleBinding :
59+ l := make (map [string ]string )
60+ maps .Copy (l , labels )
61+ l [istiocsrNamespaceMappingLabelName ] = testIstioCSRNamespace
62+ if ! reflect .DeepEqual (o .GetLabels (), l ) {
63+ return fmt .Errorf ("labels mismatch in %v resource; got: %v, want: %v" , o , o .GetLabels (), l )
64+ }
65+ }
66+ return nil
67+ })
68+ // Non-SSA resources (Deployment, ClusterRole, ClusterRoleBinding) still use Create
5169 m .CreateCalls (func (ctx context.Context , obj client.Object , option ... client.CreateOption ) error {
5270 switch o := obj .(type ) {
53- case * appsv1.Deployment , * corev1. Service , * corev1. ServiceAccount :
71+ case * appsv1.Deployment :
5472 if ! reflect .DeepEqual (o .GetLabels (), labels ) {
5573 return fmt .Errorf ("labels mismatch in %v resource; got: %v, want: %v" , o , o .GetLabels (), labels )
5674 }
57- case * certmanagerv1. Certificate , * rbacv1. Role , * rbacv1. RoleBinding , * rbacv1.ClusterRole , * rbacv1.ClusterRoleBinding :
75+ case * rbacv1.ClusterRole , * rbacv1.ClusterRoleBinding :
5876 l := make (map [string ]string )
5977 maps .Copy (l , labels )
6078 l [istiocsrNamespaceMappingLabelName ] = testIstioCSRNamespace
@@ -67,49 +85,59 @@ func TestReconcileIstioCSRDeployment(t *testing.T) {
6785 },
6886 },
6987 {
70- name : "istiocsr reconciliation fails with serviceaccount creation error" ,
88+ name : "istiocsr reconciliation fails with serviceaccount apply error" ,
7189 preReq : func (r * Reconciler , m * fakes.FakeCtrlClient ) {
72- m .CreateCalls (func (ctx context.Context , obj client.Object , option ... client.CreateOption ) error {
90+ m .PatchCalls (func (ctx context.Context , obj client.Object , patch client. Patch , opts ... client.PatchOption ) error {
7391 switch obj .(type ) {
7492 case * corev1.ServiceAccount :
7593 return errTestClient
7694 }
7795 return nil
7896 })
7997 },
80- wantErr : `failed to create istiocsr-test-ns/cert-manager-istio-csr serviceaccount resource : test client error` ,
98+ wantErr : `failed to apply ServiceAccount " istiocsr-test-ns/cert-manager-istio-csr" : test client error` ,
8199 },
82100 {
83- name : "istiocsr reconciliation fails with role creation error" ,
101+ name : "istiocsr reconciliation fails with role apply error" ,
84102 preReq : func (r * Reconciler , m * fakes.FakeCtrlClient ) {
85- m .CreateCalls (func (ctx context.Context , obj client.Object , option ... client.CreateOption ) error {
86- switch o := obj .(type ) {
103+ m .PatchCalls (func (ctx context.Context , obj client.Object , patch client. Patch , opts ... client.PatchOption ) error {
104+ switch obj .(type ) {
87105 case * rbacv1.Role :
88106 return errTestClient
107+ }
108+ return nil
109+ })
110+ m .CreateCalls (func (ctx context.Context , obj client.Object , option ... client.CreateOption ) error {
111+ switch o := obj .(type ) {
89112 case * rbacv1.ClusterRoleBinding :
90113 roleBinding := testClusterRoleBinding ()
91114 roleBinding .DeepCopyInto (o )
92115 }
93116 return nil
94117 })
95118 },
96- wantErr : `failed to create istio-test-ns/cert-manager-istio-csr role resource : test client error` ,
119+ wantErr : `failed to apply Role " istio-test-ns/cert-manager-istio-csr" : test client error` ,
97120 },
98121 {
99- name : "istiocsr reconciliation fails with certificate creation error" ,
122+ name : "istiocsr reconciliation fails with certificate apply error" ,
100123 preReq : func (r * Reconciler , m * fakes.FakeCtrlClient ) {
101- m .CreateCalls (func (ctx context.Context , obj client.Object , option ... client.CreateOption ) error {
102- switch o := obj .(type ) {
124+ m .PatchCalls (func (ctx context.Context , obj client.Object , patch client. Patch , opts ... client.PatchOption ) error {
125+ switch obj .(type ) {
103126 case * certmanagerv1.Certificate :
104127 return errTestClient
128+ }
129+ return nil
130+ })
131+ m .CreateCalls (func (ctx context.Context , obj client.Object , option ... client.CreateOption ) error {
132+ switch o := obj .(type ) {
105133 case * rbacv1.ClusterRoleBinding :
106134 roleBinding := testClusterRoleBinding ()
107135 roleBinding .DeepCopyInto (o )
108136 }
109137 return nil
110138 })
111139 },
112- wantErr : `failed to create istio-test-ns/istiod certificate resource : test client error` ,
140+ wantErr : `failed to apply Certificate " istio-test-ns/istiod" : test client error` ,
113141 },
114142 }
115143
0 commit comments