Skip to content

Commit 2d315a0

Browse files
Merge pull request #882 from stuggi/storage_request_webhook
Validate galera templates storageRequest via validation webhook
2 parents 8b2b3bf + aa9196a commit 2d315a0

5 files changed

Lines changed: 29 additions & 22 deletions

File tree

‎apis/core/v1beta1/openstackcontrolplane_webhook.go‎

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (r *OpenStackControlPlane) ValidateCreate() (admission.Warnings, error) {
9191
openstackcontrolplanelog.Info("validate create", "name", r.Name)
9292

9393
var allErrs field.ErrorList
94+
var allWarn []string
9495
basePath := field.NewPath("spec")
9596

9697
ctlplaneList := &OpenStackControlPlaneList{}
@@ -124,17 +125,14 @@ func (r *OpenStackControlPlane) ValidateCreate() (admission.Warnings, error) {
124125
)
125126
}
126127

127-
if err := r.ValidateCreateServices(basePath); err != nil {
128-
allErrs = append(allErrs, err...)
129-
}
130-
128+
allWarn, allErrs = r.ValidateCreateServices(basePath)
131129
if len(allErrs) != 0 {
132-
return nil, apierrors.NewInvalid(
130+
return allWarn, apierrors.NewInvalid(
133131
schema.GroupKind{Group: "core.openstack.org", Kind: "OpenStackControlPlane"},
134132
r.Name, allErrs)
135133
}
136134

137-
return nil, nil
135+
return allWarn, nil
138136
}
139137

140138
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
@@ -246,8 +244,9 @@ func (r *OpenStackControlPlane) checkDepsEnabled(name string) string {
246244
}
247245

248246
// ValidateCreateServices validating service definitions during the OpenstackControlPlane CR creation
249-
func (r *OpenStackControlPlane) ValidateCreateServices(basePath *field.Path) field.ErrorList {
247+
func (r *OpenStackControlPlane) ValidateCreateServices(basePath *field.Path) (admission.Warnings, field.ErrorList) {
250248
var errors field.ErrorList
249+
var warnings []string
251250

252251
errors = append(errors, r.ValidateServiceDependencies(basePath)...)
253252

@@ -304,7 +303,15 @@ func (r *OpenStackControlPlane) ValidateCreateServices(basePath *field.Path) fie
304303
errors = append(errors, r.Spec.Designate.Template.ValidateCreate(basePath.Child("designate").Child("template"))...)
305304
}
306305

307-
return errors
306+
if r.Spec.Galera.Enabled {
307+
for key, s := range *r.Spec.Galera.Templates {
308+
warn, err := s.ValidateCreate(basePath.Child("galera").Child("template").Key(key))
309+
errors = append(errors, err...)
310+
warnings = append(warnings, warn...)
311+
}
312+
}
313+
314+
return warnings, errors
308315
}
309316

310317
// ValidateUpdateServices validating service definitions during the OpenstackControlPlane CR update
@@ -497,7 +504,7 @@ func (r *OpenStackControlPlane) ValidateServiceDependencies(basePath *field.Path
497504

498505
if depErrorMsg := r.checkDepsEnabled("Telemetry.Ceilometer"); depErrorMsg != "" {
499506
err := field.Invalid(basePath.Child("telemetry").Child("template").Child("ceilometer").Child("enabled"),
500-
*r.Spec.Telemetry.Template.Ceilometer.Enabled, depErrorMsg)
507+
*r.Spec.Telemetry.Template.Ceilometer.Enabled, depErrorMsg)
501508
allErrs = append(allErrs, err)
502509
}
503510
}
@@ -507,7 +514,7 @@ func (r *OpenStackControlPlane) ValidateServiceDependencies(basePath *field.Path
507514

508515
if depErrorMsg := r.checkDepsEnabled("Telemetry.Autoscaling"); depErrorMsg != "" {
509516
err := field.Invalid(basePath.Child("telemetry").Child("template").Child("autoscaling").Child("enabled"),
510-
*r.Spec.Telemetry.Template.Autoscaling.Enabled, depErrorMsg)
517+
*r.Spec.Telemetry.Template.Autoscaling.Enabled, depErrorMsg)
511518
allErrs = append(allErrs, err)
512519
}
513520
}

‎apis/go.mod‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ require (
1616
github.com/openstack-k8s-operators/infra-operator/apis v0.3.1-0.20240622123909-205129589c38
1717
github.com/openstack-k8s-operators/ironic-operator/api v0.3.1-0.20240623150030-e53574c3da59
1818
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240623145456-c19b57192709
19-
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960
19+
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240624132705-6c8da3c0bbfd
2020
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240621144804-4b3c1fd10960
2121
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180
22-
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c
22+
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1
2323
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf
2424
github.com/openstack-k8s-operators/nova-operator/api v0.3.1-0.20240623110641-32e3cb3025cc
2525
github.com/openstack-k8s-operators/octavia-operator/api v0.3.1-0.20240623150031-5548ad9cd2a8

‎apis/go.sum‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,16 @@ github.com/openstack-k8s-operators/ironic-operator/api v0.3.1-0.20240623150030-e
108108
github.com/openstack-k8s-operators/ironic-operator/api v0.3.1-0.20240623150030-e53574c3da59/go.mod h1:Fwb2sOCgoTotPy5+CEk9Bi3PmGhTAFf7x6MYKCBuOlI=
109109
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240623145456-c19b57192709 h1:9cwQl85wJ9FP1ZC9aQ4ljtZHRyxJ6DL/Yx2ERXmjUYw=
110110
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240623145456-c19b57192709/go.mod h1:yfqcne2cL6A3JktjPmU4Jnnkd3Od4pLRG0TwmK6Oip0=
111-
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960 h1:9UpWmnaLZeN237m9YIHy6KxsSV3yPatNXryW2qabVKs=
112-
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:k9KuWN2LBtLbKHgcyh/0lrwk3Kr0cOAhiR3hi/mrwOQ=
111+
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240624132705-6c8da3c0bbfd h1:ZlZW1W+IEDNN5Vz5HG3iyQWn5kk3omno4i6J3snwy3w=
112+
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240624132705-6c8da3c0bbfd/go.mod h1:k9KuWN2LBtLbKHgcyh/0lrwk3Kr0cOAhiR3hi/mrwOQ=
113113
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240621144804-4b3c1fd10960 h1:e4lhh+OFKRZxW5r8zxcoIhQQmJF5RTUDP1HYgb/B+7E=
114114
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:zuPcZ5Kopr15AdfxvA0xqKIIGCZ0XbSe/0VHNKuvbEE=
115115
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240621144804-4b3c1fd10960 h1:EZFKu3UG317XzFpu+NSUyFl/+ZSfRhkyC+3PVp6913Q=
116116
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:v9iFrR8J5fZACS9W5pZau/4lwyWs/YmO4ezpDeoEFKU=
117117
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180 h1:urPMh7Wa8LJRHgc2SgYXuZQraBA1amusqxyRRCX5ANA=
118118
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180/go.mod h1:N8CKCTMEEtOhemnyMEcMlojUZlTmpICVliGxF21UQL0=
119-
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c h1:DBS/NK2sD3QpgTH8UrRs9cSSagyseXcKjLpYAuT9HsY=
120-
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c/go.mod h1:3kM7dn+fW16YplR9KWAVG4Kmk2reU+Pji7lvXopZ5do=
119+
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1 h1:NyDo2fqRLq8U66CBIy4wV8aKIdipZACYKnHSvJ9fuMY=
120+
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1/go.mod h1:FzdNGhUR1dH8E7INAg9sRJXpspug5OMDqqByI1/SEIY=
121121
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf h1:Ix6T1JLAP1N2hYoXXFun+nAkNdeoNeWx2m5rUWvNJLI=
122122
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf/go.mod h1:n1CV1VR6nK/yU0gIpZ02EvE33u/TBjzJTG85Wu1geIk=
123123
github.com/openstack-k8s-operators/nova-operator/api v0.3.1-0.20240623110641-32e3cb3025cc h1:XEdzsTQ0uiP3QOnDh5f19DvlAY/FRUWENgtz+Tlc7vo=

‎go.mod‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ require (
2525
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240623145456-c19b57192709
2626
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.3.1-0.20240621144804-4b3c1fd10960
2727
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.0.0-20240621144804-4b3c1fd10960
28-
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960
28+
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240624132705-6c8da3c0bbfd
2929
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240621144804-4b3c1fd10960
3030
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240621144804-4b3c1fd10960
3131
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180
32-
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c
32+
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1
3333
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf
3434
github.com/openstack-k8s-operators/nova-operator/api v0.3.1-0.20240623110641-32e3cb3025cc
3535
github.com/openstack-k8s-operators/octavia-operator/api v0.3.1-0.20240623150031-5548ad9cd2a8

‎go.sum‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ github.com/openstack-k8s-operators/lib-common/modules/ansible v0.3.1-0.202406211
120120
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:tP+nxk95PisCKJaXE/an2igG9lluxuOVhdmV9WtkR2s=
121121
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.0.0-20240621144804-4b3c1fd10960 h1:PHc/o3n3ae6Wjhc60rOSKhWb8iYIznE8mYgkrOy7ohQ=
122122
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.0.0-20240621144804-4b3c1fd10960/go.mod h1:GooNi6hM78cOUMjhBy0fXsZIcDTK1dUb1rlay170IJo=
123-
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960 h1:9UpWmnaLZeN237m9YIHy6KxsSV3yPatNXryW2qabVKs=
124-
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:k9KuWN2LBtLbKHgcyh/0lrwk3Kr0cOAhiR3hi/mrwOQ=
123+
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240624132705-6c8da3c0bbfd h1:ZlZW1W+IEDNN5Vz5HG3iyQWn5kk3omno4i6J3snwy3w=
124+
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240624132705-6c8da3c0bbfd/go.mod h1:k9KuWN2LBtLbKHgcyh/0lrwk3Kr0cOAhiR3hi/mrwOQ=
125125
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240621144804-4b3c1fd10960 h1:e4lhh+OFKRZxW5r8zxcoIhQQmJF5RTUDP1HYgb/B+7E=
126126
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:zuPcZ5Kopr15AdfxvA0xqKIIGCZ0XbSe/0VHNKuvbEE=
127127
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240621144804-4b3c1fd10960 h1:EZFKu3UG317XzFpu+NSUyFl/+ZSfRhkyC+3PVp6913Q=
@@ -130,8 +130,8 @@ github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.202406211448
130130
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:0h76CxD9g0z2Hk7fGFOZcjnzT1tQQ/yRNv3OXng+S/A=
131131
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180 h1:urPMh7Wa8LJRHgc2SgYXuZQraBA1amusqxyRRCX5ANA=
132132
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180/go.mod h1:N8CKCTMEEtOhemnyMEcMlojUZlTmpICVliGxF21UQL0=
133-
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c h1:DBS/NK2sD3QpgTH8UrRs9cSSagyseXcKjLpYAuT9HsY=
134-
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c/go.mod h1:3kM7dn+fW16YplR9KWAVG4Kmk2reU+Pji7lvXopZ5do=
133+
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1 h1:NyDo2fqRLq8U66CBIy4wV8aKIdipZACYKnHSvJ9fuMY=
134+
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1/go.mod h1:FzdNGhUR1dH8E7INAg9sRJXpspug5OMDqqByI1/SEIY=
135135
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf h1:Ix6T1JLAP1N2hYoXXFun+nAkNdeoNeWx2m5rUWvNJLI=
136136
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf/go.mod h1:n1CV1VR6nK/yU0gIpZ02EvE33u/TBjzJTG85Wu1geIk=
137137
github.com/openstack-k8s-operators/nova-operator/api v0.3.1-0.20240623110641-32e3cb3025cc h1:XEdzsTQ0uiP3QOnDh5f19DvlAY/FRUWENgtz+Tlc7vo=

0 commit comments

Comments
 (0)