@@ -18,6 +18,7 @@ package openstack
1818
1919import (
2020 "context"
21+ "errors"
2122 "fmt"
2223 "time"
2324
@@ -52,6 +53,7 @@ func NewReconciler(c client.Client, mgr manager.Manager) reconcile.Reconciler {
5253 r := & ReconcileCloudCredSecret {
5354 Client : c ,
5455 RootCredClient : mgr .GetClient (),
56+ LiveClient : utils .LiveClient (mgr ),
5557 Logger : log .WithField ("controller" , constants .SecretAnnotatorControllerName ),
5658 }
5759
@@ -105,6 +107,7 @@ var _ reconcile.Reconciler = &ReconcileCloudCredSecret{}
105107type ReconcileCloudCredSecret struct {
106108 Client client.Client
107109 RootCredClient client.Client
110+ LiveClient client.Client
108111 Logger log.FieldLogger
109112}
110113
@@ -134,7 +137,7 @@ func (r *ReconcileCloudCredSecret) Reconcile(ctx context.Context, request reconc
134137 }
135138 if conflict {
136139 r .Logger .Error ("configuration conflict between legacy configmap and operator config" )
137- return reconcile.Result {}, fmt . Errorf ("configuration conflict" )
140+ return reconcile.Result {}, errors . New ("configuration conflict" )
138141 }
139142 if mode == operatorv1 .CloudCredentialsModeManual {
140143 r .Logger .Info ("operator in disabled / manual mode" )
@@ -146,9 +149,11 @@ func (r *ReconcileCloudCredSecret) Reconcile(ctx context.Context, request reconc
146149 default :
147150 const msg = "OpenStack only supports Passthrough mode"
148151 r .Logger .Error (msg )
149- return reconcile.Result {}, fmt . Errorf (msg )
152+ return reconcile.Result {}, errors . New (msg )
150153 }
151154
155+ r .Logger .Info ("verifying clouds.yaml and syncing cacert (if any)" )
156+
152157 secret := & corev1.Secret {}
153158 err = r .RootCredClient .Get (context .Background (), request .NamespacedName , secret )
154159 if err != nil {
@@ -162,13 +167,30 @@ func (r *ReconcileCloudCredSecret) Reconcile(ctx context.Context, request reconc
162167 return reconcile.Result {}, err
163168 }
164169
170+ // Sync the cacert from its legacy location (the 'ca-bundle.pem' key of the
171+ // 'openshift-config / cloud-provider-config' CM) to the new place, if present.
172+ // TODO(stephenfin): Remove this syncer in a future release once CCM no longer
173+ // relies on the legacy place during bootstrapping.
174+ config := & corev1.ConfigMap {}
175+ err = r .LiveClient .Get (context .Background (), types.NamespacedName {Namespace : "openshift-config" , Name : "cloud-provider-config" }, config )
176+ if err != nil {
177+ r .Logger .Debugf ("cloud provider config not found: %v" , err )
178+ return reconcile.Result {}, err
179+ }
180+
181+ cacertUpdated := false
182+ if ccmCACert := config .Data ["ca-bundle.pem" ]; ccmCACert != cacert {
183+ cacert = ccmCACert
184+ cacertUpdated = true
185+ }
186+
165187 clouds , cloudsUpdated , err := r .fixInvalidCACertFile (clouds )
166188 if err != nil {
167189 r .Logger .WithError (err ).Error ("errored checking clouds.yaml" )
168190 return reconcile.Result {}, err
169191 }
170192
171- if cloudsUpdated {
193+ if cloudsUpdated || cacertUpdated {
172194 openstack .SetRootCloudCredentialsSecretData (secret , clouds , cacert )
173195 err := r .RootCredClient .Update (context .TODO (), secret )
174196 if err != nil {
0 commit comments