Skip to content

Commit

Permalink
patch whole spec
Browse files Browse the repository at this point in the history
  • Loading branch information
moklidia committed Oct 4, 2023
1 parent f3e9ae0 commit e2deda4
Showing 1 changed file with 8 additions and 62 deletions.
70 changes: 8 additions & 62 deletions clientset/v1alpha1/uffizzicluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand All @@ -31,7 +30,7 @@ type UffizziClusterProps struct {
Annotations map[string]string
}

type UpdateUffizziClusterProps struct {
type PatchUffizziClusterProps struct {
Spec v1alpha1.UffizziClusterSpec
Annotations map[string]string
}
Expand Down Expand Up @@ -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{}
Expand All @@ -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,
},
}

Expand All @@ -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.
Expand Down

0 comments on commit e2deda4

Please sign in to comment.