Skip to content

Commit

Permalink
Merge pull request #882 from stuggi/storage_request_webhook
Browse files Browse the repository at this point in the history
Validate galera templates storageRequest via validation webhook
  • Loading branch information
openshift-merge-bot[bot] authored Jun 25, 2024
2 parents 8b2b3bf + aa9196a commit 2d315a0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 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: 2 additions & 2 deletions apis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ require (
github.com/openstack-k8s-operators/infra-operator/apis v0.3.1-0.20240622123909-205129589c38
github.com/openstack-k8s-operators/ironic-operator/api v0.3.1-0.20240623150030-e53574c3da59
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240623145456-c19b57192709
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240624132705-6c8da3c0bbfd
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240621144804-4b3c1fd10960
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf
github.com/openstack-k8s-operators/nova-operator/api v0.3.1-0.20240623110641-32e3cb3025cc
github.com/openstack-k8s-operators/octavia-operator/api v0.3.1-0.20240623150031-5548ad9cd2a8
Expand Down
8 changes: 4 additions & 4 deletions apis/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,16 @@ 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/common v0.3.1-0.20240624132705-6c8da3c0bbfd h1:ZlZW1W+IEDNN5Vz5HG3iyQWn5kk3omno4i6J3snwy3w=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240624132705-6c8da3c0bbfd/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/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1 h1:NyDo2fqRLq8U66CBIy4wV8aKIdipZACYKnHSvJ9fuMY=
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1/go.mod h1:FzdNGhUR1dH8E7INAg9sRJXpspug5OMDqqByI1/SEIY=
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ require (
github.com/openstack-k8s-operators/keystone-operator/api v0.3.1-0.20240623145456-c19b57192709
github.com/openstack-k8s-operators/lib-common/modules/ansible v0.3.1-0.20240621144804-4b3c1fd10960
github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.0.0-20240621144804-4b3c1fd10960
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240621144804-4b3c1fd10960
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240624132705-6c8da3c0bbfd
github.com/openstack-k8s-operators/lib-common/modules/storage v0.3.1-0.20240621144804-4b3c1fd10960
github.com/openstack-k8s-operators/lib-common/modules/test v0.3.1-0.20240621144804-4b3c1fd10960
github.com/openstack-k8s-operators/manila-operator/api v0.3.1-0.20240623200540-210efea65180
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240622094308-5012e4d6ae8c
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1
github.com/openstack-k8s-operators/neutron-operator/api v0.3.1-0.20240623150026-b33cfbd3c3bf
github.com/openstack-k8s-operators/nova-operator/api v0.3.1-0.20240623110641-32e3cb3025cc
github.com/openstack-k8s-operators/octavia-operator/api v0.3.1-0.20240623150031-5548ad9cd2a8
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ 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/common v0.3.1-0.20240624132705-6c8da3c0bbfd h1:ZlZW1W+IEDNN5Vz5HG3iyQWn5kk3omno4i6J3snwy3w=
github.com/openstack-k8s-operators/lib-common/modules/common v0.3.1-0.20240624132705-6c8da3c0bbfd/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 +130,8 @@ 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/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1 h1:NyDo2fqRLq8U66CBIy4wV8aKIdipZACYKnHSvJ9fuMY=
github.com/openstack-k8s-operators/mariadb-operator/api v0.3.1-0.20240624150155-414cc98576d1/go.mod h1:FzdNGhUR1dH8E7INAg9sRJXpspug5OMDqqByI1/SEIY=
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

0 comments on commit 2d315a0

Please sign in to comment.