From f0bf176c41a19771c7a13ce604d2689cddd0c99f Mon Sep 17 00:00:00 2001 From: sophon Date: Mon, 23 Oct 2023 14:15:17 +0800 Subject: [PATCH] fix: failed to lint --- .../v1alpha1/oteldcollectortemplate_types.go | 13 +++++----- controllers/monitor/builder/builder.go | 1 - controllers/monitor/reconcile/oteld_agent.go | 7 ------ controllers/monitor/types/otel_config.go | 25 ++++++++++++------- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/apis/monitor/v1alpha1/oteldcollectortemplate_types.go b/apis/monitor/v1alpha1/oteldcollectortemplate_types.go index ff414782a751..dbf21cb02820 100644 --- a/apis/monitor/v1alpha1/oteldcollectortemplate_types.go +++ b/apis/monitor/v1alpha1/oteldcollectortemplate_types.go @@ -21,7 +21,6 @@ package v1alpha1 import ( corev1 "k8s.io/api/core/v1" - v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -59,7 +58,7 @@ type OTeldCollectorTemplateSpec struct { // ENV vars to set on the OpenTelemetry Collector's Pods. These can then in certain cases be // consumed in the config file for the Collector. // +optional - Env []v1.EnvVar `json:"env,omitempty"` + Env []corev1.EnvVar `json:"env,omitempty"` // PodAnnotations is the set of annotations that will be attached to // Collector and Target Allocator pods. @@ -69,19 +68,19 @@ type OTeldCollectorTemplateSpec struct { // Volumes represents which volumes to use in the underlying collector deployment(s). // +optional // +listType=atomic - Volumes []v1.Volume `json:"volumes,omitempty"` + Volumes []corev1.Volume `json:"volumes,omitempty"` // VolumeMounts represents the mount points to use in the underlying collector deployment(s) // +optional // +listType=atomic - VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"` + VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"` // Ports allows a set of ports to be exposed by the underlying v1.Service. By default, the operator // will attempt to infer the required ports by parsing the .Spec.Config property but this property can be // used to open additional ports that can't be inferred by the operator, like for custom receivers. // +optional // +listType=atomic - Ports []v1.ServicePort `json:"ports,omitempty"` + Ports []corev1.ServicePort `json:"ports,omitempty"` // SecurityContext configures the container security context for // the opentelemetry-collector container. @@ -94,7 +93,7 @@ type OTeldCollectorTemplateSpec struct { // injected sidecar container. // // +optional - SecurityContext v1.SecurityContext `json:"securityContext,omitempty"` + SecurityContext corev1.SecurityContext `json:"securityContext,omitempty"` // PodSecurityContext configures the pod security context for the // opentelemetry-collector pod, when running as a deployment, daemonset, @@ -103,7 +102,7 @@ type OTeldCollectorTemplateSpec struct { // In sidecar mode, the opentelemetry-operator will ignore this setting. // // +optional - PodSecurityContext v1.PodSecurityContext `json:"podSecurityContext,omitempty"` + PodSecurityContext corev1.PodSecurityContext `json:"podSecurityContext,omitempty"` } // CollectorDataSourceStatus defines the observed state of CollectorDataSource diff --git a/controllers/monitor/builder/builder.go b/controllers/monitor/builder/builder.go index f1fe1937222a..a1223c70c1c9 100644 --- a/controllers/monitor/builder/builder.go +++ b/controllers/monitor/builder/builder.go @@ -94,5 +94,4 @@ func MergeValMapFromYamlStr(defaultMap map[string]any, yamlStr string) { for k, v := range valMap { defaultMap[k] = v } - return } diff --git a/controllers/monitor/reconcile/oteld_agent.go b/controllers/monitor/reconcile/oteld_agent.go index 39a062787132..c7bba47f9fb4 100644 --- a/controllers/monitor/reconcile/oteld_agent.go +++ b/controllers/monitor/reconcile/oteld_agent.go @@ -55,16 +55,9 @@ func OTeldAgent(reqCtx types.ReconcileCtx, params types.OTeldParams) error { params.Recorder.Eventf(existingDaemonset, corev1.EventTypeWarning, "Failed to find secret", err.Error()) return err } - if existingDaemonset == nil { - return nil - } return k8sClient.Create(reqCtx.Ctx, oteldDaemonset) } - if existingDaemonset == nil { - return k8sClient.Delete(reqCtx.Ctx, existingDaemonset) - } - if reflect.DeepEqual(existingDaemonset.Spec, oteldDaemonset.Spec) { return nil } diff --git a/controllers/monitor/types/otel_config.go b/controllers/monitor/types/otel_config.go index e20a28f7417a..de724afbd0c2 100644 --- a/controllers/monitor/types/otel_config.go +++ b/controllers/monitor/types/otel_config.go @@ -46,25 +46,32 @@ func NewConfigGenerator() *OteldConfigGenerater { } func (cg *OteldConfigGenerater) GenerateOteldConfiguration(instance *OteldInstance, metricsExporterList []v1alpha1.MetricsExporterSink, logsExporterList []v1alpha1.LogsExporterSink) (yaml.MapSlice, error) { + var err error + var cfg = yaml.MapSlice{} + if instance == nil || instance.OteldTemplate == nil { return nil, nil } if cg.cache != nil && cg.cache[instance.OteldTemplate.Spec.Mode] != nil { return cg.cache[instance.OteldTemplate.Spec.Mode], nil } - cfg := yaml.MapSlice{} - var err error - cfg, err = cg.appendExtentions(cfg) - cfg, err = cg.appendReceiver(cfg, instance) - cfg, err = cg.appendProcessor(cfg) - cfg, err = cg.appendExporter(cfg, metricsExporterList, logsExporterList) - cfg, err = cg.appendServices(cfg, instance) - if err != nil { + if cfg, err = cg.appendExtentions(cfg); err != nil { + return nil, err + } + if cfg, err = cg.appendReceiver(cfg, instance); err != nil { + return nil, err + } + if cfg, err = cg.appendProcessor(cfg); err != nil { + return nil, err + } + if cfg, err = cg.appendExporter(cfg, metricsExporterList, logsExporterList); err != nil { + return nil, err + } + if cfg, err = cg.appendServices(cfg, instance); err != nil { return nil, err } cg.cache[instance.OteldTemplate.Spec.Mode] = cfg - return cfg, nil }