Skip to content

Commit

Permalink
Add Validate method in Func interface to validate a kanister func…
Browse files Browse the repository at this point in the history
…tion (#3017)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
viveksinghggits and mergify[bot] authored Aug 5, 2024
1 parent ea6cb88 commit d694960
Show file tree
Hide file tree
Showing 41 changed files with 372 additions and 38 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ require (
k8s.io/client-go v0.29.7
k8s.io/code-generator v0.29.7
k8s.io/kubectl v0.29.7
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/controller-runtime v0.16.6
sigs.k8s.io/yaml v1.3.0

Expand Down Expand Up @@ -232,6 +231,7 @@ require (
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 // indirect
k8s.io/klog/v2 v2.110.1 // indirect
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
Expand Down
9 changes: 9 additions & 0 deletions pkg/blueprint/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
kanister "github.com/kanisterio/kanister/pkg"
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/utils"
)

func Test(t *testing.T) { TestingT(t) }
Expand Down Expand Up @@ -454,6 +455,14 @@ func (nd *nonDefaultVersionFunc) Arguments() []string {
return []string{"ndVersionArg0", "ndVersionArg1", "ndVersionArg2", "ndVersionArg3"}
}

func (nd *nonDefaultVersionFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(nd.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(nd.RequiredArgs(), args)
}

func (nd *nonDefaultVersionFunc) Exec(context.Context, param.TemplateParams, map[string]interface{}) (map[string]interface{}, error) {
nd.progressPercent = "0"
defer func() { nd.progressPercent = "100" }()
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/backup_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/restic"
"github.com/kanisterio/kanister/pkg/utils"
)

const (
Expand Down Expand Up @@ -157,6 +158,14 @@ func (*backupDataFunc) Arguments() []string {
}
}

func (b *backupDataFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(b.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(b.RequiredArgs(), args)
}

type backupDataParsedOutput struct {
backupID string
backupTag string
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/backup_data_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/restic"
"github.com/kanisterio/kanister/pkg/utils"
)

const (
Expand Down Expand Up @@ -152,6 +153,14 @@ func (*backupDataAllFunc) Arguments() []string {
}
}

func (b *backupDataAllFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(b.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(b.RequiredArgs(), args)
}

func backupDataAll(ctx context.Context, cli kubernetes.Interface, namespace string, ps []string, container string, backupArtifactPrefix, includePath, encryptionKey string,
insecureTLS bool, tp param.TemplateParams) (map[string]interface{}, error) {
errChan := make(chan error, len(ps))
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/backup_data_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/restic"
"github.com/kanisterio/kanister/pkg/utils"
)

const (
Expand Down Expand Up @@ -198,6 +199,14 @@ func (*BackupDataStatsFunc) Arguments() []string {
}
}

func (b *BackupDataStatsFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(b.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(b.RequiredArgs(), args)
}

func (b *BackupDataStatsFunc) ExecutionProgress() (crv1alpha1.PhaseProgress, error) {
metav1Time := metav1.NewTime(time.Now())
return crv1alpha1.PhaseProgress{
Expand Down
8 changes: 8 additions & 0 deletions pkg/function/backup_data_using_kopia_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ func (*backupDataUsingKopiaServerFunc) Arguments() []string {
}
}

func (b *backupDataUsingKopiaServerFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(b.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(b.RequiredArgs(), args)
}

func (b *backupDataUsingKopiaServerFunc) Exec(ctx context.Context, tp param.TemplateParams, args map[string]any) (map[string]any, error) {
// Set progress percent
b.progressPercent = progress.StartedPercent
Expand Down
10 changes: 10 additions & 0 deletions pkg/function/checkRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/restic"
"github.com/kanisterio/kanister/pkg/utils"
)

const (
Expand Down Expand Up @@ -174,6 +175,15 @@ func (*CheckRepositoryFunc) Arguments() []string {
InsecureTLS,
}
}

func (c *CheckRepositoryFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(c.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(c.RequiredArgs(), args)
}

func (c *CheckRepositoryFunc) ExecutionProgress() (crv1alpha1.PhaseProgress, error) {
metav1Time := metav1.NewTime(time.Now())
return crv1alpha1.PhaseProgress{
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/copy_volume_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/restic"
"github.com/kanisterio/kanister/pkg/utils"
)

const (
Expand Down Expand Up @@ -245,6 +246,14 @@ func (*copyVolumeDataFunc) Arguments() []string {
}
}

func (c *copyVolumeDataFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(c.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(c.RequiredArgs(), args)
}

func (c *copyVolumeDataFunc) ExecutionProgress() (crv1alpha1.PhaseProgress, error) {
metav1Time := metav1.NewTime(time.Now())
return crv1alpha1.PhaseProgress{
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/create_csi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/kanisterio/kanister/pkg/kube/snapshot"
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/utils"
)

func init() {
Expand Down Expand Up @@ -142,6 +143,14 @@ func (*createCSISnapshotFunc) Arguments() []string {
}
}

func (c *createCSISnapshotFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(c.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(c.RequiredArgs(), args)
}

func createCSISnapshot(ctx context.Context, snapshotter snapshot.Snapshotter, name, namespace, pvc, snapshotClass string, wait bool, labels map[string]string) (*v1.VolumeSnapshot, error) {
snapshotMeta := snapshot.ObjectMeta{
Name: name,
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/create_csi_snapshot_static.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/kanisterio/kanister/pkg/kube/snapshot"
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/utils"
)

func init() {
Expand Down Expand Up @@ -151,6 +152,14 @@ func (*createCSISnapshotStaticFunc) Arguments() []string {
}
}

func (c *createCSISnapshotStaticFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(c.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(c.RequiredArgs(), args)
}

func createCSISnapshotStatic(
ctx context.Context,
snapshotter snapshot.Snapshotter,
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/create_rds_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/kanisterio/kanister/pkg/log"
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/utils"
)

func init() {
Expand Down Expand Up @@ -200,6 +201,14 @@ func (crs *createRDSSnapshotFunc) Arguments() []string {
}
}

func (c *createRDSSnapshotFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(c.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(c.RequiredArgs(), args)
}

func (crs *createRDSSnapshotFunc) ExecutionProgress() (crv1alpha1.PhaseProgress, error) {
metav1Time := metav1.NewTime(time.Now())
return crv1alpha1.PhaseProgress{
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/create_volume_from_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/kanisterio/kanister/pkg/log"
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/utils"
)

func init() {
Expand Down Expand Up @@ -183,6 +184,14 @@ func (*createVolumeFromSnapshotFunc) Arguments() []string {
}
}

func (c *createVolumeFromSnapshotFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(c.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(c.RequiredArgs(), args)
}

func (crs *createVolumeFromSnapshotFunc) ExecutionProgress() (crv1alpha1.PhaseProgress, error) {
metav1Time := metav1.NewTime(time.Now())
return crv1alpha1.PhaseProgress{
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/create_volume_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/secrets"
"github.com/kanisterio/kanister/pkg/utils"
)

func init() {
Expand Down Expand Up @@ -326,6 +327,14 @@ func (*createVolumeSnapshotFunc) Arguments() []string {
}
}

func (c *createVolumeSnapshotFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(c.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(c.RequiredArgs(), args)
}

func (c *createVolumeSnapshotFunc) ExecutionProgress() (crv1alpha1.PhaseProgress, error) {
metav1Time := metav1.NewTime(time.Now())
return crv1alpha1.PhaseProgress{
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/delete_csi_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/poll"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/utils"
)

func init() {
Expand Down Expand Up @@ -103,6 +104,14 @@ func (*deleteCSISnapshotFunc) Arguments() []string {
}
}

func (d *deleteCSISnapshotFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(d.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(d.RequiredArgs(), args)
}

func (c *deleteCSISnapshotFunc) ExecutionProgress() (crv1alpha1.PhaseProgress, error) {
metav1Time := metav1.NewTime(time.Now())
return crv1alpha1.PhaseProgress{
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/delete_csi_snapshot_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/kanisterio/kanister/pkg/kube/snapshot"
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/utils"
)

func init() {
Expand Down Expand Up @@ -92,6 +93,14 @@ func (*deleteCSISnapshotContentFunc) Arguments() []string {
}
}

func (d *deleteCSISnapshotContentFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(d.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(d.RequiredArgs(), args)
}

func (c *deleteCSISnapshotContentFunc) ExecutionProgress() (crv1alpha1.PhaseProgress, error) {
metav1Time := metav1.NewTime(time.Now())
return crv1alpha1.PhaseProgress{
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/delete_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/restic"
"github.com/kanisterio/kanister/pkg/utils"
)

const (
Expand Down Expand Up @@ -276,6 +277,14 @@ func (*deleteDataFunc) Arguments() []string {
}
}

func (d *deleteDataFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(d.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(d.RequiredArgs(), args)
}

func (d *deleteDataFunc) ExecutionProgress() (crv1alpha1.PhaseProgress, error) {
metav1Time := metav1.NewTime(time.Now())
return crv1alpha1.PhaseProgress{
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/delete_data_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/restic"
"github.com/kanisterio/kanister/pkg/utils"
)

const (
Expand Down Expand Up @@ -136,6 +137,14 @@ func (*deleteDataAllFunc) Arguments() []string {
}
}

func (d *deleteDataAllFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(d.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(d.RequiredArgs(), args)
}

func (d *deleteDataAllFunc) ExecutionProgress() (crv1alpha1.PhaseProgress, error) {
metav1Time := metav1.NewTime(time.Now())
return crv1alpha1.PhaseProgress{
Expand Down
9 changes: 9 additions & 0 deletions pkg/function/delete_data_using_kopia_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/progress"
"github.com/kanisterio/kanister/pkg/utils"
)

const (
Expand Down Expand Up @@ -72,6 +73,14 @@ func (*deleteDataUsingKopiaServerFunc) Arguments() []string {
}
}

func (d *deleteDataUsingKopiaServerFunc) Validate(args map[string]any) error {
if err := utils.CheckSupportedArgs(d.Arguments(), args); err != nil {
return err
}

return utils.CheckRequiredArgs(d.RequiredArgs(), args)
}

func (d *deleteDataUsingKopiaServerFunc) Exec(ctx context.Context, tp param.TemplateParams, args map[string]any) (map[string]any, error) {
// Set progress percent
d.progressPercent = progress.StartedPercent
Expand Down
Loading

0 comments on commit d694960

Please sign in to comment.