From e2deda46f44b1d3efaeb84d1df354519aecdebf7 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Wed, 4 Oct 2023 12:44:47 +0200 Subject: [PATCH] patch whole spec --- clientset/v1alpha1/uffizzicluster.go | 70 ++++------------------------ 1 file changed, 8 insertions(+), 62 deletions(-) diff --git a/clientset/v1alpha1/uffizzicluster.go b/clientset/v1alpha1/uffizzicluster.go index 645878d4..f05c329f 100644 --- a/clientset/v1alpha1/uffizzicluster.go +++ b/clientset/v1alpha1/uffizzicluster.go @@ -3,7 +3,6 @@ package v1alpha1 import ( "context" "encoding/json" - // "log" "github.com/UffizziCloud/uffizzi-cluster-operator/api/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -16,7 +15,7 @@ type UffizziClusterInterface interface { List(opts metav1.ListOptions) (*v1alpha1.UffizziClusterList, error) Get(name string, options metav1.GetOptions) (*v1alpha1.UffizziCluster, error) Create(UffizziClusterProps) (*v1alpha1.UffizziCluster, error) - Update(name string, updateClusterProps UpdateUffizziClusterProps) error + Patch(name string, patchClusterProps PatchUffizziClusterProps) error Delete(name string) error } @@ -31,7 +30,7 @@ type UffizziClusterProps struct { Annotations map[string]string } -type UpdateUffizziClusterProps struct { +type PatchUffizziClusterProps struct { Spec v1alpha1.UffizziClusterSpec Annotations map[string]string } @@ -93,9 +92,10 @@ func (c *UffizziClusterClient) Create(clusterProps UffizziClusterProps) (*v1alph return &result, err } -func (c *UffizziClusterClient) Update( +// The sleep mode only works if a patch is applied (not "update") +func (c *UffizziClusterClient) Patch( name string, - updateClusterProps UpdateUffizziClusterProps, + patchClusterProps PatchUffizziClusterProps, ) error { uffizziCluster := &v1alpha1.UffizziCluster{} @@ -117,13 +117,13 @@ func (c *UffizziClusterClient) Update( patchOps := []JSONPatchOperation{ JSONPatchOperation{ Op: "replace", - Path: "/spec/sleep", - Value: updateClusterProps.Spec.Sleep, + Path: "/spec", + Value: patchClusterProps.Spec, }, JSONPatchOperation{ Op: "replace", Path: "/metadata/annotations", - Value: updateClusterProps.Annotations, + Value: patchClusterProps.Annotations, }, } @@ -150,60 +150,6 @@ func (c *UffizziClusterClient) Update( return nil } -// func (c *UffizziClusterClient) Update( -// name string, -// updateClusterProps UpdateUffizziClusterProps, -// ) error { -// uffizziCluster := &v1alpha1.UffizziCluster{} - -// err := c.restClient. -// Get(). -// Namespace(c.ns). -// Resource("UffizziClusters"). -// Name(name). -// Do(context.TODO()). -// Into(uffizziCluster) - -// if err != nil { -// return err -// } - -// resourceVersion := uffizziCluster.ObjectMeta.ResourceVersion - -// log.Printf("Sleep value: %v", updateClusterProps.Spec.Sleep) - -// uffizziCluster.Spec.Sleep = updateClusterProps.Spec -// uffizziCluster.ObjectMeta.Annotations = updateClusterProps.Annotations -// uffizziCluster.TypeMeta = metav1.TypeMeta{ -// Kind: "UffizziCluster", -// APIVersion: "uffizzi.com/v1alpha1", -// } - -// log.Printf("Updated cluster: %v", uffizziCluster) -// log.Printf("Updated cluster sleep value: %v", uffizziCluster.Spec.Sleep) - -// updatedJSON, err := json.Marshal(uffizziCluster) -// if err != nil { -// return err -// } - -// result := c.restClient. -// Put(). -// Namespace(c.ns). -// Resource("UffizziClusters"). -// Name(name). -// Body(updatedJSON). -// Param("resourceVersion", resourceVersion). -// SetHeader("Content-Type", "application/json"). -// Do(context.TODO()) - -// if result.Error() != nil { -// return result.Error() -// } - -// return nil -// } - func (c *UffizziClusterClient) Delete(name string) error { result := v1alpha1.UffizziCluster{} err := c.restClient.