Skip to content

Commit

Permalink
feat(velero-plugin) : adding support for velero:v1.0.0-rc.1 (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: mayank <[email protected]>
  • Loading branch information
mynktl authored and vishnuitta committed May 17, 2019
1 parent f535b55 commit 1e39cc2
Show file tree
Hide file tree
Showing 783 changed files with 23,107 additions and 174,655 deletions.
236 changes: 57 additions & 179 deletions Gopkg.lock

Large diffs are not rendered by default.

35 changes: 4 additions & 31 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

[[constraint]]
name = "github.com/heptio/velero"
version = "v0.11.0"
version = "v1.0.0-rc.1"

[[constraint]]
name = "github.com/aws/aws-sdk-go"
Expand All @@ -36,50 +36,23 @@
name = "github.com/sirupsen/logrus"
version = "1.4.1"

[[override]]
name = "github.com/Azure/go-autorest"
revision = "1ff28809256a84bb6966640ff3d0371af82ccba4"

[[constraint]]
name = "gocloud.dev"
version = "0.13.0"

[[constraint]]
name = "k8s.io/api"
version = "kubernetes-1.11.0"
version = "kubernetes-1.12.0"

[[constraint]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.11.0"
version = "kubernetes-1.12.0"
# revision = "6dd46049f39503a1fc8d65de4bd566829e95faff"

[[constraint]]
name = "k8s.io/client-go"
version = "8.0.0"
version = "9.0.0"

[prune]
go-tests = true
unused-packages = true

[[override]]
name = "github.com/hashicorp/go-plugin"
revision = "e2fbc6864d18d3c37b6cde4297ec9fca266d28f1"

[[override]]
name = "github.com/hashicorp/go-hclog"
revision = "ca137eb4b4389c9bc6f1a6d887f056bf16c00510"

#[[projects]]
# branch = "master"
# name = "github.com/hashicorp/golang-lru"
# packages = [
# ".",
# "simplelru"
# ]
# revision = "0a025b7e63adc15a622f29b0b2c4c3848243bbf6"

#[[projects]]
# branch = "master"
# name = "github.com/hashicorp/yamux"
# packages = ["."]
# revision = "f5742cb6b85602e7fa834e9d5d91a7d7fa850824"
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
[![Build Status](https://travis-ci.org/openebs/velero-plugin.svg?branch=master)](https://travis-ci.org/openebs/velero-plugin)
[![Go Report](https://goreportcard.com/badge/github.com/openebs/velero-plugin)](https://goreportcard.com/report/github.com/openebs/velero-plugin)

Heptio Velero is a utility to back up and restore your Kubernetes resource and persistent volumes.
Velero is a utility to back up and restore your Kubernetes resource and persistent volumes.

To do backup/restore of OpenEBS CStor volumes through Velero utility, you need to install and configure
OpenEBS velero-plugin.

## Prerequisite for velero-plugin
Specific version of Heptio Velero needs to be installed as per the [compatibility matrix](#Compatibility-matrix) with OpenEBS versions.
Specific version of Velero needs to be installed as per the [compatibility matrix](#Compatibility-matrix) with OpenEBS versions.

For installation steps of Heptio Velero, visit https://heptio.github.io/velero.
For installation steps of Velero, visit https://heptio.github.io/velero.

For installation steps of OpenEBS, visit https://github.com/openebs/openebs/releases.

Expand Down Expand Up @@ -120,9 +120,10 @@ velero restore create --from-backup sched-20190513104034 --restore-volumes=true

## Compatibility matrix

| Image | Codebase | Heptio Velero v0.10.0 | Heptio Velero v0.11.0 |
| --------------- | ------------- | ---------------- | --------------- |
| ark-plugin:0.9.0-RC2 | v0.9.x || |
| velero-plugin:ci | master | ||
| Image | Codebase | Velero v0.10.0 | Velero v0.11.0 | Velero v1.0.0-rc.1 |
| ------------------- | ---------------| --------- | --------------- | ----------------- |
| velero-plugin:0.9.0-RC2 | v0.9.x || | |
| velero-plugin:0.9.0-RC3 | v0.9.x | || |
| velero-plugin:ci | master | | ||

Plugin images are available at quay.io and hub.docker.com.
54 changes: 26 additions & 28 deletions pkg/cstor/cstor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"strings"
"time"

"github.com/heptio/velero/pkg/util/collections"
cloud "github.com/openebs/velero-plugin/pkg/clouduploader"
"github.com/pkg/errors"
/* Due to dependency conflict, please ensure openebs
Expand All @@ -36,6 +35,7 @@ import (
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
Expand Down Expand Up @@ -183,35 +183,27 @@ func (p *Plugin) Init(config map[string]string) error {
}

// GetVolumeID return volume name for given PV
func (p *Plugin) GetVolumeID(pv runtime.Unstructured) (string, error) {
if !collections.Exists(pv.UnstructuredContent(), "metadata") {
return "", nil
}
func (p *Plugin) GetVolumeID(unstructuredPV runtime.Unstructured) (string, error) {
pv := new(v1.PersistentVolume)

// Seed the volume info so that GetVolumeInfo doesn't fail later.
volumeID, err := collections.GetString(pv.UnstructuredContent(), "metadata.name")
if err != nil {
p.Log.Errorf("Failed to fetch volume name from PV : %s", err.Error())
return "", errors.New("Failed to fetch volume name")
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredPV.UnstructuredContent(), pv); err != nil {
return "", errors.WithStack(err)
}

if _, exists := p.volumes[volumeID]; !exists {
sc, sret := collections.GetString(pv.UnstructuredContent(), "spec.storageClassName")
ns, nret := collections.GetString(pv.UnstructuredContent(), "spec.claimRef.namespace")

if sret != nil || nret != nil {
p.Log.Errorf("Failed to build volume info sc:{%s} ns:{%s}", sc, ns)
return "", errors.New("Failed to build volume info")
}
if pv.Name == "" || pv.Spec.StorageClassName == "" || (pv.Spec.ClaimRef != nil && pv.Spec.ClaimRef.Namespace == "") {
p.Log.Errorf("Insufficient info for PV : %v", pv)
return "", errors.New("Insufficient info for PV")
}

p.volumes[volumeID] = &Volume{
volname: volumeID,
casType: sc,
namespace: ns,
if _, exists := p.volumes[pv.Name]; !exists {
p.volumes[pv.Name] = &Volume{
volname: pv.Name,
casType: pv.Spec.StorageClassName,
namespace: pv.Spec.ClaimRef.Namespace,
}
}

return collections.GetString(pv.UnstructuredContent(), "metadata.name")
return pv.Name, nil
}

// DeleteSnapshot delete CStor volume snapshot
Expand Down Expand Up @@ -564,14 +556,20 @@ func (p *Plugin) backupPVC(volumeID string) error {
}

// SetVolumeID set volumeID for given PV
func (p *Plugin) SetVolumeID(pv runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
metadataMap, err := collections.GetMap(pv.UnstructuredContent(), "spec.iscsi")
func (p *Plugin) SetVolumeID(unstructuredPV runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
pv := new(v1.PersistentVolume)

if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredPV.UnstructuredContent(), pv); err != nil {
return nil, errors.WithStack(err)
}

// We will not update HostPath since CStor volume doesn't have one
res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(pv)
if err != nil {
return nil, err
return nil, errors.WithStack(err)
}

metadataMap["volumeID"] = volumeID
return pv, nil
return &unstructured.Unstructured{Object: res}, nil
}

// httpRestCall execute REST API
Expand Down
14 changes: 7 additions & 7 deletions pkg/snapshot/snap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package snapshot

import (
"github.com/heptio/velero/pkg/cloudprovider"
"github.com/heptio/velero/pkg/plugin/velero"
"github.com/openebs/velero-plugin/pkg/cstor"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -26,10 +26,10 @@ import (
// BlockStore : Plugin for containing state for the blockstore plugin
type BlockStore struct {
Log logrus.FieldLogger
plugin cloudprovider.BlockStore
plugin velero.VolumeSnapshotter
}

var _ cloudprovider.BlockStore = (*BlockStore)(nil)
var _ velero.VolumeSnapshotter = (*BlockStore)(nil)

// Init the plugin
func (p *BlockStore) Init(config map[string]string) error {
Expand Down Expand Up @@ -66,11 +66,11 @@ func (p *BlockStore) DeleteSnapshot(snapshotID string) error {
}

// GetVolumeID Get the volume ID from the spec
func (p *BlockStore) GetVolumeID(pv runtime.Unstructured) (string, error) {
return p.plugin.GetVolumeID(pv)
func (p *BlockStore) GetVolumeID(unstructuredPV runtime.Unstructured) (string, error) {
return p.plugin.GetVolumeID(unstructuredPV)
}

// SetVolumeID Set the volume ID in the spec
func (p *BlockStore) SetVolumeID(pv runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
return p.plugin.SetVolumeID(pv, volumeID)
func (p *BlockStore) SetVolumeID(unstructuredPV runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
return p.plugin.SetVolumeID(unstructuredPV, volumeID)
}
6 changes: 3 additions & 3 deletions velero-blockstore-cstor/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package main

import (
veleroplugin "github.com/heptio/velero/pkg/plugin"
veleroplugin "github.com/heptio/velero/pkg/plugin/framework"
snap "github.com/openebs/velero-plugin/pkg/snapshot"
"github.com/sirupsen/logrus"
)

func main() {
veleroplugin.NewServer(veleroplugin.NewLogger()).
RegisterBlockStore("cstor-blockstore", openebsSnapPlugin).
veleroplugin.NewServer().
RegisterVolumeSnapshotter("mayadata.io/cstor-blockstore", openebsSnapPlugin).
Serve()
}

Expand Down
5 changes: 0 additions & 5 deletions vendor/github.com/Azure/azure-sdk-for-go/NOTICE

This file was deleted.

53 changes: 0 additions & 53 deletions vendor/github.com/Azure/azure-sdk-for-go/arm/disk/client.go

This file was deleted.

Loading

0 comments on commit 1e39cc2

Please sign in to comment.