Skip to content

Commit

Permalink
feat(snapshot): add snapshot support for LVM PV (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: Akhil Mohan <[email protected]>
  • Loading branch information
akhilerm authored Feb 8, 2021
1 parent b370f3c commit 7e0bd8a
Show file tree
Hide file tree
Showing 50 changed files with 3,457 additions and 676 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ Features
- [ ] Supports fsTypes: `ext4`, `btrfs`, `xfs`
- [x] Volume metrics
- [x] Topology
- [ ] Snapshot
- [x] Snapshot
- [ ] Clone
- [ ] Volume Resize
- [x] Volume Resize
- [ ] Backup/Restore
- [ ] Ephemeral inline volume

### Limitation
- Resize of volumes with snapshot is not supported
2 changes: 1 addition & 1 deletion buildscripts/custom-boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The OpenEBS Authors
Copyright 2021 The OpenEBS Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
18 changes: 18 additions & 0 deletions buildscripts/generate-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ echo '
cat deploy/yamls/local.openebs.io_lvmvolumes.yaml >> deploy/yamls/lvmvolume-crd.yaml
rm deploy/yamls/local.openebs.io_lvmvolumes.yaml

echo '
##############################################
########### ############
########### LVMSnapshot CRD ############
########### ############
##############################################
# LVMSnapshot CRD is autogenerated via `make manifests` command.
# Do the modification in the code and run the `make manifests` command
# to generate the CRD definition' > deploy/yamls/lvmsnapshot-crd.yaml

cat deploy/yamls/local.openebs.io_lvmsnapshots.yaml >> deploy/yamls/lvmsnapshot-crd.yaml
rm deploy/yamls/local.openebs.io_lvmsnapshots.yaml

## create the operator file using all the yamls

echo '# This manifest is autogenerated via `make manifests` command
Expand All @@ -63,6 +78,9 @@ cat deploy/yamls/namespace.yaml >> deploy/lvm-operator.yaml
# Add LVMVolume v1alpha1 CRDs to the Operator yaml
cat deploy/yamls/lvmvolume-crd.yaml >> deploy/lvm-operator.yaml

# Add LVMSnapshot v1alpha1 CRDs to the Operator yaml
cat deploy/yamls/lvmsnapshot-crd.yaml >> deploy/lvm-operator.yaml

# Add the driver deployment to the Operator yaml
cat deploy/yamls/lvm-driver.yaml >> deploy/lvm-operator.yaml

Expand Down
1 change: 1 addition & 0 deletions changelog/unreleased/12-akhilerm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add support for create/delete snapshot for LVM localPV
972 changes: 649 additions & 323 deletions deploy/lvm-operator.yaml

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions deploy/sample/lvmsnapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
kind: VolumeSnapshotClass
apiVersion: snapshot.storage.k8s.io/v1
metadata:
name: lvm-localpv-snapclass
annotations:
snapshot.storage.kubernetes.io/is-default-class: "true"
driver: local.csi.openebs.io
deletionPolicy: Delete
---
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: lvm-localpv-snap
spec:
volumeSnapshotClassName: lvm-localpv-snapclass
source:
persistentVolumeClaimName: csi-lvmpvc
868 changes: 548 additions & 320 deletions deploy/yamls/lvm-driver.yaml

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions deploy/yamls/lvmsnapshot-crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@


##############################################
########### ############
########### LVMSnapshot CRD ############
########### ############
##############################################

# LVMSnapshot CRD is autogenerated via `make manifests` command.
# Do the modification in the code and run the `make manifests` command
# to generate the CRD definition

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.8
creationTimestamp: null
name: lvmsnapshots.local.openebs.io
spec:
group: local.openebs.io
names:
kind: LVMSnapshot
listKind: LVMSnapshotList
plural: lvmsnapshots
singular: lvmsnapshot
preserveUnknownFields: false
scope: Namespaced
validation:
openAPIV3Schema:
description: LVMSnapshot represents an LVM Snapshot of the lvm volume
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: VolumeInfo defines LVM info
properties:
capacity:
description: Capacity of the volume
minLength: 1
type: string
ownerNodeID:
description: OwnerNodeID is the Node ID where the volume group is present
which is where the volume has been provisioned. OwnerNodeID can not
be edited after the volume has been provisioned.
minLength: 1
type: string
shared:
description: Shared specifies whether the volume can be shared among
multiple pods. If it is not set to "yes", then the LVM LocalPV Driver
will not allow the volumes to be mounted by more than one pods.
enum:
- "yes"
- "no"
type: string
volGroup:
description: VolGroup specifies the name of the volume group where the
volume has been created.
minLength: 1
type: string
required:
- capacity
- ownerNodeID
- volGroup
type: object
status:
description: SnapStatus string that reflects if the snapshot was created
successfully
properties:
state:
type: string
type: object
required:
- spec
- status
type: object
version: v1alpha1
versions:
- name: v1alpha1
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
6 changes: 3 additions & 3 deletions deploy/yamls/lvmvolume-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ spec:
minLength: 1
type: string
ownerNodeID:
description: OwnerNodeID is the Node ID where the ZPOOL is running which
is where the volume has been provisioned. OwnerNodeID can not be edited
after the volume has been provisioned.
description: OwnerNodeID is the Node ID where the volume group is present
which is where the volume has been provisioned. OwnerNodeID can not
be edited after the volume has been provisioned.
minLength: 1
type: string
shared:
Expand Down
50 changes: 50 additions & 0 deletions pkg/apis/openebs.io/lvm/v1alpha1/lvmsnapshot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright 2021 The OpenEBS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=lvmsnapshot

// LVMSnapshot represents an LVM Snapshot of the lvm volume
type LVMSnapshot struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec VolumeInfo `json:"spec"`
Status SnapStatus `json:"status"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=lvmsnapshots

// LVMSnapshotList is a list of LVMSnapshot resources
type LVMSnapshotList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []LVMSnapshot `json:"items"`
}

// SnapStatus string that reflects if the snapshot was created successfully
type SnapStatus struct {
State string `json:"state,omitempty"`
}
2 changes: 1 addition & 1 deletion pkg/apis/openebs.io/lvm/v1alpha1/lvmvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type LVMVolumeList struct {
// VolumeInfo defines LVM info
type VolumeInfo struct {

// OwnerNodeID is the Node ID where the ZPOOL is running which is where
// OwnerNodeID is the Node ID where the volume group is present which is where
// the volume has been provisioned.
// OwnerNodeID can not be edited after the volume has been provisioned.
// +kubebuilder:validation:MinLength=1
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/openebs.io/lvm/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func addKnownTypes(scheme *runtime.Scheme) error {
SchemeGroupVersion,
&LVMVolume{},
&LVMVolumeList{},
&LVMSnapshot{},
&LVMSnapshotList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
79 changes: 78 additions & 1 deletion pkg/apis/openebs.io/lvm/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7e0bd8a

Please sign in to comment.