Skip to content

Commit cc9996a

Browse files
Update external snapshotter deps v4 to v7 (#197)
Signed-off-by: Md. Ishtiaq Islam <ishtiaq@appscode.com> Signed-off-by: hmsayem <hmsayem@appscode.com> Co-authored-by: hmsayem <hmsayem@appscode.com>
1 parent 2330558 commit cc9996a

40 files changed

+1673
-1454
lines changed

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ module stash.appscode.dev/cli
33
go 1.21.7
44

55
require (
6-
github.com/evanphx/json-patch v5.7.0+incompatible
7-
github.com/json-iterator/go v1.1.12
8-
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
6+
github.com/kubernetes-csi/external-snapshotter/client/v7 v7.0.0
97
github.com/pkg/errors v0.9.1
108
github.com/spf13/cobra v1.7.0
119
golang.org/x/text v0.14.0
@@ -23,6 +21,7 @@ require (
2321
k8s.io/kube-aggregator v0.29.0
2422
k8s.io/kubectl v0.29.0
2523
kmodules.xyz/client-go v0.29.7
24+
kmodules.xyz/csi-utils v0.29.1
2625
kmodules.xyz/objectstore-api v0.29.1
2726
kmodules.xyz/offshoot-api v0.29.0
2827
kmodules.xyz/openshift v0.29.0
@@ -45,6 +44,7 @@ require (
4544
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
4645
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4746
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
47+
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
4848
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
4949
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
5050
github.com/fatih/structs v1.1.0 // indirect
@@ -69,6 +69,7 @@ require (
6969
github.com/imdario/mergo v0.3.13 // indirect
7070
github.com/inconshreveable/mousetrap v1.1.0 // indirect
7171
github.com/josharian/intern v1.0.0 // indirect
72+
github.com/json-iterator/go v1.1.12 // indirect
7273
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
7374
github.com/mailru/easyjson v0.7.7 // indirect
7475
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect

go.sum

Lines changed: 4 additions & 121 deletions
Large diffs are not rendered by default.

pkg/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
cs "stash.appscode.dev/apimachinery/client/clientset/versioned"
2323
"stash.appscode.dev/apimachinery/pkg/docker"
2424

25-
vs_cs "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
25+
vs_cs "github.com/kubernetes-csi/external-snapshotter/client/v7/clientset/versioned"
2626
"k8s.io/client-go/kubernetes"
2727
"k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
2828
)

pkg/copy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package pkg
1919
import (
2020
cs "stash.appscode.dev/apimachinery/client/clientset/versioned"
2121

22-
vs_cs "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
22+
vs_cs "github.com/kubernetes-csi/external-snapshotter/client/v7/clientset/versioned"
2323
"github.com/pkg/errors"
2424
"github.com/spf13/cobra"
2525
"k8s.io/cli-runtime/pkg/genericclioptions"

pkg/copy_volumesnapshot.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ import (
2020
"context"
2121
"fmt"
2222

23-
jsoniter "github.com/json-iterator/go"
24-
vs_api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1"
25-
vs_v1alpha1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1"
23+
vsapi "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
2624
"github.com/spf13/cobra"
2725
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2826
"k8s.io/klog/v2"
27+
vsu "kmodules.xyz/csi-utils/volumesnapshot/v1"
2928
)
3029

31-
var json = jsoniter.ConfigFastest
32-
3330
func NewCmdCopyVolumeSnapshot() *cobra.Command {
3431
cmd := &cobra.Command{
3532
Use: "volumesnapshot",
@@ -44,7 +41,7 @@ func NewCmdCopyVolumeSnapshot() *cobra.Command {
4441
volumeSnapshotName := args[0]
4542

4643
// get source VolumeSnapshot object
47-
vs, err := vsClient.SnapshotV1beta1().VolumeSnapshots(srcNamespace).Get(context.TODO(), volumeSnapshotName, metav1.GetOptions{})
44+
vs, err := vsClient.SnapshotV1().VolumeSnapshots(srcNamespace).Get(context.TODO(), volumeSnapshotName, metav1.GetOptions{})
4845
if err != nil {
4946
return err
5047
}
@@ -69,8 +66,8 @@ func NewCmdCopyVolumeSnapshot() *cobra.Command {
6966
return cmd
7067
}
7168

72-
func createVolumeSnapshot(vs *vs_v1alpha1.VolumeSnapshot, meta metav1.ObjectMeta) (*vs_v1alpha1.VolumeSnapshot, error) {
73-
vs, _, err := CreateOrPatchVolumeSnapshot(context.TODO(), vsClient.SnapshotV1beta1(), meta, func(in *vs_api.VolumeSnapshot) *vs_api.VolumeSnapshot {
69+
func createVolumeSnapshot(vs *vsapi.VolumeSnapshot, meta metav1.ObjectMeta) (*vsapi.VolumeSnapshot, error) {
70+
vs, _, err := vsu.CreateOrPatchVolumeSnapshot(context.TODO(), vsClient, meta, func(in *vsapi.VolumeSnapshot) *vsapi.VolumeSnapshot {
7471
in.Spec = vs.Spec
7572
return in
7673
}, metav1.PatchOptions{})

pkg/create_restoresession.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"stash.appscode.dev/apimachinery/apis/stash/v1beta1"
2424
v1beta1_util "stash.appscode.dev/apimachinery/client/clientset/versioned/typed/stash/v1beta1/util"
2525

26-
vs "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1"
26+
vs "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
2727
"github.com/spf13/cobra"
2828
"gomodules.xyz/pointer"
2929
core "k8s.io/api/core/v1"

pkg/util.go

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,77 +26,22 @@ import (
2626
"stash.appscode.dev/apimachinery/apis"
2727
"stash.appscode.dev/apimachinery/apis/stash/v1beta1"
2828

29-
jsonpatch "github.com/evanphx/json-patch"
30-
vs_api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1beta1"
31-
vs "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned/typed/volumesnapshot/v1beta1"
3229
core "k8s.io/api/core/v1"
33-
kerr "k8s.io/apimachinery/pkg/api/errors"
3430
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
35-
"k8s.io/apimachinery/pkg/types"
3631
"k8s.io/apimachinery/pkg/util/wait"
3732
"k8s.io/client-go/kubernetes"
3833
"k8s.io/client-go/rest"
39-
"k8s.io/client-go/tools/clientcmd/api"
4034
"k8s.io/client-go/tools/remotecommand"
4135
"k8s.io/klog/v2"
4236
"k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
4337
"k8s.io/kubectl/pkg/scheme"
44-
kutil "kmodules.xyz/client-go"
4538
)
4639

4740
const (
4841
PullInterval = time.Second * 2
4942
WaitTimeOut = time.Minute * 10
5043
)
5144

52-
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) {
53-
cur, err := c.VolumeSnapshots(meta.Namespace).Get(context.TODO(), meta.Name, metav1.GetOptions{})
54-
if kerr.IsNotFound(err) {
55-
klog.V(3).Infof("Creating VolumeSnapshot %s/%s.", meta.Namespace, meta.Name)
56-
out, err := c.VolumeSnapshots(meta.Namespace).Create(ctx, transform(&vs_api.VolumeSnapshot{
57-
TypeMeta: metav1.TypeMeta{
58-
Kind: "VolumeSnapshot",
59-
APIVersion: api.SchemeGroupVersion.String(),
60-
},
61-
ObjectMeta: meta,
62-
}), metav1.CreateOptions{
63-
DryRun: opts.DryRun,
64-
FieldManager: opts.FieldManager,
65-
})
66-
return out, kutil.VerbCreated, err
67-
} else if err != nil {
68-
return nil, kutil.VerbUnchanged, err
69-
}
70-
return PatchVolumeSnapshot(ctx, c, cur, transform, opts)
71-
}
72-
73-
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) {
74-
return PatchVolumesnapshotObject(ctx, c, cur, transform(cur.DeepCopy()), opts)
75-
}
76-
77-
func PatchVolumesnapshotObject(ctx context.Context, c vs.SnapshotV1beta1Interface, cur, mod *vs_api.VolumeSnapshot, opts metav1.PatchOptions) (*vs_api.VolumeSnapshot, kutil.VerbType, error) {
78-
curJson, err := json.Marshal(cur)
79-
if err != nil {
80-
return nil, kutil.VerbUnchanged, err
81-
}
82-
83-
modJson, err := json.Marshal(mod)
84-
if err != nil {
85-
return nil, kutil.VerbUnchanged, err
86-
}
87-
88-
patch, err := jsonpatch.CreateMergePatch(curJson, modJson)
89-
if err != nil {
90-
return nil, kutil.VerbUnchanged, err
91-
}
92-
if len(patch) == 0 || string(patch) == "{}" {
93-
return cur, kutil.VerbUnchanged, nil
94-
}
95-
klog.V(3).Infof("Patching VolumeSnapshot %s/%s with %s.", cur.Namespace, cur.Name, string(patch))
96-
out, err := c.VolumeSnapshots(cur.Namespace).Patch(ctx, cur.Name, types.MergePatchType, patch, opts)
97-
return out, kutil.VerbPatched, err
98-
}
99-
10045
func WaitUntilBackupSessionCompleted(name string, namespace string) error {
10146
return wait.PollUntilContextTimeout(context.Background(), PullInterval, WaitTimeOut, true, func(ctx context.Context) (done bool, err error) {
10247
backupSession, err := stashClient.StashV1beta1().BackupSessions(namespace).Get(ctx, name, metav1.GetOptions{})

0 commit comments

Comments
 (0)