Skip to content

Commit

Permalink
added profile feature
Browse files Browse the repository at this point in the history
  • Loading branch information
sharmaansh21 authored and Anshul Sharma committed Dec 6, 2023
1 parent 9cff5ef commit 8752d02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
24 changes: 20 additions & 4 deletions pkg/kn/commands/service/configuration_edit_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,27 @@ func (p *ConfigurationEditFlags) Apply(

if cmd.Flags().Changed("profile") {
if len(knconfig.GlobalConfig.Profile(p.Profile).Annotations) > 0 {
return fmt.Errorf("profile doesn't exist %s", p.Profile)
} else if len(knconfig.GlobalConfig.Profile(p.Profile).Annotations) == 0 {
return fmt.Errorf("profile %s doesn't contain any annotations.", p.Profile)
annotations := knconfig.GlobalConfig.Profile(p.Profile).Annotations
profileAnnotations := make(util.StringMap)
profileAnnotations.Merge(annotations)
// if strings.HasSuffix(p.Profile, "-") {
// nothingToDelete := make(map[string]string)
// err = servinglib.UpdateRevisionTemplateAnnotations(template, nothingToAdd, profileAnnotations)
// } else {
emptySlice := []string{}
err = servinglib.UpdateRevisionTemplateAnnotations(template, profileAnnotations, emptySlice)
// }

if err != nil {
return err
}
} else {
return fmt.Errorf("profile %s doesn't exist.", p.Profile)
return fmt.Errorf("profile %s doesn't exist", p.Profile)
}

if strings.HasSuffix(p.Profile, "-") {

Check failure on line 509 in pkg/kn/commands/service/configuration_edit_flags.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

SA4017: HasSuffix doesn't have side effects and its return value is ignored (staticcheck)
} else {

Check failure on line 510 in pkg/kn/commands/service/configuration_edit_flags.go

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

SA9003: empty branch (staticcheck)

}
}

Expand Down
13 changes: 0 additions & 13 deletions pkg/kn/commands/service/configuration_edit_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,3 @@ func TestApplyProfileFlagError(t *testing.T) {
err := editFlags.Apply(&svc, nil, cmd)
assert.Assert(t, util.ContainsAll(err.Error(), "profile", "invalidprofile"))
}

func TestApplyProfileFlagAnnotationError(t *testing.T) {
var editFlags ConfigurationEditFlags
knParams := &commands.KnParams{}
cmd, _, _ := commands.CreateTestKnCommand(NewServiceCreateCommand(knParams), knParams)

editFlags.AddCreateFlags(cmd)
svc := createTestService("test-svc", []string{"test-svc-00001", "test-svc-00002"}, goodConditions())
cmd.SetArgs([]string{"--profile", "istio"})
cmd.Execute()
err := editFlags.Apply(&svc, nil, cmd)
assert.Assert(t, util.ContainsAll(err.Error(), "profile", "istio", "doesn't contain any annotations"))
}

0 comments on commit 8752d02

Please sign in to comment.