Skip to content

Commit

Permalink
Calling PlacementAPI validation webhook
Browse files Browse the repository at this point in the history
The placement-operator now has validation webhook, so openstack-operator
should call it during validation.

Depends-On: openstack-k8s-operators/placement-operator#148
  • Loading branch information
gibizer authored and stuggi committed Feb 13, 2024
1 parent 51f1b63 commit 62f9ccb
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 6 deletions.
8 changes: 8 additions & 0 deletions apis/core/v1beta1/openstackcontrolplane_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func (r *OpenStackControlPlane) ValidateCreateServices(basePath *field.Path) fie
errors = append(errors, r.Spec.Nova.Template.ValidateCreate(basePath.Child("nova").Child("template"))...)
}

if r.Spec.Placement.Enabled {
errors = append(errors, r.Spec.Placement.Template.ValidateCreate(basePath.Child("placement").Child("template"))...)
}

return errors
}

Expand All @@ -209,6 +213,10 @@ func (r *OpenStackControlPlane) ValidateUpdateServices(old OpenStackControlPlane
errors = append(errors, r.Spec.Nova.Template.ValidateUpdate(old.Nova.Template, basePath.Child("nova").Child("template"))...)
}

if r.Spec.Placement.Enabled {
errors = append(errors, r.Spec.Placement.Template.ValidateUpdate(old.Placement.Template, basePath.Child("placement").Child("template"))...)
}

return errors
}

Expand Down
2 changes: 1 addition & 1 deletion apis/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/openstack-k8s-operators/nova-operator/api v0.3.1-0.20240206080218-0a39e8ee1c07
github.com/openstack-k8s-operators/octavia-operator/api v0.3.1-0.20240205082155-fca054830e06
github.com/openstack-k8s-operators/ovn-operator/api v0.3.1-0.20240206110402-41e2d7f8870e
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240206120950-4285571a7211
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240209144511-533e51daa424
github.com/openstack-k8s-operators/swift-operator/api v0.3.1-0.20240206105420-de58be701128
github.com/openstack-k8s-operators/telemetry-operator/api v0.3.1-0.20240205163246-3add3edb159c
github.com/rabbitmq/cluster-operator/v2 v2.5.0
Expand Down
4 changes: 2 additions & 2 deletions apis/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ github.com/openstack-k8s-operators/octavia-operator/api v0.3.1-0.20240205082155-
github.com/openstack-k8s-operators/octavia-operator/api v0.3.1-0.20240205082155-fca054830e06/go.mod h1:u5RKT1S7MJqUqnEVIDOmwidFhBRIjMcUG78tWW1SUuE=
github.com/openstack-k8s-operators/ovn-operator/api v0.3.1-0.20240206110402-41e2d7f8870e h1:/E9k0cDpYcsvV4P10WSC4k0KKJgC06IwAs+Z+GTkDQ0=
github.com/openstack-k8s-operators/ovn-operator/api v0.3.1-0.20240206110402-41e2d7f8870e/go.mod h1:rYCOWkIWOBRf+6GijQo4uadwR9Sz/prV4HVTdUZoFHQ=
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240206120950-4285571a7211 h1:WPMYG5TQl7a7G4Acknp41Er3qjYcp1Onbl1kqvnMQX0=
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240206120950-4285571a7211/go.mod h1:G4XUqjS1C8V5U066HUcjnCyxTNhU4cSZOOGXcOCOhz4=
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240209144511-533e51daa424 h1:JdJDQ60QVjkTV6+mDt9zQQUIMc/51Cn9vY77QsBjhew=
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240209144511-533e51daa424/go.mod h1:xM0W1YMKuIoQnXhFVf4656QpyJlGa9m3cMj45KQt1pQ=
github.com/openstack-k8s-operators/swift-operator/api v0.3.1-0.20240206105420-de58be701128 h1:j3iwtF7ptHjneP9tboCd1K6H3PdhhdTGXiKbXddEqZY=
github.com/openstack-k8s-operators/swift-operator/api v0.3.1-0.20240206105420-de58be701128/go.mod h1:WxFJzl/l+1EjCEiBrQ+KydXEnZhxXtRvtcCn5O3q47E=
github.com/openstack-k8s-operators/telemetry-operator/api v0.3.1-0.20240205163246-3add3edb159c h1:w5/UiRR7xyJ2qtQ6gA/Exp8XJd3MhVpBOUrnfmDQ92o=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.3.1-0.20240125112403-f184903f8706
github.com/openstack-k8s-operators/openstack-operator/apis v0.0.0-20230725141229-4ce90d0120fd
github.com/openstack-k8s-operators/ovn-operator/api v0.3.1-0.20240206110402-41e2d7f8870e
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240206120950-4285571a7211
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240209144511-533e51daa424
github.com/openstack-k8s-operators/swift-operator/api v0.3.1-0.20240206105420-de58be701128
github.com/openstack-k8s-operators/telemetry-operator/api v0.3.1-0.20240205163246-3add3edb159c
github.com/operator-framework/api v0.20.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.3.1-0.202
github.com/openstack-k8s-operators/openstack-baremetal-operator/api v0.3.1-0.20240125112403-f184903f8706/go.mod h1:UTK7po+fGYND9AwrTpQvEhWMYXmViwJaaWt0LzhleDE=
github.com/openstack-k8s-operators/ovn-operator/api v0.3.1-0.20240206110402-41e2d7f8870e h1:/E9k0cDpYcsvV4P10WSC4k0KKJgC06IwAs+Z+GTkDQ0=
github.com/openstack-k8s-operators/ovn-operator/api v0.3.1-0.20240206110402-41e2d7f8870e/go.mod h1:rYCOWkIWOBRf+6GijQo4uadwR9Sz/prV4HVTdUZoFHQ=
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240206120950-4285571a7211 h1:WPMYG5TQl7a7G4Acknp41Er3qjYcp1Onbl1kqvnMQX0=
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240206120950-4285571a7211/go.mod h1:G4XUqjS1C8V5U066HUcjnCyxTNhU4cSZOOGXcOCOhz4=
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240209144511-533e51daa424 h1:JdJDQ60QVjkTV6+mDt9zQQUIMc/51Cn9vY77QsBjhew=
github.com/openstack-k8s-operators/placement-operator/api v0.3.1-0.20240209144511-533e51daa424/go.mod h1:xM0W1YMKuIoQnXhFVf4656QpyJlGa9m3cMj45KQt1pQ=
github.com/openstack-k8s-operators/swift-operator/api v0.3.1-0.20240206105420-de58be701128 h1:j3iwtF7ptHjneP9tboCd1K6H3PdhhdTGXiKbXddEqZY=
github.com/openstack-k8s-operators/swift-operator/api v0.3.1-0.20240206105420-de58be701128/go.mod h1:WxFJzl/l+1EjCEiBrQ+KydXEnZhxXtRvtcCn5O3q47E=
github.com/openstack-k8s-operators/telemetry-operator/api v0.3.1-0.20240205163246-3add3edb159c h1:w5/UiRR7xyJ2qtQ6gA/Exp8XJd3MhVpBOUrnfmDQ92o=
Expand Down
42 changes: 42 additions & 0 deletions tests/functional/openstackoperator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ limitations under the License.
package functional_test

import (
"errors"
"os"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"github.com/openstack-k8s-operators/lib-common/modules/common/service"
. "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
Expand Down Expand Up @@ -264,3 +268,41 @@ var _ = Describe("OpenStackOperator controller", func() {
})
})
})

var _ = Describe("OpenStackOperator Webhook", func() {

It("calls placement validation webhook", func() {
spec := GetDefaultOpenStackControlPlaneSpec()
spec["placement"] = map[string]interface{}{
"template": map[string]interface{}{
"defaultConfigOverwrite": map[string]interface{}{
"api-paste.ini": "not supported",
},
},
}
raw := map[string]interface{}{
"apiVersion": "core.openstack.org/v1beta1",
"kind": "OpenStackControlPlane",
"metadata": map[string]interface{}{
"name": "openstack",
"namespace": namespace,
},
"spec": spec,
}
unstructuredObj := &unstructured.Unstructured{Object: raw}
_, err := controllerutil.CreateOrPatch(
ctx, k8sClient, unstructuredObj, func() error { return nil })

Expect(err).Should(HaveOccurred())
var statusError *k8s_errors.StatusError
Expect(errors.As(err, &statusError)).To(BeTrue())
Expect(statusError.ErrStatus.Details.Kind).To(Equal("OpenStackControlPlane"))
Expect(statusError.ErrStatus.Message).To(
ContainSubstring(
"invalid: spec.placement.template.defaultConfigOverwrite: " +
"Invalid value: \"api-paste.ini\": " +
"Only the following keys are valid: policy.yaml",
),
)
})
})

0 comments on commit 62f9ccb

Please sign in to comment.