Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisecheng committed Dec 20, 2023
1 parent de6c293 commit 4395ddf
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/logstash/v1alpha1/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ func TestLogstashName(t *testing.T) {
}
})
}
}
}
2 changes: 1 addition & 1 deletion pkg/controller/logstash/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ log:
}
require.NoError(t, err)

gotBytes, err := got.Render()
gotBytes, _ := got.Render()
gotStr := string(gotBytes)
if gotStr != tt.want {
t.Errorf("newConfig() got = \n%v\n, want \n%v\n", gotStr, tt.want)
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/logstash/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ func internalReconcile(params Params) (*reconciler.Results, logstashv1alpha1.Log

configHash := fnv.New32a()

if cfg, err := reconcileConfig(params, configHash); err != nil {
cfg, err := reconcileConfig(params, configHash)
if err != nil {
return results.WithError(err), params.Status
} else {
params.LogstashConfig = cfg
}
params.LogstashConfig = cfg

// reconcile beats config secrets if Stack Monitoring is defined
if err := stackmon.ReconcileConfigSecrets(params.Context, params.Client, params.Logstash, params.UseTLS, params.LogstashConfig); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/logstash/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ func readinessProbe(params Params) corev1.Probe {
// getHttpHeaders when api.auth.basic.type is set, take api.auth.basic.username and api.auth.basic.password from logstash.yml
// to build Authorization header
func getHttpHeaders(params Params) []corev1.HTTPHeader {
var credentials stackmon.ApiServerCredentials
var credentials stackmon.APIServerCredentials
_ = params.LogstashConfig.Unpack(&credentials)

if strings.ToLower(credentials.Api.Auth.Type) != "basic" {
if strings.ToLower(credentials.API.Auth.Type) != "basic" {
return nil
}

usernamePassword := fmt.Sprintf("%s:%s", credentials.Api.Auth.Basic.Username, credentials.Api.Auth.Basic.Password)
usernamePassword := fmt.Sprintf("%s:%s", credentials.API.Auth.Basic.Username, credentials.API.Auth.Basic.Password)
encodedUsernamePassword := base64.StdEncoding.EncodeToString([]byte(usernamePassword))
authHeader := corev1.HTTPHeader{Name: "Authorization", Value: fmt.Sprintf("Basic %s", encodedUsernamePassword)}

Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/logstash/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
"strings"
"testing"

"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/settings"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/settings"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/logstash/sset/sset.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ func Reconcile(ctx context.Context, c k8s.Client, expected appsv1.StatefulSet, o
// EqualTemplateHashLabels reports whether actual and expected StatefulSets have the same template hash label value.
func EqualTemplateHashLabels(expected, actual appsv1.StatefulSet) bool {
return expected.Labels[hash.TemplateHashLabelName] == actual.Labels[hash.TemplateHashLabelName]
}
}
10 changes: 5 additions & 5 deletions pkg/controller/logstash/stackmon/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const (
cfgHashAnnotation = "logstash.k8s.elastic.co/monitoring-config-hash"
)

type ApiServerCredentials struct {
Api struct {
type APIServerCredentials struct {
API struct {
Auth struct {
Type string `yaml:"type"`
Basic struct {
Expand All @@ -45,7 +45,7 @@ func Metricbeat(ctx context.Context, client k8s.Client, logstash logstashv1alpha
protocol = "https"
}

var credentials ApiServerCredentials
var credentials APIServerCredentials
_ = logstashConfig.Unpack(&credentials)

metricbeat, err := stackmon.NewMetricBeatSidecar(
Expand All @@ -57,8 +57,8 @@ func Metricbeat(ctx context.Context, client k8s.Client, logstash logstashv1alpha
metricbeatConfigTemplate,
logstashv1alpha1.Namer,
fmt.Sprintf("%s://localhost:%d", protocol, network.HTTPPort),
credentials.Api.Auth.Basic.Username,
credentials.Api.Auth.Basic.Password,
credentials.API.Auth.Basic.Username,
credentials.API.Auth.Basic.Password,
useTLS,
)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/logstash/volume/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ package volume
import (
"fmt"

"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates"
corev1 "k8s.io/api/core/v1"

"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/certificates"

commonv1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/common/v1"
logstashv1alpha1 "github.com/elastic/cloud-on-k8s/v2/pkg/apis/logstash/v1alpha1"
"github.com/elastic/cloud-on-k8s/v2/pkg/controller/common/volume"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/test/enterprisesearch/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ type CredentialsCollection struct {
func (a AppSearchClient) GetAPIKey() (string, error) {
url := a.endpoint + "/as/credentials/collection"

req, err := http.NewRequest(http.MethodGet, url, nil) //nolint:noctx
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 4395ddf

Please sign in to comment.