Skip to content

feat: add serviceaccount annotations to the helm charts; bump sops version to 3.6.1; bump golang version to 1.14.9 - #21

Merged
isindir merged 2 commits into
masterfrom
bump_versions
Sep 19, 2020
Merged

isindir merged 2 commits into
masterfrom
bump_versions

Conversation

@isindir

@isindir isindir commented Sep 19, 2020

Copy link
Copy Markdown
Owner

What this PR does / why we need it:

Release new version

@isindir
isindir merged commit 32265c0 into master Sep 19, 2020
@isindir
isindir deleted the bump_versions branch September 19, 2020 07:32
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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant