Skip to content

Commit 20474eb

Browse files
Merge pull request #312 from chiragkyal/istio-ca-config
CM-679: Implements user-configurable CA certificate support for Istio CSR
2 parents d346a70 + ddf7e7b commit 20474eb

File tree

9 files changed

+1303
-55
lines changed

9 files changed

+1303
-55
lines changed

pkg/controller/istiocsr/constants.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ const (
6565
// created in other namespaces by the controller.
6666
istiocsrNamespaceMappingLabelName = "cert-manager-istio-csr-namespace"
6767

68-
// istiocsrResourceWatchLabelName is the label name for identifying the resources of interest for the
68+
// IstiocsrResourceWatchLabelName is the label name for identifying the resources of interest for the
6969
// controller but does not create or manage the resource.
70-
istiocsrResourceWatchLabelName = "istiocsr.openshift.operator.io/watched-by"
70+
IstiocsrResourceWatchLabelName = "istiocsr.openshift.operator.io/watched-by"
7171

7272
// istiocsrResourceWatchLabelName is the value format assigned to istiocsrResourceWatchLabelName label, which
7373
// will be of the form <istiocsr_namespace>/<istiocsr_instance-Name>
7474
istiocsrResourceWatchLabelValueFmt = "%s_%s"
7575

76-
// istiocsrCAConfigMapName is the name o the configmap which is mounted in istiocsr container, containing the
76+
// IstiocsrCAConfigMapName is the name o the configmap which is mounted in istiocsr container, containing the
7777
// CA certificate configured in the secret referenced in the issuer.
78-
istiocsrCAConfigMapName = istiocsrCommonName + "-issuer-ca-copy"
78+
IstiocsrCAConfigMapName = istiocsrCommonName + "-issuer-ca-copy"
7979

80-
// istiocsrCAKeyName is the key name holding the CA certificate in the issuer secret or the controller
80+
// IstiocsrCAKeyName is the key name holding the CA certificate in the issuer secret or the controller
8181
// CA configmap.
82-
istiocsrCAKeyName = "ca.crt"
82+
IstiocsrCAKeyName = "ca.crt"
8383
)
8484

8585
var (

pkg/controller/istiocsr/controller.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
135135
if objLabels[requestEnqueueLabelKey] == requestEnqueueLabelValue {
136136
return true
137137
}
138-
value := objLabels[istiocsrResourceWatchLabelName]
138+
value := objLabels[IstiocsrResourceWatchLabelName]
139139
if value == "" {
140140
return false
141141
}
142142
key := strings.Split(value, "_")
143143
if len(key) != 2 {
144-
r.log.Error(fmt.Errorf("invalid label format"), "%s label value(%s) not in expected format on %s resource", istiocsrResourceWatchLabelName, value, obj.GetName())
144+
r.log.Error(fmt.Errorf("invalid label format"), "%s label value(%s) not in expected format on %s resource", IstiocsrResourceWatchLabelName, value, obj.GetName())
145145
return false
146146
}
147147
namespace = key[0]
@@ -172,12 +172,22 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
172172
// predicate function to filter events for objects which controller is interested in, but
173173
// not managed or created by controller.
174174
controllerWatchResources := predicate.NewPredicateFuncs(func(object client.Object) bool {
175-
return object.GetLabels() != nil && object.GetLabels()[istiocsrResourceWatchLabelName] != ""
175+
return object.GetLabels() != nil && object.GetLabels()[IstiocsrResourceWatchLabelName] != ""
176+
})
177+
178+
controllerConfigMapPredicates := predicate.NewPredicateFuncs(func(object client.Object) bool {
179+
if object.GetLabels() == nil {
180+
return false
181+
}
182+
// Accept if it's a managed ConfigMap OR a watched ConfigMap
183+
return object.GetLabels()[requestEnqueueLabelKey] == requestEnqueueLabelValue ||
184+
object.GetLabels()[IstiocsrResourceWatchLabelName] != ""
176185
})
177186

178187
withIgnoreStatusUpdatePredicates := builder.WithPredicates(predicate.GenerationChangedPredicate{}, controllerManagedResources)
179188
controllerWatchResourcePredicates := builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}, controllerWatchResources)
180189
controllerManagedResourcePredicates := builder.WithPredicates(controllerManagedResources)
190+
controllerConfigMapWatchPredicates := builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}, controllerConfigMapPredicates)
181191

182192
return ctrl.NewControllerManagedBy(mgr).
183193
For(&v1alpha1.IstioCSR{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
@@ -190,6 +200,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
190200
Watches(&rbacv1.RoleBinding{}, handler.EnqueueRequestsFromMapFunc(mapFunc), controllerManagedResourcePredicates).
191201
Watches(&corev1.Service{}, handler.EnqueueRequestsFromMapFunc(mapFunc), controllerManagedResourcePredicates).
192202
Watches(&corev1.ServiceAccount{}, handler.EnqueueRequestsFromMapFunc(mapFunc), controllerManagedResourcePredicates).
203+
Watches(&corev1.ConfigMap{}, handler.EnqueueRequestsFromMapFunc(mapFunc), controllerConfigMapWatchPredicates).
193204
WatchesMetadata(&corev1.Secret{}, handler.EnqueueRequestsFromMapFunc(mapFunc), controllerWatchResourcePredicates).
194205
Complete(r)
195206
}

pkg/controller/istiocsr/controller_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ func TestReconcile(t *testing.T) {
4444
case *appsv1.Deployment:
4545
deployment := testDeployment()
4646
deployment.DeepCopyInto(o)
47+
case *certmanagerv1.Issuer:
48+
issuer := testIssuer()
49+
issuer.DeepCopyInto(o)
50+
case *corev1.Secret:
51+
secret := testSecret()
52+
secret.DeepCopyInto(o)
4753
}
4854
return nil
4955
})
@@ -52,6 +58,9 @@ func TestReconcile(t *testing.T) {
5258
case *appsv1.Deployment:
5359
deployment := testDeployment()
5460
deployment.DeepCopyInto(o)
61+
case *corev1.ConfigMap:
62+
configmap := testConfigMap()
63+
configmap.DeepCopyInto(o)
5564
}
5665
return true, nil
5766
})
@@ -121,6 +130,12 @@ func TestReconcile(t *testing.T) {
121130
case *corev1.ServiceAccount:
122131
serviceAccount := testServiceAccount()
123132
serviceAccount.DeepCopyInto(o)
133+
case *certmanagerv1.Issuer:
134+
issuer := testIssuer()
135+
issuer.DeepCopyInto(o)
136+
case *corev1.Secret:
137+
secret := testSecret()
138+
secret.DeepCopyInto(o)
124139
}
125140
return nil
126141
})
@@ -139,6 +154,9 @@ func TestReconcile(t *testing.T) {
139154
case *appsv1.Deployment:
140155
deployment := testDeployment()
141156
deployment.DeepCopyInto(o)
157+
case *corev1.ConfigMap:
158+
configmap := testConfigMap()
159+
configmap.DeepCopyInto(o)
142160
}
143161
return true, nil
144162
})
@@ -208,13 +226,21 @@ func TestReconcile(t *testing.T) {
208226
case *corev1.ServiceAccount:
209227
serviceAccount := testServiceAccount()
210228
serviceAccount.DeepCopyInto(o)
229+
case *certmanagerv1.Issuer:
230+
issuer := testIssuer()
231+
issuer.DeepCopyInto(o)
232+
case *corev1.Secret:
233+
secret := testSecret()
234+
secret.DeepCopyInto(o)
211235
}
212236
return nil
213237
})
214238
m.ExistsCalls(func(ctx context.Context, ns types.NamespacedName, obj client.Object) (bool, error) {
215239
switch obj.(type) {
216240
case *appsv1.Deployment:
217241
return false, nil
242+
case *corev1.ConfigMap:
243+
return true, nil
218244
}
219245
return true, nil
220246
})
@@ -438,6 +464,12 @@ func TestProcessReconcileRequest(t *testing.T) {
438464
case *appsv1.Deployment:
439465
deployment := testDeployment()
440466
deployment.DeepCopyInto(o)
467+
case *certmanagerv1.Issuer:
468+
issuer := testIssuer()
469+
issuer.DeepCopyInto(o)
470+
case *corev1.Secret:
471+
secret := testSecret()
472+
secret.DeepCopyInto(o)
441473
}
442474
return nil
443475
})
@@ -446,6 +478,9 @@ func TestProcessReconcileRequest(t *testing.T) {
446478
case *appsv1.Deployment:
447479
deployment := testDeployment()
448480
deployment.DeepCopyInto(o)
481+
case *corev1.ConfigMap:
482+
configmap := testConfigMap()
483+
configmap.DeepCopyInto(o)
449484
}
450485
return true, nil
451486
})
@@ -490,6 +525,12 @@ func TestProcessReconcileRequest(t *testing.T) {
490525
case *appsv1.Deployment:
491526
deployment := testDeployment()
492527
deployment.DeepCopyInto(o)
528+
case *certmanagerv1.Issuer:
529+
issuer := testIssuer()
530+
issuer.DeepCopyInto(o)
531+
case *corev1.Secret:
532+
secret := testSecret()
533+
secret.DeepCopyInto(o)
493534
}
494535
return nil
495536
})
@@ -498,6 +539,9 @@ func TestProcessReconcileRequest(t *testing.T) {
498539
case *appsv1.Deployment:
499540
deployment := testDeployment()
500541
deployment.DeepCopyInto(o)
542+
case *corev1.ConfigMap:
543+
configmap := testConfigMap()
544+
configmap.DeepCopyInto(o)
501545
}
502546
return true, nil
503547
})

0 commit comments

Comments
 (0)