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 35e06fd commit 1b32be2
Show file tree
Hide file tree
Showing 9 changed files with 2,232 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ informer:
manifests:
@echo "+ Generating zfs localPV crds"
$(PWD)/buildscripts/generate-manifests.sh
for file in volume snapshot restore;do cp ./deploy/yamls/zfs"$$file"-crd.yaml ./pkg/patcher/;done

helm:
@echo "+ Copying generated CRDs to helm charts"
Expand Down
1 change: 1 addition & 0 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func NewController(d *CSIDriver) csi.ControllerServer {
}

func (cs *controller) init() error {

cfg, err := k8sapi.Config().Get()
if err != nil {
return errors.Wrapf(err, "failed to build kubeconfig")
Expand Down
35 changes: 35 additions & 0 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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":
Expand Down
27 changes: 27 additions & 0 deletions pkg/patcher/newcrd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package patcher

import (
_ "embed"
"sigs.k8s.io/yaml"
)

//go:embed zfsvolume-crd.yaml
var vol []byte

//go:embed zfssnapshot-crd.yaml
var snap []byte

//go:embed zfsrestore-crd.yaml
var res []byte

func NewZfsVolumesCrd() ([]byte, error) {
return yaml.YAMLToJSON(vol)
}

func NewZfsSnapshotsCrd() ([]byte, error) {
return yaml.YAMLToJSON(snap)
}

func NewZfsRestoresCrd() ([]byte, error) {
return yaml.YAMLToJSON(res)
}
Loading

0 comments on commit 1b32be2

Please sign in to comment.