Skip to content

Commit

Permalink
Merge pull request #482 from mengqiy/builtinexample
Browse files Browse the repository at this point in the history
📖 minor updates to the examples
  • Loading branch information
k8s-ci-robot committed Jun 11, 2019
2 parents 386a7bd + df54457 commit f99287c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
13 changes: 3 additions & 10 deletions examples/builtins/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,11 @@ func main() {

// Setup webhooks
entryLog.Info("setting up webhook server")
hookServer := &webhook.Server{
Port: 9876,
CertDir: "/tmp/cert",
}
if err := mgr.Add(hookServer); err != nil {
entryLog.Error(err, "unable register webhook server with manager")
os.Exit(1)
}
hookServer := mgr.GetWebhookServer()

entryLog.Info("registering webhooks to the webhook server")
hookServer.Register("/mutate-pods", &webhook.Admission{Handler: &podAnnotator{}})
hookServer.Register("/validate-pods", &webhook.Admission{Handler: &podValidator{}})
hookServer.Register("/mutate-v1-pod", &webhook.Admission{Handler: &podAnnotator{}})
hookServer.Register("/validate-v1-pod", &webhook.Admission{Handler: &podValidator{}})

entryLog.Info("starting manager")
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions examples/builtins/mutatingwebhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// +kubebuilder:webhook:path=/mutate-v1-pod,mutating=true,failurePolicy=fail,groups="",resources=pods,verbs=create;update,versions=v1,name=mpod.kb.io

// podAnnotator annotates Pods
type podAnnotator struct {
client client.Client
Expand Down
2 changes: 2 additions & 0 deletions examples/builtins/validatingwebhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// +kubebuilder:webhook:path=/validate-v1-pod,mutating=false,failurePolicy=fail,groups="",resources=pods,verbs=create;update,versions=v1,name=vpod.kb.io

// podValidator validates Pods
type podValidator struct {
client client.Client
Expand Down
4 changes: 2 additions & 2 deletions examples/crd/pkg/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type ChaosPodList struct {
Items []ChaosPod `json:"items"`
}

// +kubebuilder:webhook:failurePolicy=fail,groups=chaosapps.metamagical.io,resources=chaospods,verbs=create;update,versions=v1,name=vchaospod.kb.io,path=/validate-chaosapps-metamagical-io-v1-chaospod,mutating=false
// +kubebuilder:webhook:path=/validate-chaosapps-metamagical-io-v1-chaospod,mutating=false,failurePolicy=fail,groups=chaosapps.metamagical.io,resources=chaospods,verbs=create;update,versions=v1,name=vchaospod.kb.io

var _ webhook.Validator = &ChaosPod{}

Expand Down Expand Up @@ -93,7 +93,7 @@ func (c *ChaosPod) ValidateUpdate(old runtime.Object) error {
return nil
}

// +kubebuilder:webhook:failurePolicy=fail,groups=chaosapps.metamagical.io,resources=chaospods,verbs=create;update,versions=v1,name=mchaospod.kb.io,path=/mutate-chaosapps-metamagical-io-v1-chaospod,mutating=true
// +kubebuilder:webhook:path=/mutate-chaosapps-metamagical-io-v1-chaospod,mutating=true,failurePolicy=fail,groups=chaosapps.metamagical.io,resources=chaospods,verbs=create;update,versions=v1,name=mchaospod.kb.io

var _ webhook.Defaulter = &ChaosPod{}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require (
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
google.golang.org/appengine v1.1.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/fsnotify.v1 v1.4.7
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8
Expand Down

0 comments on commit f99287c

Please sign in to comment.