Skip to content

Commit

Permalink
Use VolumeSnapshot v1beta1 api
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <tamal@appscode.com>
  • Loading branch information
tamalsaha committed Nov 28, 2019
1 parent 7223ba9 commit 2fd6976
Show file tree
Hide file tree
Showing 30 changed files with 748 additions and 515 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ replace (
github.com/Azure/go-autorest/autorest/validation => github.com/Azure/go-autorest/autorest/validation v0.1.0
github.com/Azure/go-autorest/logger => github.com/Azure/go-autorest/logger v0.1.0
github.com/Azure/go-autorest/tracing => github.com/Azure/go-autorest/tracing v0.5.0
github.com/kubernetes-csi/external-snapshotter => github.com/kmodules/external-snapshotter v1.2.1-0.20191128100451-0265c5fa679a
google.golang.org/api => google.golang.org/api v0.6.1-0.20190607001116-5213b8090861
k8s.io/api => k8s.io/api v0.0.0-20191114100352-16d7abae0d2a
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20191114105449-027877536833
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ github.com/kmodules/apimachinery v0.0.0-20191119091232-0553326db082 h1:Fut+qzge/
github.com/kmodules/apimachinery v0.0.0-20191119091232-0553326db082/go.mod h1:llRdnznGEAqC3DcNm6yEj472xaFVfLM7hnYofMb12tQ=
github.com/kmodules/apiserver v0.0.0-20191119111000-36ac3646ae82 h1:7YgT9xEZLII4FfFA8qDafK06xl06qMs3vNaUTY2lCCU=
github.com/kmodules/apiserver v0.0.0-20191119111000-36ac3646ae82/go.mod h1:Idob8Va6/sMX5SmwPLsU0pdvFlkwxuJ5x+fXMG8NbKE=
github.com/kmodules/external-snapshotter v1.2.1-0.20191128100451-0265c5fa679a h1:m5lRkgKIVs2A5oW5Yycm1Pjf8OYygRe1HZra+Xzc6Ao=
github.com/kmodules/external-snapshotter v1.2.1-0.20191128100451-0265c5fa679a/go.mod h1:AOawSVYDFABiUvZfz80qIDQB5G9YFGRQQPaMvb8pKvI=
github.com/kmodules/kubernetes v1.17.0-alpha.0.0.20191127022853-9d027e3886fd h1:6YA0k2t8FcyWw8kqHpv5clX73LjBfsi5I2oELS0r43s=
github.com/kmodules/kubernetes v1.17.0-alpha.0.0.20191127022853-9d027e3886fd/go.mod h1:SJfd/nrBVxpEiliWZ8PhAdyREKhxmcuOV8m2hn2WsqY=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
Expand All @@ -292,8 +294,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kubernetes-csi/external-snapshotter v1.2.2 h1:OPXoJydNqkWjhLwJ20dSqOhkmUYcpm+CCO0pYm+C8Q8=
github.com/kubernetes-csi/external-snapshotter v1.2.2/go.mod h1:oYfxnsuh48V1UDYORl77YQxQbbdokNy7D73phuFpksY=
github.com/kubernetes-csi/csi-lib-utils v0.6.1/go.mod h1:GVmlUmxZ+SUjVLXicRFjqWUUvWez0g0Y78zNV9t7KfQ=
github.com/kubernetes-csi/csi-test v2.2.0+incompatible/go.mod h1:YxJ4UiuPWIhMBkxUKY5c267DyA0uDZ/MtAimhx/2TA0=
github.com/kubernetes-incubator/service-catalog v0.2.2/go.mod h1:D0CRODiXUJs6VCZDB15TmCkesbuizkac9fYEiTA78BA=
github.com/kubernetes-sigs/service-catalog v0.2.2/go.mod h1:fmRsWJ38Od93DQ7cOXR9mMSSwmjyDS1EAomWxBlumuo=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
Expand Down
9 changes: 4 additions & 5 deletions pkg/cmds/create_volumesnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"stash.appscode.dev/stash/pkg/volumesnapshot"

"github.com/appscode/go/log"
vs "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
vs "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1beta1"
vs_cs "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned"
"github.com/spf13/cobra"
appsv1 "k8s.io/api/apps/v1"
Expand Down Expand Up @@ -130,7 +130,7 @@ func (opt *VSoption) createVolumeSnapshot() (*restic.BackupOutput, error) {
// use timestamp suffix of BackupSession name as suffix of the VolumeSnapshots name
parts := strings.Split(backupSession.Name, "-")
volumeSnapshot := opt.getVolumeSnapshotDefinition(backupConfig, pvcName, parts[len(parts)-1])
snapshot, err := opt.snapshotClient.SnapshotV1alpha1().VolumeSnapshots(opt.namespace).Create(&volumeSnapshot)
snapshot, err := opt.snapshotClient.SnapshotV1beta1().VolumeSnapshots(opt.namespace).Create(&volumeSnapshot)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -219,9 +219,8 @@ func (opt *VSoption) getVolumeSnapshotDefinition(backupConfiguration *v1beta1.Ba
},
Spec: vs.VolumeSnapshotSpec{
VolumeSnapshotClassName: &backupConfiguration.Spec.Target.VolumeSnapshotClassName,
Source: &corev1.TypedLocalObjectReference{
Kind: apis.KindPersistentVolumeClaim,
Name: pvcName,
Source: vs.VolumeSnapshotSource{
PersistentVolumeClaimName: &pvcName,
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmds/restore_volumesnapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (opt *VSoption) restoreVolumeSnapshot() (*restic.RestoreOutput, error) {
for i := range pvcList {
// verify that the respective VolumeSnapshot exist
if pvcList[i].Spec.DataSource != nil {
_, err = opt.snapshotClient.SnapshotV1alpha1().VolumeSnapshots(opt.namespace).Get(pvcList[i].Spec.DataSource.Name, metav1.GetOptions{})
_, err = opt.snapshotClient.SnapshotV1beta1().VolumeSnapshots(opt.namespace).Get(pvcList[i].Spec.DataSource.Name, metav1.GetOptions{})
if err != nil {
if kerr.IsNotFound(err) { // respective VolumeSnapshot does not exist
restoreOutput.HostRestoreStats = append(restoreOutput.HostRestoreStats, api_v1beta1.HostRestoreStats{
Expand Down
2 changes: 1 addition & 1 deletion pkg/rbac/volume_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
api_v1alpha1 "stash.appscode.dev/stash/apis/stash/v1alpha1"
api_v1beta1 "stash.appscode.dev/stash/apis/stash/v1beta1"

crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1beta1"
apps "k8s.io/api/apps/v1"
core "k8s.io/api/core/v1"
rbac "k8s.io/api/rbac/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (r *REST) List(ctx context.Context, options *metainternalversion.ListOption
return snapshotList, nil
}

func (r *REST) Delete(ctx context.Context, name string, options *metav1.DeleteOptions) (runtime.Object, bool, error) {
func (r *REST) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions) (runtime.Object, bool, error) {
ns, ok := apirequest.NamespaceFrom(ctx)
if !ok {
return nil, false, apierrors.NewBadRequest("missing namespace")
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ func WaitUntilDeploymentConfigReady(c oc_cs.Interface, meta metav1.ObjectMeta) e

func WaitUntilVolumeSnapshotReady(c snapshot_cs.Interface, meta metav1.ObjectMeta) error {
return wait.PollImmediate(RetryInterval, 2*time.Hour, func() (bool, error) {
if obj, err := c.SnapshotV1alpha1().VolumeSnapshots(meta.Namespace).Get(meta.Name, metav1.GetOptions{}); err == nil {
return obj.Status.ReadyToUse, nil
if obj, err := c.SnapshotV1beta1().VolumeSnapshots(meta.Namespace).Get(meta.Name, metav1.GetOptions{}); err == nil {
return obj.Status.ReadyToUse != nil && *obj.Status.ReadyToUse, nil
}
return false, nil
})
Expand Down
15 changes: 11 additions & 4 deletions pkg/volumesnapshot/volumesnapshot_cleanup_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"stash.appscode.dev/stash/apis/stash/v1beta1"

"github.com/appscode/go/log"
vs_api "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
vs_api "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1beta1"
vs_cs "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned"
kerr "k8s.io/apimachinery/pkg/api/errors"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -142,7 +142,7 @@ func applyRetentionPolicy(policy v1alpha1.RetentionPolicy, volumeSnapshots Volum
}

for _, vs := range removed {
err := vsClient.SnapshotV1alpha1().VolumeSnapshots(namespace).Delete(vs.VolumeSnap.Name, &v1.DeleteOptions{})
err := vsClient.SnapshotV1beta1().VolumeSnapshots(namespace).Delete(vs.VolumeSnap.Name, &v1.DeleteOptions{})
if err != nil {
if kerr.IsNotFound(err) {
return nil
Expand All @@ -156,7 +156,7 @@ func applyRetentionPolicy(policy v1alpha1.RetentionPolicy, volumeSnapshots Volum
}

func CleanupSnapshots(policy v1alpha1.RetentionPolicy, hostBackupStats []v1beta1.HostBackupStats, namespace string, vsClient vs_cs.Interface) error {
vsList, err := vsClient.SnapshotV1alpha1().VolumeSnapshots(namespace).List(v1.ListOptions{})
vsList, err := vsClient.SnapshotV1beta1().VolumeSnapshots(namespace).List(v1.ListOptions{})
if err != nil {
if kerr.IsNotFound(err) || len(vsList.Items) == 0 {
return nil
Expand All @@ -168,7 +168,14 @@ func CleanupSnapshots(policy v1alpha1.RetentionPolicy, hostBackupStats []v1beta1
for _, host := range hostBackupStats {
var volumeSnapshots VolumeSnapshots
for _, vs := range vsList.Items {
if host.Hostname == vs.Spec.Source.Name {
var src string
if vs.Spec.Source.PersistentVolumeClaimName != nil {
src = *vs.Spec.Source.PersistentVolumeClaimName
}
if vs.Spec.Source.VolumeSnapshotContentName != nil {
src = *vs.Spec.Source.VolumeSnapshotContentName
}
if host.Hostname == src {
volumeSnapshots = append(volumeSnapshots, VolumeSnapshot{VolumeSnap: vs})
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/volumesnapshot/volumesnapshot_cleanup_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"github.com/appscode/go/strings"
type_util "github.com/appscode/go/types"
crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1beta1"
vsfake "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned/fake"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestCleanupSnapshots(t *testing.T) {
t.Errorf("Failed to cleanup VolumeSnapshots. Reason: %v", err)
return
}
vsList, err := vsClient.SnapshotV1alpha1().VolumeSnapshots(testNamespace).List(metav1.ListOptions{})
vsList, err := vsClient.SnapshotV1beta1().VolumeSnapshots(testNamespace).List(metav1.ListOptions{})
if err != nil {
t.Errorf("Failed to list remaining VolumeSnapshots. Reason: %v", err)
return
Expand Down
Loading

0 comments on commit 2fd6976

Please sign in to comment.