Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanp - Adding a single variable for default configmaps. #6639

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/apis/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const (
defaultResolverTypeKey = "default-resolver-type"
)

// DefaultConfig holds all the default configurations for the config.
var DefaultConfig, _ = NewDefaultsFromMap(map[string]string{})

// Defaults holds the default configurations
// +k8s:deepcopy-gen=true
type Defaults struct {
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/config/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ const (
maxResultSize = "max-result-size"
)

// DefaultFeatureFlags holds all the default configurations for the feature flags configmap.
var DefaultFeatureFlags, _ = NewFeatureFlagsFromMap(map[string]string{})

// FeatureFlags holds the features configurations
// +k8s:deepcopy-gen=true
//
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/config/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ const (
DurationPipelinerunTypeLastValue = "lastvalue"
)

// DefaultMetrics holds all the default configurations for the metrics.
var DefaultMetrics, _ = newMetricsFromMap(map[string]string{})

// Metrics holds the configurations for the metrics
// +k8s:deepcopy-gen=true
type Metrics struct {
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/config/spire_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ const (
SpireNodeAliasPrefixDefault = "/tekton-node/"
)

// DefaultSpire hols all the default configurations for the spire.
var DefaultSpire, _ = NewSpireConfigFromMap(map[string]string{})

// NewSpireConfigFromMap creates a Config from the supplied map
func NewSpireConfigFromMap(data map[string]string) (*sc.SpireConfig, error) {
cfg := &sc.SpireConfig{}
Expand Down
20 changes: 8 additions & 12 deletions pkg/apis/config/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,12 @@ func FromContextOrDefaults(ctx context.Context) *Config {
if cfg := FromContext(ctx); cfg != nil {
return cfg
}
defaults, _ := NewDefaultsFromMap(map[string]string{})
featureFlags, _ := NewFeatureFlagsFromMap(map[string]string{})
metrics, _ := newMetricsFromMap(map[string]string{})
spireconfig, _ := NewSpireConfigFromMap(map[string]string{})

return &Config{
Defaults: defaults,
FeatureFlags: featureFlags,
Metrics: metrics,
SpireConfig: spireconfig,
Defaults: DefaultConfig.DeepCopy(),
FeatureFlags: DefaultFeatureFlags.DeepCopy(),
Metrics: DefaultMetrics.DeepCopy(),
SpireConfig: DefaultSpire.DeepCopy(),
}
}

Expand Down Expand Up @@ -102,20 +98,20 @@ func (s *Store) ToContext(ctx context.Context) context.Context {
func (s *Store) Load() *Config {
defaults := s.UntypedLoad(GetDefaultsConfigName())
if defaults == nil {
defaults, _ = NewDefaultsFromMap(map[string]string{})
defaults = DefaultConfig.DeepCopy()
}
featureFlags := s.UntypedLoad(GetFeatureFlagsConfigName())
if featureFlags == nil {
featureFlags, _ = NewFeatureFlagsFromMap(map[string]string{})
featureFlags = DefaultFeatureFlags.DeepCopy()
}
metrics := s.UntypedLoad(GetMetricsConfigName())
if metrics == nil {
metrics, _ = newMetricsFromMap(map[string]string{})
metrics = DefaultMetrics.DeepCopy()
}

spireconfig := s.UntypedLoad(GetSpireConfigName())
if spireconfig == nil {
spireconfig, _ = NewSpireConfigFromMap(map[string]string{})
spireconfig = DefaultSpire.DeepCopy()
}

return &Config{
Expand Down
14 changes: 4 additions & 10 deletions pkg/apis/config/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/tektoncd/pipeline/pkg/apis/config"
test "github.com/tektoncd/pipeline/pkg/reconciler/testing"
"github.com/tektoncd/pipeline/test/diff"
corev1 "k8s.io/api/core/v1"
logtesting "knative.dev/pkg/logging/testing"
)

Expand Down Expand Up @@ -60,16 +59,11 @@ func TestStoreLoadWithContext(t *testing.T) {
}

func TestStoreLoadWithContext_Empty(t *testing.T) {
defaults, _ := config.NewDefaultsFromMap(map[string]string{})
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{})
metrics, _ := config.NewMetricsFromConfigMap(&corev1.ConfigMap{Data: map[string]string{}})
spireConfig, _ := config.NewSpireConfigFromMap(map[string]string{})

want := &config.Config{
Defaults: defaults,
FeatureFlags: featureFlags,
Metrics: metrics,
SpireConfig: spireConfig,
Defaults: config.DefaultConfig.DeepCopy(),
FeatureFlags: config.DefaultFeatureFlags.DeepCopy(),
Metrics: config.DefaultMetrics.DeepCopy(),
SpireConfig: config.DefaultSpire.DeepCopy(),
}

store := config.NewStore(logtesting.TestLogger(t))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,9 @@ func TestEmitCloudEvents(t *testing.T) {

// Setup the config and add it to the context
defaults, _ := config.NewDefaultsFromMap(tc.data)
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{})
cfg := &config.Config{
Defaults: defaults,
FeatureFlags: featureFlags,
FeatureFlags: config.DefaultFeatureFlags.DeepCopy(),
}
ctx = config.ToContext(ctx, cfg)

Expand Down Expand Up @@ -241,10 +240,9 @@ func TestEmitCloudEventsWhenConditionChange(t *testing.T) {

// Setup the config and add it to the context
defaults, _ := config.NewDefaultsFromMap(data)
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{})
cfg := &config.Config{
Defaults: defaults,
FeatureFlags: featureFlags,
FeatureFlags: config.DefaultFeatureFlags.DeepCopy(),
}
ctx = config.ToContext(ctx, cfg)

Expand Down
3 changes: 1 addition & 2 deletions pkg/reconciler/events/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ func TestEmit(t *testing.T) {

// Setup the config and add it to the context
defaults, _ := config.NewDefaultsFromMap(tc.data)
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{})
cfg := &config.Config{
Defaults: defaults,
FeatureFlags: featureFlags,
FeatureFlags: config.DefaultFeatureFlags.DeepCopy(),
}
ctx = config.ToContext(ctx, cfg)

Expand Down
3 changes: 1 addition & 2 deletions pkg/reconciler/events/k8sevent/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,9 @@ func TestEmitK8sEvents(t *testing.T) {

// Setup the config and add it to the context
defaults, _ := config.NewDefaultsFromMap(tc.data)
featureFlags, _ := config.NewFeatureFlagsFromMap(map[string]string{})
cfg := &config.Config{
Defaults: defaults,
FeatureFlags: featureFlags,
FeatureFlags: config.DefaultFeatureFlags.DeepCopy(),
}
ctx = config.ToContext(ctx, cfg)

Expand Down