Skip to content

Commit

Permalink
Update external snapshotter deps v4 to v7
Browse files Browse the repository at this point in the history
Signed-off-by: Md. Ishtiaq Islam <[email protected]>
  • Loading branch information
ishtiaqhimel committed Apr 8, 2024
1 parent 2330558 commit 2783996
Show file tree
Hide file tree
Showing 40 changed files with 1,673 additions and 1,453 deletions.
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module stash.appscode.dev/cli
go 1.21.7

require (
github.com/evanphx/json-patch v5.7.0+incompatible
github.com/json-iterator/go v1.1.12
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
github.com/kubernetes-csi/external-snapshotter/client/v7 v7.0.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.7.0
golang.org/x/text v0.14.0
Expand All @@ -23,6 +21,7 @@ require (
k8s.io/kube-aggregator v0.29.0
k8s.io/kubectl v0.29.0
kmodules.xyz/client-go v0.29.7
kmodules.xyz/csi-utils v0.29.1
kmodules.xyz/objectstore-api v0.29.1
kmodules.xyz/offshoot-api v0.29.0
kmodules.xyz/openshift v0.29.0
Expand All @@ -45,6 +44,7 @@ require (
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/structs v1.1.0 // indirect
Expand All @@ -69,6 +69,7 @@ require (
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
Expand Down
125 changes: 4 additions & 121 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
cs "stash.appscode.dev/apimachinery/client/clientset/versioned"
"stash.appscode.dev/apimachinery/pkg/docker"

vs_cs "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
vs_cs "github.com/kubernetes-csi/external-snapshotter/client/v7/clientset/versioned"
"k8s.io/client-go/kubernetes"
"k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package pkg
import (
cs "stash.appscode.dev/apimachinery/client/clientset/versioned"

vs_cs "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
vs_cs "github.com/kubernetes-csi/external-snapshotter/client/v7/clientset/versioned"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
Expand Down
12 changes: 5 additions & 7 deletions pkg/copy_volumesnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ import (
"context"
"fmt"

jsoniter "github.com/json-iterator/go"
vs_api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1"
vs_v1alpha1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1"
vs_api "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
vs_v1alpha1 "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
vsu "kmodules.xyz/csi-utils/volumesnapshot/v1"
)

var json = jsoniter.ConfigFastest

func NewCmdCopyVolumeSnapshot() *cobra.Command {
cmd := &cobra.Command{
Use: "volumesnapshot",
Expand All @@ -44,7 +42,7 @@ func NewCmdCopyVolumeSnapshot() *cobra.Command {
volumeSnapshotName := args[0]

// get source VolumeSnapshot object
vs, err := vsClient.SnapshotV1beta1().VolumeSnapshots(srcNamespace).Get(context.TODO(), volumeSnapshotName, metav1.GetOptions{})
vs, err := vsClient.SnapshotV1().VolumeSnapshots(srcNamespace).Get(context.TODO(), volumeSnapshotName, metav1.GetOptions{})
if err != nil {
return err
}
Expand All @@ -70,7 +68,7 @@ func NewCmdCopyVolumeSnapshot() *cobra.Command {
}

func createVolumeSnapshot(vs *vs_v1alpha1.VolumeSnapshot, meta metav1.ObjectMeta) (*vs_v1alpha1.VolumeSnapshot, error) {
vs, _, err := CreateOrPatchVolumeSnapshot(context.TODO(), vsClient.SnapshotV1beta1(), meta, func(in *vs_api.VolumeSnapshot) *vs_api.VolumeSnapshot {
vs, _, err := vsu.CreateOrPatchVolumeSnapshot(context.TODO(), vsClient, meta, func(in *vs_api.VolumeSnapshot) *vs_api.VolumeSnapshot {
in.Spec = vs.Spec
return in
}, metav1.PatchOptions{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/create_restoresession.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"stash.appscode.dev/apimachinery/apis/stash/v1beta1"
v1beta1_util "stash.appscode.dev/apimachinery/client/clientset/versioned/typed/stash/v1beta1/util"

vs "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1"
vs "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
"github.com/spf13/cobra"
"gomodules.xyz/pointer"
core "k8s.io/api/core/v1"
Expand Down
55 changes: 0 additions & 55 deletions pkg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,77 +26,22 @@ import (
"stash.appscode.dev/apimachinery/apis"
"stash.appscode.dev/apimachinery/apis/stash/v1beta1"

jsonpatch "github.com/evanphx/json-patch"
vs_api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1"
vs "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned/typed/volumesnapshot/v1beta1"
core "k8s.io/api/core/v1"
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/tools/remotecommand"
"k8s.io/klog/v2"
"k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
"k8s.io/kubectl/pkg/scheme"
kutil "kmodules.xyz/client-go"
)

const (
PullInterval = time.Second * 2
WaitTimeOut = time.Minute * 10
)

func CreateOrPatchVolumeSnapshot(ctx context.Context, c vs.SnapshotV1beta1Interface, meta metav1.ObjectMeta, transform func(alert *vs_api.VolumeSnapshot) *vs_api.VolumeSnapshot, opts metav1.PatchOptions) (*vs_api.VolumeSnapshot, kutil.VerbType, error) {
cur, err := c.VolumeSnapshots(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{})
if kerr.IsNotFound(err) {
klog.V(3).Infof("Creating VolumeSnapshot %s/%s.", meta.Namespace, meta.Name)
out, err := c.VolumeSnapshots(meta.Namespace).Create(ctx, transform(&vs_api.VolumeSnapshot{
TypeMeta: metav1.TypeMeta{
Kind: "VolumeSnapshot",
APIVersion: api.SchemeGroupVersion.String(),
},
ObjectMeta: meta,
}), metav1.CreateOptions{
DryRun: opts.DryRun,
FieldManager: opts.FieldManager,
})
return out, kutil.VerbCreated, err
} else if err != nil {
return nil, kutil.VerbUnchanged, err
}
return PatchVolumeSnapshot(ctx, c, cur, transform, opts)
}

func PatchVolumeSnapshot(ctx context.Context, c vs.SnapshotV1beta1Interface, cur *vs_api.VolumeSnapshot, transform func(alert *vs_api.VolumeSnapshot) *vs_api.VolumeSnapshot, opts metav1.PatchOptions) (*vs_api.VolumeSnapshot, kutil.VerbType, error) {
return PatchVolumesnapshotObject(ctx, c, cur, transform(cur.DeepCopy()), opts)
}

func PatchVolumesnapshotObject(ctx context.Context, c vs.SnapshotV1beta1Interface, cur, mod *vs_api.VolumeSnapshot, opts metav1.PatchOptions) (*vs_api.VolumeSnapshot, kutil.VerbType, error) {
curJson, err := json.Marshal(cur)
if err != nil {
return nil, kutil.VerbUnchanged, err
}

modJson, err := json.Marshal(mod)
if err != nil {
return nil, kutil.VerbUnchanged, err
}

patch, err := jsonpatch.CreateMergePatch(curJson, modJson)
if err != nil {
return nil, kutil.VerbUnchanged, err
}
if len(patch) == 0 || string(patch) == "{}" {
return cur, kutil.VerbUnchanged, nil
}
klog.V(3).Infof("Patching VolumeSnapshot %s/%s with %s.", cur.Namespace, cur.Name, string(patch))
out, err := c.VolumeSnapshots(cur.Namespace).Patch(ctx, cur.Name, types.MergePatchType, patch, opts)
return out, kutil.VerbPatched, err
}

func WaitUntilBackupSessionCompleted(name string, namespace string) error {
return wait.PollUntilContextTimeout(context.Background(), PullInterval, WaitTimeOut, true, func(ctx context.Context) (done bool, err error) {
backupSession, err := stashClient.StashV1beta1().BackupSessions(namespace).Get(ctx, name, metav1.GetOptions{})
Expand Down
Loading

0 comments on commit 2783996

Please sign in to comment.