Skip to content

Commit

Permalink
additional-redacted-vars
Browse files Browse the repository at this point in the history
Also remove unused AssertLogsDoNotContain
  • Loading branch information
DrJosh9000 committed Mar 25, 2024
1 parent 4a6d1b1 commit c5a057c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 33 deletions.
2 changes: 1 addition & 1 deletion charts/agent-stack-k8s/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 13 additions & 13 deletions internal/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 6 additions & 6 deletions internal/controller/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)
Expand Down
4 changes: 2 additions & 2 deletions internal/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions internal/integration/testcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c5a057c

Please sign in to comment.