Skip to content

Commit

Permalink
Fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed Feb 27, 2024
1 parent 86337f4 commit f7f8f9e
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions controllers/spec/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
v1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
Expand Down Expand Up @@ -2282,33 +2283,39 @@ func makeFilebeatContainer(volumeMounts []corev1.VolumeMount, envVar []corev1.En

func MergeGlobalAndNamespacedEnv(ctx context.Context, r client.Reader, namespace string, statefulSet *appsv1.StatefulSet) {
var globalEnvs []corev1.EnvVar

Check failure on line 2285 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.19)

Consider pre-allocating `globalEnvs` (prealloc)

Check failure on line 2285 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.20.4)

Consider pre-allocating `globalEnvs` (prealloc)
var envData map[string]string
if utils.GlobalConfigMap != "" {
globalCM := &corev1.ConfigMap{}

Check failure on line 2288 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.19)

SA4031(related information): this is the value of globalCM (staticcheck)

Check failure on line 2288 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.20.4)

SA4031(related information): this is the value of globalCM (staticcheck)
err := r.Get(ctx, types.NamespacedName{Namespace: utils.GlobalConfigMapNamespace, Name: utils.GlobalConfigMap}, globalCM)
if err != nil {
if err != nil && !k8serrors.IsNotFound(err) {
return
}
for key, val := range globalCM.Data {
globalEnvs = append(globalEnvs, corev1.EnvVar{
Name: key,
Value: val,
})
if globalCM != nil {

Check failure on line 2293 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.19)

SA4031: this nil check is always true (staticcheck)

Check failure on line 2293 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.20.4)

SA4031: this nil check is always true (staticcheck)
for key, val := range globalCM.Data {
envData[key] = val

Check failure on line 2295 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.19)

SA5000: assignment to nil map (staticcheck)

Check failure on line 2295 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.20.4)

SA5000: assignment to nil map (staticcheck)
}
}
}
if utils.NamespacedConfigMap != "" {
namespacedCM := &corev1.ConfigMap{}

Check failure on line 2300 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.19)

SA4031(related information): this is the value of namespacedCM (staticcheck)

Check failure on line 2300 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.20.4)

SA4031(related information): this is the value of namespacedCM (staticcheck)
err := r.Get(ctx, types.NamespacedName{Namespace: namespace, Name: utils.NamespacedConfigMap}, namespacedCM)
if err != nil {
if err != nil && !k8serrors.IsNotFound(err) {
return
}
for key, val := range namespacedCM.Data {
globalEnvs = append(globalEnvs, corev1.EnvVar{
Name: key,
Value: val,
})
if namespacedCM != nil {

Check failure on line 2305 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.19)

SA4031: this nil check is always true (staticcheck)

Check failure on line 2305 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.20.4)

SA4031: this nil check is always true (staticcheck)
for key, val := range namespacedCM.Data {
envData[key] = val

Check failure on line 2307 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.19)

SA5000: assignment to nil map (staticcheck)

Check failure on line 2307 in controllers/spec/common.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.20.4)

SA5000: assignment to nil map (staticcheck)
}
}
}

for key, val := range envData {
globalEnvs = append(globalEnvs, corev1.EnvVar{
Name: key,
Value: val,
})
}

for i := range statefulSet.Spec.Template.Spec.Containers {
statefulSet.Spec.Template.Spec.Containers[i].Env = append(statefulSet.Spec.Template.Spec.Containers[i].Env, globalEnvs...)
}
Expand Down

0 comments on commit f7f8f9e

Please sign in to comment.