-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Santosh Pillai <[email protected]>
- Loading branch information
Showing
9 changed files
with
311 additions
and
0 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
config/crd/bases/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.8.0 | ||
api-approved.kubernetes.io: "https://github.com/kubernetes-csi/external-snapshotter/pull/665" | ||
creationTimestamp: null | ||
name: volumesnapshotclasses.snapshot.storage.k8s.io | ||
spec: | ||
group: snapshot.storage.k8s.io | ||
names: | ||
kind: VolumeSnapshotClass | ||
listKind: VolumeSnapshotClassList | ||
plural: volumesnapshotclasses | ||
shortNames: | ||
- vsclass | ||
- vsclasses | ||
singular: volumesnapshotclass | ||
scope: Cluster | ||
versions: | ||
- additionalPrinterColumns: | ||
- jsonPath: .driver | ||
name: Driver | ||
type: string | ||
- description: Determines whether a VolumeSnapshotContent created through the | ||
VolumeSnapshotClass should be deleted when its bound VolumeSnapshot is deleted. | ||
jsonPath: .deletionPolicy | ||
name: DeletionPolicy | ||
type: string | ||
- jsonPath: .metadata.creationTimestamp | ||
name: Age | ||
type: date | ||
name: v1 | ||
schema: | ||
openAPIV3Schema: | ||
description: VolumeSnapshotClass specifies parameters that a underlying storage | ||
system uses when creating a volume snapshot. A specific VolumeSnapshotClass | ||
is used by specifying its name in a VolumeSnapshot object. VolumeSnapshotClasses | ||
are non-namespaced | ||
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/sig-architecture/api-conventions.md#resources' | ||
type: string | ||
deletionPolicy: | ||
description: deletionPolicy determines whether a VolumeSnapshotContent | ||
created through the VolumeSnapshotClass should be deleted when its bound | ||
VolumeSnapshot is deleted. Supported values are "Retain" and "Delete". | ||
"Retain" means that the VolumeSnapshotContent and its physical snapshot | ||
on underlying storage system are kept. "Delete" means that the VolumeSnapshotContent | ||
and its physical snapshot on underlying storage system are deleted. | ||
Required. | ||
enum: | ||
- Delete | ||
- Retain | ||
type: string | ||
driver: | ||
description: driver is the name of the storage driver that handles this | ||
VolumeSnapshotClass. Required. | ||
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/sig-architecture/api-conventions.md#types-kinds' | ||
type: string | ||
parameters: | ||
additionalProperties: | ||
type: string | ||
description: parameters is a key-value map with storage driver specific parameters for creating snapshots. These values are opaque to Kubernetes. | ||
type: object | ||
required: | ||
- deletionPolicy | ||
- driver | ||
type: object | ||
served: true | ||
storage: true | ||
subresources: {} | ||
- additionalPrinterColumns: | ||
- jsonPath: .driver | ||
name: Driver | ||
type: string | ||
- description: Determines whether a VolumeSnapshotContent created through the VolumeSnapshotClass should be deleted when its bound VolumeSnapshot is deleted. | ||
jsonPath: .deletionPolicy | ||
name: DeletionPolicy | ||
type: string | ||
- jsonPath: .metadata.creationTimestamp | ||
name: Age | ||
type: date | ||
name: v1beta1 | ||
# This indicates the v1beta1 version of the custom resource is deprecated. | ||
# API requests to this version receive a warning in the server response. | ||
deprecated: true | ||
# This overrides the default warning returned to clients making v1beta1 API requests. | ||
deprecationWarning: "snapshot.storage.k8s.io/v1beta1 VolumeSnapshotClass is deprecated; use snapshot.storage.k8s.io/v1 VolumeSnapshotClass" | ||
schema: | ||
openAPIV3Schema: | ||
description: VolumeSnapshotClass specifies parameters that a underlying storage system uses when creating a volume snapshot. A specific VolumeSnapshotClass is used by specifying its name in a VolumeSnapshot object. VolumeSnapshotClasses are non-namespaced | ||
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/sig-architecture/api-conventions.md#resources' | ||
type: string | ||
deletionPolicy: | ||
description: deletionPolicy determines whether a VolumeSnapshotContent created through the VolumeSnapshotClass should be deleted when its bound VolumeSnapshot is deleted. Supported values are "Retain" and "Delete". "Retain" means that the VolumeSnapshotContent and its physical snapshot on underlying storage system are kept. "Delete" means that the VolumeSnapshotContent and its physical snapshot on underlying storage system are deleted. Required. | ||
enum: | ||
- Delete | ||
- Retain | ||
type: string | ||
driver: | ||
description: driver is the name of the storage driver that handles this VolumeSnapshotClass. Required. | ||
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/sig-architecture/api-conventions.md#types-kinds' | ||
type: string | ||
parameters: | ||
additionalProperties: | ||
type: string | ||
description: parameters is a key-value map with storage driver specific parameters for creating snapshots. These values are opaque to Kubernetes. | ||
type: object | ||
required: | ||
- deletionPolicy | ||
- driver | ||
type: object | ||
served: true | ||
storage: false | ||
subresources: {} | ||
status: | ||
acceptedNames: | ||
kind: "" | ||
plural: "" | ||
conditions: [] | ||
storedVersions: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package controllers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
snapapi "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" | ||
lvmv1alpha1 "github.com/red-hat-storage/lvm-operator/api/v1alpha1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
cutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
const ( | ||
vscName = "topolvm-volumeSnapshotClass" | ||
) | ||
|
||
type topolvmVolumeSnapshotClass struct{} | ||
|
||
// topolvmVolumeSnapshotClass unit satisfies resourceManager interface | ||
var _ resourceManager = topolvmVolumeSnapshotClass{} | ||
|
||
func (s topolvmVolumeSnapshotClass) getName() string { | ||
return vscName | ||
} | ||
|
||
//+kubebuilder:rbac:groups=snapshot.storage.k8s.io,resources=volumesnapshotclasses,verbs=get;create;delete;watch;list | ||
|
||
func (s topolvmVolumeSnapshotClass) ensureCreated(r *LVMClusterReconciler, ctx context.Context, lvmCluster *lvmv1alpha1.LVMCluster) error { | ||
|
||
// one volume snapshot class for every deviceClass based on CR is created | ||
topolvmSnapshotClasses := getTopolvmSnapshotClasses(lvmCluster) | ||
for _, vsc := range topolvmSnapshotClasses { | ||
|
||
// we anticipate no edits to volume snapshot class | ||
result, err := cutil.CreateOrUpdate(ctx, r.Client, vsc, func() error { return nil }) | ||
if err != nil { | ||
r.Log.Error(err, "topolvm volume snapshot class reconcile failure", "name", vsc.Name) | ||
return err | ||
} else { | ||
r.Log.Info("topolvm volume snapshot class", "operation", result, "name", vsc.Name) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (s topolvmVolumeSnapshotClass) ensureDeleted(r *LVMClusterReconciler, ctx context.Context, lvmCluster *lvmv1alpha1.LVMCluster) error { | ||
|
||
// construct name of volume snapshot class based on CR spec deviceClass field and | ||
// delete the corresponding volume snapshot class | ||
for _, deviceClass := range lvmCluster.Spec.Storage.DeviceClasses { | ||
vsc := &snapapi.VolumeSnapshotClass{} | ||
vscName := fmt.Sprintf("odf-lvm-%s", deviceClass.Name) | ||
err := r.Client.Get(ctx, types.NamespacedName{Name: vscName}, vsc) | ||
|
||
if err != nil { | ||
// already deleted in previous reconcile | ||
if errors.IsNotFound(err) { | ||
r.Log.Info("topolvm volume snapshot class is deleted", "VolumeSnapshotClass", vscName) | ||
return nil | ||
} | ||
r.Log.Error(err, "failed to retrieve topolvm volume snapshot class", "VolumeSnapshotClass", vscName) | ||
return err | ||
} | ||
|
||
// VolumeSnapshotClass exists, initiate deletion | ||
if vsc.GetDeletionTimestamp().IsZero() { | ||
if err = r.Client.Delete(ctx, vsc); err != nil { | ||
r.Log.Error(err, "failed to delete topolvm volume snapshot class", "VolumeSnapshotClass", vscName) | ||
return err | ||
} else { | ||
r.Log.Info("initiated topolvm volume snapshot class deletion", "VolumeSnapshotClass", vscName) | ||
} | ||
} else { | ||
// return error for next reconcile to confirm deletion | ||
return fmt.Errorf("topolvm volume snapshot class %s is already marked for deletion", vscName) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (s topolvmVolumeSnapshotClass) updateStatus(r *LVMClusterReconciler, ctx context.Context, lvmCluster *lvmv1alpha1.LVMCluster) error { | ||
// intentionally empty as there'll be no status field on VolumeSnapshotClass resource | ||
return nil | ||
} | ||
|
||
func getTopolvmSnapshotClasses(lvmCluster *lvmv1alpha1.LVMCluster) []*snapapi.VolumeSnapshotClass { | ||
vsc := []*snapapi.VolumeSnapshotClass{} | ||
|
||
for _, deviceClass := range lvmCluster.Spec.Storage.DeviceClasses { | ||
snapshotClass := &snapapi.VolumeSnapshotClass{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: fmt.Sprintf("odf-lvm-%s", deviceClass.Name), | ||
}, | ||
|
||
Driver: "topolvm.cybozu.com", | ||
DeletionPolicy: snapapi.VolumeSnapshotContentDelete, | ||
} | ||
vsc = append(vsc, snapshotClass) | ||
} | ||
return vsc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.