Skip to content

Commit 4455e7e

Browse files
committed
test fixes
1 parent b9c874d commit 4455e7e

7 files changed

Lines changed: 46 additions & 22 deletions

File tree

apis/core/v1beta1/openstackcontrolplane_conversion.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,19 @@ func (src *OpenStackControlPlane) convertKeystoneTemplateSpecifics(dstRaw conver
120120
}
121121

122122
// Handle field conversion from DatabaseInstance (v1beta1) to DatabaseName (v1beta2)
123-
// The JSON marshaling won't handle this field name change automatically
124123
if src.Spec.Keystone.Template.DatabaseInstance != "" {
125124
v1beta2Template.DatabaseName = src.Spec.Keystone.Template.DatabaseInstance
126125
openstackcontrolplaneconversionlog.V(1).Info("Converted DatabaseInstance to DatabaseName",
127126
"value", src.Spec.Keystone.Template.DatabaseInstance)
128127
}
129128

129+
// Apply defaults that might have been lost during JSON marshaling
130+
// APITimeout has default: 60, minimum: 10 in the CRD
131+
if v1beta2Template.APITimeout == 0 {
132+
v1beta2Template.APITimeout = 60
133+
openstackcontrolplaneconversionlog.V(1).Info("Applied default APITimeout for v1beta2 template", "value", 60)
134+
}
135+
130136
// Set the converted template
131137
templateField.Set(reflect.ValueOf(&v1beta2Template))
132138

@@ -174,7 +180,6 @@ func (dst *OpenStackControlPlane) convertKeystoneTemplateSpecificsFrom(srcRaw co
174180
}
175181

176182
// Handle field conversion from DatabaseName (v1beta2) to DatabaseInstance (v1beta1)
177-
// The JSON marshaling won't handle this field name change automatically
178183
// We need to access the DatabaseName field from the v1beta2 template using reflection
179184
v1beta2TemplateValue := templateField.Elem()
180185
databaseNameField := v1beta2TemplateValue.FieldByName("DatabaseName")
@@ -184,6 +189,13 @@ func (dst *OpenStackControlPlane) convertKeystoneTemplateSpecificsFrom(srcRaw co
184189
"value", databaseNameField.String())
185190
}
186191

192+
// Apply defaults that might have been lost during JSON marshaling
193+
// APITimeout has default: 60, minimum: 10 in the CRD
194+
if v1beta1Template.APITimeout == 0 {
195+
v1beta1Template.APITimeout = 60
196+
openstackcontrolplaneconversionlog.V(1).Info("Applied default APITimeout for v1beta1 template", "value", 60)
197+
}
198+
187199
dst.Spec.Keystone.Template = &v1beta1Template
188200

189201
openstackcontrolplaneconversionlog.V(1).Info("Successfully converted Keystone template from v1beta2 to v1beta1")

apis/core/v1beta2/funcs.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,37 @@ package v1beta2
1818

1919
import (
2020
"context"
21+
"fmt"
2122

2223
keystonev2 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta2"
2324
corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1"
2425
"k8s.io/apimachinery/pkg/util/validation/field"
2526
"sigs.k8s.io/controller-runtime/pkg/client"
2627
)
2728

28-
// KeystoneDefault is a no-op to be compatible with the old API
29-
// This function can be removed once openstack-operator is not calling the
30-
// Default method on the keystone spec anymore.
29+
// KeystoneDefault applies default values to KeystoneAPISpecCore fields
3130
func KeystoneDefault(spec *keystonev2.KeystoneAPISpecCore) {
32-
// nothing to do
31+
// Apply default APITimeout if not set (minimum is 10, default is 60)
32+
if spec.APITimeout == 0 {
33+
spec.APITimeout = 60
34+
}
3335
}
3436

35-
// KeystoneSetDefaultRouteAnnotations is a no-op to be compatible with the old API
36-
// This function can be removed once openstack-operator is not calling the
37-
// SetDefaultRouteAnnotations method on the keystone spec anymore.
38-
func KeystoneSetDefaultRouteAnnotations(spec *keystonev2.KeystoneAPISpecCore) {
39-
// nothing to do
37+
// KeystoneSetDefaultRouteAnnotations sets default route timeout annotations for Keystone
38+
func KeystoneSetDefaultRouteAnnotations(spec *keystonev2.KeystoneAPISpecCore, annotations map[string]string) {
39+
const haProxyAnno = "haproxy.router.openshift.io/timeout"
40+
const keystoneAnno = "api.keystone.openstack.org/timeout"
41+
42+
// Set timeout from APITimeout field (defaults to 60 seconds)
43+
timeout := fmt.Sprintf("%ds", spec.APITimeout)
44+
45+
// Only set defaults if annotations don't already exist
46+
if _, exists := annotations[haProxyAnno]; !exists {
47+
annotations[haProxyAnno] = timeout
48+
}
49+
if _, exists := annotations[keystoneAnno]; !exists {
50+
annotations[keystoneAnno] = timeout
51+
}
4052
}
4153

4254
// KeystoneValidateCreate validates if KeystoneAPI fields are compatible

apis/core/v1beta2/openstackcontrolplane_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ func (r *OpenStackControlPlane) DefaultServices() {
868868
}
869869
KeystoneDefault(r.Spec.Keystone.Template)
870870
initializeOverrideSpec(&r.Spec.Keystone.APIOverride.Route, true)
871-
KeystoneSetDefaultRouteAnnotations(r.Spec.Keystone.Template)
871+
KeystoneSetDefaultRouteAnnotations(r.Spec.Keystone.Template, r.Spec.Keystone.APIOverride.Route.Annotations)
872872
}
873873

874874
// Manila

controllers/core/openstackcontrolplane_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
networkv1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1"
3131
redisv1 "github.com/openstack-k8s-operators/infra-operator/apis/redis/v1beta1"
3232
ironicv1 "github.com/openstack-k8s-operators/ironic-operator/api/v1beta1"
33-
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
33+
keystonev2 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta2"
3434
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
3535
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
3636
common_helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
@@ -694,7 +694,7 @@ func (r *OpenStackControlPlaneReconciler) SetupWithManager(
694694
Owns(&corev1.Secret{}).
695695
Owns(&mariadbv1.Galera{}).
696696
Owns(&memcachedv1.Memcached{}).
697-
Owns(&keystonev1.KeystoneAPI{}).
697+
Owns(&keystonev2.KeystoneAPI{}).
698698
Owns(&placementv1.PlacementAPI{}).
699699
Owns(&glancev1.Glance{}).
700700
Owns(&cinderv1.Cinder{}).

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func init() {
103103
utilruntime.Must(corev1.AddToScheme(scheme))
104104
utilruntime.Must(dataplanev1.AddToScheme(scheme))
105105
utilruntime.Must(keystonev1.AddToScheme(scheme))
106+
utilruntime.Must(keystonev2.AddToScheme(scheme))
106107
utilruntime.Must(mariadbv1.AddToScheme(scheme))
107108
utilruntime.Must(memcachedv1.AddToScheme(scheme))
108109
utilruntime.Must(rabbitmqclusterv2.AddToScheme(scheme))
@@ -135,7 +136,6 @@ func init() {
135136
utilruntime.Must(operatorv1beta1.AddToScheme(scheme))
136137
utilruntime.Must(topologyv1.AddToScheme(scheme))
137138
utilruntime.Must(corev1beta2.AddToScheme(scheme))
138-
utilruntime.Must(keystonev2.AddToScheme(scheme))
139139
// +kubebuilder:scaffold:scheme
140140
}
141141

tests/functional/ctlplane/base_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ func GetDefaultOpenStackControlPlaneSpec() map[string]interface{} {
520520
},
521521
}
522522
keystoneTemplate := map[string]interface{}{
523-
"databaseInstance": names.KeystoneAPIName.Name,
524-
"secret": "osp-secret",
523+
"databaseName": names.KeystoneAPIName.Name,
524+
"secret": "osp-secret",
525525
}
526526
ironicTemplate := map[string]interface{}{
527527
"ironicConductors": []interface{}{},

tests/functional/ctlplane/openstackoperator_controller_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,8 +1306,8 @@ var _ = Describe("OpenStackOperator controller", func() {
13061306
},
13071307
},
13081308
"template": map[string]interface{}{
1309-
"databaseInstance": names.KeystoneAPIName.Name,
1310-
"secret": "osp-secret",
1309+
"databaseName": names.KeystoneAPIName.Name,
1310+
"secret": "osp-secret",
13111311
},
13121312
}
13131313
DeferCleanup(
@@ -2003,7 +2003,7 @@ var _ = Describe("OpenStackOperator controller", func() {
20032003

20042004
It("rejects the OpenStackControlPlane if its name is not that same as the OpenStackVersion's name", func() {
20052005
raw := map[string]interface{}{
2006-
"apiVersion": "core.openstack.org/v1beta1",
2006+
"apiVersion": "core.openstack.org/v1beta2",
20072007
"kind": "OpenStackControlPlane",
20082008
"metadata": map[string]interface{}{
20092009
"name": names.OpenStackControlplaneName.Name,
@@ -2035,7 +2035,7 @@ var _ = Describe("OpenStackOperator controller", func() {
20352035

20362036
It("accepts the OpenStackControlPlane if its name is the same as the OpenStackVersion's name", func() {
20372037
raw := map[string]interface{}{
2038-
"apiVersion": "core.openstack.org/v1beta1",
2038+
"apiVersion": "core.openstack.org/v1beta2",
20392039
"kind": "OpenStackControlPlane",
20402040
"metadata": map[string]interface{}{
20412041
"name": names.OpenStackVersionName2.Name,
@@ -2549,7 +2549,7 @@ var _ = Describe("OpenStackOperator Webhook", func() {
25492549
spec := GetDefaultOpenStackControlPlaneSpec()
25502550
spec["tls"] = GetTLSPublicSpec()
25512551
raw := map[string]interface{}{
2552-
"apiVersion": "core.openstack.org/v1beta1",
2552+
"apiVersion": "core.openstack.org/v1beta2",
25532553
"kind": "OpenStackControlPlane",
25542554
"metadata": map[string]interface{}{
25552555
"name": "openstack",

0 commit comments

Comments
 (0)