Skip to content

Commit

Permalink
Validate galera templates storageRequest via validation webhook
Browse files Browse the repository at this point in the history
Notify the enduser if the configured DB storageRequest is
too low for production use. It is not blocking to allow lower
settings for test/ci systems. The output would be like:

$ oc apply -n openstack -f core_v1beta1_openstackcontrolplane_galera_network_isolation_3replicas.yaml
Warning: spec.galera.template[openstack-cell1].storageRequest: 1G is not appropriate for production! For production use at least 5G!
Warning: spec.galera.template[openstack].storageRequest: 500M is not appropriate for production! For production use at least 5G!

Depends-On: openstack-k8s-operators/lib-common#522
Depends-On: openstack-k8s-operators/mariadb-operator#234

Signed-off-by: Martin Schuppert <mschuppert@redhat.com>
  • Loading branch information
stuggi committed Jun 24, 2024
1 parent fe6804f commit d37b929
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
27 changes: 17 additions & 10 deletions apis/core/v1beta1/openstackcontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (r *OpenStackControlPlane) ValidateCreate() (admission.Warnings, error) {
openstackcontrolplanelog.Info("validate create", "name", r.Name)

var allErrs field.ErrorList
var allWarn []string
basePath := field.NewPath("spec")

ctlplaneList := &OpenStackControlPlaneList{}
Expand Down Expand Up @@ -124,17 +125,14 @@ func (r *OpenStackControlPlane) ValidateCreate() (admission.Warnings, error) {
)
}

if err := r.ValidateCreateServices(basePath); err != nil {
allErrs = append(allErrs, err...)
}

allWarn, allErrs = r.ValidateCreateServices(basePath)
if len(allErrs) != 0 {
return nil, apierrors.NewInvalid(
return allWarn, apierrors.NewInvalid(
schema.GroupKind{Group: "core.openstack.org", Kind: "OpenStackControlPlane"},
r.Name, allErrs)
}

return nil, nil
return allWarn, nil
}

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

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

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

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

return errors
if r.Spec.Galera.Enabled {
for key, s := range *r.Spec.Galera.Templates {
warn, err := s.ValidateCreate(basePath.Child("galera").Child("template").Key(key))
errors = append(errors, err...)
warnings = append(warnings, warn...)
}
}

return warnings, errors
}

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

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

if depErrorMsg := r.checkDepsEnabled("Telemetry.Autoscaling"); depErrorMsg != "" {
err := field.Invalid(basePath.Child("telemetry").Child("template").Child("autoscaling").Child("enabled"),
*r.Spec.Telemetry.Template.Autoscaling.Enabled, depErrorMsg)
*r.Spec.Telemetry.Template.Autoscaling.Enabled, depErrorMsg)
allErrs = append(allErrs, err)
}
}
Expand Down
4 changes: 4 additions & 0 deletions apis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,7 @@ replace github.com/openshift/api => github.com/openshift/api v0.0.0-202304141430

// custom RabbitmqClusterSpecCore for OpenStackControlplane (v2.6.0_patches_tag)
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20240612145157-629e537392b3 //allow-merging

replace github.com/openstack-k8s-operators/mariadb-operator/api => github.com/stuggi/mariadb-operator/api v0.0.0-20240624125703-7f344bbba641

replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/stuggi/lib-common/modules/common v0.0.0-20240624123550-13c4ff7caf62
8 changes: 4 additions & 4 deletions apis/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,12 @@ github.com/openstack-k8s-operators/ironic-operator/api v0.3.1-0.20240623150030-e
github.com/openstack-k8s-operators/ironic-operator/api v0.3.1-0.20240623150030-e53574c3da59/go.mod h1:Fwb2sOCgoTotPy5+CEk9Bi3PmGhTAFf7x6MYKCBuOlI=
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240623145456-c19b57192709 h1:9cwQl85wJ9FP1ZC9aQ4ljtZHRyxJ6DL/Yx2ERXmjUYw=
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240623145456-c19b57192709/go.mod h1:yfqcne2cL6A3JktjPmU4Jnnkd3Od4pLRG0TwmK6Oip0=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960 h1:9UpWmnaLZeN237m9YIHy6KxsSV3yPatNXryW2qabVKs=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:k9KuWN2LBtLbKHgcyh/0lrwk3Kr0cOAhiR3hi/mrwOQ=
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240621144804-4b3c1fd10960 h1:e4lhh+OFKRZxW5r8zxcoIhQQmJF5RTUDP1HYgb/B+7E=
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:zuPcZ5Kopr15AdfxvA0xqKIIGCZ0XbSe/0VHNKuvbEE=
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240621144804-4b3c1fd10960 h1:EZFKu3UG317XzFpu+NSUyFl/+ZSfRhkyC+3PVp6913Q=
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:v9iFrR8J5fZACS9W5pZau/4lwyWs/YmO4ezpDeoEFKU=
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180 h1:urPMh7Wa8LJRHgc2SgYXuZQraBA1amusqxyRRCX5ANA=
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180/go.mod h1:N8CKCTMEEtOhemnyMEcMlojUZlTmpICVliGxF21UQL0=
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c h1:DBS/NK2sD3QpgTH8UrRs9cSSagyseXcKjLpYAuT9HsY=
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c/go.mod h1:3kM7dn+fW16YplR9KWAVG4Kmk2reU+Pji7lvXopZ5do=
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf h1:Ix6T1JLAP1N2hYoXXFun+nAkNdeoNeWx2m5rUWvNJLI=
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf/go.mod h1:n1CV1VR6nK/yU0gIpZ02EvE33u/TBjzJTG85Wu1geIk=
github.com/openstack-k8s-operators/nova-operator/api v0.3.1-0.20240623110641-32e3cb3025cc h1:XEdzsTQ0uiP3QOnDh5f19DvlAY/FRUWENgtz+Tlc7vo=
Expand Down Expand Up @@ -160,6 +156,10 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stuggi/lib-common/modules/common v0.0.0-20240624123550-13c4ff7caf62 h1:MXrFgYuYtR1kSX3zsx3xyQlgJUv12k6HIZJMiwyMU+4=
github.com/stuggi/lib-common/modules/common v0.0.0-20240624123550-13c4ff7caf62/go.mod h1:k9KuWN2LBtLbKHgcyh/0lrwk3Kr0cOAhiR3hi/mrwOQ=
github.com/stuggi/mariadb-operator/api v0.0.0-20240624125703-7f344bbba641 h1:Snx1sKW1H7ofrxOHXBeZ0sU2kVjVxQrXVdSDiupZFiI=
github.com/stuggi/mariadb-operator/api v0.0.0-20240624125703-7f344bbba641/go.mod h1:EwWXTntm3sypD8kP6lmoLxxxD9s3Mv2U2iu+yHkDGes=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ replace github.com/openshift/api => github.com/openshift/api v0.0.0-202304141430

// custom RabbitmqClusterSpecCore for OpenStackControlplane (v2.6.0_patches_tag)
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20240612145157-629e537392b3 //allow-merging

replace github.com/openstack-k8s-operators/mariadb-operator/api => github.com/stuggi/mariadb-operator/api v0.0.0-20240624125703-7f344bbba641

replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/stuggi/lib-common/modules/common v0.0.0-20240624123550-13c4ff7caf62
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ github.com/openstack-k8s-operators/lib-common/modules/ansible v0.3.1-0.202406211
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:tP+nxk95PisCKJaXE/an2igG9lluxuOVhdmV9WtkR2s=
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.0.0-20240621144804-4b3c1fd10960 h1:PHc/o3n3ae6Wjhc60rOSKhWb8iYIznE8mYgkrOy7ohQ=
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.0.0-20240621144804-4b3c1fd10960/go.mod h1:GooNi6hM78cOUMjhBy0fXsZIcDTK1dUb1rlay170IJo=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960 h1:9UpWmnaLZeN237m9YIHy6KxsSV3yPatNXryW2qabVKs=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:k9KuWN2LBtLbKHgcyh/0lrwk3Kr0cOAhiR3hi/mrwOQ=
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240621144804-4b3c1fd10960 h1:e4lhh+OFKRZxW5r8zxcoIhQQmJF5RTUDP1HYgb/B+7E=
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:zuPcZ5Kopr15AdfxvA0xqKIIGCZ0XbSe/0VHNKuvbEE=
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240621144804-4b3c1fd10960 h1:EZFKu3UG317XzFpu+NSUyFl/+ZSfRhkyC+3PVp6913Q=
Expand All @@ -130,8 +128,6 @@ github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.202406211448
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240621144804-4b3c1fd10960/go.mod h1:0h76CxD9g0z2Hk7fGFOZcjnzT1tQQ/yRNv3OXng+S/A=
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180 h1:urPMh7Wa8LJRHgc2SgYXuZQraBA1amusqxyRRCX5ANA=
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180/go.mod h1:N8CKCTMEEtOhemnyMEcMlojUZlTmpICVliGxF21UQL0=
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c h1:DBS/NK2sD3QpgTH8UrRs9cSSagyseXcKjLpYAuT9HsY=
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c/go.mod h1:3kM7dn+fW16YplR9KWAVG4Kmk2reU+Pji7lvXopZ5do=
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf h1:Ix6T1JLAP1N2hYoXXFun+nAkNdeoNeWx2m5rUWvNJLI=
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf/go.mod h1:n1CV1VR6nK/yU0gIpZ02EvE33u/TBjzJTG85Wu1geIk=
github.com/openstack-k8s-operators/nova-operator/api v0.3.1-0.20240623110641-32e3cb3025cc h1:XEdzsTQ0uiP3QOnDh5f19DvlAY/FRUWENgtz+Tlc7vo=
Expand Down Expand Up @@ -183,6 +179,10 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stuggi/lib-common/modules/common v0.0.0-20240624123550-13c4ff7caf62 h1:MXrFgYuYtR1kSX3zsx3xyQlgJUv12k6HIZJMiwyMU+4=
github.com/stuggi/lib-common/modules/common v0.0.0-20240624123550-13c4ff7caf62/go.mod h1:k9KuWN2LBtLbKHgcyh/0lrwk3Kr0cOAhiR3hi/mrwOQ=
github.com/stuggi/mariadb-operator/api v0.0.0-20240624125703-7f344bbba641 h1:Snx1sKW1H7ofrxOHXBeZ0sU2kVjVxQrXVdSDiupZFiI=
github.com/stuggi/mariadb-operator/api v0.0.0-20240624125703-7f344bbba641/go.mod h1:EwWXTntm3sypD8kP6lmoLxxxD9s3Mv2U2iu+yHkDGes=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down

0 comments on commit d37b929

Please sign in to comment.