From c5a057c31f6419e44c51e4ac62faba531a2dc26e Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Tue, 26 Mar 2024 10:57:11 +1100 Subject: [PATCH] additional-redacted-vars Also remove unused AssertLogsDoNotContain --- charts/agent-stack-k8s/values.schema.json | 2 +- internal/controller/config/config.go | 26 +++++++++++----------- internal/controller/controller.go | 10 ++++----- internal/controller/scheduler/scheduler.go | 12 +++++----- internal/integration/integration_test.go | 4 ++-- internal/integration/testcase_test.go | 6 ----- 6 files changed, 27 insertions(+), 33 deletions(-) diff --git a/charts/agent-stack-k8s/values.schema.json b/charts/agent-stack-k8s/values.schema.json index c957cea6..27d34b94 100644 --- a/charts/agent-stack-k8s/values.schema.json +++ b/charts/agent-stack-k8s/values.schema.json @@ -205,7 +205,7 @@ "title": "The UUID of the Buildkite cluster to pull Jobs from", "examples": [""] }, - "redacted-vars": { + "additional-redacted-vars": { "type": "array", "default": [], "title": "Additional environment variables to redact values from logs", diff --git a/internal/controller/config/config.go b/internal/controller/config/config.go index b8649e34..d3fb2d5e 100644 --- a/internal/controller/config/config.go +++ b/internal/controller/config/config.go @@ -15,18 +15,18 @@ const ( ) type Config struct { - Debug bool `mapstructure:"debug"` - AgentTokenSecret string `mapstructure:"agent-token-secret" validate:"required"` - BuildkiteToken string `mapstructure:"buildkite-token" validate:"required"` - Image string `mapstructure:"image" validate:"required"` - JobTTL time.Duration `mapstructure:"job-ttl"` - MaxInFlight int `mapstructure:"max-in-flight" validate:"min=0"` - Namespace string `mapstructure:"namespace" validate:"required"` - Org string `mapstructure:"org" validate:"required"` - Tags stringSlice `mapstructure:"tags" validate:"min=1"` - ProfilerAddress string `mapstructure:"profiler-address" validate:"omitempty,hostname_port"` - ClusterUUID string `mapstructure:"cluster-uuid" validate:"omitempty"` - RedactedVars stringSlice `mapstructure:"redacted-vars" validate:"omitempty"` + Debug bool `mapstructure:"debug"` + AgentTokenSecret string `mapstructure:"agent-token-secret" validate:"required"` + BuildkiteToken string `mapstructure:"buildkite-token" validate:"required"` + Image string `mapstructure:"image" validate:"required"` + JobTTL time.Duration `mapstructure:"job-ttl"` + MaxInFlight int `mapstructure:"max-in-flight" validate:"min=0"` + Namespace string `mapstructure:"namespace" validate:"required"` + Org string `mapstructure:"org" validate:"required"` + Tags stringSlice `mapstructure:"tags" validate:"min=1"` + ProfilerAddress string `mapstructure:"profiler-address" validate:"omitempty,hostname_port"` + ClusterUUID string `mapstructure:"cluster-uuid" validate:"omitempty"` + AdditionalRedactedVars stringSlice `mapstructure:"additional-redacted-vars" validate:"omitempty"` } type stringSlice []string @@ -48,7 +48,7 @@ func (c Config) MarshalLogObject(enc zapcore.ObjectEncoder) error { enc.AddString("org", c.Org) enc.AddString("profiler-address", c.ProfilerAddress) enc.AddString("cluster-uuid", c.ClusterUUID) - if err := enc.AddArray("redacted-vars", c.RedactedVars); err != nil { + if err := enc.AddArray("additional-redacted-vars", c.AdditionalRedactedVars); err != nil { return err } return enc.AddArray("tags", c.Tags) diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 33dec087..bc87679f 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -49,11 +49,11 @@ func Run( } sched := scheduler.New(logger.Named("scheduler"), k8sClient, scheduler.Config{ - Namespace: cfg.Namespace, - Image: cfg.Image, - AgentToken: cfg.AgentTokenSecret, - JobTTL: cfg.JobTTL, - RedactedVars: cfg.RedactedVars, + Namespace: cfg.Namespace, + Image: cfg.Image, + AgentToken: cfg.AgentTokenSecret, + JobTTL: cfg.JobTTL, + AdditionalRedactedVars: cfg.AdditionalRedactedVars, }) limiter := scheduler.NewLimiter(logger.Named("limiter"), sched, cfg.MaxInFlight) diff --git a/internal/controller/scheduler/scheduler.go b/internal/controller/scheduler/scheduler.go index 96689adb..7e267bc0 100644 --- a/internal/controller/scheduler/scheduler.go +++ b/internal/controller/scheduler/scheduler.go @@ -30,11 +30,11 @@ const ( ) type Config struct { - Namespace string - Image string - AgentToken string - JobTTL time.Duration - RedactedVars []string + Namespace string + Image string + AgentToken string + JobTTL time.Duration + AdditionalRedactedVars []string } func New(logger *zap.Logger, client kubernetes.Interface, cfg Config) *worker { @@ -229,7 +229,7 @@ func (w *jobWrapper) Build(skipCheckout bool) (*batchv1.Job, error) { } } - redactedVars := append(w.cfg.RedactedVars, clicommand.RedactedVars.Value.Value()...) + redactedVars := append(w.cfg.AdditionalRedactedVars, clicommand.RedactedVars.Value.Value()...) volumeMounts := []corev1.VolumeMount{{Name: "workspace", MountPath: "/workspace"}} volumeMounts = append(volumeMounts, w.k8sPlugin.ExtraVolumeMounts...) diff --git a/internal/integration/integration_test.go b/internal/integration/integration_test.go index 21ca1d83..5adae9af 100644 --- a/internal/integration/integration_test.go +++ b/internal/integration/integration_test.go @@ -54,7 +54,7 @@ func TestControllerPicksUpJobsWithSubsetOfAgentTags(t *testing.T) { tc.AssertSuccess(ctx, build) } -func TestControllerSetsRedactedVars(t *testing.T) { +func TestControllerSetsAdditionalRedactedVars(t *testing.T) { tc := testcase{ T: t, Fixture: "redacted-vars.yaml", @@ -67,7 +67,7 @@ func TestControllerSetsRedactedVars(t *testing.T) { t.Cleanup(cleanup) cfg := cfg - cfg.RedactedVars = []string{"ELEVEN_HERBS_AND_SPICES"} + cfg.AdditionalRedactedVars = []string{"ELEVEN_HERBS_AND_SPICES"} tc.StartController(ctx, cfg) build := tc.TriggerBuild(ctx, pipelineID) diff --git a/internal/integration/testcase_test.go b/internal/integration/testcase_test.go index 0a70266d..1140f592 100644 --- a/internal/integration/testcase_test.go +++ b/internal/integration/testcase_test.go @@ -196,12 +196,6 @@ func (t testcase) AssertLogsContain(build api.Build, content string) { assert.Contains(t, t.FetchLogs(build), content) } -func (t testcase) AssertLogsDoNotContain(build api.Build, content string) { - t.Helper() - - assert.NotContains(t, t.FetchLogs, content) -} - func (t testcase) AssertArtifactsContain(build api.Build, expected ...string) { t.Helper() config, err := buildkite.NewTokenConfig(cfg.BuildkiteToken, false)