Skip to content

Commit

Permalink
Added in-place snapshot restore feature
Browse files Browse the repository at this point in the history
Co-authored-by: Rohit Arora <[email protected]>
  • Loading branch information
clintonk and rohit-arora-dev authored May 31, 2023
1 parent 45fc576 commit 3527955
Show file tree
Hide file tree
Showing 109 changed files with 3,900 additions and 276 deletions.
29 changes: 15 additions & 14 deletions cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ const (
PreferredNamespace = tridentconfig.OrchestratorName

// CRD names

ActionMirrorUpdateCRDName = "tridentactionmirrorupdates.trident.netapp.io"
BackendConfigCRDName = "tridentbackendconfigs.trident.netapp.io"
BackendCRDName = "tridentbackends.trident.netapp.io"
MirrorRelationshipCRDName = "tridentmirrorrelationships.trident.netapp.io"
NodeCRDName = "tridentnodes.trident.netapp.io"
SnapshotCRDName = "tridentsnapshots.trident.netapp.io"
SnapshotInfoCRDName = "tridentsnapshotinfos.trident.netapp.io"
StorageClassCRDName = "tridentstorageclasses.trident.netapp.io"
TransactionCRDName = "tridenttransactions.trident.netapp.io"
VersionCRDName = "tridentversions.trident.netapp.io"
VolumeCRDName = "tridentvolumes.trident.netapp.io"
VolumePublicationCRDName = "tridentvolumepublications.trident.netapp.io"
VolumeReferenceCRDName = "tridentvolumereferences.trident.netapp.io"
ActionMirrorUpdateCRDName = "tridentactionmirrorupdates.trident.netapp.io"
ActionSnapshotRestoreCRDName = "tridentactionsnapshotrestores.trident.netapp.io"
BackendConfigCRDName = "tridentbackendconfigs.trident.netapp.io"
BackendCRDName = "tridentbackends.trident.netapp.io"
MirrorRelationshipCRDName = "tridentmirrorrelationships.trident.netapp.io"
NodeCRDName = "tridentnodes.trident.netapp.io"
SnapshotCRDName = "tridentsnapshots.trident.netapp.io"
SnapshotInfoCRDName = "tridentsnapshotinfos.trident.netapp.io"
StorageClassCRDName = "tridentstorageclasses.trident.netapp.io"
TransactionCRDName = "tridenttransactions.trident.netapp.io"
VersionCRDName = "tridentversions.trident.netapp.io"
VolumeCRDName = "tridentvolumes.trident.netapp.io"
VolumePublicationCRDName = "tridentvolumepublications.trident.netapp.io"
VolumeReferenceCRDName = "tridentvolumereferences.trident.netapp.io"

ControllerRoleFilename = "trident-controller-role.yaml"
ControllerClusterRoleFilename = "trident-controller-clusterrole.yaml"
Expand Down Expand Up @@ -168,6 +168,7 @@ var (
VersionCRDName,
VolumeCRDName,
VolumePublicationCRDName,
ActionSnapshotRestoreCRDName,
}
)

Expand Down
63 changes: 63 additions & 0 deletions cli/cmd/obliviate_crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func deleteCRs() error {
return err
}

if err := deleteActionSnapshotRestores(); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -892,6 +896,64 @@ func deleteVolumeReferences() error {
return nil
}

func deleteActionSnapshotRestores() error {
crd := "tridentactionsnapshotrestores.trident.netapp.io"
logFields := LogFields{"CRD": crd}

// See if CRD exists
exists, err := k8sClient.CheckCRDExists(crd)
if err != nil {
return err
} else if !exists {
Log().WithField("CRD", crd).Debug("CRD not present.")
return nil
}

vrefs, err := crdClientset.TridentV1().TridentActionSnapshotRestores(allNamespaces).List(ctx(), listOpts)
if err != nil {
return err
} else if len(vrefs.Items) == 0 {
Log().WithFields(logFields).Info("Resources not present.")
return nil
}

for _, vref := range vrefs.Items {
if vref.DeletionTimestamp.IsZero() {
_ = crdClientset.TridentV1().TridentActionSnapshotRestores(vref.Namespace).Delete(ctx(),
vref.Name, deleteOpts)
}
}

vrefs, err = crdClientset.TridentV1().TridentActionSnapshotRestores(allNamespaces).List(ctx(), listOpts)
if err != nil {
return err
}

for _, vref := range vrefs.Items {
if vref.HasTridentFinalizers() {
crCopy := vref.DeepCopy()
crCopy.RemoveTridentFinalizers()
_, err := crdClientset.TridentV1().TridentActionSnapshotRestores(vref.Namespace).Update(ctx(),
crCopy, updateOpts)
if isNotFoundError(err) {
continue
} else if err != nil {
Log().Errorf("Problem removing finalizers: %v", err)
return err
}
}

deleteFunc := crdClientset.TridentV1().TridentActionSnapshotRestores(vref.Namespace).Delete
if err = deleteWithRetry(deleteFunc, ctx(), vref.Name, nil); err != nil {
Log().Errorf("Problem deleting resource: %v", err)
return err
}
}

Log().WithFields(logFields).Info("Resources deleted.")
return nil
}

func deleteCRDs() error {
crdNames := []string{
"tridentversions.trident.netapp.io",
Expand All @@ -907,6 +969,7 @@ func deleteCRDs() error {
"tridentsnapshots.trident.netapp.io",
"tridentvolumepublications.trident.netapp.io",
"tridentvolumereferences.trident.netapp.io",
"tridentactionsnapshotrestores.trident.netapp.io",
}

for _, crdName := range crdNames {
Expand Down
72 changes: 70 additions & 2 deletions cli/k8s_client/yaml_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ rules:
"tridenttransactions", "tridentsnapshots", "tridentbackendconfigs", "tridentbackendconfigs/status",
"tridentmirrorrelationships", "tridentmirrorrelationships/status", "tridentsnapshotinfos",
"tridentsnapshotinfos/status", "tridentvolumepublications", "tridentvolumereferences",
"tridentactionmirrorupdates", "tridentactionmirrorupdates/status"]
"tridentactionmirrorupdates", "tridentactionmirrorupdates/status",
"tridentactionsnapshotrestores", "tridentactionsnapshotrestores/status"]
verbs: ["get", "list", "watch", "create", "delete", "update", "patch"]
- apiGroups: ["policy"]
resources: ["podsecuritypolicies"]
Expand Down Expand Up @@ -1530,6 +1531,12 @@ func GetVolumeReferenceCRDYAML() string {
return tridentVolumeReferenceCRDYAMLv1
}

func GetActionSnapshotRestoreCRDYAML() string {
Log().Trace(">>>> GetActionSnapshotRestoreCRDYAML")
defer func() { Log().Trace("<<<< GetActionSnapshotRestoreCRDYAML") }()
return tridentActionSnapshotRestoreCRDYAMLv1
}

func GetOrchestratorCRDYAML() string {
Log().Trace(">>>> GetOrchestratorCRDYAML")
defer func() { Log().Trace("<<<< GetOrchestratorCRDYAML") }()
Expand All @@ -1549,6 +1556,7 @@ kubectl delete crd tridentnodes.trident.netapp.io --wait=false
kubectl delete crd tridenttransactions.trident.netapp.io --wait=false
kubectl delete crd tridentsnapshots.trident.netapp.io --wait=false
kubectl delete crd tridentvolumereferences.trident.netapp.io --wait=false
kubectl delete crd tridentactionsnapshotrestores.trident.netapp.io --wait=false
kubectl patch crd tridentversions.trident.netapp.io -p '{"metadata":{"finalizers": []}}' --type=merge
kubectl patch crd tridentbackends.trident.netapp.io -p '{"metadata":{"finalizers": []}}' --type=merge
Expand All @@ -1562,6 +1570,7 @@ kubectl patch crd tridentnodes.trident.netapp.io -p '{"metadata":{"finalizers":
kubectl patch crd tridenttransactions.trident.netapp.io -p '{"metadata":{"finalizers": []}}' --type=merge
kubectl patch crd tridentsnapshots.trident.netapp.io -p '{"metadata":{"finalizers": []}}' --type=merge
kubectl patch crd tridentvolumereferences.trident.netapp.io -p '{"metadata":{"finalizers": []}}' --type=merge
kubectl patch crd tridentactionsnapshotrestores.trident.netapp.io -p '{"metadata":{"finalizers": []}}' --type=merge
kubectl delete crd tridentversions.trident.netapp.io
kubectl delete crd tridentbackends.trident.netapp.io
Expand All @@ -1575,6 +1584,7 @@ kubectl delete crd tridentnodes.trident.netapp.io
kubectl delete crd tridenttransactions.trident.netapp.io
kubectl delete crd tridentsnapshots.trident.netapp.io
kubectl delete crd tridentvolumereferences.trident.netapp.io
kubectl delete crd tridentactionsnapshotrestores.trident.netapp.io
*/

const tridentVersionCRDYAMLv1 = `
Expand Down Expand Up @@ -2227,6 +2237,63 @@ spec:
- trident-external
- trident-internal`

const tridentActionSnapshotRestoreCRDYAMLv1 = `
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: tridentactionsnapshotrestores.trident.netapp.io
spec:
group: trident.netapp.io
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
x-kubernetes-preserve-unknown-fields: true
additionalPrinterColumns:
- description: Namespace
jsonPath: .metadata.namespace
name: Namespace
type: string
priority: 0
- description: PVC
jsonPath: .spec.pvcName
name: PVC
type: string
priority: 0
- description: Snapshot
jsonPath: .spec.volumeSnapshotName
name: Snapshot
type: string
priority: 0
- description: State
jsonPath: .status.state
name: State
type: string
priority: 0
- description: CompletionTime
jsonPath: .status.completionTime
name: CompletionTime
type: date
priority: 0
- description: Message
jsonPath: .status.message
name: Message
type: string
priority: 1
scope: Namespaced
names:
plural: tridentactionsnapshotrestores
singular: tridentactionsnapshotrestore
kind: TridentActionSnapshotRestore
shortNames:
- tasr
categories:
- trident
- trident-external`

const customResourceDefinitionYAMLv1 = tridentVersionCRDYAMLv1 +
"\n---" + tridentBackendCRDYAMLv1 +
"\n---" + tridentBackendConfigCRDYAMLv1 +
Expand All @@ -2239,7 +2306,8 @@ const customResourceDefinitionYAMLv1 = tridentVersionCRDYAMLv1 +
"\n---" + tridentNodeCRDYAMLv1 +
"\n---" + tridentTransactionCRDYAMLv1 +
"\n---" + tridentSnapshotCRDYAMLv1 +
"\n---" + tridentVolumeReferenceCRDYAMLv1 + "\n"
"\n---" + tridentVolumeReferenceCRDYAMLv1 +
"\n---" + tridentActionSnapshotRestoreCRDYAMLv1 + "\n"

func GetCSIDriverYAML(name string, labels, controllingCRDetails map[string]string) string {
Log().WithFields(LogFields{
Expand Down
Loading

0 comments on commit 3527955

Please sign in to comment.