Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(controller): patch CRDs to upgrade them #460

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading