Skip to content

Commit

Permalink
Replace maiigned by fieldalignment (#1005)
Browse files Browse the repository at this point in the history
* Replace maiigned by fieldalignment

Signed-off-by: Israel Blancas <[email protected]>

* Disable unwanted linters

Signed-off-by: Israel Blancas <[email protected]>

* Apply changes requested by fieldalignment

Signed-off-by: Israel Blancas <[email protected]>

* Add autogenerated changes to the repository

Signed-off-by: Israel Blancas <[email protected]>

* Revert "Add autogenerated changes to the repository"

This reverts commit b49cf7a.

* Fix field descriptions

Signed-off-by: Israel Blancas <[email protected]>
  • Loading branch information
iblancasa authored Jul 28, 2022
1 parent 03af42e commit 42a6d60
Show file tree
Hide file tree
Showing 28 changed files with 162 additions and 178 deletions.
6 changes: 5 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ linters-settings:
suggest-new: true
misspell:
locale: US
govet:
disable-all: true
enable:
- fieldalignment

linters:
enable:
- goheader
- goimports
- maligned
- misspell
- gosec
- govet
- exhaustive
- godot
- unparam
4 changes: 2 additions & 2 deletions apis/v1alpha1/instrumentation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ type InstrumentationStatus struct {
// Instrumentation is the spec for OpenTelemetry instrumentation.
type Instrumentation struct {
Status InstrumentationStatus `json:"status,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec InstrumentationSpec `json:"spec,omitempty"`
metav1.TypeMeta `json:",inline"`
Spec InstrumentationSpec `json:"spec,omitempty"`
metav1.ObjectMeta `json:"metadata,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha1/instrumentation_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func TestInstrumentationDefaultingWebhookOtelDotNetTracesEnabledInstruEnvSet(t *
func TestInstrumentationValidatingWebhook(t *testing.T) {
tests := []struct {
name string
inst Instrumentation
err string
inst Instrumentation
}{
{
name: "argument is not a number",
Expand Down
114 changes: 45 additions & 69 deletions apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,130 +21,106 @@ import (

// OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector.
type OpenTelemetryCollectorSpec struct {
// Config is the raw JSON to be used as the collector's configuration. Refer to the OpenTelemetry Collector documentation for details.
// +required
Config string `json:"config,omitempty"`

// UpgradeStrategy represents how the operator will handle upgrades to the CR when a newer version of the operator is deployed
// Resources to set on the OpenTelemetry Collector pods.
// +optional
UpgradeStrategy UpgradeStrategy `json:"upgradeStrategy"`

Resources v1.ResourceRequirements `json:"resources,omitempty"`
// NodeSelector to schedule OpenTelemetry Collector pods.
// This is only relevant to daemonset, statefulset, and deployment mode
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Args is the set of arguments to pass to the OpenTelemetry Collector binary
// +optional
Args map[string]string `json:"args,omitempty"`

// Replicas is the number of pod instances for the underlying OpenTelemetry Collector. Set this if your are not using autoscaling
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// MinReplicas sets a lower bound to the autoscaling feature. Set this if your are using autoscaling. It must be at least 1
// +optional
MinReplicas *int32 `json:"minReplicas,omitempty"`

// MaxReplicas sets an upper bound to the autoscaling feature. If MaxReplicas is set autoscaling is enabled.
// +optional
MaxReplicas *int32 `json:"maxReplicas,omitempty"`

// ImagePullPolicy indicates the pull policy to be used for retrieving the container image (Always, Never, IfNotPresent)
// SecurityContext will be set as the container security context.
// +optional
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
SecurityContext *v1.SecurityContext `json:"securityContext,omitempty"`

// Image indicates the container image to use for the OpenTelemetry Collector.
PodSecurityContext *v1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// PodAnnotations is the set of annotations that will be attached to
// Collector and Target Allocator pods.
// +optional
Image string `json:"image,omitempty"`

PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
// TargetAllocator indicates a value which determines whether to spawn a target allocation resource or not.
// +optional
TargetAllocator OpenTelemetryTargetAllocator `json:"targetAllocator,omitempty"`

// Mode represents how the collector should be deployed (deployment, daemonset, statefulset or sidecar)
// +optional
Mode Mode `json:"mode,omitempty"`

// ServiceAccount indicates the name of an existing service account to use with this instance.
// +optional
ServiceAccount string `json:"serviceAccount,omitempty"`

// SecurityContext will be set as the container security context.
// Image indicates the container image to use for the OpenTelemetry Collector.
// +optional
SecurityContext *v1.SecurityContext `json:"securityContext,omitempty"`

PodSecurityContext *v1.PodSecurityContext `json:"podSecurityContext,omitempty"`

// HostNetwork indicates if the pod should run in the host networking namespace.
Image string `json:"image,omitempty"`
// UpgradeStrategy represents how the operator will handle upgrades to the CR when a newer version of the operator is deployed
// +optional
HostNetwork bool `json:"hostNetwork,omitempty"`
UpgradeStrategy UpgradeStrategy `json:"upgradeStrategy"`

// VolumeClaimTemplates will provide stable storage using PersistentVolumes. Only available when the mode=statefulset.
// ImagePullPolicy indicates the pull policy to be used for retrieving the container image (Always, Never, IfNotPresent)
// +optional
// +listType=atomic
VolumeClaimTemplates []v1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"`

ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
// Config is the raw JSON to be used as the collector's configuration. Refer to the OpenTelemetry Collector documentation for details.
// +required
Config string `json:"config,omitempty"`
// VolumeMounts represents the mount points to use in the underlying collector deployment(s)
// +optional
// +listType=atomic
VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"`

// Volumes represents which volumes to use in the underlying collector deployment(s).
// +optional
// +listType=atomic
Volumes []v1.Volume `json:"volumes,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 aditional ports that can't be inferred by the operator, like for custom receivers.
// +optional
// +listType=atomic
Ports []v1.ServicePort `json:"ports,omitempty"`

// 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"`

// List of sources to populate environment variables on the OpenTelemetry Collector's Pods.
// These can then in certain cases be consumed in the config file for the Collector.
// +optional
EnvFrom []v1.EnvFromSource `json:"envFrom,omitempty"`

// Resources to set on the OpenTelemetry Collector pods.
// VolumeClaimTemplates will provide stable storage using PersistentVolumes. Only available when the mode=statefulset.
// +optional
Resources v1.ResourceRequirements `json:"resources,omitempty"`

// +listType=atomic
VolumeClaimTemplates []v1.PersistentVolumeClaim `json:"volumeClaimTemplates,omitempty"`
// Toleration to schedule OpenTelemetry Collector pods.
// This is only relevant to daemonset, statefulset, and deployment mode
// +optional
Tolerations []v1.Toleration `json:"tolerations,omitempty"`

// NodeSelector to schedule OpenTelemetry Collector pods.
// This is only relevant to daemonset, statefulset, and deployment mode
// Volumes represents which volumes to use in the underlying collector deployment(s).
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`

// PodAnnotations is the set of annotations that will be attached to
// Collector and Target Allocator pods.
// +listType=atomic
Volumes []v1.Volume `json:"volumes,omitempty"`
// HostNetwork indicates if the pod should run in the host networking namespace.
// +optional
PodAnnotations map[string]string `json:"podAnnotations,omitempty"`
HostNetwork bool `json:"hostNetwork,omitempty"`
}

// OpenTelemetryTargetAllocator defines the configurations for the Prometheus target allocator.
type OpenTelemetryTargetAllocator struct {
// ServiceAccount indicates the name of an existing service account to use with this instance.
// +optional
ServiceAccount string `json:"serviceAccount,omitempty"`
// Image indicates the container image to use for the OpenTelemetry TargetAllocator.
// +optional
Image string `json:"image,omitempty"`
// Enabled indicates whether to use a target allocation mechanism for Prometheus targets or not.
// +optional
Enabled bool `json:"enabled,omitempty"`

// PrometheusCR defines the configuration for the retrieval of PrometheusOperator CRDs ( servicemonitor.monitoring.coreos.com/v1 and podmonitor.monitoring.coreos.com/v1 ) retrieval.
// All CR instances which the ServiceAccount has access to will be retrieved. This includes other namespaces.
// +optional
PrometheusCR OpenTelemetryTargetAllocatorPrometheusCR `json:"prometheusCR,omitempty"`

// ServiceAccount indicates the name of an existing service account to use with this instance.
// +optional
ServiceAccount string `json:"serviceAccount,omitempty"`

// Image indicates the container image to use for the OpenTelemetry TargetAllocator.
// +optional
Image string `json:"image,omitempty"`
}

type OpenTelemetryTargetAllocatorPrometheusCR struct {
Expand All @@ -156,24 +132,19 @@ type OpenTelemetryTargetAllocatorPrometheusCR struct {
// ScaleSubresourceStatus defines the observed state of the OpenTelemetryCollector's
// scale subresource.
type ScaleSubresourceStatus struct {
// The total number non-terminated pods targeted by this
// OpenTelemetryCollector's deployment or statefulSet.
// +optional
Replicas int32 `json:"replicas,omitempty"`

// The selector used to match the OpenTelemetryCollector's
// deployment or statefulSet pods.
// +optional
Selector string `json:"selector,omitempty"`
}

// OpenTelemetryCollectorStatus defines the observed state of OpenTelemetryCollector.
type OpenTelemetryCollectorStatus struct {
// Replicas is currently not being set and might be removed in the next version.
// The total number non-terminated pods targeted by this
// OpenTelemetryCollector's deployment or statefulSet.
// +optional
// Deprecated: use "OpenTelemetryCollector.Status.Scale.Replicas" instead.
Replicas int32 `json:"replicas,omitempty"`
}

// OpenTelemetryCollectorStatus defines the observed state of OpenTelemetryCollector.
type OpenTelemetryCollectorStatus struct {
// Scale is the OpenTelemetryCollector's scale subresource status.
// +optional
Scale ScaleSubresourceStatus `json:"scale,omitempty"`
Expand All @@ -187,6 +158,11 @@ type OpenTelemetryCollectorStatus struct {
// +listType=atomic
// Deprecated: use Kubernetes events instead.
Messages []string `json:"messages,omitempty"`

// Replicas is currently not being set and might be removed in the next version.
// +optional
// Deprecated: use "OpenTelemetryCollector.Status.Scale.Replicas" instead.
Replicas int32 `json:"replicas,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
30 changes: 15 additions & 15 deletions controllers/opentelemetrycollector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,72 +37,72 @@ import (
// OpenTelemetryCollectorReconciler reconciles a OpenTelemetryCollector object.
type OpenTelemetryCollectorReconciler struct {
client.Client
log logr.Logger
recorder record.EventRecorder
scheme *runtime.Scheme
config config.Config
log logr.Logger
tasks []Task
recorder record.EventRecorder
config config.Config
}

// Task represents a reconciliation task to be executed by the reconciler.
type Task struct {
Name string
Do func(context.Context, reconcile.Params) error
Name string
BailOnError bool
}

// Params is the set of options to build a new openTelemetryCollectorReconciler.
type Params struct {
client.Client
Log logr.Logger
Recorder record.EventRecorder
Scheme *runtime.Scheme
Config config.Config
Log logr.Logger
Tasks []Task
Recorder record.EventRecorder
Config config.Config
}

// NewReconciler creates a new reconciler for OpenTelemetryCollector objects.
func NewReconciler(p Params) *OpenTelemetryCollectorReconciler {
if len(p.Tasks) == 0 {
p.Tasks = []Task{
{
"config maps",
reconcile.ConfigMaps,
"config maps",
true,
},
{
"service accounts",
reconcile.ServiceAccounts,
"service accounts",
true,
},
{
"services",
reconcile.Services,
"services",
true,
},
{
"deployments",
reconcile.Deployments,
"deployments",
true,
},
{
"horizontal pod autoscalers",
reconcile.HorizontalPodAutoscalers,
"horizontal pod autoscalers",
true,
},
{
"daemon sets",
reconcile.DaemonSets,
"daemon sets",
true,
},
{
"stateful sets",
reconcile.StatefulSets,
"stateful sets",
true,
},
{
"opentelemetry",
reconcile.Self,
"opentelemetry",
true,
},
}
Expand Down
24 changes: 10 additions & 14 deletions internal/config/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,21 @@ const (

// Config holds the static configuration for this operator.
type Config struct {
// Registers a callback, to be called once a configuration change happens
OnChange func() error

logger logr.Logger
autoDetect autodetect.AutoDetect
autoDetectFrequency time.Duration
onChange []func() error

// config state
autoDetect autodetect.AutoDetect
OnChange func() error
logger logr.Logger
targetAllocatorImage string
autoInstrumentationPythonImage string
collectorImage string
collectorConfigMapEntry string
targetAllocatorImage string
autoInstrumentationDotNetImage string
targetAllocatorConfigMapEntry string
platform platform.Platform
autoInstrumentationJavaImage string
autoInstrumentationNodeJSImage string
autoInstrumentationPythonImage string
autoInstrumentationDotNetImage string
autoInstrumentationJavaImage string
onChange []func() error
labelsFilter []string
platform platform.Platform
autoDetectFrequency time.Duration
}

// New constructs a new configuration based on the given options.
Expand Down
Loading

0 comments on commit 42a6d60

Please sign in to comment.