Repository navigation
feat: add serviceaccount annotations to the helm charts; bump sops version to 3.6.1; bump golang version to 1.14.9 - #21
Merged
Merged
Conversation
…rsion to 3.6.1; bump golang version to 1.14.9
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it:
Release new version