Skip to content

Commit c3c7fd0

Browse files
committed
Webhooks for default images
1 parent 5ff7452 commit c3c7fd0

36 files changed

+702
-56
lines changed

Makefile

+15
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ build: generate fmt vet ## Build manager binary.
112112
go build -o bin/manager main.go
113113

114114
.PHONY: run
115+
run: export ENABLE_WEBHOOKS?=false
115116
run: manifests generate fmt vet ## Run a controller from your host.
117+
/bin/bash hack/clean_local_webhook.sh
116118
OPERATOR_TEMPLATES=./templates go run ./main.go
117119

118120
# If you wish built the manager image targeting other platforms you can use the --platform flag.
@@ -314,3 +316,16 @@ gowork: ## Generate go.work file
314316
tidy: ## Run go mod tidy on every mod file in the repo
315317
go mod tidy
316318
cd ./api && go mod tidy
319+
320+
# Used for webhook testing
321+
# Please ensure the horizon-controller-manager deployment and
322+
# webhook definitions are removed from the csv before running
323+
# this. Also, cleanup the webhook configuration for local testing
324+
# before deplying with olm again.
325+
# $oc delete -n openstack validatingwebhookconfiguration/vhorizon.kb.io
326+
# $oc delete -n openstack mutatingwebhookconfiguration/mhorizon.kb.io
327+
SKIP_CERT ?=false
328+
.PHONY: run-with-webhook
329+
run-with-webhook: manifests generate fmt vet ## Run a controller from your host.
330+
/bin/bash hack/configure_local_webhook.sh
331+
OPERATOR_TEMPLATES=./templates go run ./main.go

PROJECT

+6-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ resources:
1414
domain: openstack.org
1515
group: horizon
1616
kind: Horizon
17-
path: github.com/openstack-k8s-operators/horizon-operator/api/v1alpha1
18-
version: v1alpha1
17+
path: github.com/openstack-k8s-operators/horizon-operator/api/v1beta1
18+
version: v1beta1
19+
webhooks:
20+
defaulting: true
21+
validation: true
22+
webhookVersion: v1
1923
version: "3"

api/go.mod

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@ module github.com/openstack-k8s-operators/horizon-operator/api
33
go 1.19
44

55
require (
6-
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20230427065458-ec1b923df88c
6+
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20230504085832-c15c933c2300
77
k8s.io/api v0.26.3
88
k8s.io/apimachinery v0.26.3
99
sigs.k8s.io/controller-runtime v0.14.6
1010
)
1111

12+
require (
13+
github.com/go-logr/zapr v1.2.3 // indirect
14+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
15+
go.uber.org/atomic v1.7.0 // indirect
16+
go.uber.org/zap v1.24.0 // indirect
17+
golang.org/x/tools v0.7.0 // indirect
18+
)
19+
1220
require (
1321
github.com/beorn7/perks v1.0.1 // indirect
1422
github.com/cespare/xxhash/v2 v2.1.2 // indirect
@@ -36,8 +44,8 @@ require (
3644
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3745
github.com/modern-go/reflect2 v1.0.2 // indirect
3846
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
39-
github.com/onsi/ginkgo/v2 v2.9.2 // indirect
40-
github.com/onsi/gomega v1.27.6 // indirect
47+
github.com/onsi/ginkgo/v2 v2.9.2
48+
github.com/onsi/gomega v1.27.6
4149
github.com/openshift/api v3.9.0+incompatible // indirect
4250
github.com/pkg/errors v0.9.1 // indirect
4351
github.com/prometheus/client_golang v1.14.0 // indirect
@@ -59,7 +67,7 @@ require (
5967
gopkg.in/yaml.v2 v2.4.0 // indirect
6068
gopkg.in/yaml.v3 v3.0.1 // indirect
6169
k8s.io/apiextensions-apiserver v0.26.2 // indirect
62-
k8s.io/client-go v0.26.3 // indirect
70+
k8s.io/client-go v0.26.3
6371
k8s.io/component-base v0.26.2 // indirect
6472
k8s.io/klog/v2 v2.80.1 // indirect
6573
k8s.io/kube-openapi v0.0.0-20230308215209-15aac26d736a // indirect

api/go.sum

+14-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF
4040
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
4141
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
4242
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
43+
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
44+
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
4345
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
4446
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
4547
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -90,9 +92,11 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
9092
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
9193
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
9294
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
95+
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
9396
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
9497
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
9598
github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A=
99+
github.com/go-logr/zapr v1.2.3/go.mod h1:eIauM6P8qSvTw5o2ez6UEAfGjQKrxQTl5EoK+Qa2oG4=
96100
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
97101
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
98102
github.com/go-openapi/jsonreference v0.20.1 h1:FBLnyygC4/IZZr893oiomc9XaghoveYTrLC1F86HID8=
@@ -101,6 +105,7 @@ github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/
101105
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
102106
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
103107
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
108+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
104109
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
105110
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
106111
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
@@ -225,8 +230,8 @@ github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
225230
github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
226231
github.com/openshift/api v3.9.0+incompatible h1:fJ/KsefYuZAjmrr3+5U9yZIZbTOpVkDDLDLFresAeYs=
227232
github.com/openshift/api v3.9.0+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY=
228-
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20230427065458-ec1b923df88c h1:NdiOLRgA3hMnfWq92lgnPfeNVb7d/7dTh+XPByq9yxg=
229-
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20230427065458-ec1b923df88c/go.mod h1:jDSW6narykfQyBtGTx6Kb6ZfTZgfzlyn/hF2zFs6sAs=
233+
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20230504085832-c15c933c2300 h1:Crt1fEgKu+zW0qKuD6rh97DOuqSx5J7l+15QEbonUbg=
234+
github.com/openstack-k8s-operators/lib-common/modules/common v0.0.0-20230504085832-c15c933c2300/go.mod h1:jDSW6narykfQyBtGTx6Kb6ZfTZgfzlyn/hF2zFs6sAs=
230235
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
231236
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
232237
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -276,6 +281,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
276281
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
277282
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
278283
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
284+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
279285
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
280286
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
281287
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
@@ -296,10 +302,14 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
296302
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
297303
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
298304
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
305+
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
299306
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
307+
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
300308
go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec=
301309
go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
310+
go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
302311
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
312+
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
303313
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
304314
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
305315
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@@ -469,6 +479,7 @@ golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgw
469479
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
470480
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
471481
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
482+
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
472483
golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
473484
golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
474485
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
@@ -497,6 +508,7 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc
497508
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
498509
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
499510
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
511+
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
500512
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
501513
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
502514
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

api/v1alpha1/conditions.go api/v1beta1/conditions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package v1alpha1
1+
package v1beta1
22

33
import (
44
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"

api/v1alpha1/groupversion_info.go api/v1beta1/groupversion_info.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
// Package v1alpha1 contains API Schema definitions for the horizon v1alpha1 API group
17+
// Package v1beta1 contains API Schema definitions for the horizon v1beta1 API group
1818
// +kubebuilder:object:generate=true
1919
// +groupName=horizon.openstack.org
20-
package v1alpha1
20+
package v1beta1
2121

2222
import (
2323
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -26,7 +26,7 @@ import (
2626

2727
var (
2828
// GroupVersion is group version used to register these objects
29-
GroupVersion = schema.GroupVersion{Group: "horizon.openstack.org", Version: "v1alpha1"}
29+
GroupVersion = schema.GroupVersion{Group: "horizon.openstack.org", Version: "v1beta1"}
3030

3131
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
3232
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

api/v1alpha1/horizon_types.go api/v1beta1/horizon_types.go

+18-3
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,27 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v1alpha1
17+
package v1beta1
1818

1919
import (
2020
"fmt"
2121

2222
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2323
endpoint "github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
24+
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
2425

2526
corev1 "k8s.io/api/core/v1"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
)
2829

30+
const (
31+
// ContainerImage - default fall-back container image for Horizon if associated env var not provided
32+
ContainerImage = "quay.io/podified-antelope-centos9/openstack-horizon:current-podified"
33+
)
34+
2935
// HorizonSpec defines the desired state of Horizon
3036
type HorizonSpec struct {
31-
// +kubebuilder:validation:Optional
32-
// +kubebuilder:default="quay.io/podified-antelope-centos9/openstack-horizon:current-podified"
37+
// +kubebuilder:validation:Required
3338
// horizon Container Image URL
3439
ContainerImage string `json:"containerImage"`
3540

@@ -188,3 +193,13 @@ func (instance Horizon) RbacNamespace() string {
188193
func (instance Horizon) RbacResourceName() string {
189194
return "horizon-" + instance.Name
190195
}
196+
197+
// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
198+
func SetupDefaults() {
199+
// Acquire environmental defaults and initialize Horizon defaults with them
200+
horizonDefaults := HorizonDefaults{
201+
ContainerImageURL: util.GetEnvVar("HORIZON_IMAGE_URL_DEFAULT", ContainerImage),
202+
}
203+
204+
SetupHorizonDefaults(horizonDefaults)
205+
}

api/v1beta1/horizon_webhook.go

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
//
18+
// Generated by:
19+
//
20+
// operator-sdk create webhook --group horizon --version v1beta1 --kind Horizon --programmatic-validation --defaulting
21+
//
22+
23+
package v1beta1
24+
25+
import (
26+
"k8s.io/apimachinery/pkg/runtime"
27+
ctrl "sigs.k8s.io/controller-runtime"
28+
logf "sigs.k8s.io/controller-runtime/pkg/log"
29+
"sigs.k8s.io/controller-runtime/pkg/webhook"
30+
)
31+
32+
// HorizonDefaults -
33+
type HorizonDefaults struct {
34+
ContainerImageURL string
35+
}
36+
37+
var horizonDefaults HorizonDefaults
38+
39+
// log is for logging in this package.
40+
var horizonlog = logf.Log.WithName("horizon-resource")
41+
42+
// SetupHorizonDefaults - initialize Horizon spec defaults for use with either internal or external webhooks
43+
func SetupHorizonDefaults(defaults HorizonDefaults) {
44+
horizonDefaults = defaults
45+
horizonlog.Info("Horizon defaults initialized", "defaults", defaults)
46+
}
47+
48+
// SetupWebhookWithManager sets up the webhook with the Manager
49+
func (r *Horizon) SetupWebhookWithManager(mgr ctrl.Manager) error {
50+
return ctrl.NewWebhookManagedBy(mgr).
51+
For(r).
52+
Complete()
53+
}
54+
55+
//+kubebuilder:webhook:path=/mutate-horizon-openstack-org-v1beta1-horizon,mutating=true,failurePolicy=fail,sideEffects=None,groups=horizon.openstack.org,resources=horizons,verbs=create;update,versions=v1beta1,name=mhorizon.kb.io,admissionReviewVersions=v1
56+
57+
var _ webhook.Defaulter = &Horizon{}
58+
59+
// Default implements webhook.Defaulter so a webhook will be registered for the type
60+
func (r *Horizon) Default() {
61+
horizonlog.Info("default", "name", r.Name)
62+
63+
r.Spec.Default()
64+
}
65+
66+
// Default - set defaults for this Horizon spec
67+
func (spec *HorizonSpec) Default() {
68+
if spec.ContainerImage == "" {
69+
spec.ContainerImage = horizonDefaults.ContainerImageURL
70+
}
71+
}
72+
73+
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
74+
//+kubebuilder:webhook:path=/validate-horizon-openstack-org-v1beta1-horizon,mutating=false,failurePolicy=fail,sideEffects=None,groups=horizon.openstack.org,resources=horizons,verbs=create;update,versions=v1beta1,name=vhorizon.kb.io,admissionReviewVersions=v1
75+
76+
var _ webhook.Validator = &Horizon{}
77+
78+
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
79+
func (r *Horizon) ValidateCreate() error {
80+
horizonlog.Info("validate create", "name", r.Name)
81+
82+
// TODO(user): fill in your validation logic upon object creation.
83+
return nil
84+
}
85+
86+
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
87+
func (r *Horizon) ValidateUpdate(old runtime.Object) error {
88+
horizonlog.Info("validate update", "name", r.Name)
89+
90+
// TODO(user): fill in your validation logic upon object update.
91+
return nil
92+
}
93+
94+
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
95+
func (r *Horizon) ValidateDelete() error {
96+
horizonlog.Info("validate delete", "name", r.Name)
97+
98+
// TODO(user): fill in your validation logic upon object deletion.
99+
return nil
100+
}

0 commit comments

Comments
 (0)