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

Make defaults config map name customizable #2260

Merged
merged 1 commit into from
Mar 26, 2020
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
6 changes: 3 additions & 3 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func NewConfigValidationController(ctx context.Context, cmw configmap.Watcher) *

// The configmaps to validate.
configmap.Constructors{
logging.ConfigMapName(): logging.NewConfigFromConfigMap,
defaultconfig.DefaultsConfigName: defaultconfig.NewDefaultsFromConfigMap,
pkgleaderelection.ConfigMapName(): pkgleaderelection.NewConfigFromConfigMap,
logging.ConfigMapName(): logging.NewConfigFromConfigMap,
defaultconfig.GetDefaultsConfigName(): defaultconfig.NewDefaultsFromConfigMap,
pkgleaderelection.ConfigMapName(): pkgleaderelection.NewConfigFromConfigMap,
},
)
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/apis/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package config

import (
"fmt"
"os"
"strconv"
"time"

Expand All @@ -27,8 +28,6 @@ import (
)

const (
// ConfigName is the name of the configmap
DefaultsConfigName = "config-defaults"
DefaultTimeoutMinutes = 60
NoTimeoutDuration = 0 * time.Minute
defaultTimeoutMinutesKey = "default-timeout-minutes"
Expand All @@ -47,6 +46,15 @@ type Defaults struct {
DefaultPodTemplate *pod.Template
}

// GetBucketConfigName returns the name of the configmap containing all
// customizations for the storage bucket.
func GetDefaultsConfigName() string {
if e := os.Getenv("CONFIG_DEFAULTS_NAME"); e != "" {
return e
}
return "config-defaults"
}

// Equals returns true if two Configs are identical
func (cfg *Defaults) Equals(other *Defaults) bool {
if cfg == nil && other == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/config/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
DefaultServiceAccount: "tekton",
DefaultManagedByLabelValue: "something-else",
},
fileName: DefaultsConfigName,
fileName: GetDefaultsConfigName(),
},
{
expectedConfig: &Defaults{
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/config/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func NewStore(logger configmap.Logger, onAfterStore ...func(name string, value i
"defaults",
logger,
configmap.Constructors{
DefaultsConfigName: NewDefaultsFromConfigMap,
GetDefaultsConfigName(): NewDefaultsFromConfigMap,
},
onAfterStore...,
),
Expand All @@ -87,6 +87,6 @@ func (s *Store) ToContext(ctx context.Context) context.Context {
// Load creates a Config from the current config state of the Store.
func (s *Store) Load() *Config {
return &Config{
Defaults: s.UntypedLoad(DefaultsConfigName).(*Defaults).DeepCopy(),
Defaults: s.UntypedLoad(GetDefaultsConfigName()).(*Defaults).DeepCopy(),
}
}
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestPipelineRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand All @@ -167,7 +167,7 @@ func TestPipelineRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestPipelineRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestPipelineRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/pipeline/v1alpha1/taskrun_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func TestTaskRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestTaskRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestTaskRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down Expand Up @@ -282,7 +282,7 @@ func TestTaskRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down Expand Up @@ -317,7 +317,7 @@ func TestTaskRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down Expand Up @@ -358,7 +358,7 @@ func TestTaskRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1beta1/pipelinerun_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestPipelineRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand All @@ -185,7 +185,7 @@ func TestPipelineRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestPipelineRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestPipelineRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/taskrun_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func TestTaskRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand All @@ -207,7 +207,7 @@ func TestTaskRunDefaulting(t *testing.T) {
s := config.NewStore(logtesting.TestLogger(t))
s.OnConfigChanged(&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: config.DefaultsConfigName,
Name: config.GetDefaultsConfigName(),
},
Data: map[string]string{
"default-timeout-minutes": "5",
Expand Down