Skip to content

Commit

Permalink
Add constants to define function names (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavannd1 authored and mergify[bot] committed Nov 8, 2019
1 parent 88a527d commit 4b0a0a4
Show file tree
Hide file tree
Showing 28 changed files with 101 additions and 61 deletions.
4 changes: 3 additions & 1 deletion pkg/function/backup_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
)

const (
// BackupDataFuncName gives the name of the function
BackupDataFuncName = "BackupData"
// BackupDataNamespaceArg provides the namespace
BackupDataNamespaceArg = "namespace"
// BackupDataPodArg provides the pod connected to the data volume
Expand Down Expand Up @@ -63,7 +65,7 @@ var _ kanister.Func = (*backupDataFunc)(nil)
type backupDataFunc struct{}

func (*backupDataFunc) Name() string {
return "BackupData"
return BackupDataFuncName
}

func (*backupDataFunc) Exec(ctx context.Context, tp param.TemplateParams, args map[string]interface{}) (map[string]interface{}, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/function/backup_data_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import (
)

const (
// BackupDataAllFuncName gives the name of the function
BackupDataAllFuncName = "BackupDataAll"
// BackupDataAllNamespaceArg provides the namespace
BackupDataAllNamespaceArg = "namespace"
// BackupDataAllPodsArg provides the pods connected to the data volumes
Expand Down Expand Up @@ -63,7 +65,7 @@ var _ kanister.Func = (*backupDataAllFunc)(nil)
type backupDataAllFunc struct{}

func (*backupDataAllFunc) Name() string {
return "BackupDataAll"
return BackupDataAllFuncName
}

func (*backupDataAllFunc) Exec(ctx context.Context, tp param.TemplateParams, args map[string]interface{}) (map[string]interface{}, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/function/backup_data_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (

const (
backupDataStatsJobPrefix = "backup-data-stats-"
// BackupDataStatsFuncName gives the name of the stats function
BackupDataStatsFuncName = "BackupDataStats"
// BackupDataStatsNamespaceArg provides the namespace
BackupDataStatsNamespaceArg = "namespace"
// BackupDataStatsBackupArtifactPrefixArg provides the path to store artifacts on the object store
Expand All @@ -55,7 +57,7 @@ var _ kanister.Func = (*BackupDataStatsFunc)(nil)
type BackupDataStatsFunc struct{}

func (*BackupDataStatsFunc) Name() string {
return "BackupDataStats"
return BackupDataStatsFuncName
}

func backupDataStats(ctx context.Context, cli kubernetes.Interface, tp param.TemplateParams, namespace, encryptionKey, backupArtifactPrefix, backupID, mode, jobPrefix string) (map[string]interface{}, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/function/checkRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
)

const (
// CheckRepositoryFuncName gives the name of the function
CheckRepositoryFuncName = "CheckRepository"
// CheckRepositoryArtifactPrefixArg provides the path to restore backed up data
CheckRepositoryArtifactPrefixArg = "backupArtifactPrefix"
// CheckRepositoryEncryptionKeyArg provides the encryption key to be used for deletes
Expand All @@ -36,7 +38,7 @@ var _ kanister.Func = (*CheckRepositoryFunc)(nil)
type CheckRepositoryFunc struct{}

func (*CheckRepositoryFunc) Name() string {
return "CheckRepository"
return CheckRepositoryFuncName
}

func CheckRepository(ctx context.Context, cli kubernetes.Interface, tp param.TemplateParams, encryptionKey, targetPaths, jobPrefix string, podOverride crv1alpha1.JSONMap) (map[string]interface{}, error) {
Expand Down
6 changes: 4 additions & 2 deletions pkg/function/copy_volume_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ import (
)

const (
kanisterToolsImage = "kanisterio/kanister-tools:0.21.0"
kanisterToolsImage = "kanisterio/kanister-tools:0.21.0"
// CopyVolumeDataFuncName gives the function name
CopyVolumeDataFuncName = "CopyVolumeData"
copyVolumeDataMountPoint = "/mnt/vol_data/%s"
copyVolumeDataJobPrefix = "copy-vol-data-"
CopyVolumeDataNamespaceArg = "namespace"
Expand All @@ -58,7 +60,7 @@ var _ kanister.Func = (*copyVolumeDataFunc)(nil)
type copyVolumeDataFunc struct{}

func (*copyVolumeDataFunc) Name() string {
return "CopyVolumeData"
return CopyVolumeDataFuncName
}

func copyVolumeData(ctx context.Context, cli kubernetes.Interface, tp param.TemplateParams, namespace, pvc, targetPath, encryptionKey string, podOverride map[string]interface{}) (map[string]interface{}, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/function/create_volume_from_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ var (
)

const (
// CreateVolumeFromSnapshotFuncName gives the name of the function
CreateVolumeFromSnapshotFuncName = "CreateVolumeFromSnapshot"
CreateVolumeFromSnapshotNamespaceArg = "namespace"
CreateVolumeFromSnapshotManifestArg = "snapshots"
CreateVolumeFromSnapshotPVCNamesArg = "pvcNames"
Expand All @@ -50,7 +52,7 @@ const (
type createVolumeFromSnapshotFunc struct{}

func (*createVolumeFromSnapshotFunc) Name() string {
return "CreateVolumeFromSnapshot"
return CreateVolumeFromSnapshotFuncName
}

func createVolumeFromSnapshot(ctx context.Context, cli kubernetes.Interface, namespace, snapshotinfo string, pvcNames []string, profile *param.Profile, getter getter.Getter) (map[string]blockstorage.Provider, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/function/create_volume_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ var (
)

const (
// CreateVolumeSnapshotFuncName gives the name of the function
CreateVolumeSnapshotFuncName = "CreateVolumeSnapshot"
CreateVolumeSnapshotNamespaceArg = "namespace"
CreateVolumeSnapshotPVCsArg = "pvcs"
CreateVolumeSnapshotSkipWaitArg = "skipWait"
Expand All @@ -56,7 +58,7 @@ const (
type createVolumeSnapshotFunc struct{}

func (*createVolumeSnapshotFunc) Name() string {
return "CreateVolumeSnapshot"
return CreateVolumeSnapshotFuncName
}

type VolumeSnapshotInfo struct {
Expand Down
28 changes: 14 additions & 14 deletions pkg/function/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func newRestoreDataBlueprint(pvc, identifierArg, identifierVal string) *crv1alph
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testRestore",
Func: "RestoreData",
Func: RestoreDataFuncName,
Args: map[string]interface{}{
RestoreDataNamespaceArg: "{{ .StatefulSet.Namespace }}",
RestoreDataImageArg: "kanisterio/kanister-tools:0.21.0",
Expand All @@ -153,7 +153,7 @@ func newBackupDataBlueprint() *crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testBackup",
Func: "BackupData",
Func: BackupDataFuncName,
Args: map[string]interface{}{
BackupDataNamespaceArg: "{{ .StatefulSet.Namespace }}",
BackupDataPodArg: "{{ index .StatefulSet.Pods 0 }}",
Expand All @@ -177,7 +177,7 @@ func newDescribeBackupsBlueprint() *crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testDescribeBackups",
Func: "DescribeBackups",
Func: DescribeBackupsFuncName,
Args: map[string]interface{}{
DescribeBackupsArtifactPrefixArg: "{{ .Profile.Location.Bucket }}/{{ .Profile.Location.Prefix }}",
DescribeBackupsEncryptionKeyArg: "{{ .Secrets.backupKey.Data.password | toString }}",
Expand All @@ -197,7 +197,7 @@ func newCheckRepositoryBlueprint() *crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testCheckRepository",
Func: "CheckRepository",
Func: CheckRepositoryFuncName,
Args: map[string]interface{}{
CheckRepositoryArtifactPrefixArg: "{{ .Profile.Location.Bucket }}/{{ .Profile.Location.Prefix }}",
CheckRepositoryEncryptionKeyArg: "{{ .Secrets.backupKey.Data.password | toString }}",
Expand All @@ -217,7 +217,7 @@ func newLocationDeleteBlueprint() *crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testLocationDelete",
Func: "LocationDelete",
Func: LocationDeleteFuncName,
Args: map[string]interface{}{
LocationDeleteArtifactArg: "{{ .Profile.Location.Bucket }}",
},
Expand All @@ -236,7 +236,7 @@ func newBackupDataAllBlueprint() *crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testBackupDataAll",
Func: "BackupDataAll",
Func: BackupDataAllFuncName,
Args: map[string]interface{}{
BackupDataAllNamespaceArg: "{{ .StatefulSet.Namespace }}",
BackupDataAllContainerArg: "{{ index .StatefulSet.Containers 0 0 }}",
Expand All @@ -258,7 +258,7 @@ func newRestoreDataAllBlueprint() *crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testRestoreDataAll",
Func: "RestoreDataAll",
Func: RestoreDataAllFuncName,
Args: map[string]interface{}{
RestoreDataAllNamespaceArg: "{{ .StatefulSet.Namespace }}",
RestoreDataAllImageArg: "kanisterio/kanister-tools:0.21.0",
Expand All @@ -280,8 +280,8 @@ func newDeleteDataAllBlueprint() *crv1alpha1.Blueprint {
Kind: param.StatefulSetKind,
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testDelete",
Func: "DeleteDataAll",
Name: "testDeleteDataAll",
Func: DeleteDataAllFuncName,
Args: map[string]interface{}{
DeleteDataAllNamespaceArg: "{{ .StatefulSet.Namespace }}",
DeleteDataAllBackupArtifactPrefixArg: "{{ .Profile.Location.Bucket }}/{{ .Profile.Location.Prefix }}",
Expand Down Expand Up @@ -439,7 +439,7 @@ func newCopyDataTestBlueprint() crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
{
Name: "test1",
Func: "PrepareData",
Func: PrepareDataFuncName,
Args: map[string]interface{}{
PrepareDataNamespaceArg: "{{ .PVC.Namespace }}",
PrepareDataImageArg: "busybox",
Expand All @@ -456,7 +456,7 @@ func newCopyDataTestBlueprint() crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testCopy",
Func: "CopyVolumeData",
Func: CopyVolumeDataFuncName,
Args: map[string]interface{}{
CopyVolumeDataNamespaceArg: "{{ .PVC.Namespace }}",
CopyVolumeDataVolumeArg: "{{ .PVC.Name }}",
Expand All @@ -469,7 +469,7 @@ func newCopyDataTestBlueprint() crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testRestore",
Func: "RestoreData",
Func: RestoreDataFuncName,
Args: map[string]interface{}{
RestoreDataNamespaceArg: "{{ .PVC.Namespace }}",
RestoreDataImageArg: "kanisterio/kanister-tools:0.21.0",
Expand All @@ -485,7 +485,7 @@ func newCopyDataTestBlueprint() crv1alpha1.Blueprint {
"checkfile": {
Phases: []crv1alpha1.BlueprintPhase{
{
Func: "PrepareData",
Func: PrepareDataFuncName,
Args: map[string]interface{}{
PrepareDataNamespaceArg: "{{ .PVC.Namespace }}",
PrepareDataImageArg: "busybox",
Expand All @@ -503,7 +503,7 @@ func newCopyDataTestBlueprint() crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
crv1alpha1.BlueprintPhase{
Name: "testDelete",
Func: "DeleteData",
Func: DeleteDataFuncName,
Args: map[string]interface{}{
DeleteDataNamespaceArg: "{{ .PVC.Namespace }}",
DeleteDataBackupArtifactPrefixArg: fmt.Sprintf("{{ .Options.%s }}", CopyVolumeDataOutputBackupArtifactLocation),
Expand Down
4 changes: 3 additions & 1 deletion pkg/function/delete_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
)

const (
// DeleteDataFuncName gives the function name
DeleteDataFuncName = "DeleteData"
// DeleteDataNamespaceArg provides the namespace
DeleteDataNamespaceArg = "namespace"
// DeleteDataBackupArtifactPrefixArg provides the path to restore backed up data
Expand All @@ -57,7 +59,7 @@ var _ kanister.Func = (*deleteDataFunc)(nil)
type deleteDataFunc struct{}

func (*deleteDataFunc) Name() string {
return "DeleteData"
return DeleteDataFuncName
}

func deleteData(ctx context.Context, cli kubernetes.Interface, tp param.TemplateParams, reclaimSpace bool, namespace, encryptionKey string, targetPaths, deleteTags, deleteIdentifiers []string, jobPrefix string, podOverride crv1alpha1.JSONMap) (map[string]interface{}, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/function/delete_data_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
)

const (
// DeleteDataAllFuncName gives the name of the function
DeleteDataAllFuncName = "DeleteDataAll"
// DeleteDataAllNamespaceArg provides the namespace
DeleteDataAllNamespaceArg = "namespace"
// DeleteDataAllBackupArtifactPrefixArg provides the path to restore backed up data
Expand All @@ -52,7 +54,7 @@ var _ kanister.Func = (*deleteDataAllFunc)(nil)
type deleteDataAllFunc struct{}

func (*deleteDataAllFunc) Name() string {
return "DeleteDataAll"
return DeleteDataAllFuncName
}

func (*deleteDataAllFunc) Exec(ctx context.Context, tp param.TemplateParams, args map[string]interface{}) (map[string]interface{}, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/function/delete_volume_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ var (
)

const (
// DeleteVolumeSnapshotFuncName gives the function name
DeleteVolumeSnapshotFuncName = "DeleteVolumeSnapshot"
DeleteVolumeSnapshotNamespaceArg = "namespace"
DeleteVolumeSnapshotManifestArg = "snapshots"
SnapshotDoesNotExistError = "does not exist"
Expand All @@ -49,7 +51,7 @@ const (
type deleteVolumeSnapshotFunc struct{}

func (*deleteVolumeSnapshotFunc) Name() string {
return "DeleteVolumeSnapshot"
return DeleteVolumeSnapshotFuncName
}

func deleteVolumeSnapshot(ctx context.Context, cli kubernetes.Interface, namespace, snapshotinfo string, profile *param.Profile, getter getter.Getter) (map[string]blockstorage.Provider, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/function/describe_backups.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
)

const (
// DescribeBackupsFuncName gives the function name
DescribeBackupsFuncName = "DescribeBackups"
// DescribeBackupsArtifactPrefixArg provides the path to restore backed up data
DescribeBackupsArtifactPrefixArg = "backupArtifactPrefix"
// DescribeBackupsEncryptionKeyArg provides the encryption key to be used for deletes
Expand All @@ -54,7 +56,7 @@ var _ kanister.Func = (*DescribeBackupsFunc)(nil)
type DescribeBackupsFunc struct{}

func (*DescribeBackupsFunc) Name() string {
return "DescribeBackups"
return DescribeBackupsFuncName
}

func describeBackups(ctx context.Context, cli kubernetes.Interface, tp param.TemplateParams, encryptionKey, targetPaths, jobPrefix string, podOverride crv1alpha1.JSONMap) (map[string]interface{}, error) {
Expand Down
14 changes: 7 additions & 7 deletions pkg/function/e2e_volume_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

. "gopkg.in/check.v1"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
k8sresource "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/dynamic/fake"
Expand Down Expand Up @@ -185,15 +185,15 @@ func newVolumeSnapshotBlueprint() *crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
{
Name: "testBackupVolume",
Func: "CreateVolumeSnapshot",
Func: CreateVolumeSnapshotFuncName,
Args: map[string]interface{}{
CreateVolumeSnapshotNamespaceArg: "{{ .StatefulSet.Namespace }}",
CreateVolumeSnapshotSkipWaitArg: true,
},
},
{
Name: "waitOnSnapshots",
Func: "WaitForSnapshotCompletion",
Func: WaitForSnapshotCompletionFuncName,
Args: map[string]interface{}{
WaitForSnapshotCompletionSnapshotsArg: "{{ .Phases.testBackupVolume.Output.volumeSnapshotInfo }}",
},
Expand All @@ -208,23 +208,23 @@ func newVolumeSnapshotBlueprint() *crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
{
Name: "testShutdownPod",
Func: "ScaleWorkload",
Func: ScaleWorkloadFuncName,
Args: map[string]interface{}{
ScaleWorkloadNamespaceArg: "{{ .StatefulSet.Namespace }}",
ScaleWorkloadReplicas: 0,
},
},
{
Name: "testRestoreVolume",
Func: "CreateVolumeFromSnapshot",
Func: CreateVolumeFromSnapshotFuncName,
Args: map[string]interface{}{
CreateVolumeFromSnapshotNamespaceArg: "{{ .StatefulSet.Namespace }}",
CreateVolumeFromSnapshotManifestArg: "{{ .ArtifactsIn.backupInfo.KeyValue.manifest }}",
},
},
{
Name: "testBringupPod",
Func: "ScaleWorkload",
Func: ScaleWorkloadFuncName,
Args: map[string]interface{}{
ScaleWorkloadNamespaceArg: "{{ .StatefulSet.Namespace }}",
ScaleWorkloadReplicas: 1,
Expand All @@ -240,7 +240,7 @@ func newVolumeSnapshotBlueprint() *crv1alpha1.Blueprint {
Phases: []crv1alpha1.BlueprintPhase{
{
Name: "deleteVolumeSnapshot",
Func: "DeleteVolumeSnapshot",
Func: DeleteVolumeSnapshotFuncName,
Args: map[string]interface{}{
DeleteVolumeSnapshotNamespaceArg: "{{ .StatefulSet.Namespace }}",
DeleteVolumeSnapshotManifestArg: "{{ .ArtifactsIn.backupInfo.KeyValue.manifest }}",
Expand Down
4 changes: 3 additions & 1 deletion pkg/function/kube_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var (
)

const (
// KubeExecFuncName gives the function name
KubeExecFuncName = "KubeExec"
KubeExecNamespaceArg = "namespace"
KubeExecPodNameArg = "pod"
KubeExecContainerNameArg = "container"
Expand All @@ -47,7 +49,7 @@ const (
type kubeExecFunc struct{}

func (*kubeExecFunc) Name() string {
return "KubeExec"
return KubeExecFuncName
}

func parseLogAndCreateOutput(out string) (map[string]interface{}, error) {
Expand Down
Loading

0 comments on commit 4b0a0a4

Please sign in to comment.