Skip to content

Commit db1d8d6

Browse files
stephenfinmandre
authored andcommitted
openstack: Sync cacert from CCM to root credential
There's some rework needed around CCM and the docs to get users to start using the new location of the CA cert. That is not going to happen in 4.19, so for now we opt to simply sync from the old place to the new place and leave the existing docs in place. In a future release, we can fully remove the old place (with a release note) and remove this syncer. Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 94d5188 commit db1d8d6

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

pkg/operator/secretannotator/openstack/reconciler.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,30 @@ func (r *ReconcileCloudCredSecret) Reconcile(ctx context.Context, request reconc
163163
return reconcile.Result{}, err
164164
}
165165

166+
// Sync the cacert from its legacy location (the 'ca-bundle.pem' key of the
167+
// 'openshift-config / cloud-provider-config' CM) to the new place, if present.
168+
// TODO(stephenfin): Remove this syncer in a future release once CCM no longer
169+
// relies on the legacy place during bootstrapping.
170+
config := &corev1.ConfigMap{}
171+
err = r.RootCredClient.Get(context.Background(), types.NamespacedName{Namespace: "openshift-config", Name: "cloud-provider-config"}, config)
172+
if err != nil {
173+
r.Logger.Debugf("cloud provider config not found: %v", err)
174+
return reconcile.Result{}, err
175+
}
176+
177+
cacertUpdated := false
178+
if ccmCACert := config.Data["ca-bundle.pem"]; ccmCACert != cacert {
179+
cacert = ccmCACert
180+
cacertUpdated = true
181+
}
182+
166183
clouds, cloudsUpdated, err := r.fixInvalidCACertFile(clouds)
167184
if err != nil {
168185
r.Logger.WithError(err).Error("errored checking clouds.yaml")
169186
return reconcile.Result{}, err
170187
}
171188

172-
if cloudsUpdated {
189+
if cloudsUpdated || cacertUpdated {
173190
openstack.SetRootCloudCredentialsSecretData(secret, clouds, cacert)
174191
err := r.RootCredClient.Update(context.TODO(), secret)
175192
if err != nil {

pkg/operator/secretannotator/openstack/reconciler_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ func TestReconcileCloudCredSecret_Reconcile(t *testing.T) {
108108
},
109109
}
110110

111+
ccmConfig := &corev1.ConfigMap{
112+
ObjectMeta: metav1.ObjectMeta{
113+
Name: "cloud-provider-config",
114+
Namespace: "openshift-config",
115+
},
116+
Data: map[string]string{},
117+
}
118+
111119
/*
112120
Test parsing of CCO configuration and the resulting annotation of the
113121
root secret. Most of this is boilerplate behaviour.
@@ -181,7 +189,7 @@ func TestReconcileCloudCredSecret_Reconcile(t *testing.T) {
181189
secret := testSecret(fmt.Sprintf(cloudsWithCACert, correctCACertFile))
182190
existing := append(tc.existing, infra, testOperatorConfig(tc.mode))
183191
fakeClient := fake.NewClientBuilder().WithRuntimeObjects(existing...).Build()
184-
fakeRootCredClient := fake.NewClientBuilder().WithRuntimeObjects(secret).Build()
192+
fakeRootCredClient := fake.NewClientBuilder().WithRuntimeObjects(secret, ccmConfig).Build()
185193

186194
r := &ReconcileCloudCredSecret{
187195
Client: fakeClient,
@@ -270,7 +278,7 @@ func TestReconcileCloudCredSecret_Reconcile(t *testing.T) {
270278
t.Run(tc.name, func(t *testing.T) {
271279
secret := testSecret(tc.cloudsYAML)
272280
fakeClient := fake.NewClientBuilder().WithRuntimeObjects(infra, passthrough).Build()
273-
fakeRootCredClient := fake.NewClientBuilder().WithRuntimeObjects(secret).Build()
281+
fakeRootCredClient := fake.NewClientBuilder().WithRuntimeObjects(secret, ccmConfig).Build()
274282

275283
t.Logf("clouds.yaml: %s", tc.cloudsYAML)
276284
r := &ReconcileCloudCredSecret{

0 commit comments

Comments
 (0)