Created
January 29, 2025 06:29
-
-
Save bigkevmcd/2be4e0835f6a865cf7a01c1af28a3680 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| diff --git a/pkg/client/typed_client.go b/pkg/client/typed_client.go | |
| index 92afd9a9..f721e1ed 100644 | |
| --- a/pkg/client/typed_client.go | |
| +++ b/pkg/client/typed_client.go | |
| @@ -85,7 +85,7 @@ func (c *typedClient) Delete(ctx context.Context, obj Object, opts ...DeleteOpti | |
| Name(o.GetName()). | |
| Body(deleteOpts.AsDeleteOptions()). | |
| Do(ctx). | |
| - Error() | |
| + Into(obj) | |
| } |
This file contains hidden or 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
| // controller-runtime client testing - requires a patched controller-runtime. | |
| // ONLY RUN THIS AGAINST A TEST CLUSTER IT WILL CREATE AND DELETE A CONFIGMAP! | |
| package main | |
| import ( | |
| "context" | |
| "log" | |
| corev1 "k8s.io/api/core/v1" | |
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | |
| "k8s.io/apimachinery/pkg/types" | |
| "sigs.k8s.io/controller-runtime/pkg/client" | |
| "sigs.k8s.io/controller-runtime/pkg/client/config" | |
| "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | |
| ) | |
| var c client.Client | |
| func main() { | |
| cfg := config.GetConfigOrDie() | |
| k8sClient, err := client.New(cfg, client.Options{}) | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| configMap := &corev1.ConfigMap{ | |
| ObjectMeta: metav1.ObjectMeta{ | |
| Namespace: "default", | |
| Name: "my-config", | |
| }, | |
| } | |
| if err := k8sClient.Create(context.Background(), configMap); err != nil { | |
| log.Fatal(err) | |
| } | |
| log.Printf("Deletion timestamp = %v\n", configMap.ObjectMeta.DeletionTimestamp) | |
| controllerutil.AddFinalizer(configMap, "example.com/test") | |
| if err := k8sClient.Update(context.Background(), configMap); err != nil { | |
| log.Fatal(err) | |
| } | |
| log.Printf("Deletion timestamp = %v\n", configMap.ObjectMeta.DeletionTimestamp) | |
| if err := k8sClient.Delete(context.Background(), configMap); err != nil { | |
| log.Fatal(err) | |
| } | |
| log.Printf("Deletion timestamp = %v\n", configMap.ObjectMeta.DeletionTimestamp) | |
| if err := k8sClient.Get(context.Background(), types.NamespacedName{Namespace: "default", Name: "my-config"}, configMap); err != nil { | |
| log.Fatal(err) | |
| } | |
| log.Printf("Deletion timestamp = %v\n", configMap.ObjectMeta.DeletionTimestamp) | |
| controllerutil.RemoveFinalizer(configMap, "example.com/test") | |
| if err := k8sClient.Update(context.Background(), configMap); err != nil { | |
| log.Fatal(err) | |
| } | |
| log.Printf("Deletion timestamp = %v\n", configMap.ObjectMeta.DeletionTimestamp) | |
| if err := k8sClient.Get(context.Background(), types.NamespacedName{Namespace: "default", Name: "my-config"}, configMap); err != nil { | |
| log.Fatal(err) | |
| } | |
| log.Printf("Deletion timestamp = %v\n", configMap.ObjectMeta.DeletionTimestamp) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment