From b328054f5e955ae0fda5d16aabea1492a9a7867d Mon Sep 17 00:00:00 2001 From: Niladri Halder Date: Wed, 26 Jul 2023 07:57:35 +0000 Subject: [PATCH] 6f99521b7561895de978956ade9e5b18dafd474e Signed-off-by: Niladri Halder --- pkg/driver/controller.go | 34 ------------------------------- pkg/driver/driver.go | 35 ++++++++++++++++++++++++++++++++ pkg/patcher/patcher.go | 10 ++++----- pkg/patcher/zfsrestore-crd.yaml | 2 +- pkg/patcher/zfssnapshot-crd.yaml | 2 +- pkg/patcher/zfsvolume-crd.yaml | 2 +- 6 files changed, 43 insertions(+), 42 deletions(-) diff --git a/pkg/driver/controller.go b/pkg/driver/controller.go index 7888330a2..edb8a6f2f 100644 --- a/pkg/driver/controller.go +++ b/pkg/driver/controller.go @@ -18,8 +18,6 @@ package driver import ( "fmt" - "github.com/openebs/zfs-localpv/pkg/patcher" - "k8s.io/apimachinery/pkg/runtime/schema" "strconv" "strings" "time" @@ -87,38 +85,6 @@ func NewController(d *CSIDriver) csi.ControllerServer { } func (cs *controller) init() error { - // CRD upgrade - // Ref: https://github.com/openebs/zfs-localpv/pull/439 - // Ref: https://github.com/openebs/zfs-localpv/pull/457 - crdGvr := schema.GroupVersionResource{ - Group: "apiextensions.k8s.io", - Version: "v1", - Resource: "CustomResourceDefinition", - } - - oldCrd, _ := patcher.OldZfsVolumesCrd() - newCrd, _ := patcher.NewZfsVolumesCrd() - patcher.PatchCrdOrIgnore(crdGvr, "").WithMergePatchFrom( - "zfsvolumes.zfs.openebs.io", - oldCrd, - newCrd, - ) - - oldCrd, _ = patcher.OldZfsSnapshotsCrd() - newCrd, _ = patcher.NewZfsSnapshotsCrd() - patcher.PatchCrdOrIgnore(crdGvr, "").WithMergePatchFrom( - "zfssnapshots.zfs.openebs.io", - oldCrd, - newCrd, - ) - - oldCrd, _ = patcher.OldZfsRestoresCrd() - newCrd, _ = patcher.NewZfsRestoresCrd() - patcher.PatchCrdOrIgnore(crdGvr, "").WithMergePatchFrom( - "zfsrestores.zfs.openebs.io", - oldCrd, - newCrd, - ) cfg, err := k8sapi.Config().Get() if err != nil { diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index 2d7d2bfcc..00c49485c 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -19,6 +19,8 @@ package driver import ( "github.com/container-storage-interface/spec/lib/go/csi" config "github.com/openebs/zfs-localpv/pkg/config" + "github.com/openebs/zfs-localpv/pkg/patcher" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/klog/v2" ) @@ -64,6 +66,39 @@ func New(config *config.Config) *CSIDriver { switch config.PluginType { case "controller": + // CRD upgrade + // Ref: https://github.com/openebs/zfs-localpv/pull/439 + // Ref: https://github.com/openebs/zfs-localpv/pull/457 + crdGvr := schema.GroupVersionResource{ + Group: "apiextensions.k8s.io", + Version: "v1", + Resource: "CustomResourceDefinition", + } + + oldCrd, _ := patcher.OldZfsVolumesCrd() + newCrd, _ := patcher.NewZfsVolumesCrd() + patcher.PatchCrdOrIgnore(crdGvr, "").WithMergePatchFrom( + "zfsvolumes.zfs.openebs.io", + oldCrd, + newCrd, + ) + + oldCrd, _ = patcher.OldZfsSnapshotsCrd() + newCrd, _ = patcher.NewZfsSnapshotsCrd() + patcher.PatchCrdOrIgnore(crdGvr, "").WithMergePatchFrom( + "zfssnapshots.zfs.openebs.io", + oldCrd, + newCrd, + ) + + oldCrd, _ = patcher.OldZfsRestoresCrd() + newCrd, _ = patcher.NewZfsRestoresCrd() + patcher.PatchCrdOrIgnore(crdGvr, "").WithMergePatchFrom( + "zfsrestores.zfs.openebs.io", + oldCrd, + newCrd, + ) + driver.cs = NewController(driver) case "agent": diff --git a/pkg/patcher/patcher.go b/pkg/patcher/patcher.go index 8204a42e8..afe289a6c 100644 --- a/pkg/patcher/patcher.go +++ b/pkg/patcher/patcher.go @@ -3,7 +3,6 @@ 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" @@ -11,6 +10,7 @@ import ( "k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/client-go/dynamic" "k8s.io/client-go/rest" + "os" ) type Patchable struct { @@ -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 } @@ -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 } diff --git a/pkg/patcher/zfsrestore-crd.yaml b/pkg/patcher/zfsrestore-crd.yaml index c606faa7f..3bf56ec31 100644 --- a/pkg/patcher/zfsrestore-crd.yaml +++ b/pkg/patcher/zfsrestore-crd.yaml @@ -100,7 +100,7 @@ spec: data. For instance, if the Volume was created with "off" and the next day the compression was modified to "on", the data written prior to setting "on" will not be compressed. Default Value: off.' - pattern: ^(on|off|lzjb|zstd|gzip|gzip-[1-9]|zle|lz4|halder)$ + pattern: ^(on|off|lzjb|zstd|gzip|gzip-[1-9]|zle|lz4)$ type: string dedup: description: 'Deduplication is the process for removing redundant diff --git a/pkg/patcher/zfssnapshot-crd.yaml b/pkg/patcher/zfssnapshot-crd.yaml index 0b7dd80bb..ed3ce1c27 100644 --- a/pkg/patcher/zfssnapshot-crd.yaml +++ b/pkg/patcher/zfssnapshot-crd.yaml @@ -69,7 +69,7 @@ spec: data. For instance, if the Volume was created with "off" and the next day the compression was modified to "on", the data written prior to setting "on" will not be compressed. Default Value: off.' - pattern: ^(on|off|lzjb|zstd|gzip|gzip-[1-9]|zle|lz4|niladri)$ + pattern: ^(on|off|lzjb|zstd|gzip|gzip-[1-9]|zle|lz4)$ type: string dedup: description: 'Deduplication is the process for removing redundant diff --git a/pkg/patcher/zfsvolume-crd.yaml b/pkg/patcher/zfsvolume-crd.yaml index 6200b0027..99ff81336 100644 --- a/pkg/patcher/zfsvolume-crd.yaml +++ b/pkg/patcher/zfsvolume-crd.yaml @@ -95,7 +95,7 @@ spec: data. For instance, if the Volume was created with "off" and the next day the compression was modified to "on", the data written prior to setting "on" will not be compressed. Default Value: off.' - pattern: ^(on|off|lzjb|zstd|gzip|gzip-[1-9]|zle|lz4|maa)$ + pattern: ^(on|off|lzjb|zstd|gzip|gzip-[1-9]|zle|lz4)$ type: string dedup: description: 'Deduplication is the process for removing redundant