Skip to content

Commit 2c4aedd

Browse files
Merge pull request openstack-k8s-operators#297 from booxter/dirty-hack-to-pass-mariadb-sync-failures
Hardcode neutron database and database-account CR names to `neutron`
2 parents ca38cd1 + 5331396 commit 2c4aedd

File tree

7 files changed

+55
-28
lines changed

7 files changed

+55
-28
lines changed

config/rbac/role.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ rules:
122122
- patch
123123
- update
124124
- watch
125+
- apiGroups:
126+
- mariadb.openstack.org
127+
resources:
128+
- mariadbaccounts
129+
verbs:
130+
- create
131+
- delete
132+
- get
133+
- list
134+
- patch
135+
- update
136+
- watch
137+
- apiGroups:
138+
- mariadb.openstack.org
139+
resources:
140+
- mariadbaccounts/finalizers
141+
verbs:
142+
- update
125143
- apiGroups:
126144
- mariadb.openstack.org
127145
resources:

controllers/neutronapi_controller.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ type NeutronAPIReconciler struct {
8888
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;patch;update;delete;
8989
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;patch;update;delete;
9090
// +kubebuilder:rbac:groups=mariadb.openstack.org,resources=mariadbdatabases,verbs=get;list;watch;create;update;patch;delete;
91+
// +kubebuilder:rbac:groups=mariadb.openstack.org,resources=mariadbaccounts,verbs=get;list;watch;create;update;patch;delete
92+
// +kubebuilder:rbac:groups=mariadb.openstack.org,resources=mariadbaccounts/finalizers,verbs=update
9193
// +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneapis,verbs=get;list;watch;
9294
// +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneservices,verbs=get;list;watch;create;update;patch;delete;
9395
// +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneendpoints,verbs=get;list;watch;create;update;patch;delete;
@@ -213,18 +215,15 @@ const (
213215
tlsAPIPublicField = ".spec.tls.api.public.secretName"
214216
)
215217

216-
var (
217-
allWatchFields = []string{
218-
passwordSecretField,
219-
caBundleSecretNameField,
220-
tlsAPIInternalField,
221-
tlsAPIPublicField,
222-
}
223-
)
218+
var allWatchFields = []string{
219+
passwordSecretField,
220+
caBundleSecretNameField,
221+
tlsAPIInternalField,
222+
tlsAPIPublicField,
223+
}
224224

225225
// SetupWithManager -
226226
func (r *NeutronAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
227-
228227
// index passwordSecretField
229228
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &neutronv1beta1.NeutronAPI{}, passwordSecretField, func(rawObj client.Object) []string {
230229
// Extract the secret name from the spec, if one is provided
@@ -277,6 +276,7 @@ func (r *NeutronAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Ma
277276
return ctrl.NewControllerManagedBy(mgr).
278277
For(&neutronv1beta1.NeutronAPI{}).
279278
Owns(&mariadbv1.MariaDBDatabase{}).
279+
Owns(&mariadbv1.MariaDBAccount{}).
280280
Owns(&batchv1.Job{}).
281281
Owns(&corev1.Service{}).
282282
Owns(&corev1.Secret{}).
@@ -400,21 +400,22 @@ func (r *NeutronAPIReconciler) reconcileInit(
400400

401401
// create neutron DB instance
402402
//
403-
db := mariadbv1.NewDatabase(
404-
instance.Name,
403+
db := mariadbv1.NewDatabaseWithNamespace(
404+
neutronapi.Database,
405405
instance.Spec.DatabaseUser,
406406
instance.Spec.Secret,
407407
map[string]string{
408408
"dbName": instance.Spec.DatabaseInstance,
409409
},
410+
neutronapi.Database,
411+
instance.Namespace,
410412
)
411413
// create or patch the DB
412414
ctrlResult, err := db.CreateOrPatchDBByName(
413415
ctx,
414416
helper,
415417
instance.Spec.DatabaseInstance,
416418
)
417-
418419
if err != nil {
419420
instance.Status.Conditions.Set(condition.FalseCondition(
420421
condition.DBReadyCondition,
@@ -574,7 +575,7 @@ func (r *NeutronAPIReconciler) reconcileInit(
574575
//
575576
// expose the service (create service and return the created endpoint URLs)
576577
//
577-
var neutronEndpoints = map[service.Endpoint]endpoint.Data{
578+
neutronEndpoints := map[service.Endpoint]endpoint.Data{
578579
service.EndpointPublic: {
579580
Port: neutronapi.NeutronPublicPort,
580581
},
@@ -799,7 +800,6 @@ func (r *NeutronAPIReconciler) reconcileNormal(ctx context.Context, instance *ne
799800
//
800801

801802
transportURL, op, err := r.transportURLCreateOrUpdate(instance)
802-
803803
if err != nil {
804804
instance.Status.Conditions.Set(condition.FalseCondition(
805805
condition.RabbitMqTransportURLReadyCondition,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240129151020-c9467a8fbbfc
1414
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240129151020-c9467a8fbbfc
1515
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240129151020-c9467a8fbbfc
16-
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240124160436-36095347284f
16+
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240208072109-4447f245e487
1717
github.com/openstack-k8s-operators/neutron-operator/api v0.1.1-0.20230824160722-048e30e1d426
1818
github.com/openstack-k8s-operators/ovn-operator/api v0.3.1-0.20240129231730-d76ba56d1e14
1919
go.uber.org/zap v1.26.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.202401291
246246
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240129151020-c9467a8fbbfc/go.mod h1:lf4VSkNgy2mPyf4tR5xBXs8wQU9TJ9BYfY/Ay9/JkP0=
247247
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240129151020-c9467a8fbbfc h1:1vqB6G8qvXH030JyVsx4acl5xtbCqwdbTHivc9f4vvY=
248248
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240129151020-c9467a8fbbfc/go.mod h1:ni4mvKeubWsTjKmcToJ+hIo7pJipM9hwiUv8qhm1R6Y=
249-
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240124160436-36095347284f h1:01HrDX32rjFdvbSOMfz0fBCfxK6Kqthv0BgvimWL7Vc=
250-
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240124160436-36095347284f/go.mod h1:gAIo5SMvTTgUomxGC51T3PHIyremhe8xUvz2xpbuCsI=
249+
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240208072109-4447f245e487 h1:CyrE+x+AuXjURsiqj+fxOSEbn73hjOvh9g6ZXD4eU9k=
250+
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240208072109-4447f245e487/go.mod h1:D4sr4UipU4qjyrcO2mjW8YlSm48AdkY69dloASUbNYE=
251251
github.com/openstack-k8s-operators/ovn-operator/api v0.3.1-0.20240129231730-d76ba56d1e14 h1:myQoacgZNtKCOQlpGYTXEStt+zvxw79DtiCGM987Fc4=
252252
github.com/openstack-k8s-operators/ovn-operator/api v0.3.1-0.20240129231730-d76ba56d1e14/go.mod h1:STNUzUkKShzw3QbVFMajJYN+AZUME8ULoOIm1qccJxM=
253253
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

test/functional/neutronapi_controller_test.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ var _ = Describe("NeutronAPI controller", func() {
392392
),
393393
)
394394
SimulateTransportURLReady(apiTransportURLName)
395-
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name})
395+
mariadb.SimulateMariaDBAccountCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
396+
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
396397
})
397398

398399
It("should create a Secret for 01-neutron.conf with the auth_url config option set based on the KeystoneAPI", func() {
@@ -782,10 +783,12 @@ var _ = Describe("NeutronAPI controller", func() {
782783
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(namespace))
783784
})
784785
It("Should set DBReady Condition and set DatabaseHostname Status when DB is Created", func() {
785-
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name})
786+
mariadb.SimulateMariaDBAccountCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
787+
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
786788
th.SimulateJobSuccess(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name + "-db-sync"})
787789
NeutronAPI := GetNeutronAPI(neutronAPIName)
788-
Expect(NeutronAPI.Status.DatabaseHostname).To(Equal("hostname-for-" + NeutronAPI.Spec.DatabaseInstance))
790+
hostname := "hostname-for-" + NeutronAPI.Spec.DatabaseInstance + "." + namespace + ".svc"
791+
Expect(NeutronAPI.Status.DatabaseHostname).To(Equal(hostname))
789792
th.ExpectCondition(
790793
neutronAPIName,
791794
ConditionGetterFunc(NeutronAPIConditionGetter),
@@ -832,7 +835,8 @@ var _ = Describe("NeutronAPI controller", func() {
832835
infra.SimulateMemcachedReady(memcachedName)
833836
DeferCleanup(DeleteOVNDBClusters, CreateOVNDBClusters(namespace))
834837
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(namespace))
835-
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name})
838+
mariadb.SimulateMariaDBAccountCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
839+
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
836840
th.SimulateJobSuccess(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name + "-db-sync"})
837841
keystone.SimulateKeystoneServiceReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})
838842
keystone.SimulateKeystoneEndpointReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})
@@ -941,7 +945,8 @@ var _ = Describe("NeutronAPI controller", func() {
941945
internalAPINADName := types.NamespacedName{Namespace: namespace, Name: "internalapi"}
942946
nad := th.CreateNetworkAttachmentDefinition(internalAPINADName)
943947
DeferCleanup(th.DeleteInstance, nad)
944-
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: name})
948+
mariadb.SimulateMariaDBAccountCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
949+
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
945950
th.SimulateJobSuccess(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name + "-db-sync"})
946951
keystone.SimulateKeystoneServiceReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})
947952
keystone.SimulateKeystoneEndpointReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})
@@ -983,7 +988,8 @@ var _ = Describe("NeutronAPI controller", func() {
983988
internalAPINADName := types.NamespacedName{Namespace: namespace, Name: "internalapi"}
984989
nad := th.CreateNetworkAttachmentDefinition(internalAPINADName)
985990
DeferCleanup(th.DeleteInstance, nad)
986-
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: name})
991+
mariadb.SimulateMariaDBAccountCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
992+
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
987993
th.SimulateJobSuccess(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name + "-db-sync"})
988994
keystone.SimulateKeystoneServiceReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})
989995
keystone.SimulateKeystoneEndpointReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})
@@ -1027,7 +1033,8 @@ var _ = Describe("NeutronAPI controller", func() {
10271033
internalAPINADName := types.NamespacedName{Namespace: namespace, Name: "internalapi"}
10281034
nad := th.CreateNetworkAttachmentDefinition(internalAPINADName)
10291035
DeferCleanup(th.DeleteInstance, nad)
1030-
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: name})
1036+
mariadb.SimulateMariaDBAccountCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
1037+
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
10311038
th.SimulateJobSuccess(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name + "-db-sync"})
10321039
keystone.SimulateKeystoneServiceReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})
10331040
keystone.SimulateKeystoneEndpointReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})
@@ -1103,7 +1110,8 @@ var _ = Describe("NeutronAPI controller", func() {
11031110
infra.SimulateMemcachedReady(memcachedName)
11041111
DeferCleanup(DeleteOVNDBClusters, CreateOVNDBClusters(namespace))
11051112
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(namespace))
1106-
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name})
1113+
mariadb.SimulateMariaDBAccountCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
1114+
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
11071115
th.SimulateJobSuccess(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name + "-db-sync"})
11081116
keystone.SimulateKeystoneServiceReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})
11091117
keystone.SimulateKeystoneEndpointReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})
@@ -1238,7 +1246,8 @@ var _ = Describe("NeutronAPI controller", func() {
12381246
infra.SimulateMemcachedReady(memcachedName)
12391247
DeferCleanup(DeleteOVNDBClusters, CreateOVNDBClusters(namespace))
12401248
DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(namespace))
1241-
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name})
1249+
mariadb.SimulateMariaDBAccountCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
1250+
mariadb.SimulateMariaDBDatabaseCompleted(types.NamespacedName{Namespace: namespace, Name: neutronapi.Database})
12421251
th.SimulateJobSuccess(types.NamespacedName{Namespace: namespace, Name: neutronAPIName.Name + "-db-sync"})
12431252
keystone.SimulateKeystoneServiceReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})
12441253
keystone.SimulateKeystoneEndpointReady(types.NamespacedName{Namespace: namespace, Name: "neutron"})

test/kuttl/common/assert_sample_deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ spec:
2727
secret: osp-secret
2828
serviceUser: neutron
2929
status:
30-
databaseHostname: openstack
30+
databaseHostname: openstack.neutron-kuttl-tests.svc
3131
transportURLSecret: rabbitmq-transport-url-neutron-neutron-transport
3232
readyCount: 1
3333
---

test/kuttl/tests/neutron_tls/01-assert.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
secretName: cert-neutron-public-svc
1818
caBundleSecretName: combined-ca-bundle
1919
status:
20-
databaseHostname: openstack
20+
databaseHostname: openstack.neutron-kuttl-tests.svc
2121
readyCount: 1
2222
---
2323
apiVersion: apps/v1

0 commit comments

Comments
 (0)