Skip to content

Commit f8b3b5a

Browse files
stuggiopenshift-merge-bot[bot]
authored andcommitted
Watch KeystoneAPI status updates to reconcile
Adds watches of the Nova controller on the KeystoneAPI status to reconcile if e.g. the endpoint list changes. This triggers setting the new KeystoneAuthURL on the sub components to update their configuration. Depends-On: openstack-k8s-operators/keystone-operator#591 Jira: OSPRH-16994 Signed-off-by: Martin Schuppert <mschuppert@redhat.com>
1 parent a318f74 commit f8b3b5a

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed

controllers/nova_controller.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,6 +2077,37 @@ func (r *NovaReconciler) findObjectsForSrc(ctx context.Context, src client.Objec
20772077
return requests
20782078
}
20792079

2080+
func (r *NovaReconciler) findObjectForSrc(ctx context.Context, src client.Object) []reconcile.Request {
2081+
requests := []reconcile.Request{}
2082+
2083+
l := log.FromContext(ctx).WithName("Controllers").WithName("Nova")
2084+
2085+
crList := &novav1.NovaList{}
2086+
listOps := &client.ListOptions{
2087+
Namespace: src.GetNamespace(),
2088+
}
2089+
err := r.Client.List(ctx, crList, listOps)
2090+
if err != nil {
2091+
l.Error(err, fmt.Sprintf("listing %s for namespace: %s", crList.GroupVersionKind().Kind, src.GetNamespace()))
2092+
return requests
2093+
}
2094+
2095+
for _, item := range crList.Items {
2096+
l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace()))
2097+
2098+
requests = append(requests,
2099+
reconcile.Request{
2100+
NamespacedName: types.NamespacedName{
2101+
Name: item.GetName(),
2102+
Namespace: item.GetNamespace(),
2103+
},
2104+
},
2105+
)
2106+
}
2107+
2108+
return requests
2109+
}
2110+
20802111
func (r *NovaReconciler) memcachedNamespaceMapFunc(ctx context.Context, src client.Object) []reconcile.Request {
20812112

20822113
result := []reconcile.Request{}
@@ -2151,5 +2182,8 @@ func (r *NovaReconciler) SetupWithManager(mgr ctrl.Manager) error {
21512182
&memcachedv1.Memcached{},
21522183
handler.EnqueueRequestsFromMapFunc(r.memcachedNamespaceMapFunc),
21532184
).
2185+
Watches(&keystonev1.KeystoneAPI{},
2186+
handler.EnqueueRequestsFromMapFunc(r.findObjectForSrc),
2187+
builder.WithPredicates(keystonev1.KeystoneAPIStatusChangedPredicate)).
21542188
Complete(r)
21552189
}

test/functional/base_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ type NovaNames struct {
537537
MemcachedNamespace types.NamespacedName
538538
Cells map[string]CellNames
539539
NovaTopologies []types.NamespacedName
540+
KeystoneAPIName types.NamespacedName
540541
}
541542

542543
func GetNovaNames(novaName types.NamespacedName, cellNames []string) NovaNames {

test/functional/nova_reconfiguration_test.go

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import (
3939
"k8s.io/utils/ptr"
4040
)
4141

42-
func CreateNovaWith3CellsAndEnsureReady(novaNames NovaNames) {
42+
func CreateNovaWith3CellsAndEnsureReady(novaNames *NovaNames) {
4343
cell0 := novaNames.Cells["cell0"]
4444
cell1 := novaNames.Cells["cell1"]
4545
cell2 := novaNames.Cells["cell2"]
@@ -107,7 +107,8 @@ func CreateNovaWith3CellsAndEnsureReady(novaNames NovaNames) {
107107
spec["apiMessageBusInstance"] = cell0.TransportURLName.Name
108108

109109
DeferCleanup(th.DeleteInstance, CreateNova(novaNames.NovaName, spec))
110-
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(novaNames.NovaName.Namespace))
110+
novaNames.KeystoneAPIName = keystone.CreateKeystoneAPI(novaNames.NovaName.Namespace)
111+
DeferCleanup(keystone.DeleteKeystoneAPI, novaNames.KeystoneAPIName)
111112
memcachedSpec := infra.GetDefaultMemcachedSpec()
112113

113114
DeferCleanup(infra.DeleteMemcached, infra.CreateMemcached(novaNames.NovaName.Namespace, MemcachedInstance, memcachedSpec))
@@ -166,7 +167,7 @@ var _ = Describe("Nova reconfiguration", func() {
166167
// matchers
167168
// format.MaxLength = 0
168169

169-
CreateNovaWith3CellsAndEnsureReady(novaNames)
170+
CreateNovaWith3CellsAndEnsureReady(&novaNames)
170171
})
171172
When("cell1 is deleted", func() {
172173
It("cell cr is deleted", func() {
@@ -1178,4 +1179,52 @@ var _ = Describe("Nova reconfiguration", func() {
11781179
g.Expect(diff).To(BeEmpty())
11791180
}, timeout, interval).Should(Succeed())
11801181
})
1182+
1183+
It("updates the KeystoneAuthURL of the sub components if keystone internal endpoint changes", func() {
1184+
newInternalEndpoint := "https://keystone-internal"
1185+
1186+
keystone.UpdateKeystoneAPIEndpoint(novaNames.KeystoneAPIName, "internal", newInternalEndpoint)
1187+
logger.Info("Reconfigured")
1188+
1189+
SimulateReadyOfNovaTopServices()
1190+
th.SimulateJobSuccess(cell0.DBSyncJobName)
1191+
th.SimulateJobSuccess(cell1.DBSyncJobName)
1192+
th.SimulateJobSuccess(cell2.DBSyncJobName)
1193+
th.SimulateStatefulSetReplicaReady(cell0.ConductorStatefulSetName)
1194+
1195+
for _, cell := range []types.NamespacedName{cell0.ConductorName, cell1.ConductorName, cell2.ConductorName} {
1196+
Eventually(func(g Gomega) {
1197+
cond := GetNovaConductor(cell)
1198+
g.Expect(cond).ToNot(BeNil())
1199+
g.Expect(cond.Spec.KeystoneAuthURL).To(Equal(newInternalEndpoint))
1200+
}, timeout, interval).Should(Succeed())
1201+
}
1202+
1203+
for _, cell := range []types.NamespacedName{cell1.NoVNCProxyName, cell2.NoVNCProxyName} {
1204+
Eventually(func(g Gomega) {
1205+
vnc := GetNovaNoVNCProxy(cell)
1206+
g.Expect(vnc).ToNot(BeNil())
1207+
g.Expect(vnc.Spec.KeystoneAuthURL).To(Equal(newInternalEndpoint))
1208+
}, timeout, interval).Should(Succeed())
1209+
}
1210+
1211+
Eventually(func(g Gomega) {
1212+
api := GetNovaAPI(novaNames.APIName)
1213+
g.Expect(api).ToNot(BeNil())
1214+
g.Expect(api.Spec.KeystoneAuthURL).To(Equal(newInternalEndpoint))
1215+
}, timeout, interval).Should(Succeed())
1216+
1217+
Eventually(func(g Gomega) {
1218+
sch := GetNovaScheduler(novaNames.SchedulerName)
1219+
g.Expect(sch).ToNot(BeNil())
1220+
g.Expect(sch.Spec.KeystoneAuthURL).To(Equal(newInternalEndpoint))
1221+
}, timeout, interval).Should(Succeed())
1222+
1223+
Eventually(func(g Gomega) {
1224+
metadata := GetNovaMetadata(novaNames.MetadataName)
1225+
g.Expect(metadata).ToNot(BeNil())
1226+
g.Expect(metadata.Spec.KeystoneAuthURL).To(Equal(newInternalEndpoint))
1227+
}, timeout, interval).Should(Succeed())
1228+
})
1229+
11811230
})

0 commit comments

Comments
 (0)