Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ab963fa

Browse files
committedMar 12, 2025··
fixup! Add a linter to forbid env var usage
1 parent ea174d6 commit ab963fa

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed
 

‎.golangci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ issues:
1616
- goconst
1717
- golint
1818
text: "underscore"
19-
- path: pkg/util/envvar/
19+
- path: ^pkg\/util\/envvar
20+
linters:
21+
- forbidigo
22+
- path: ^cmd\/(readiness|versionhook|manager)\/main\.go$
2023
linters:
2124
- forbidigo
2225
linters:

‎cmd/manager/main.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func configureLogger() (*zap.Logger, error) {
4444
func hasRequiredVariables(logger *zap.Logger, envVariables ...string) bool {
4545
allPresent := true
4646
for _, envVariable := range envVariables {
47-
if _, envSpecified := os.LookupEnv(envVariable); !envSpecified { // nolint:forbidigo
47+
if _, envSpecified := os.LookupEnv(envVariable); !envSpecified {
4848
logger.Error(fmt.Sprintf("required environment variable %s not found", envVariable))
4949
allPresent = false
5050
}
@@ -70,7 +70,7 @@ func main() {
7070
}
7171

7272
// Get watch namespace from environment variable.
73-
namespace, nsSpecified := os.LookupEnv(WatchNamespaceEnv) // nolint:forbidigo
73+
namespace, nsSpecified := os.LookupEnv(WatchNamespaceEnv)
7474
if !nsSpecified {
7575
log.Sugar().Fatal("No namespace specified to watch")
7676
}
@@ -110,12 +110,12 @@ func main() {
110110
// Setup Controller.
111111
if err = controllers.NewReconciler(
112112
mgr,
113-
os.Getenv(construct.MongodbRepoUrlEnv), // nolint:forbidigo
114-
os.Getenv(construct.MongodbImageEnv), // nolint:forbidigo
115-
envvar.GetEnvOrDefault(construct.MongoDBImageTypeEnv, construct.DefaultImageType), // nolint:forbidigo
116-
os.Getenv(construct.AgentImageEnv), // nolint:forbidigo
117-
os.Getenv(construct.VersionUpgradeHookImageEnv), // nolint:forbidigo
118-
os.Getenv(construct.ReadinessProbeImageEnv), // nolint:forbidigo
113+
os.Getenv(construct.MongodbRepoUrlEnv),
114+
os.Getenv(construct.MongodbImageEnv),
115+
envvar.GetEnvOrDefault(construct.MongoDBImageTypeEnv, construct.DefaultImageType),
116+
os.Getenv(construct.AgentImageEnv),
117+
os.Getenv(construct.VersionUpgradeHookImageEnv),
118+
os.Getenv(construct.ReadinessProbeImageEnv),
119119
).SetupWithManager(mgr); err != nil {
120120
log.Sugar().Fatalf("Unable to create controller: %v", err)
121121
}

‎cmd/readiness/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func performCheckOMMode(health health.Status) bool {
180180
}
181181

182182
func isHeadlessMode() bool {
183-
return os.Getenv(headlessAgent) == "true" // nolint:forbidigo
183+
return os.Getenv(headlessAgent) == "true"
184184
}
185185

186186
func kubernetesClientset() (kubernetes.Interface, error) {

‎cmd/versionhook/main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func main() {
3232

3333
logger.Info("Running version change post-start hook")
3434

35-
if statusPath := os.Getenv(agentStatusFilePathEnv); statusPath == "" { // nolint:forbidigo
35+
if statusPath := os.Getenv(agentStatusFilePathEnv); statusPath == "" {
3636
logger.Fatalf(`Required environment variable "%s" not set`, agentStatusFilePathEnv)
3737
return
3838
}
@@ -124,7 +124,7 @@ func waitForAgentHealthStatus() (agent.Health, error) {
124124
// getAgentHealthStatus returns an instance of agent.Health read
125125
// from the health file on disk
126126
func getAgentHealthStatus() (agent.Health, error) {
127-
f, err := os.Open(os.Getenv(agentStatusFilePathEnv)) // nolint:forbidigo
127+
f, err := os.Open(os.Getenv(agentStatusFilePathEnv))
128128
if err != nil {
129129
return agent.Health{}, err
130130
}
@@ -150,7 +150,7 @@ func readAgentHealthStatus(reader io.Reader) (agent.Health, error) {
150150
}
151151

152152
func getHostname() string {
153-
return os.Getenv("HOSTNAME") // nolint:forbidigo
153+
return os.Getenv("HOSTNAME")
154154
}
155155

156156
// shouldDeletePod returns a boolean value indicating if this pod should be deleted

0 commit comments

Comments
 (0)
Please sign in to comment.