Skip to content

fix: Refresh base images to improve security; Bump some pipeline deps - #49

Merged
isindir merged 3 commits into
masterfrom
update_base_docker_image
Feb 15, 2021
Merged

isindir merged 3 commits into
masterfrom
update_base_docker_image

Conversation

@isindir

@isindir isindir commented Feb 15, 2021

Copy link
Copy Markdown
Owner

What this PR does / why we need it:

@isindir isindir added the fix label Feb 15, 2021
@isindir isindir self-assigned this Feb 15, 2021
@isindir

isindir commented Feb 15, 2021

Copy link
Copy Markdown
Owner Author

Fixes #48

@isindir isindir linked an issue Feb 15, 2021 that may be closed by this pull request
@isindir
isindir merged commit 2c9c5e9 into master Feb 15, 2021
@isindir
isindir deleted the update_base_docker_image branch February 15, 2021 11:59
isindir added a commit that referenced this pull request Nov 1, 2026
#259)

* fix: code quality fixes from Go-mistakes audit (ticket 01)

Three corrections identified in the 100 Go Mistakes audit:

1. Error wrapping (mistake #49): cloneTemplateData used %v to format
   the base64 decode error, discarding the original error from the
   chain. Changed to %w so callers can inspect the root cause via
   errors.Is / errors.As / errors.Unwrap.

2. Map pre-sizing (mistake #21): garbageCollectOrphanedSecrets
   allocated make(map[string]bool) with no capacity hint on every
   reconciliation. Changed to make(map[string]bool,
   len(sopsSecret.Spec.SecretsTemplate)) to avoid repeated rehashing
   for secrets with many templates.

3. UpdateSopsSecretStatus doc comment + rationale: added a Go doc
   comment explaining the function's purpose and an inline comment on
   the intentionally ignored status-update error, making the design
   decision explicit for future contributors.

Also adds:
- TestCloneTemplateDataErrorWrapping unit test (TDD red→green for fix 1)
- .scratch/ to .gitignore (local ticket scratch directory)

* fix(controllers): correct two log-level bugs in reconciler (Go Mistakes #48)

## What

Two logging correctness fixes in sopssecret_controller.go:

1. garbageCollectOrphanedSecrets: move the "Garbage collected an orphaned
   secret" info log into the else{} branch of the Delete error check so it
   only fires when Delete returns nil. Previously it fired unconditionally,
   meaning a failed delete would still log success.

2. getSecretFromClusterOrCreateFromTemplate: change r.Log.Error → r.Log.V(0).Info
   on the errors.IsNotFound path. Secret-not-found is the normal creation
   path, not a failure; logging it at error level causes false alerts.
   Message updated from "Creating a new Secret" to "Secret not found, creating"
   to be accurate about what triggered the log.

## Tests

- TestIsNotFoundDoesNotLogError: spyLogSink verifies no r.Log.Error call on
  the IsNotFound path.
- TestGarbageCollectSuccessLogOnlyOnSuccess: two sub-tests verify success log
  fires only when deleteErr == nil.
- Full envtest integration suite passes (8 Ginkgo specs).

Addresses Go Mistakes #48 (error vs non-error log levels).

* refactor(controllers): decouple Prometheus metrics from init() (Go Mistakes #62)

## What

Replace the package-level init() in custom_metrics.go with an explicit
RegisterMetrics(registry prometheus.Registerer) function, wired into
SetupWithManager. This removes the global side-effect from package import,
making the controllers package safe to import in unit tests without touching
the global Prometheus registry.

Changes:
- custom_metrics.go: remove func init(); add exported RegisterMetrics that
  accepts any prometheus.Registerer and calls MustRegister on the three
  existing counters.
- sopssecret_controller.go: import ctrlmetrics and call
  RegisterMetrics(ctrlmetrics.Registry) in SetupWithManager before returning,
  preserving existing registration behaviour in production.
- enforce_ownership_test.go: add TestRegisterMetrics that calls
  RegisterMetrics(prometheus.NewRegistry()) and asserts no panic, using a
  fresh registry to avoid double-registration against the global one.

Note: mgr.GetMetricsServer().GetRegistry() does not exist in the vendored
controller-runtime version; ctrlmetrics.Registry is the canonical pattern
used by all controller-runtime internal packages (workqueue, certwatcher,
webhook).

Addresses Go Mistakes #62 (init() side-effects / dependency injection).

* Fix typo

* fix(controllers): log levels, error wrapping, metrics init side-effect, test data clumps

* Fix typo

* update logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setup Security Policy

1 participant