Skip to content

Commit

Permalink
fix: failed to lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt committed Oct 23, 2023
1 parent e25ceda commit f0bf176
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
13 changes: 6 additions & 7 deletions apis/monitor/v1alpha1/oteldcollectortemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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,
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion controllers/monitor/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,4 @@ func MergeValMapFromYamlStr(defaultMap map[string]any, yamlStr string) {
for k, v := range valMap {
defaultMap[k] = v
}
return
}
7 changes: 0 additions & 7 deletions controllers/monitor/reconcile/oteld_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
25 changes: 16 additions & 9 deletions controllers/monitor/types/otel_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit f0bf176

Please sign in to comment.