Skip to content

Commit 675dad5

Browse files
Merge pull request #866 from shiftstack/cherry-pick-850-to-release-4.19
[release-4.19] OCPBUGS-55798: Sync OpenStack CA Bundles from legacy location
2 parents d381fe7 + d5af20b commit 675dad5

6 files changed

Lines changed: 80 additions & 9 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
kind: RoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
name: cloud-credential-operator
5+
namespace: openshift-config-managed
6+
annotations:
7+
capability.openshift.io/name: CloudCredential
8+
include.release.openshift.io/ibm-cloud-managed: "true"
9+
include.release.openshift.io/self-managed-high-availability: "true"
10+
subjects:
11+
- kind: ServiceAccount
12+
name: cloud-credential-operator
13+
namespace: openshift-cloud-credential-operator
14+
roleRef:
15+
kind: Role
16+
apiGroup: rbac.authorization.k8s.io
17+
name: cloud-credential-operator-role
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
name: cloud-credential-operator-role
5+
namespace: openshift-config-managed
6+
annotations:
7+
capability.openshift.io/name: CloudCredential
8+
include.release.openshift.io/ibm-cloud-managed: "true"
9+
include.release.openshift.io/self-managed-high-availability: "true"
10+
rules:
11+
- apiGroups:
12+
- ""
13+
resources:
14+
- configmaps
15+
resourceNames:
16+
- kube-cloud-config
17+
verbs:
18+
- "get"

manifests/01-config-role-binding.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ kind: RoleBinding
22
apiVersion: rbac.authorization.k8s.io/v1
33
metadata:
44
name: cloud-credential-operator
5-
namespace: openshift-config-managed
5+
namespace: openshift-config
66
annotations:
77
capability.openshift.io/name: CloudCredential
88
include.release.openshift.io/ibm-cloud-managed: "true"

manifests/01-config-role.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: rbac.authorization.k8s.io/v1
22
kind: Role
33
metadata:
44
name: cloud-credential-operator-role
5-
namespace: openshift-config-managed
5+
namespace: openshift-config
66
annotations:
77
capability.openshift.io/name: CloudCredential
88
include.release.openshift.io/ibm-cloud-managed: "true"
@@ -13,6 +13,8 @@ rules:
1313
resources:
1414
- configmaps
1515
resourceNames:
16-
- kube-cloud-config
16+
- cloud-provider-config
1717
verbs:
18-
- "get"
18+
- get
19+
- list
20+
- watch

pkg/operator/secretannotator/openstack/reconciler.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package openstack
1818

1919
import (
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{}
105107
type 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 {

pkg/operator/secretannotator/openstack/reconciler_test.go

Lines changed: 14 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,11 +189,13 @@ 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()
193+
fakeLiveClient := fake.NewClientBuilder().WithRuntimeObjects(ccmConfig).Build()
185194

186195
r := &ReconcileCloudCredSecret{
187196
Client: fakeClient,
188197
RootCredClient: fakeRootCredClient,
198+
LiveClient: fakeLiveClient,
189199
Logger: log.WithField("controller", "testController"),
190200
}
191201
_, err := r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{
@@ -270,12 +280,14 @@ func TestReconcileCloudCredSecret_Reconcile(t *testing.T) {
270280
t.Run(tc.name, func(t *testing.T) {
271281
secret := testSecret(tc.cloudsYAML)
272282
fakeClient := fake.NewClientBuilder().WithRuntimeObjects(infra, passthrough).Build()
273-
fakeRootCredClient := fake.NewClientBuilder().WithRuntimeObjects(secret).Build()
283+
fakeRootCredClient := fake.NewClientBuilder().WithRuntimeObjects(secret, ccmConfig).Build()
284+
fakeLiveClient := fake.NewClientBuilder().WithRuntimeObjects(ccmConfig).Build()
274285

275286
t.Logf("clouds.yaml: %s", tc.cloudsYAML)
276287
r := &ReconcileCloudCredSecret{
277288
Client: fakeClient,
278289
RootCredClient: fakeRootCredClient,
290+
LiveClient: fakeLiveClient,
279291
Logger: log.WithField("controller", "testController"),
280292
}
281293

0 commit comments

Comments
 (0)