-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added update for named entity Signed-off-by: Prafulla Mahindrakar <[email protected]> * Added docs Signed-off-by: Prafulla Mahindrakar <[email protected]> * Incorporated the feedback Signed-off-by: Prafulla Mahindrakar <[email protected]> * Fixed unit test Signed-off-by: Prafulla Mahindrakar <[email protected]> * Removed unarchive comment on activate Signed-off-by: Prafulla Mahindrakar <[email protected]>
- Loading branch information
1 parent
89f6e6f
commit cf3ffa1
Showing
23 changed files
with
994 additions
and
28 deletions.
There are no files selected for viewing
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,17 @@ | ||
package clierrors | ||
|
||
var ( | ||
ErrInvalidStateUpdate = "Invalid state passed. Specify either activate or archive\n" | ||
|
||
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" | ||
|
||
ErrWorkflowNotPassed = "Workflow name not passed\n" | ||
ErrFailedWorkflowUpdate = "Workflow %v failed to get updated to due to %v\n" | ||
|
||
ErrTaskNotPassed = "Task name not passed\n" // #nosec | ||
ErrFailedTaskUpdate = "Task %v failed to get updated to due to %v\n" | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,14 @@ | ||
package interfaces | ||
|
||
import ( | ||
"context" | ||
|
||
cmdCore "github.com/flyteorg/flytectl/cmd/core" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
) | ||
|
||
//go:generate mockery -name=Updater -case=underscore | ||
|
||
type Updater interface { | ||
UpdateNamedEntity(ctx context.Context, name, project, domain string, rsType core.ResourceType, cmdCtx cmdCore.CommandContext) error | ||
} |
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,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 ( | ||
updateLPShort = "Updates launch plan metadata" | ||
updateLPLong = ` | ||
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 updateLPFunc(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 | ||
} |
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,44 @@ | ||
package update | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/flyteorg/flytectl/cmd/testutils" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func UpdateLPSetup() { | ||
ctx = testutils.Ctx | ||
cmdCtx = testutils.CmdCtx | ||
mockClient = testutils.MockClient | ||
} | ||
|
||
func TestLPUpdate(t *testing.T) { | ||
testutils.Setup() | ||
UpdateLPSetup() | ||
namedEntityConfig = &NamedEntityConfig{} | ||
args = []string{"task1"} | ||
mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(&admin.NamedEntityUpdateResponse{}, nil) | ||
assert.Nil(t, updateLPFunc(ctx, args, cmdCtx)) | ||
} | ||
|
||
func TestLPUpdateFail(t *testing.T) { | ||
testutils.Setup() | ||
UpdateLPSetup() | ||
namedEntityConfig = &NamedEntityConfig{} | ||
args = []string{"task1"} | ||
mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) | ||
assert.NotNil(t, updateTaskFunc(ctx, args, cmdCtx)) | ||
} | ||
|
||
func TestLPUpdateInvalidArgs(t *testing.T) { | ||
testutils.Setup() | ||
UpdateLPSetup() | ||
namedEntityConfig = &NamedEntityConfig{} | ||
args = []string{} | ||
assert.NotNil(t, updateTaskFunc(ctx, args, cmdCtx)) | ||
} |
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,50 @@ | ||
package update | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/flyteorg/flytectl/clierrors" | ||
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" | ||
) | ||
|
||
//go:generate pflags NamedEntityConfig --default-var namedEntityConfig | ||
|
||
var ( | ||
namedEntityConfig = &NamedEntityConfig{} | ||
) | ||
|
||
type NamedEntityConfig struct { | ||
Archive bool `json:"archive" pflag:",archive named entity."` | ||
Activate bool `json:"activate" pflag:",activate the named entity."` | ||
Description string `json:"description" pflag:",description of the named entity."` | ||
} | ||
|
||
func (n NamedEntityConfig) UpdateNamedEntity(ctx context.Context, name string, project string, domain string, rsType core.ResourceType, cmdCtx cmdCore.CommandContext) error { | ||
archiveProject := n.Archive | ||
activateProject := n.Activate | ||
if activateProject == archiveProject && activateProject { | ||
return fmt.Errorf(clierrors.ErrInvalidStateUpdate) | ||
} | ||
var nameEntityState admin.NamedEntityState | ||
if activateProject { | ||
nameEntityState = admin.NamedEntityState_NAMED_ENTITY_ACTIVE | ||
} else if archiveProject { | ||
nameEntityState = admin.NamedEntityState_NAMED_ENTITY_ARCHIVED | ||
} | ||
_, err := cmdCtx.AdminClient().UpdateNamedEntity(ctx, &admin.NamedEntityUpdateRequest{ | ||
ResourceType: rsType, | ||
Id: &admin.NamedEntityIdentifier{ | ||
Project: project, | ||
Domain: domain, | ||
Name: name, | ||
}, | ||
Metadata: &admin.NamedEntityMetadata{ | ||
Description: n.Description, | ||
State: nameEntityState, | ||
}, | ||
}) | ||
return err | ||
} |
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,48 @@ | ||
package update | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/flyteorg/flytectl/cmd/testutils" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
"github.com/stretchr/testify/mock" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func NamedEntitySetup() { | ||
ctx = testutils.Ctx | ||
cmdCtx = testutils.CmdCtx | ||
mockClient = testutils.MockClient | ||
} | ||
|
||
func TestNamedEntity(t *testing.T) { | ||
testutils.Setup() | ||
NamedEntitySetup() | ||
mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(&admin.NamedEntityUpdateResponse{}, nil) | ||
namedEntityConfig = &NamedEntityConfig{Archive: false, Activate: true, Description: "named entity description"} | ||
assert.Nil(t, namedEntityConfig.UpdateNamedEntity(ctx, "namedEntity", "project", "domain", | ||
core.ResourceType_WORKFLOW, cmdCtx)) | ||
namedEntityConfig = &NamedEntityConfig{Archive: true, Activate: false, Description: "named entity description"} | ||
assert.Nil(t, namedEntityConfig.UpdateNamedEntity(ctx, "namedEntity", "project", "domain", | ||
core.ResourceType_WORKFLOW, cmdCtx)) | ||
} | ||
|
||
func TestNamedEntityValidationFailure(t *testing.T) { | ||
testutils.Setup() | ||
NamedEntitySetup() | ||
namedEntityConfig = &NamedEntityConfig{Archive: true, Activate: true, Description: "named entity description"} | ||
assert.NotNil(t, namedEntityConfig.UpdateNamedEntity(ctx, "namedEntity", "project", "domain", | ||
core.ResourceType_WORKFLOW, cmdCtx)) | ||
} | ||
|
||
func TestNamedEntityFailure(t *testing.T) { | ||
testutils.Setup() | ||
NamedEntitySetup() | ||
namedEntityConfig = &NamedEntityConfig{Archive: true, Activate: true, Description: "named entity description"} | ||
mockClient.OnUpdateNamedEntityMatch(mock.Anything, mock.Anything).Return(nil, fmt.Errorf("failed to update")) | ||
assert.NotNil(t, namedEntityConfig.UpdateNamedEntity(ctx, "namedEntity", "project", "domain", | ||
core.ResourceType_WORKFLOW, cmdCtx)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.