-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
📖 Add more examples in documentation #2498
📖 Add more examples in documentation #2498
Conversation
aerfio
commented
Sep 18, 2023
•
edited
Loading
edited
- Adds an example showing how to use Server Side Apply with controller-runtime client and structs from k8s.io/client-go/applyconfigurations/*
- Adds an example how to watch any resource and map its changes to main reconciled resource
Welcome @aerfio! |
Hi @aerfio. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
0121327
to
77fdfc7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ok-to-test
example_test.go
Outdated
// This example creates a simple application Controller that is configured for ExampleCRDWithConfigMapRef CRD. | ||
// Any change in the configMap referenced in this Custom Resource will cause the re-reconcile of the parent ExampleCRDWithConfigMapRef | ||
// due to the implementation of the .Watches method of "sigs.k8s.io/controller-runtime/pkg/builder".Builder. | ||
func Example_watches() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the fact that this has a watch is the special bit about this example. And I'd rather not have an example that doesn't implement DeepCopy
but just panics. Maybe do something like a special configmap key that references something else or such?
func Example_watches() { | |
func ExampleCustomHandler() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the fact that this has a watch is the special bit about this example.
That was my intention, to have an easy to grasp example for "Watches" 😢
Maybe do something like a special configmap key that references something else or such?
I didn't want to complicate this example too much, I thought about switching from LocalObjectReference to e.g ConfigMapKeySelector, but the code inside Watches would a too complicated for an example imho.
And I'd rather not have an example that doesn't implement DeepCopy but just panics.
Sure, I've changed it to json.Marshal + json.Unmarshal with panic on error, is that enough? I could use controller-gen
for that, but that would result in new file in the root of the repo + some changes in makefile, which I wanted to omit
Update: I tried it and controller-gen seems to ignore *_test.go files 🤷🏻
And lastly, for example name I changed it now like that:
diff --git a/example_test.go b/example_test.go
index cbbf032b..83f6fcdb 100644
--- a/example_test.go
+++ b/example_test.go
@@ -108,7 +108,7 @@ func (in *ExampleCRDWithConfigMapRefList) DeepCopyObject() runtime.Object {
// This example creates a simple application Controller that is configured for ExampleCRDWithConfigMapRef CRD.
// Any change in the configMap referenced in this Custom Resource will cause the re-reconcile of the parent ExampleCRDWithConfigMapRef
// due to the implementation of the .Watches method of "sigs.k8s.io/controller-runtime/pkg/builder".Builder.
-func Example_watches() {
+func Example_customHandler() {
log := ctrl.Log.WithName("builder-examples")
manager, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{})
to follow other examples in this repo (in this file also, see https://github.com/kubernetes-sigs/controller-runtime/blob/v0.16.2/example_test.go#L77) and also https://go.dev/blog/examples#example-function-names
@@ -188,6 +191,16 @@ func ExampleClient_patch() { | |||
}, client.RawPatch(types.StrategicMergePatchType, patch)) | |||
} | |||
|
|||
// This example shows how to use the client with unstructured objects to create/patch objects using Server Side Apply, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please mention why the dance of converting to unstructured is needed
@alvaroaleman done |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aerfio, alvaroaleman The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |