Skip to content

Commit

Permalink
Respect project state in project.yaml file (flyteorg#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
katrogan authored Apr 17, 2023
1 parent bd00706 commit bd6b856
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
5 changes: 5 additions & 0 deletions cmd/config/subcommand/project/project_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (c *ConfigProject) GetProjectSpec(id string) (*admin.Project, error) {
projectSpec.Labels = &admin.Labels{
Values: c.Labels,
}
projectState, err := c.MapToAdminState()
if err != nil {
return nil, err
}
projectSpec.State = projectState
return &projectSpec, nil
}

Expand Down
5 changes: 0 additions & 5 deletions cmd/update/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ func updateProjectsFunc(ctx context.Context, args []string, cmdCtx cmdCore.Comma
return fmt.Errorf(clierrors.ErrProjectNotPassed)
}

state, err := project.DefaultProjectConfig.MapToAdminState()
if err != nil {
return err
}
projectSpec.State = state
if project.DefaultProjectConfig.DryRun {
logger.Infof(ctx, "skipping UpdateProject request (dryRun)")
} else {
Expand Down
20 changes: 11 additions & 9 deletions cmd/update/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ func updateProjectSetup() {
}
}

func modifyProjectFlags(archiveProject *bool, newArchiveVal bool, activateProject *bool, newActivateVal bool) {
*archiveProject = newArchiveVal
*activateProject = newActivateVal
func modifyProjectFlags(newArchiveVal bool, newActivateVal bool) {
project.DefaultProjectConfig.ArchiveProject = newArchiveVal
project.DefaultProjectConfig.Archive = newArchiveVal
project.DefaultProjectConfig.ActivateProject = newActivateVal
project.DefaultProjectConfig.Activate = newActivateVal
}

func TestActivateProjectFunc(t *testing.T) {
s := setup()
updateProjectSetup()
config.GetConfig().Project = projectValue
project.DefaultProjectConfig.Name = projectValue
modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), false, &(project.DefaultProjectConfig.ActivateProject), true)
modifyProjectFlags(false, true)
projectUpdateRequest = &admin.Project{
Id: projectValue,
Name: projectValue,
Expand All @@ -58,7 +60,7 @@ func TestActivateProjectFuncWithError(t *testing.T) {
updateProjectSetup()
config.GetConfig().Project = projectValue
project.DefaultProjectConfig.Name = projectValue
modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), false, &(project.DefaultProjectConfig.ActivateProject), true)
modifyProjectFlags(false, true)
projectUpdateRequest = &admin.Project{
Id: projectValue,
Name: projectValue,
Expand All @@ -80,7 +82,7 @@ func TestArchiveProjectFunc(t *testing.T) {
config.GetConfig().Project = projectValue
project.DefaultProjectConfig = &project.ConfigProject{}
project.DefaultProjectConfig.Name = projectValue
modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), true, &(project.DefaultProjectConfig.ActivateProject), false)
modifyProjectFlags(true, false)
projectUpdateRequest = &admin.Project{
Id: projectValue,
Name: projectValue,
Expand All @@ -101,7 +103,7 @@ func TestArchiveProjectFuncWithError(t *testing.T) {
updateProjectSetup()
project.DefaultProjectConfig.Name = projectValue
project.DefaultProjectConfig.Labels = map[string]string{}
modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), true, &(project.DefaultProjectConfig.ActivateProject), false)
modifyProjectFlags(true, false)
projectUpdateRequest = &admin.Project{
Id: projectValue,
Name: projectValue,
Expand All @@ -122,7 +124,7 @@ func TestEmptyProjectInput(t *testing.T) {
s := setup()
updateProjectSetup()
config.GetConfig().Project = ""
modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), false, &(project.DefaultProjectConfig.ActivateProject), true)
modifyProjectFlags(false, true)
err := updateProjectsFunc(s.Ctx, []string{}, s.CmdCtx)
assert.NotNil(t, err)
assert.Equal(t, fmt.Errorf(clierrors.ErrProjectNotPassed), err)
Expand All @@ -133,7 +135,7 @@ func TestInvalidInput(t *testing.T) {
updateProjectSetup()
config.GetConfig().Project = projectValue
project.DefaultProjectConfig.Name = projectValue
modifyProjectFlags(&(project.DefaultProjectConfig.ArchiveProject), true, &(project.DefaultProjectConfig.ActivateProject), true)
modifyProjectFlags(true, true)
err := updateProjectsFunc(s.Ctx, []string{}, s.CmdCtx)
assert.NotNil(t, err)
assert.Equal(t, fmt.Errorf(clierrors.ErrInvalidStateUpdate), err)
Expand Down

0 comments on commit bd6b856

Please sign in to comment.