Skip to content

Commit

Permalink
Added launchplan update command and moved namedentity (flyteorg#170)
Browse files Browse the repository at this point in the history
* Added launchplan update command and moved namedentity

Signed-off-by: Prafulla Mahindrakar <[email protected]>
  • Loading branch information
pmahindrakar-oss authored and austin362667 committed May 7, 2024
1 parent c611187 commit 9502a24
Show file tree
Hide file tree
Showing 15 changed files with 392 additions and 34 deletions.
5 changes: 3 additions & 2 deletions flytectl/clierrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ var (
ErrProjectNotPassed = "Project not passed\n"
ErrFailedProjectUpdate = "Project %v failed to get updated to %v state due to %v\n"

ErrLPNotPassed = "Launch plan name not passed\n"
ErrFailedLPUpdate = "Launch plan %v failed to get updated due to %v\n"
ErrLPNotPassed = "Launch plan name not passed\n"
ErrLPVersionNotPassed = "Launch plan version not passed\n" //nolint
ErrFailedLPUpdate = "Launch plan %v failed to get updated due to %v\n"

ErrWorkflowNotPassed = "Workflow name not passed\n"
ErrFailedWorkflowUpdate = "Workflow %v failed to get updated to due to %v\n"
Expand Down
14 changes: 14 additions & 0 deletions flytectl/cmd/config/subcommand/launchplan/updateconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package launchplan

//go:generate pflags UpdateConfig --default-var UConfig --bind-default-var
var (
UConfig = &UpdateConfig{}
)

// Config
type UpdateConfig struct {
Archive bool `json:"archive" pflag:",archive launchplan."`
Activate bool `json:"activate" pflag:",activate launchplan."`
DryRun bool `json:"dryRun" pflag:",execute command without making any modifications."`
Version string `json:"version" pflag:",version of the launchplan to be fetched."`
}
58 changes: 58 additions & 0 deletions flytectl/cmd/config/subcommand/launchplan/updateconfig_flags.go

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

158 changes: 158 additions & 0 deletions flytectl/cmd/config/subcommand/launchplan/updateconfig_flags_test.go

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

1 change: 1 addition & 0 deletions flytectl/cmd/get/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var executionColumns = []printer.Column{
{Header: "Launch Plan Name", JSONPath: "$.spec.launchPlan.name"},
{Header: "Type", JSONPath: "$.spec.launchPlan.resourceType"},
{Header: "Phase", JSONPath: "$.closure.phase"},
{Header: "Scheduled Time", JSONPath: "$.spec.metadata.scheduledAt"},
{Header: "Started", JSONPath: "$.closure.startedAt"},
{Header: "Elapsed Time", JSONPath: "$.closure.duration"},
{Header: "Abort data (Trunc)", JSONPath: "$.closure.abortMetadata[\"cause\"]", TruncateTo: &hundredChars},
Expand Down
57 changes: 43 additions & 14 deletions flytectl/cmd/update/launch_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@ import (

"github.com/flyteorg/flytectl/clierrors"
"github.com/flyteorg/flytectl/cmd/config"
"github.com/flyteorg/flytectl/cmd/config/subcommand/launchplan"
cmdCore "github.com/flyteorg/flytectl/cmd/core"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"github.com/flyteorg/flytestdlib/logger"
)

const (
updateLPShort = "Updates launch plan metadata"
updateLPShort = "Updates launch plan status"
updateLPLong = `
Following command updates the description on the launchplan.
Activating launchplan activates the scheduled job associated with it
::
flytectl update launchplan -p flytectldemo -d development core.advanced.run_merge_sort.merge_sort --description "Mergesort example"
flytectl update launchplan -p flytectldemo -d development core.advanced.run_merge_sort.merge_sort --version v1 --activate
Archiving launchplan named entity is not supported and would throw an error.
Archiving launchplan deschedules any scheduled job associated with it
::
flytectl update launchplan -p flytectldemo -d development core.advanced.run_merge_sort.merge_sort --archive
flytectl update launchplan -p flytectldemo -d development core.advanced.run_merge_sort.merge_sort --version v1 --archive
Activating launchplan named entity would be a noop.
::
flytectl update launchplan -p flytectldemo -d development core.advanced.run_merge_sort.merge_sort --activate
Usage
`
Expand All @@ -39,11 +38,41 @@ func updateLPFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandCont
return fmt.Errorf(clierrors.ErrLPNotPassed)
}
name := args[0]
err := namedEntityConfig.UpdateNamedEntity(ctx, name, project, domain, core.ResourceType_LAUNCH_PLAN, cmdCtx)
if err != nil {
fmt.Printf(clierrors.ErrFailedLPUpdate, name, err)
return err
version := launchplan.UConfig.Version
if len(version) == 0 {
return fmt.Errorf(clierrors.ErrLPVersionNotPassed)
}
activateLP := launchplan.UConfig.Activate
archiveLP := launchplan.UConfig.Archive
if activateLP == archiveLP && archiveLP {
return fmt.Errorf(clierrors.ErrInvalidStateUpdate)
}

var lpState admin.LaunchPlanState
if activateLP {
lpState = admin.LaunchPlanState_ACTIVE
} else if archiveLP {
lpState = admin.LaunchPlanState_INACTIVE
}

if launchplan.UConfig.DryRun {
logger.Debugf(ctx, "skipping CreateExecution request (DryRun)")
} else {
_, err := cmdCtx.AdminClient().UpdateLaunchPlan(ctx, &admin.LaunchPlanUpdateRequest{
Id: &core.Identifier{
Project: project,
Domain: domain,
Name: name,
Version: version,
},
State: lpState,
})
if err != nil {
fmt.Printf(clierrors.ErrFailedLPUpdate, name, err)
return err
}
}
fmt.Printf("updated metadata successfully on %v", name)
fmt.Printf("updated launchplan successfully on %v", name)

return nil
}
49 changes: 49 additions & 0 deletions flytectl/cmd/update/launch_plan_meta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package update

import (
"context"
"fmt"

"github.com/flyteorg/flytectl/clierrors"
"github.com/flyteorg/flytectl/cmd/config"
cmdCore "github.com/flyteorg/flytectl/cmd/core"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
)

const (
updateLPMetaShort = "Updates launch plan metadata"
updateLPMetaLong = `
Following command updates the description on the launchplan.
::
flytectl update launchplan -p flytectldemo -d development core.advanced.run_merge_sort.merge_sort --description "Mergesort example"
Archiving launchplan named entity is not supported and would throw an error.
::
flytectl update launchplan -p flytectldemo -d development core.advanced.run_merge_sort.merge_sort --archive
Activating launchplan named entity would be a noop.
::
flytectl update launchplan -p flytectldemo -d development core.advanced.run_merge_sort.merge_sort --activate
Usage
`
)

func updateLPMetaFunc(ctx context.Context, args []string, cmdCtx cmdCore.CommandContext) error {
project := config.GetConfig().Project
domain := config.GetConfig().Domain
if len(args) != 1 {
return fmt.Errorf(clierrors.ErrLPNotPassed)
}
name := args[0]
err := namedEntityConfig.UpdateNamedEntity(ctx, name, project, domain, core.ResourceType_LAUNCH_PLAN, cmdCtx)
if err != nil {
fmt.Printf(clierrors.ErrFailedLPUpdate, name, err)
return err
}
fmt.Printf("updated metadata successfully on %v", name)
return nil
}
Loading

0 comments on commit 9502a24

Please sign in to comment.