@@ -221,12 +221,11 @@ func (r *AutoscalingReconciler) Reconcile(ctx context.Context, req ctrl.Request)
221221
222222// fields to index to reconcile when change
223223const (
224- autoscalingPasswordSecretField = ".spec.secret"
225- autoscalingCaBundleSecretNameField = ".spec.tls.caBundleSecretName" //nolint:gosec // G101: Not actual credentials, just field path
226- autoscalingTLSAPIInternalField = ".spec.tls.api.internal.secretName"
227- autoscalingTLSAPIPublicField = ".spec.tls.api.public.secretName"
228- autoscalingTLSField = ".spec.tls.secretName"
229- topologyField = ".spec.topologyRef.Name"
224+ autoscalingPasswordSecretField = ".spec.aodh.secret" //nolint:gosec // G101: Not actual credentials, just field path
225+ autoscalingCaBundleSecretNameField = ".spec.aodh.tls.caBundleSecretName" //nolint:gosec // G101: Not actual credentials, just field path
226+ autoscalingTLSAPIInternalField = ".spec.aodh.tls.api.internal.secretName"
227+ autoscalingTLSAPIPublicField = ".spec.aodh.tls.api.public.secretName"
228+ topologyField = ".spec.aodh.topologyRef.Name"
230229)
231230
232231var (
@@ -235,7 +234,6 @@ var (
235234 autoscalingCaBundleSecretNameField ,
236235 autoscalingTLSAPIInternalField ,
237236 autoscalingTLSAPIPublicField ,
238- autoscalingTLSField ,
239237 topologyField ,
240238 }
241239)
@@ -538,7 +536,70 @@ func (r *AutoscalingReconciler) reconcileNormal(
538536 return ctrl.Result {}, err
539537 }
540538
539+ //
540+ // TLS input validation
541+ //
542+ // Validate the CA cert secret if provided
543+ if instance .Spec .Aodh .TLS .CaBundleSecretName != "" {
544+ hash , err := tls .ValidateCACertSecret (
545+ ctx ,
546+ helper .GetClient (),
547+ types.NamespacedName {
548+ Name : instance .Spec .Aodh .TLS .CaBundleSecretName ,
549+ Namespace : instance .Namespace ,
550+ },
551+ )
552+ if err != nil {
553+ if k8s_errors .IsNotFound (err ) {
554+ // Since the CA cert secret should have been manually created by the user and provided in the spec,
555+ // we treat this as a warning because it means that the service will not be able to start.
556+ instance .Status .Conditions .Set (condition .FalseCondition (
557+ condition .TLSInputReadyCondition ,
558+ condition .ErrorReason ,
559+ condition .SeverityWarning ,
560+ condition .TLSInputReadyWaitingMessage , instance .Spec .Aodh .TLS .CaBundleSecretName ))
561+ return ctrl.Result {}, nil
562+ }
563+ instance .Status .Conditions .Set (condition .FalseCondition (
564+ condition .TLSInputReadyCondition ,
565+ condition .ErrorReason ,
566+ condition .SeverityWarning ,
567+ condition .TLSInputErrorMessage ,
568+ err .Error ()))
569+ return ctrl.Result {}, err
570+ }
571+
572+ if hash != "" {
573+ configMapVars [tls .CABundleKey ] = env .SetValue (hash )
574+ }
575+ // Validate API service certs secrets
576+ certsHash , err := instance .Spec .Aodh .TLS .API .ValidateCertSecrets (ctx , helper , instance .Namespace )
577+ if err != nil {
578+ if k8s_errors .IsNotFound (err ) {
579+ instance .Status .Conditions .Set (condition .FalseCondition (
580+ condition .TLSInputReadyCondition ,
581+ condition .RequestedReason ,
582+ condition .SeverityInfo ,
583+ condition .TLSInputReadyWaitingMessage , err .Error ()))
584+ return ctrl.Result {}, nil
585+ }
586+ instance .Status .Conditions .Set (condition .FalseCondition (
587+ condition .TLSInputReadyCondition ,
588+ condition .ErrorReason ,
589+ condition .SeverityWarning ,
590+ condition .TLSInputErrorMessage ,
591+ err .Error ()))
592+ return ctrl.Result {}, err
593+ }
594+
595+ configMapVars [tls .TLSHashName ] = env .SetValue (certsHash )
596+ }
597+
598+ // all cert input checks out so report InputReady
599+ instance .Status .Conditions .MarkTrue (condition .TLSInputReadyCondition , condition .InputReadyMessage )
600+
541601 inputHash , hashChanged , err := r .createHashOfInputHashes (ctx , instance , configMapVars )
602+
542603 if err != nil {
543604 instance .Status .Conditions .Set (condition .FalseCondition (
544605 condition .ServiceConfigReadyCondition ,
@@ -886,6 +947,19 @@ func (r *AutoscalingReconciler) SetupWithManager(ctx context.Context, mgr ctrl.M
886947 }
887948 return nil
888949 }
950+
951+ // index autoscalingPasswordSecretField
952+ if err := mgr .GetFieldIndexer ().IndexField (context .Background (), & telemetryv1.Autoscaling {}, autoscalingPasswordSecretField , func (rawObj client.Object ) []string {
953+ // Extract the secret name from the spec, if one is provided
954+ cr := rawObj .(* telemetryv1.Autoscaling )
955+ if cr .Spec .Aodh .Secret == "" {
956+ return nil
957+ }
958+ return []string {cr .Spec .Aodh .Secret }
959+ }); err != nil {
960+ return err
961+ }
962+
889963 // index autoscalingCaBundleSecretNameField
890964 if err := mgr .GetFieldIndexer ().IndexField (context .Background (), & telemetryv1.Autoscaling {}, autoscalingCaBundleSecretNameField , func (rawObj client.Object ) []string {
891965 // Extract the secret name from the spec, if one is provided
@@ -981,6 +1055,7 @@ func (r *AutoscalingReconciler) findObjectsForSrc(ctx context.Context, src clien
9811055 }
9821056 err := r .List (ctx , crList , listOps )
9831057 if err != nil {
1058+ Log .Error (err , fmt .Sprintf ("listing %s for field: %s - %s" , crList .GroupVersionKind ().Kind , field , src .GetNamespace ()))
9841059 return []reconcile.Request {}
9851060 }
9861061
0 commit comments