Skip to content

Commit

Permalink
feat(controller): patch CRDs to upgrade them
Browse files Browse the repository at this point in the history
Signed-off-by: Niladri Halder <niladri.halder26@gmail.com>
  • Loading branch information
niladrih committed Jul 26, 2023
1 parent 79376b3 commit a9c3794
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/patcher/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package patcher
import (
"context"
"fmt"
"github.com/openebs/lib-csi/pkg/common/errors"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
k8stypes "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
"os"
)

type Patchable struct {
Expand All @@ -20,13 +20,13 @@ type Patchable struct {
func PatchCrdOrIgnore(gvr schema.GroupVersionResource, namespace string) *Patchable {
cfg, err := rest.InClusterConfig()
if err != nil {
errors.Errorf("failed to generate in-cluster config: %s", err.Error())
fmt.Fprintf(os.Stderr, "failed to generate in-cluster config: %s", err.Error())
return nil
}

client, err := dynamic.NewForConfig(cfg)
if err != nil {
errors.Errorf("failed to generate in-cluster kubernetes client: %s", err.Error())
fmt.Fprintf(os.Stderr, "failed to generate in-cluster kubernetes client", err.Error())
return nil
}

Expand All @@ -40,12 +40,12 @@ func (p *Patchable) WithMergePatchFrom(name string, original, modified []byte) {

patch, err := strategicpatch.CreateTwoWayMergePatch(original, modified, apiextensions.CustomResourceDefinition{})
if err != nil {
errors.Errorf("failed to create merge patch for %s: %s", name, err.Error())
fmt.Fprintf(os.Stderr, "failed to create merge patch for %s: %s", name, err.Error())
return
}
_, err = p.inner.Patch(context.TODO(), name, k8stypes.MergePatchType, patch, metav1.PatchOptions{})
if err != nil {
errors.Errorf("failed to patch resource %s: %s", name, err.Error())
fmt.Fprintf(os.Stderr, "failed to patch resource %s: %s", name, err.Error())
return
}

Expand Down

0 comments on commit a9c3794

Please sign in to comment.