-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deps): update module sigs.k8s.io/controller-runtime to v0.16.1 (#265
) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Naka Masato <[email protected]>
- Loading branch information
1 parent
23a7160
commit 15a11e3
Showing
10 changed files
with
280 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
contents/kubernetes-operator/controller-runtime/webhook/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
|
||
ctrl "sigs.k8s.io/controller-runtime" | ||
. "sigs.k8s.io/controller-runtime/pkg/webhook" | ||
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
) | ||
|
||
var ( | ||
// Build webhooks used for the various server | ||
// configuration options | ||
// | ||
// These handlers could be also be implementations | ||
// of the AdmissionHandler interface for more complex | ||
// implementations. | ||
mutatingHook = &Admission{ | ||
Handler: admission.HandlerFunc(func(ctx context.Context, req AdmissionRequest) AdmissionResponse { | ||
return Patched("some changes", | ||
JSONPatchOp{Operation: "add", Path: "/metadata/annotations/access", Value: "granted"}, | ||
JSONPatchOp{Operation: "add", Path: "/metadata/annotations/reason", Value: "not so secret"}, | ||
) | ||
}), | ||
} | ||
|
||
validatingHook = &Admission{ | ||
Handler: admission.HandlerFunc(func(ctx context.Context, req AdmissionRequest) AdmissionResponse { | ||
return Denied("none shall pass!") | ||
}), | ||
} | ||
) | ||
|
||
func main() { | ||
// Create a manager | ||
// Note: GetConfigOrDie will os.Exit(1) w/o any message if no kube-config can be found | ||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Create a webhook server. | ||
hookServer := NewServer(Options{Port: 8443}) | ||
if err := mgr.Add(hookServer); err != nil { | ||
panic(err) | ||
} | ||
|
||
// Register the webhooks in the server. | ||
hookServer.Register("/mutating", mutatingHook) | ||
hookServer.Register("/validating", validatingHook) | ||
|
||
// Start the server by starting a previously-set-up manager | ||
err = mgr.Start(ctrl.SetupSignalHandler()) | ||
if err != nil { | ||
// handle error | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.