Skip to content

Update golangci config #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ linters:
forbid:
- pattern: os\.(Getenv|LookupEnv|Environ|ExpandEnv)
pkg: os
msg: "Reading environemnt variables here is prohibited. Please read environment variables in the main package."
msg: "Reading environment variables here is prohibited. Please read environment variables in the main package."
- pattern: os\.(Clearenv|Unsetenv|Setenv)
pkg: os
msg: "Modifying environemnt variables is prohibited."
msg: "Modifying environment variables is prohibited."
- pattern: env\.(Read.*?|EnsureVar)
pkg: github.com/10gen/ops-manager-kubernetes/pkg/util/env
msg: "Using this env package here is prohibited. Please work with environment variables in the main package."
- p: envvar\.(Read.*?|MergeWithOverride|GetEnvOrDefault)
pkg: github.com/10gen/ops-manager-kubernetes/mongodb-community-operator/pkg/util/envvar
msg: "Using this envvar package here is prohibited. Please work with environment variables in the main package."
# Rules with the `pkg` depend on it
analyze-types: true
staticcheck:
Expand Down Expand Up @@ -85,7 +88,13 @@ linters:
path: ^pkg\/util\/env
- linters:
- forbidigo
path: main.go$
path: ^main.go$
- linters:
- forbidigo
path: ^mongodb-community-operator\/pkg\/util\/envvar
- linters:
- forbidigo
path: ^mongodb-community-operator\/cmd\/(readiness|versionhook)\/main\.go$
formatters:
enable:
- gci
Expand Down
2 changes: 1 addition & 1 deletion pkg/images/Imageurls.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func GetOfficialImage(imageUrls ImageUrls, version string, annotations map[strin
repoUrl = strings.TrimRight(repoUrl, "/")
}

assumeOldFormat := envvar.ReadBool(util.MdbAppdbAssumeOldFormat)
assumeOldFormat := envvar.ReadBool(util.MdbAppdbAssumeOldFormat) // nolint:forbidigo
if IsEnterpriseImage(imageURL) && !assumeOldFormat {
// 5.0.6-ent -> 5.0.6-ubi8
if strings.HasSuffix(version, "-ent") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/telemetry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func NewClient(retryClient *retryablehttp.Client) (*Client, error) {
&http.Client{Transport: &retryablehttp.RoundTripper{Client: retryClient}},
)

if urlStr := envvar.GetEnvOrDefault(BaseUrl, ""); urlStr != "" {
if urlStr := envvar.GetEnvOrDefault(BaseUrl, ""); urlStr != "" { // nolint:forbidigo
Logger.Debugf("Using different base url configured for atlasclient: %s", urlStr)
parsed, err := url.Parse(urlStr)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/telemetry/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func detectKubernetesFlavour(ctx context.Context, uncachedClient kubeclient.Read
// We are using a non-cached client to ensure we are properly timing out in case we don't have the
// necessary RBACs.
func getKubernetesClusterUUID(ctx context.Context, uncachedClient kubeclient.Reader) string {
timeoutLengthStr := envvar.GetEnvOrDefault(KubeTimeout, "5m")
timeoutLengthStr := envvar.GetEnvOrDefault(KubeTimeout, "5m") // nolint:forbidigo
duration, err := time.ParseDuration(timeoutLengthStr)
if err != nil {
Logger.Warnf("Failed converting %s to a duration, using default 5m", KubeTimeout)
Expand Down
4 changes: 2 additions & 2 deletions pkg/telemetry/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type snapshotCollector func(ctx context.Context, memberClusterMap map[string]Con
func RunTelemetry(ctx context.Context, mongodbImage, databaseNonStaticImage, namespace string, operatorClusterMgr manager.Manager, clusterMap map[string]cluster.Cluster, atlasClient *Client, configuredOperatorEnv util.OperatorEnvironment) {
Logger.Debug("sending telemetry!")

intervalStr := envvar.GetEnvOrDefault(CollectionFrequency, DefaultCollectionFrequencyStr)
intervalStr := envvar.GetEnvOrDefault(CollectionFrequency, DefaultCollectionFrequencyStr) // nolint:forbidigo
duration, err := time.ParseDuration(intervalStr)
if err != nil || duration < time.Minute {
Logger.Warn("Failed converting %s to a duration or value is too small (minimum is one minute), using default 1h", CollectionFrequency)
Expand Down Expand Up @@ -370,7 +370,7 @@ func getMaxNumberOfClustersSCIsDeployedOn(item mdbv1.MongoDB) int {
}

func ReadBoolWithTrueAsDefault(envVarName string) bool {
envVar := envvar.GetEnvOrDefault(envVarName, "true")
envVar := envvar.GetEnvOrDefault(envVarName, "true") // nolint:forbidigo
return strings.TrimSpace(strings.ToLower(envVar)) == "true"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/telemetry/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func createInitialConfigmap(namespace string) (string, *corev1.ConfigMap) {
// isTimestampOlderThanConfiguredFrequency is used to get the timestamp from the ConfigMap and check whether it's time to
// send the data to atlas.
func isTimestampOlderThanConfiguredFrequency(ctx context.Context, k8sClient kubeclient.Client, namespace string, OperatorConfigMapTelemetryConfigMapName string, et EventType) (bool, error) {
durationStr := envvar.GetEnvOrDefault(SendFrequency, DefaultSendFrequencyStr)
durationStr := envvar.GetEnvOrDefault(SendFrequency, DefaultSendFrequencyStr) // nolint:forbidigo
duration, err := time.ParseDuration(durationStr)
if err != nil || duration < 10*time.Minute {
Logger.Warn("Failed to parse or given durationString: %s too low (min: 10 minutes), defaulting to one week", durationStr)
Expand Down