Skip to content

Commit

Permalink
changed config profiles to be a map, added an accessor method for get…
Browse files Browse the repository at this point in the history
…ting a certain configuration profile
  • Loading branch information
rhuss committed Dec 6, 2023
1 parent b0690fc commit a476ba6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions pkg/kn/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type config struct {
// channelTypeMappings is a list of channel type mapping
channelTypeMappings []ChannelTypeMapping

profiles Profiles
profiles map[string]Profile
}

func (c *config) ContextSharing() bool {
Expand Down Expand Up @@ -102,8 +102,8 @@ func (c *config) SinkMappings() []SinkMapping {
return c.sinkMappings
}

func (c *config) Profiles() Profiles {
return c.profiles
func (c *config) Profile(profile string) Profile {
return c.profiles[profile]
}

func (c *config) ChannelTypeMappings() []ChannelTypeMapping {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ eventing:
assert.Equal(t, GlobalConfig.PluginsDir(), "/tmp")
assert.Equal(t, GlobalConfig.LookupPluginsInPath(), true)
assert.Equal(t, len(GlobalConfig.SinkMappings()), 1)
assert.Equal(t, len(GlobalConfig.Profiles().Profile), 1)
assert.Equal(t, GlobalConfig.Profile("istio").Annotations["sidecar.istio.io/inject"], "true")
assert.DeepEqual(t, (GlobalConfig.SinkMappings())[0], SinkMapping{
Prefix: "service",
Resource: "services",
Expand Down
4 changes: 2 additions & 2 deletions pkg/kn/config/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type TestConfig struct {
TestLookupPluginsInPath bool
TestSinkMappings []SinkMapping
TestChannelTypeMappings []ChannelTypeMapping
TestProfiles Profiles
TestProfiles map[string]Profile
}

// Ensure that TestConfig implements the configuration interface
Expand All @@ -36,4 +36,4 @@ func (t TestConfig) ConfigFile() string { return t.TestCo
func (t TestConfig) LookupPluginsInPath() bool { return t.TestLookupPluginsInPath }
func (t TestConfig) SinkMappings() []SinkMapping { return t.TestSinkMappings }
func (t TestConfig) ChannelTypeMappings() []ChannelTypeMapping { return t.TestChannelTypeMappings }
func (t TestConfig) Profiles() Profiles { return t.TestProfiles }
func (t TestConfig) Profile(profile string) Profile { return t.TestProfiles[profile] }
7 changes: 3 additions & 4 deletions pkg/kn/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type Config interface {
// ChannelTypeMappings returns additional mappings for channel type aliases
ChannelTypeMappings() []ChannelTypeMapping

Profiles() Profiles
// Profile returns a configured profile with this name or nil of no such profile is configured
Profile(profile string) Profile
}

// SinkMappings is the struct of sink prefix config in kn config
Expand Down Expand Up @@ -77,9 +78,7 @@ type Profile struct {
Annotations map[string]string `yaml:"annotations"`
}

type Profiles struct {
Profiles []Profile `yaml:"profiles"`
}
type Profiles map[string]Profile

This comment has been minimized.

Copy link
@rhuss

rhuss Dec 6, 2023

Author Contributor

We can remove that definition as I used directly the map declaration map[string]Profile in the config struct. I think it makes it clearer to see directly that Profiles are a map keyed with the profile name (and don't obscure it with yet-another-type)


// config Keys for looking up in viper
const (
Expand Down

0 comments on commit a476ba6

Please sign in to comment.