77import io .fabric8 .kubernetes .api .model .LocalObjectReference ;
88import io .fabric8 .kubernetes .api .model .Secret ;
99import io .fabric8 .kubernetes .api .model .apps .Deployment ;
10+ import io .strimzi .api .kafka .model .common .CertificateManagerType ;
1011import io .strimzi .api .kafka .model .kafka .Kafka ;
1112import io .strimzi .api .kafka .model .kafka .exporter .KafkaExporterResources ;
1213import io .strimzi .operator .cluster .ClusterOperatorConfig ;
14+ import io .strimzi .operator .cluster .model .CertManagerUtils ;
1315import io .strimzi .operator .cluster .model .CertUtils ;
1416import io .strimzi .operator .cluster .model .ClusterCa ;
1517import io .strimzi .operator .cluster .model .ImagePullPolicy ;
1618import io .strimzi .operator .cluster .model .KafkaExporter ;
1719import io .strimzi .operator .cluster .model .KafkaVersion ;
1820import io .strimzi .operator .cluster .operator .resource .ResourceOperatorSupplier ;
21+ import io .strimzi .operator .cluster .operator .resource .kubernetes .CertManagerCertificateOperator ;
1922import io .strimzi .operator .cluster .operator .resource .kubernetes .DeploymentOperator ;
2023import io .strimzi .operator .cluster .operator .resource .kubernetes .NetworkPolicyOperator ;
2124import io .strimzi .operator .cluster .operator .resource .kubernetes .PodDisruptionBudgetOperator ;
@@ -49,6 +52,7 @@ public class KafkaExporterReconciler {
4952 private final ServiceAccountOperator serviceAccountOperator ;
5053 private final NetworkPolicyOperator networkPolicyOperator ;
5154 private final PodDisruptionBudgetOperator podDisruptionBudgetOperator ;
55+ private final CertManagerCertificateOperator certManagerCertificateOperator ;
5256
5357 private String certificateHash = "" ;
5458
@@ -83,6 +87,7 @@ public KafkaExporterReconciler(
8387 this .serviceAccountOperator = supplier .serviceAccountOperations ;
8488 this .networkPolicyOperator = supplier .networkPolicyOperator ;
8589 this .podDisruptionBudgetOperator = supplier .podDisruptionBudgetOperator ;
90+ this .certManagerCertificateOperator = supplier .certManagerCertificateOperator ;
8691 }
8792
8893 /**
@@ -99,7 +104,8 @@ public KafkaExporterReconciler(
99104 */
100105 public Future <Void > reconcile (boolean isOpenShift , ImagePullPolicy imagePullPolicy , List <LocalObjectReference > imagePullSecrets , Clock clock ) {
101106 return serviceAccount ()
102- .compose (i -> certificatesSecret (clock ))
107+ .compose (i -> maybeReconcileCertManagerCertificates ())
108+ .compose (secret -> certificatesSecret (clock , secret ))
103109 .compose (i -> networkPolicy ())
104110 .compose (i -> podDisruptionBudget ())
105111 .compose (i -> deployment (isOpenShift , imagePullPolicy , imagePullSecrets ))
@@ -121,27 +127,51 @@ private Future<Void> serviceAccount() {
121127 ).mapEmpty ();
122128 }
123129
130+ /**
131+ * Manages the Certificate object that is used when cert-manager is the Certificate issuer
132+ *
133+ * @return Completes when the Certificate object was successfully created, deleted or updated and returns the related Secret
134+ */
135+ protected Future <Secret > maybeReconcileCertManagerCertificates () {
136+ //TODO handle empty reconciles when kafka exporter not enabled
137+ if (CertificateManagerType .CERT_MANAGER_IO .equals (clusterCa .getType ())) {
138+ return certManagerCertificateOperator .reconcile (reconciliation , reconciliation .namespace (), KafkaExporterResources .secretName (reconciliation .name ()), kafkaExporter .generateCertificateResource (clusterCa ))
139+ .compose (v -> certManagerCertificateOperator .waitForReady (reconciliation , reconciliation .namespace (), KafkaExporterResources .secretName (reconciliation .name ())))
140+ .compose (v -> secretOperator .getAsync (reconciliation .namespace (), CertManagerUtils .certManagerSecretName (KafkaExporterResources .secretName (reconciliation .name ()))));
141+ } else {
142+ return Future .succeededFuture ();
143+ }
144+ }
145+
124146 /**
125147 * Manages the Kafka Exporter Secret with certificates.
126148 *
127- * @param clock The clock for supplying the reconciler with the time instant of each reconciliation cycle.
128- * That time is used for checking maintenance windows
149+ * @param clock The clock for supplying the reconciler with the time instant of each reconciliation cycle.
150+ * That time is used for checking maintenance windows
151+ * @param certManagerSecret Secret managed by cert-manager containing the Kafka Exporter certificate, may be null if Strimzi is issuing certificates.
129152 *
130- * @return Future which completes when the reconciliation is done
153+ * @return Future which completes when the reconciliation is done
131154 */
132- private Future <Void > certificatesSecret (Clock clock ) {
155+ private Future <Void > certificatesSecret (Clock clock , Secret certManagerSecret ) {
133156 if (kafkaExporter != null ) {
134157 return secretOperator .getAsync (reconciliation .namespace (), KafkaExporterResources .secretName (reconciliation .name ()))
135158 .compose (oldSecret -> {
136- Secret newSecret = kafkaExporter .generateCertificatesSecret (clusterCa , oldSecret , Util .isMaintenanceTimeWindowsSatisfied (reconciliation , maintenanceWindows , clock .instant ()));
137-
138- return secretOperator
139- .reconcile (reconciliation , reconciliation .namespace (), KafkaExporterResources .secretName (reconciliation .name ()), newSecret )
140- .compose (i -> {
141- certificateHash = CertUtils .getCertificateShortThumbprint (newSecret , Ca .SecretEntry .CRT .asKey (KafkaExporter .COMPONENT_TYPE ));
159+ Future <Secret > secretFuture ;
160+ if (CertificateManagerType .CERT_MANAGER_IO .equals (clusterCa .getType ())) {
161+ secretFuture = ReconcilerUtils .clusterCaPemTrustSet (reconciliation , secretOperator )
162+ .map (pemTrustSet -> kafkaExporter .generateCertificatesSecretForCertManagerCA (clusterCa , oldSecret , certManagerSecret , pemTrustSet ));
163+ } else {
164+ secretFuture = Future .succeededFuture (kafkaExporter .generateCertificatesSecretForStrimziCa (clusterCa , oldSecret , Util .isMaintenanceTimeWindowsSatisfied (reconciliation , maintenanceWindows , clock .instant ())));
165+ }
142166
167+ return secretFuture .compose (secret -> secretOperator .reconcile (reconciliation ,
168+ reconciliation .namespace (),
169+ KafkaExporterResources .secretName (reconciliation .name ()),
170+ secret )
171+ .compose (result -> {
172+ certificateHash = CertUtils .getCertificateShortThumbprint (secret , Ca .SecretEntry .CRT .asKey (KafkaExporter .COMPONENT_TYPE ));
143173 return Future .succeededFuture ();
144- });
174+ })) ;
145175 });
146176 } else {
147177 return secretOperator
0 commit comments