@@ -63,6 +63,7 @@ const (
6363 deploymentUpdated = "DeploymentUpdated"
6464 serviceCreated = "ServiceCreated"
6565 certificateCreated = "CertificateCreated"
66+ certificateUpdated = "CertificateUpdated"
6667 serviceUpdated = "ServiceUpdated"
6768)
6869
@@ -176,7 +177,6 @@ func (r *Reconciler) reconcileService(ctx context.Context, sink *sinks.Integrati
176177}
177178
178179func (r * Reconciler ) reconcileIntegrationSinkCertificate (ctx context.Context , sink * sinks.IntegrationSink ) (* cmv1.Certificate , error ) {
179-
180180 if f := feature .FromContext (ctx ); ! f .IsStrictTransportEncryption () && ! f .IsPermissiveTransportEncryption () {
181181 return nil , r .deleteIntegrationSinkCertificate (ctx , sink )
182182 }
@@ -188,22 +188,41 @@ func (r *Reconciler) reconcileIntegrationSinkCertificate(ctx context.Context, si
188188 return nil , fmt .Errorf ("no cert-manager certificate lister created yet, this should rarely happen and recover" )
189189 }
190190
191- cert , err := (* cmCertificateLister ).Certificates (sink . Namespace ) .Get (expected .Name )
191+ curr , err := (* cmCertificateLister ).Certificates (expected . GetNamespace ()) .Get (expected .GetName () )
192192 if apierrors .IsNotFound (err ) {
193- cert , err := r .certManagerClient . CertmanagerV1 (). Certificates ( sink . Namespace ). Create ( ctx , expected , metav1. CreateOptions {} )
193+ created , err := r .createCertificate ( ctx , sink , expected )
194194 if err != nil {
195- return nil , fmt . Errorf ( "creating new Certificate: %v" , err )
195+ return nil , err
196196 }
197- controller .GetEventRecorder (ctx ).Eventf (sink , corev1 .EventTypeNormal , certificateCreated , "Certificate created %q" , cert .Name )
198- } else if err != nil {
199- return nil , fmt .Errorf ("getting Certificate: %v" , err )
200- } else if ! metav1 .IsControlledBy (cert , sink ) {
201- return nil , fmt .Errorf ("Certificate %q is not owned by IntegrationSink %q" , cert .Name , sink .Name )
202- } else {
203- logging .FromContext (ctx ).Debugw ("Reusing existing Certificate" , zap .Any ("Certificate" , cert ))
197+ if ! sink .Status .PropagateCertificateStatus (created .Status ) {
198+ // Wait for Certificate to become ready before continuing.
199+ return nil , controller .NewSkipKey ("" )
200+ }
201+ return created , nil
202+ }
203+ if err != nil {
204+ return nil , fmt .Errorf ("failed to get certificate %s/%s: %w" , expected .GetNamespace (), expected .GetName (), err )
204205 }
205206
206- return cert , nil
207+ if equality .Semantic .DeepDerivative (expected .Spec , curr .Spec ) &&
208+ equality .Semantic .DeepDerivative (expected .Labels , curr .Labels ) &&
209+ equality .Semantic .DeepDerivative (expected .Annotations , curr .Annotations ) {
210+ if ! sink .Status .PropagateCertificateStatus (curr .Status ) {
211+ // Wait for Certificate to become ready before continuing.
212+ return nil , controller .NewSkipKey ("" )
213+ }
214+ return curr , nil
215+ }
216+ expected .ResourceVersion = curr .ResourceVersion
217+ updated , err := r .updateCertificate (ctx , sink , expected )
218+ if err != nil {
219+ return nil , err
220+ }
221+ if ! sink .Status .PropagateCertificateStatus (updated .Status ) {
222+ // Wait for Certificate to become ready before continuing.
223+ return nil , controller .NewSkipKey ("" )
224+ }
225+ return updated , nil
207226}
208227
209228func (r * Reconciler ) deleteIntegrationSinkCertificate (ctx context.Context , sink * sinks.IntegrationSink ) error {
@@ -342,3 +361,21 @@ func integrationSinkCertificate(sink *sinks.IntegrationSink) *cmv1.Certificate {
342361 ),
343362 )
344363}
364+
365+ func (r * Reconciler ) createCertificate (ctx context.Context , sink * sinks.IntegrationSink , expected * cmv1.Certificate ) (* cmv1.Certificate , error ) {
366+ created , err := r .certManagerClient .CertmanagerV1 ().Certificates (expected .GetNamespace ()).Create (ctx , expected , metav1.CreateOptions {})
367+ if err != nil {
368+ return nil , fmt .Errorf ("creating new Certificate %s/%s: %w" , expected .GetNamespace (), expected .GetName (), err )
369+ }
370+ controller .GetEventRecorder (ctx ).Eventf (sink , corev1 .EventTypeNormal , certificateCreated , "Certificate created %q" , expected .GetName ())
371+ return created , nil
372+ }
373+
374+ func (r * Reconciler ) updateCertificate (ctx context.Context , sink * sinks.IntegrationSink , expected * cmv1.Certificate ) (* cmv1.Certificate , error ) {
375+ updated , err := r .certManagerClient .CertmanagerV1 ().Certificates (expected .GetNamespace ()).Update (ctx , expected , metav1.UpdateOptions {})
376+ if err != nil {
377+ return nil , fmt .Errorf ("failed to update certificate %s/%s: %w" , expected .GetNamespace (), expected .GetName (), err )
378+ }
379+ controller .GetEventRecorder (ctx ).Event (sink , corev1 .EventTypeNormal , certificateUpdated , expected .GetName ())
380+ return updated , nil
381+ }
0 commit comments