diff --git a/apis/v1beta1/common.go b/apis/common/common.go similarity index 89% rename from apis/v1beta1/common.go rename to apis/common/common.go index d4c421553d..c842d24457 100644 --- a/apis/v1beta1/common.go +++ b/apis/common/common.go @@ -12,7 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package v1beta1 +// +kubebuilder:object:generate=true +// +groupName=opentelemetry.io +package common import ( autoscalingv2 "k8s.io/api/autoscaling/v2" @@ -94,6 +96,33 @@ type PortsSpec struct { v1.ServicePort `json:",inline"` } +// ObservabilitySpec defines how telemetry data gets handled. +type ObservabilitySpec struct { + // Metrics defines the metrics configuration for operands. + // + // +optional + // +kubebuilder:validation:Optional + // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Metrics Config" + Metrics MetricsConfigSpec `json:"metrics,omitempty"` +} + +// MetricsConfigSpec defines a metrics config. +type MetricsConfigSpec struct { + // EnableMetrics specifies if ServiceMonitor or PodMonitor(for sidecar mode) should be created for the service managed by the OpenTelemetry Operator. + // The operator.observability.prometheus feature gate must be enabled to use this feature. + // + // +optional + // +kubebuilder:validation:Optional + // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Create ServiceMonitors for OpenTelemetry Collector" + EnableMetrics bool `json:"enableMetrics,omitempty"` + // DisablePrometheusAnnotations controls the automatic addition of default Prometheus annotations + // ('prometheus.io/scrape', 'prometheus.io/port', and 'prometheus.io/path') + // + // +optional + // +kubebuilder:validation:Optional + DisablePrometheusAnnotations bool `json:"disablePrometheusAnnotations,omitempty"` +} + type OpenTelemetryCommonFields struct { // ManagementState defines if the CR should be managed by the operator or not. // Default is managed. diff --git a/apis/v1beta1/config.go b/apis/common/config.go similarity index 99% rename from apis/v1beta1/config.go rename to apis/common/config.go index 61f166b0f3..d168b7a059 100644 --- a/apis/v1beta1/config.go +++ b/apis/common/config.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package v1beta1 +package common import ( "bytes" @@ -102,7 +102,7 @@ func (c *Config) Yaml() (string, error) { } // Returns null objects in the config. -func (c *Config) nullObjects() []string { +func (c *Config) NullObjects() []string { var nullKeys []string if nulls := hasNullValue(c.Receivers.Object); len(nulls) > 0 { nullKeys = append(nullKeys, addPrefix("receivers.", nulls)...) diff --git a/apis/v1beta1/config_test.go b/apis/common/config_test.go similarity index 98% rename from apis/v1beta1/config_test.go rename to apis/common/config_test.go index cf148c5d91..cebab64354 100644 --- a/apis/v1beta1/config_test.go +++ b/apis/common/config_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package v1beta1 +package common import ( "encoding/json" @@ -69,7 +69,7 @@ func TestNullObjects(t *testing.T) { err = json.Unmarshal(collectorJson, cfg) require.NoError(t, err) - nullObjects := cfg.nullObjects() + nullObjects := cfg.NullObjects() assert.Equal(t, []string{"connectors.spanmetrics:", "exporters.otlp.endpoint:", "extensions.health_check:", "processors.batch:", "receivers.otlp.protocols.grpc:", "receivers.otlp.protocols.http:"}, nullObjects) } @@ -107,7 +107,7 @@ func TestNullObjects_go_yaml(t *testing.T) { err = go_yaml.Unmarshal(collectorYaml, cfg) require.NoError(t, err) - nullObjects := cfg.nullObjects() + nullObjects := cfg.NullObjects() assert.Equal(t, []string{"connectors.spanmetrics:", "exporters.otlp.endpoint:", "extensions.health_check:", "processors.batch:", "receivers.otlp.protocols.grpc:", "receivers.otlp.protocols.http:"}, nullObjects) } diff --git a/apis/common/targetallocator_types.go b/apis/common/targetallocator_types.go new file mode 100644 index 0000000000..61c32a2373 --- /dev/null +++ b/apis/common/targetallocator_types.go @@ -0,0 +1,64 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package common + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +type ( + // TargetAllocatorAllocationStrategy represent a strategy Target Allocator uses to distribute targets to each collector + // +kubebuilder:validation:Enum=least-weighted;consistent-hashing;per-node + TargetAllocatorAllocationStrategy string + // TargetAllocatorFilterStrategy represent a filtering strategy for targets before they are assigned to collectors + // +kubebuilder:validation:Enum="";relabel-config + TargetAllocatorFilterStrategy string +) + +const ( + // TargetAllocatorAllocationStrategyLeastWeighted targets will be distributed to collector with fewer targets currently assigned. + TargetAllocatorAllocationStrategyLeastWeighted TargetAllocatorAllocationStrategy = "least-weighted" + + // TargetAllocatorAllocationStrategyConsistentHashing targets will be consistently added to collectors, which allows a high-availability setup. + TargetAllocatorAllocationStrategyConsistentHashing TargetAllocatorAllocationStrategy = "consistent-hashing" + + // TargetAllocatorAllocationStrategyPerNode targets will be assigned to the collector on the node they reside on (use only with daemon set). + TargetAllocatorAllocationStrategyPerNode TargetAllocatorAllocationStrategy = "per-node" + + // TargetAllocatorFilterStrategyRelabelConfig targets will be consistently drops targets based on the relabel_config. + TargetAllocatorFilterStrategyRelabelConfig TargetAllocatorFilterStrategy = "relabel-config" +) + +// TargetAllocatorPrometheusCR configures Prometheus CustomResource handling in the Target Allocator. +type TargetAllocatorPrometheusCR struct { + // Enabled indicates whether to use a PrometheusOperator custom resources as targets or not. + // +optional + Enabled bool `json:"enabled,omitempty"` + // Default interval between consecutive scrapes. Intervals set in ServiceMonitors and PodMonitors override it. + //Equivalent to the same setting on the Prometheus CR. + // + // Default: "30s" + // +kubebuilder:default:="30s" + // +kubebuilder:validation:Format:=duration + ScrapeInterval *metav1.Duration `json:"scrapeInterval,omitempty"` + // PodMonitors to be selected for target discovery. + // This is a map of {key,value} pairs. Each {key,value} in the map is going to exactly match a label in a + // PodMonitor's meta labels. The requirements are ANDed. + // +optional + PodMonitorSelector *metav1.LabelSelector `json:"podMonitorSelector,omitempty"` + // ServiceMonitors to be selected for target discovery. + // This is a map of {key,value} pairs. Each {key,value} in the map is going to exactly match a label in a + // ServiceMonitor's meta labels. The requirements are ANDed. + // +optional + ServiceMonitorSelector *metav1.LabelSelector `json:"serviceMonitorSelector,omitempty"` +} diff --git a/apis/v1beta1/testdata/otelcol-connectors.yaml b/apis/common/testdata/otelcol-connectors.yaml similarity index 100% rename from apis/v1beta1/testdata/otelcol-connectors.yaml rename to apis/common/testdata/otelcol-connectors.yaml diff --git a/apis/v1beta1/testdata/otelcol-couchbase.yaml b/apis/common/testdata/otelcol-couchbase.yaml similarity index 100% rename from apis/v1beta1/testdata/otelcol-couchbase.yaml rename to apis/common/testdata/otelcol-couchbase.yaml diff --git a/apis/v1beta1/testdata/otelcol-demo.yaml b/apis/common/testdata/otelcol-demo.yaml similarity index 100% rename from apis/v1beta1/testdata/otelcol-demo.yaml rename to apis/common/testdata/otelcol-demo.yaml diff --git a/apis/v1beta1/testdata/otelcol-extensions.yaml b/apis/common/testdata/otelcol-extensions.yaml similarity index 100% rename from apis/v1beta1/testdata/otelcol-extensions.yaml rename to apis/common/testdata/otelcol-extensions.yaml diff --git a/apis/v1beta1/testdata/otelcol-filelog.yaml b/apis/common/testdata/otelcol-filelog.yaml similarity index 100% rename from apis/v1beta1/testdata/otelcol-filelog.yaml rename to apis/common/testdata/otelcol-filelog.yaml diff --git a/apis/v1beta1/testdata/otelcol-null-values.yaml b/apis/common/testdata/otelcol-null-values.yaml similarity index 100% rename from apis/v1beta1/testdata/otelcol-null-values.yaml rename to apis/common/testdata/otelcol-null-values.yaml diff --git a/apis/common/zz_generated.deepcopy.go b/apis/common/zz_generated.deepcopy.go new file mode 100644 index 0000000000..90602be6cf --- /dev/null +++ b/apis/common/zz_generated.deepcopy.go @@ -0,0 +1,448 @@ +//go:build !ignore_autogenerated + +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by controller-gen. DO NOT EDIT. + +package common + +import ( + "k8s.io/api/autoscaling/v2" + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AutoscalerSpec) DeepCopyInto(out *AutoscalerSpec) { + *out = *in + if in.MinReplicas != nil { + in, out := &in.MinReplicas, &out.MinReplicas + *out = new(int32) + **out = **in + } + if in.MaxReplicas != nil { + in, out := &in.MaxReplicas, &out.MaxReplicas + *out = new(int32) + **out = **in + } + if in.Behavior != nil { + in, out := &in.Behavior, &out.Behavior + *out = new(v2.HorizontalPodAutoscalerBehavior) + (*in).DeepCopyInto(*out) + } + if in.Metrics != nil { + in, out := &in.Metrics, &out.Metrics + *out = make([]MetricSpec, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.TargetCPUUtilization != nil { + in, out := &in.TargetCPUUtilization, &out.TargetCPUUtilization + *out = new(int32) + **out = **in + } + if in.TargetMemoryUtilization != nil { + in, out := &in.TargetMemoryUtilization, &out.TargetMemoryUtilization + *out = new(int32) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutoscalerSpec. +func (in *AutoscalerSpec) DeepCopy() *AutoscalerSpec { + if in == nil { + return nil + } + out := new(AutoscalerSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Config) DeepCopyInto(out *Config) { + *out = *in + in.Receivers.DeepCopyInto(&out.Receivers) + in.Exporters.DeepCopyInto(&out.Exporters) + if in.Processors != nil { + in, out := &in.Processors, &out.Processors + *out = (*in).DeepCopy() + } + if in.Connectors != nil { + in, out := &in.Connectors, &out.Connectors + *out = (*in).DeepCopy() + } + if in.Extensions != nil { + in, out := &in.Extensions, &out.Extensions + *out = (*in).DeepCopy() + } + in.Service.DeepCopyInto(&out.Service) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Config. +func (in *Config) DeepCopy() *Config { + if in == nil { + return nil + } + out := new(Config) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MetricSpec) DeepCopyInto(out *MetricSpec) { + *out = *in + if in.Pods != nil { + in, out := &in.Pods, &out.Pods + *out = new(v2.PodsMetricSource) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricSpec. +func (in *MetricSpec) DeepCopy() *MetricSpec { + if in == nil { + return nil + } + out := new(MetricSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MetricsConfig) DeepCopyInto(out *MetricsConfig) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricsConfig. +func (in *MetricsConfig) DeepCopy() *MetricsConfig { + if in == nil { + return nil + } + out := new(MetricsConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MetricsConfigSpec) DeepCopyInto(out *MetricsConfigSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricsConfigSpec. +func (in *MetricsConfigSpec) DeepCopy() *MetricsConfigSpec { + if in == nil { + return nil + } + out := new(MetricsConfigSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ObservabilitySpec) DeepCopyInto(out *ObservabilitySpec) { + *out = *in + out.Metrics = in.Metrics +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ObservabilitySpec. +func (in *ObservabilitySpec) DeepCopy() *ObservabilitySpec { + if in == nil { + return nil + } + out := new(ObservabilitySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OpenTelemetryCommonFields) DeepCopyInto(out *OpenTelemetryCommonFields) { + *out = *in + in.Resources.DeepCopyInto(&out.Resources) + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Args != nil { + in, out := &in.Args, &out.Args + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.Replicas != nil { + in, out := &in.Replicas, &out.Replicas + *out = new(int32) + **out = **in + } + if in.Autoscaler != nil { + in, out := &in.Autoscaler, &out.Autoscaler + *out = new(AutoscalerSpec) + (*in).DeepCopyInto(*out) + } + if in.PodDisruptionBudget != nil { + in, out := &in.PodDisruptionBudget, &out.PodDisruptionBudget + *out = new(PodDisruptionBudgetSpec) + (*in).DeepCopyInto(*out) + } + if in.SecurityContext != nil { + in, out := &in.SecurityContext, &out.SecurityContext + *out = new(v1.SecurityContext) + (*in).DeepCopyInto(*out) + } + if in.PodSecurityContext != nil { + in, out := &in.PodSecurityContext, &out.PodSecurityContext + *out = new(v1.PodSecurityContext) + (*in).DeepCopyInto(*out) + } + if in.PodAnnotations != nil { + in, out := &in.PodAnnotations, &out.PodAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + if in.VolumeMounts != nil { + in, out := &in.VolumeMounts, &out.VolumeMounts + *out = make([]v1.VolumeMount, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Ports != nil { + in, out := &in.Ports, &out.Ports + *out = make([]PortsSpec, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Env != nil { + in, out := &in.Env, &out.Env + *out = make([]v1.EnvVar, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.EnvFrom != nil { + in, out := &in.EnvFrom, &out.EnvFrom + *out = make([]v1.EnvFromSource, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.VolumeClaimTemplates != nil { + in, out := &in.VolumeClaimTemplates, &out.VolumeClaimTemplates + *out = make([]v1.PersistentVolumeClaim, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Tolerations != nil { + in, out := &in.Tolerations, &out.Tolerations + *out = make([]v1.Toleration, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Volumes != nil { + in, out := &in.Volumes, &out.Volumes + *out = make([]v1.Volume, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Affinity != nil { + in, out := &in.Affinity, &out.Affinity + *out = new(v1.Affinity) + (*in).DeepCopyInto(*out) + } + if in.Lifecycle != nil { + in, out := &in.Lifecycle, &out.Lifecycle + *out = new(v1.Lifecycle) + (*in).DeepCopyInto(*out) + } + if in.TerminationGracePeriodSeconds != nil { + in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds + *out = new(int64) + **out = **in + } + if in.TopologySpreadConstraints != nil { + in, out := &in.TopologySpreadConstraints, &out.TopologySpreadConstraints + *out = make([]v1.TopologySpreadConstraint, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.InitContainers != nil { + in, out := &in.InitContainers, &out.InitContainers + *out = make([]v1.Container, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.AdditionalContainers != nil { + in, out := &in.AdditionalContainers, &out.AdditionalContainers + *out = make([]v1.Container, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenTelemetryCommonFields. +func (in *OpenTelemetryCommonFields) DeepCopy() *OpenTelemetryCommonFields { + if in == nil { + return nil + } + out := new(OpenTelemetryCommonFields) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PodDisruptionBudgetSpec) DeepCopyInto(out *PodDisruptionBudgetSpec) { + *out = *in + if in.MinAvailable != nil { + in, out := &in.MinAvailable, &out.MinAvailable + *out = new(intstr.IntOrString) + **out = **in + } + if in.MaxUnavailable != nil { + in, out := &in.MaxUnavailable, &out.MaxUnavailable + *out = new(intstr.IntOrString) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodDisruptionBudgetSpec. +func (in *PodDisruptionBudgetSpec) DeepCopy() *PodDisruptionBudgetSpec { + if in == nil { + return nil + } + out := new(PodDisruptionBudgetSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PortsSpec) DeepCopyInto(out *PortsSpec) { + *out = *in + in.ServicePort.DeepCopyInto(&out.ServicePort) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PortsSpec. +func (in *PortsSpec) DeepCopy() *PortsSpec { + if in == nil { + return nil + } + out := new(PortsSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Service) DeepCopyInto(out *Service) { + *out = *in + if in.Extensions != nil { + in, out := &in.Extensions, &out.Extensions + *out = new([]string) + if **in != nil { + in, out := *in, *out + *out = make([]string, len(*in)) + copy(*out, *in) + } + } + if in.Telemetry != nil { + in, out := &in.Telemetry, &out.Telemetry + *out = (*in).DeepCopy() + } + in.Pipelines.DeepCopyInto(&out.Pipelines) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Service. +func (in *Service) DeepCopy() *Service { + if in == nil { + return nil + } + out := new(Service) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TargetAllocatorPrometheusCR) DeepCopyInto(out *TargetAllocatorPrometheusCR) { + *out = *in + if in.ScrapeInterval != nil { + in, out := &in.ScrapeInterval, &out.ScrapeInterval + *out = new(metav1.Duration) + **out = **in + } + if in.PodMonitorSelector != nil { + in, out := &in.PodMonitorSelector, &out.PodMonitorSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } + if in.ServiceMonitorSelector != nil { + in, out := &in.ServiceMonitorSelector, &out.ServiceMonitorSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocatorPrometheusCR. +func (in *TargetAllocatorPrometheusCR) DeepCopy() *TargetAllocatorPrometheusCR { + if in == nil { + return nil + } + out := new(TargetAllocatorPrometheusCR) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Telemetry) DeepCopyInto(out *Telemetry) { + *out = *in + out.Metrics = in.Metrics + if in.Resource != nil { + in, out := &in.Resource, &out.Resource + *out = make(map[string]*string, len(*in)) + for key, val := range *in { + var outVal *string + if val == nil { + (*out)[key] = nil + } else { + inVal := (*in)[key] + in, out := &inVal, &outVal + *out = new(string) + **out = **in + } + (*out)[key] = outVal + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Telemetry. +func (in *Telemetry) DeepCopy() *Telemetry { + if in == nil { + return nil + } + out := new(Telemetry) + in.DeepCopyInto(out) + return out +} diff --git a/apis/v1alpha1/convert.go b/apis/v1alpha1/convert.go index fb37e1c781..50f35bfae5 100644 --- a/apis/v1alpha1/convert.go +++ b/apis/v1alpha1/convert.go @@ -24,6 +24,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/conversion" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" ) @@ -65,7 +66,7 @@ func (dst *OpenTelemetryCollector) ConvertFrom(srcRaw conversion.Hub) error { func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error) { copy := in.DeepCopy() - cfg := &v1beta1.Config{} + cfg := &common.Config{} if err := yaml.Unmarshal([]byte(copy.Spec.Config), cfg); err != nil { return v1beta1.OpenTelemetryCollector{}, errors.New("could not convert config json to v1beta1.Config") } @@ -82,8 +83,8 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error Image: in.Status.Image, }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - ManagementState: v1beta1.ManagementStateType(copy.Spec.ManagementState), + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + ManagementState: common.ManagementStateType(copy.Spec.ManagementState), Resources: copy.Spec.Resources, NodeSelector: copy.Spec.NodeSelector, Args: copy.Spec.Args, @@ -129,8 +130,8 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error }, }, LivenessProbe: tov1beta1Probe(copy.Spec.LivenessProbe), - Observability: v1beta1.ObservabilitySpec{ - Metrics: v1beta1.MetricsConfigSpec{ + Observability: common.ObservabilitySpec{ + Metrics: common.MetricsConfigSpec{ EnableMetrics: copy.Spec.Observability.Metrics.EnableMetrics, DisablePrometheusAnnotations: copy.Spec.Observability.Metrics.DisablePrometheusAnnotations, }, @@ -145,11 +146,11 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error }, nil } -func tov1beta1Ports(in []PortsSpec) []v1beta1.PortsSpec { - var ports []v1beta1.PortsSpec +func tov1beta1Ports(in []PortsSpec) []common.PortsSpec { + var ports []common.PortsSpec for _, p := range in { - ports = append(ports, v1beta1.PortsSpec{ + ports = append(ports, common.PortsSpec{ ServicePort: v1.ServicePort{ Name: p.ServicePort.Name, Protocol: p.ServicePort.Protocol, @@ -170,13 +171,13 @@ func tov1beta1TA(in OpenTelemetryTargetAllocator) v1beta1.TargetAllocatorEmbedde Replicas: in.Replicas, NodeSelector: in.NodeSelector, Resources: in.Resources, - AllocationStrategy: tov1beta1TAAllocationStrategy(in.AllocationStrategy), - FilterStrategy: tov1beta1TAFilterStrategy(in.FilterStrategy), + AllocationStrategy: in.AllocationStrategy, + FilterStrategy: in.FilterStrategy, ServiceAccount: in.ServiceAccount, Image: in.Image, Enabled: in.Enabled, Affinity: in.Affinity, - PrometheusCR: v1beta1.TargetAllocatorPrometheusCR{ + PrometheusCR: common.TargetAllocatorPrometheusCR{ Enabled: in.PrometheusCR.Enabled, ScrapeInterval: in.PrometheusCR.ScrapeInterval, // prometheus_cr.pod_monitor_selector shouldn't be nil when selector is empty @@ -192,8 +193,8 @@ func tov1beta1TA(in OpenTelemetryTargetAllocator) v1beta1.TargetAllocatorEmbedde TopologySpreadConstraints: in.TopologySpreadConstraints, Tolerations: in.Tolerations, Env: in.Env, - Observability: v1beta1.ObservabilitySpec{ - Metrics: v1beta1.MetricsConfigSpec{ + Observability: common.ObservabilitySpec{ + Metrics: common.MetricsConfigSpec{ EnableMetrics: in.Observability.Metrics.EnableMetrics, DisablePrometheusAnnotations: in.Observability.Metrics.DisablePrometheusAnnotations, }, @@ -203,7 +204,7 @@ func tov1beta1TA(in OpenTelemetryTargetAllocator) v1beta1.TargetAllocatorEmbedde } // The conversion takes into account deprecated v1alpha1 spec.minReplicas and spec.maxReplicas. -func tov1beta1Autoscaler(in *AutoscalerSpec, minReplicas, maxReplicas *int32) *v1beta1.AutoscalerSpec { +func tov1beta1Autoscaler(in *AutoscalerSpec, minReplicas, maxReplicas *int32) *common.AutoscalerSpec { if in == nil && minReplicas == nil && maxReplicas == nil { return nil } @@ -211,9 +212,9 @@ func tov1beta1Autoscaler(in *AutoscalerSpec, minReplicas, maxReplicas *int32) *v in = &AutoscalerSpec{} } - var metrics []v1beta1.MetricSpec + var metrics []common.MetricSpec for _, m := range in.Metrics { - metrics = append(metrics, v1beta1.MetricSpec{ + metrics = append(metrics, common.MetricSpec{ Type: m.Type, Pods: m.Pods, }) @@ -225,7 +226,7 @@ func tov1beta1Autoscaler(in *AutoscalerSpec, minReplicas, maxReplicas *int32) *v in.MinReplicas = minReplicas } - return &v1beta1.AutoscalerSpec{ + return &common.AutoscalerSpec{ MinReplicas: in.MinReplicas, MaxReplicas: in.MaxReplicas, Behavior: in.Behavior, @@ -235,11 +236,11 @@ func tov1beta1Autoscaler(in *AutoscalerSpec, minReplicas, maxReplicas *int32) *v } } -func tov1beta1PodDisruptionBudget(in *PodDisruptionBudgetSpec) *v1beta1.PodDisruptionBudgetSpec { +func tov1beta1PodDisruptionBudget(in *PodDisruptionBudgetSpec) *common.PodDisruptionBudgetSpec { if in == nil { return nil } - return &v1beta1.PodDisruptionBudgetSpec{ + return &common.PodDisruptionBudgetSpec{ MinAvailable: in.MinAvailable, MaxUnavailable: in.MaxUnavailable, } @@ -270,7 +271,7 @@ func tov1beta1ConfigMaps(in []ConfigMapsSpec) []v1beta1.ConfigMapsSpec { return mapsSpecs } -func tov1alpha1Ports(in []v1beta1.PortsSpec) []PortsSpec { +func tov1alpha1Ports(in []common.PortsSpec) []PortsSpec { var ports []PortsSpec for _, p := range in { @@ -368,7 +369,7 @@ func tov1alpha1(in v1beta1.OpenTelemetryCollector) (*OpenTelemetryCollector, err }, nil } -func tov1alpha1PodDisruptionBudget(in *v1beta1.PodDisruptionBudgetSpec) *PodDisruptionBudgetSpec { +func tov1alpha1PodDisruptionBudget(in *common.PodDisruptionBudgetSpec) *PodDisruptionBudgetSpec { if in == nil { return nil } @@ -392,7 +393,7 @@ func tov1alpha1Probe(in *v1beta1.Probe) *Probe { } } -func tov1alpha1Autoscaler(in *v1beta1.AutoscalerSpec) *AutoscalerSpec { +func tov1alpha1Autoscaler(in *common.AutoscalerSpec) *AutoscalerSpec { if in == nil { return nil } @@ -440,8 +441,8 @@ func tov1alpha1TA(in v1beta1.TargetAllocatorEmbedded) OpenTelemetryTargetAllocat Replicas: in.Replicas, NodeSelector: in.NodeSelector, Resources: in.Resources, - AllocationStrategy: tov1alpha1TAAllocationStrategy(in.AllocationStrategy), - FilterStrategy: tov1alpha1TAFilterStrategy(in.FilterStrategy), + AllocationStrategy: in.AllocationStrategy, + FilterStrategy: in.FilterStrategy, ServiceAccount: in.ServiceAccount, Image: in.Image, Enabled: in.Enabled, @@ -466,42 +467,3 @@ func tov1alpha1TA(in v1beta1.TargetAllocatorEmbedded) OpenTelemetryTargetAllocat PodDisruptionBudget: tov1alpha1PodDisruptionBudget(in.PodDisruptionBudget), } } - -func tov1alpha1TAFilterStrategy(strategy v1beta1.TargetAllocatorFilterStrategy) string { - switch strategy { - case v1beta1.TargetAllocatorFilterStrategyRelabelConfig: - return string(strategy) - } - return "" -} - -func tov1alpha1TAAllocationStrategy(strategy v1beta1.TargetAllocatorAllocationStrategy) OpenTelemetryTargetAllocatorAllocationStrategy { - switch strategy { - case v1beta1.TargetAllocatorAllocationStrategyConsistentHashing: - return OpenTelemetryTargetAllocatorAllocationStrategyConsistentHashing - case v1beta1.TargetAllocatorAllocationStrategyPerNode: - return OpenTelemetryTargetAllocatorAllocationStrategyPerNode - case v1beta1.TargetAllocatorAllocationStrategyLeastWeighted: - return OpenTelemetryTargetAllocatorAllocationStrategyLeastWeighted - } - return "" -} - -func tov1beta1TAFilterStrategy(strategy string) v1beta1.TargetAllocatorFilterStrategy { - if strategy == string(v1beta1.TargetAllocatorFilterStrategyRelabelConfig) { - return v1beta1.TargetAllocatorFilterStrategyRelabelConfig - } - return "" -} - -func tov1beta1TAAllocationStrategy(strategy OpenTelemetryTargetAllocatorAllocationStrategy) v1beta1.TargetAllocatorAllocationStrategy { - switch strategy { - case OpenTelemetryTargetAllocatorAllocationStrategyPerNode: - return v1beta1.TargetAllocatorAllocationStrategyPerNode - case OpenTelemetryTargetAllocatorAllocationStrategyConsistentHashing: - return v1beta1.TargetAllocatorAllocationStrategyConsistentHashing - case OpenTelemetryTargetAllocatorAllocationStrategyLeastWeighted: - return v1beta1.TargetAllocatorAllocationStrategyLeastWeighted - } - return "" -} diff --git a/apis/v1alpha1/convert_test.go b/apis/v1alpha1/convert_test.go index ba8bb063d0..9beeb3f652 100644 --- a/apis/v1alpha1/convert_test.go +++ b/apis/v1alpha1/convert_test.go @@ -29,6 +29,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" ) @@ -85,7 +86,7 @@ func Test_tov1beta1_config(t *testing.T) { } func Test_tov1alpha1_config(t *testing.T) { - cfg := v1beta1.Config{} + cfg := common.Config{} err := yaml.Unmarshal([]byte(collectorCfg), &cfg) require.NoError(t, err) @@ -427,7 +428,7 @@ func createTA() OpenTelemetryTargetAllocator { v1.ResourceMemory: resource.MustParse("128Mi"), }, }, - AllocationStrategy: OpenTelemetryTargetAllocatorAllocationStrategyConsistentHashing, + AllocationStrategy: common.TargetAllocatorAllocationStrategyConsistentHashing, FilterStrategy: "relabel-config", ServiceAccount: "serviceAccountName", Image: "custom_image", @@ -527,11 +528,11 @@ func TestConvertTo(t *testing.T) { Name: "otel", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ ServiceAccount: "otelcol", }, TargetAllocator: v1beta1.TargetAllocatorEmbedded{ - PrometheusCR: v1beta1.TargetAllocatorPrometheusCR{ + PrometheusCR: common.TargetAllocatorPrometheusCR{ PodMonitorSelector: &metav1.LabelSelector{}, ServiceMonitorSelector: &metav1.LabelSelector{}, }, @@ -549,7 +550,7 @@ func TestConvertFrom(t *testing.T) { Name: "otel", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ ServiceAccount: "otelcol", }, }, diff --git a/apis/v1alpha1/opentelemetrycollector_types.go b/apis/v1alpha1/opentelemetrycollector_types.go index a2c5055fd0..e1330b30be 100644 --- a/apis/v1alpha1/opentelemetrycollector_types.go +++ b/apis/v1alpha1/opentelemetrycollector_types.go @@ -21,6 +21,8 @@ import ( networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" + + "github.com/open-telemetry/opentelemetry-operator/apis/common" ) // ManagementStateType defines the type for CR management states. @@ -320,13 +322,13 @@ type OpenTelemetryTargetAllocator struct { // WARNING: The per-node strategy currently ignores targets without a Node, like control plane components. // +optional // +kubebuilder:default:=consistent-hashing - AllocationStrategy OpenTelemetryTargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"` + AllocationStrategy common.TargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"` // FilterStrategy determines how to filter targets before allocating them among the collectors. // The only current option is relabel-config (drops targets based on prom relabel_config). // The default is relabel-config. // +optional // +kubebuilder:default:=relabel-config - FilterStrategy string `json:"filterStrategy,omitempty"` + FilterStrategy common.TargetAllocatorFilterStrategy `json:"filterStrategy,omitempty"` // ServiceAccount indicates the name of an existing service account to use with this instance. When set, // the operator will not automatically create a ServiceAccount for the TargetAllocator. // +optional diff --git a/apis/v1beta1/targetallocator_types.go b/apis/v1alpha1/targetallocator_types.go similarity index 91% rename from apis/v1beta1/targetallocator_types.go rename to apis/v1alpha1/targetallocator_types.go index c833c54816..b238f1bdfb 100644 --- a/apis/v1beta1/targetallocator_types.go +++ b/apis/v1alpha1/targetallocator_types.go @@ -12,10 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -package v1beta1 +package v1alpha1 import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/open-telemetry/opentelemetry-operator/apis/common" ) func init() { @@ -57,7 +59,7 @@ type TargetAllocatorStatus struct { // TargetAllocatorSpec defines the desired state of TargetAllocator. type TargetAllocatorSpec struct { // Common defines fields that are common to all OpenTelemetry CRD workloads. - OpenTelemetryCommonFields `json:",inline"` + common.OpenTelemetryCommonFields `json:",inline"` // CollectorSelector is the selector for Collector Pods the target allocator will allocate targets to. CollectorSelector metav1.LabelSelector `json:"collectorSelector,omitempty"` // AllocationStrategy determines which strategy the target allocator should use for allocation. @@ -66,29 +68,29 @@ type TargetAllocatorSpec struct { // WARNING: The per-node strategy currently ignores targets without a Node, like control plane components. // +optional // +kubebuilder:default:=consistent-hashing - AllocationStrategy TargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"` + AllocationStrategy common.TargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"` // FilterStrategy determines how to filter targets before allocating them among the collectors. // The only current option is relabel-config (drops targets based on prom relabel_config). // The default is relabel-config. // +optional // +kubebuilder:default:=relabel-config - FilterStrategy TargetAllocatorFilterStrategy `json:"filterStrategy,omitempty"` + FilterStrategy common.TargetAllocatorFilterStrategy `json:"filterStrategy,omitempty"` // ScrapeConfigs define static Prometheus scrape configurations for the target allocator. // To use dynamic configurations from ServiceMonitors and PodMonitors, see the PrometheusCR section. // For the exact format, see https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config. // +optional // +listType=atomic // +kubebuilder:pruning:PreserveUnknownFields - ScrapeConfigs []AnyConfig `json:"scrapeConfigs,omitempty"` + ScrapeConfigs []common.AnyConfig `json:"scrapeConfigs,omitempty"` // PrometheusCR defines the configuration for the retrieval of PrometheusOperator CRDs ( servicemonitor.monitoring.coreos.com/v1 and podmonitor.monitoring.coreos.com/v1 ). // +optional - PrometheusCR TargetAllocatorPrometheusCR `json:"prometheusCR,omitempty"` + PrometheusCR common.TargetAllocatorPrometheusCR `json:"prometheusCR,omitempty"` // ObservabilitySpec defines how telemetry data gets handled. // // +optional // +kubebuilder:validation:Optional // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Observability" - Observability ObservabilitySpec `json:"observability,omitempty"` + Observability common.ObservabilitySpec `json:"observability,omitempty"` } // TargetAllocatorPrometheusCR configures Prometheus CustomResource handling in the Target Allocator. diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 8f47cb64dc..0810b70ee3 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -19,6 +19,7 @@ package v1alpha1 import ( + "github.com/open-telemetry/opentelemetry-operator/apis/common" "k8s.io/api/autoscaling/v2" "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" @@ -1243,3 +1244,133 @@ func (in *ScaleSubresourceStatus) DeepCopy() *ScaleSubresourceStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TargetAllocator) DeepCopyInto(out *TargetAllocator) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocator. +func (in *TargetAllocator) DeepCopy() *TargetAllocator { + if in == nil { + return nil + } + out := new(TargetAllocator) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TargetAllocator) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TargetAllocatorList) DeepCopyInto(out *TargetAllocatorList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]OpenTelemetryCollector, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocatorList. +func (in *TargetAllocatorList) DeepCopy() *TargetAllocatorList { + if in == nil { + return nil + } + out := new(TargetAllocatorList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *TargetAllocatorList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TargetAllocatorPrometheusCR) DeepCopyInto(out *TargetAllocatorPrometheusCR) { + *out = *in + if in.ScrapeInterval != nil { + in, out := &in.ScrapeInterval, &out.ScrapeInterval + *out = new(metav1.Duration) + **out = **in + } + if in.PodMonitorSelector != nil { + in, out := &in.PodMonitorSelector, &out.PodMonitorSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } + if in.ServiceMonitorSelector != nil { + in, out := &in.ServiceMonitorSelector, &out.ServiceMonitorSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocatorPrometheusCR. +func (in *TargetAllocatorPrometheusCR) DeepCopy() *TargetAllocatorPrometheusCR { + if in == nil { + return nil + } + out := new(TargetAllocatorPrometheusCR) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TargetAllocatorSpec) DeepCopyInto(out *TargetAllocatorSpec) { + *out = *in + in.OpenTelemetryCommonFields.DeepCopyInto(&out.OpenTelemetryCommonFields) + in.CollectorSelector.DeepCopyInto(&out.CollectorSelector) + if in.ScrapeConfigs != nil { + in, out := &in.ScrapeConfigs, &out.ScrapeConfigs + *out = make([]common.AnyConfig, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + in.PrometheusCR.DeepCopyInto(&out.PrometheusCR) + out.Observability = in.Observability +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocatorSpec. +func (in *TargetAllocatorSpec) DeepCopy() *TargetAllocatorSpec { + if in == nil { + return nil + } + out := new(TargetAllocatorSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TargetAllocatorStatus) DeepCopyInto(out *TargetAllocatorStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocatorStatus. +func (in *TargetAllocatorStatus) DeepCopy() *TargetAllocatorStatus { + if in == nil { + return nil + } + out := new(TargetAllocatorStatus) + in.DeepCopyInto(out) + return out +} diff --git a/apis/v1beta1/collector_webhook.go b/apis/v1beta1/collector_webhook.go index e26f4e232c..876d7abdb7 100644 --- a/apis/v1beta1/collector_webhook.go +++ b/apis/v1beta1/collector_webhook.go @@ -29,6 +29,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/internal/config" ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters" "github.com/open-telemetry/opentelemetry-operator/internal/rbac" @@ -124,7 +125,7 @@ func (c CollectorWebhook) Default(_ context.Context, obj runtime.Object) error { // not blocking node drains but preventing out-of-the-box // from disruption generated by them with replicas > 1 if otelcol.Spec.PodDisruptionBudget == nil { - otelcol.Spec.PodDisruptionBudget = &PodDisruptionBudgetSpec{ + otelcol.Spec.PodDisruptionBudget = &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -138,9 +139,9 @@ func (c CollectorWebhook) Default(_ context.Context, obj runtime.Object) error { // just one replica, not blocking node drains but preventing // out-of-the-box from disruption generated by them with replicas > 1 if otelcol.Spec.TargetAllocator.Enabled && - otelcol.Spec.TargetAllocator.AllocationStrategy == TargetAllocatorAllocationStrategyConsistentHashing && + otelcol.Spec.TargetAllocator.AllocationStrategy == common.TargetAllocatorAllocationStrategyConsistentHashing && otelcol.Spec.TargetAllocator.PodDisruptionBudget == nil { - otelcol.Spec.TargetAllocator.PodDisruptionBudget = &PodDisruptionBudgetSpec{ + otelcol.Spec.TargetAllocator.PodDisruptionBudget = &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -157,7 +158,7 @@ func (c CollectorWebhook) Default(_ context.Context, obj runtime.Object) error { // If someone upgrades to a later version without upgrading their CRD they will not have a management state set. // This results in a default state of unmanaged preventing reconciliation from continuing. if len(otelcol.Spec.ManagementState) == 0 { - otelcol.Spec.ManagementState = ManagementStateManaged + otelcol.Spec.ManagementState = common.ManagementStateManaged } return nil } @@ -189,7 +190,7 @@ func (c CollectorWebhook) ValidateDelete(ctx context.Context, obj runtime.Object func (c CollectorWebhook) validate(ctx context.Context, r *OpenTelemetryCollector) (admission.Warnings, error) { warnings := admission.Warnings{} - nullObjects := r.Spec.Config.nullObjects() + nullObjects := r.Spec.Config.NullObjects() if len(nullObjects) > 0 { warnings = append(warnings, fmt.Sprintf("Collector config spec.config has null objects: %s. For compatibility tooling (kustomize and kubectl edit) it is recommended to use empty obejects e.g. batch: {}.", strings.Join(nullObjects, ", "))) } @@ -329,12 +330,12 @@ func (c CollectorWebhook) validateTargetAllocatorConfig(ctx context.Context, r * return nil, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which does not support the target allocation deployment", r.Spec.Mode) } - if r.Spec.Mode == ModeDaemonSet && r.Spec.TargetAllocator.AllocationStrategy != TargetAllocatorAllocationStrategyPerNode { - return nil, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which must be used with target allocation strategy %s ", r.Spec.Mode, TargetAllocatorAllocationStrategyPerNode) + if r.Spec.Mode == ModeDaemonSet && r.Spec.TargetAllocator.AllocationStrategy != common.TargetAllocatorAllocationStrategyPerNode { + return nil, fmt.Errorf("the OpenTelemetry Collector mode is set to %s, which must be used with target allocation strategy %s ", r.Spec.Mode, common.TargetAllocatorAllocationStrategyPerNode) } - if r.Spec.TargetAllocator.AllocationStrategy == TargetAllocatorAllocationStrategyPerNode && r.Spec.Mode != ModeDaemonSet { - return nil, fmt.Errorf("target allocation strategy %s is only supported in OpenTelemetry Collector mode %s", TargetAllocatorAllocationStrategyPerNode, ModeDaemonSet) + if r.Spec.TargetAllocator.AllocationStrategy == common.TargetAllocatorAllocationStrategyPerNode && r.Spec.Mode != ModeDaemonSet { + return nil, fmt.Errorf("target allocation strategy %s is only supported in OpenTelemetry Collector mode %s", common.TargetAllocatorAllocationStrategyPerNode, ModeDaemonSet) } cfgYaml, err := r.Spec.Config.Yaml() @@ -366,7 +367,7 @@ func (c CollectorWebhook) validateTargetAllocatorConfig(ctx context.Context, r * return nil, nil } -func checkAutoscalerSpec(autoscaler *AutoscalerSpec) error { +func checkAutoscalerSpec(autoscaler *common.AutoscalerSpec) error { if autoscaler.Behavior != nil { if autoscaler.Behavior.ScaleDown != nil && autoscaler.Behavior.ScaleDown.StabilizationWindowSeconds != nil && *autoscaler.Behavior.ScaleDown.StabilizationWindowSeconds < int32(1) { diff --git a/apis/v1beta1/collector_webhook_test.go b/apis/v1beta1/collector_webhook_test.go index 253ae99971..23cceea207 100644 --- a/apis/v1beta1/collector_webhook_test.go +++ b/apis/v1beta1/collector_webhook_test.go @@ -36,6 +36,7 @@ import ( "k8s.io/client-go/kubernetes/scheme" kubeTesting "k8s.io/client-go/testing" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/rbac" ) @@ -55,14 +56,14 @@ func TestValidate(t *testing.T) { name: "Test ", collector: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - Config: Config{ - Processors: &AnyConfig{ + Config: common.Config{ + Processors: &common.AnyConfig{ Object: map[string]interface{}{ "batch": nil, "foo": nil, }, }, - Extensions: &AnyConfig{ + Extensions: &common.AnyConfig{ Object: map[string]interface{}{ "foo": nil, }, @@ -116,10 +117,10 @@ func TestCollectorDefaultingWebhook(t *testing.T) { }, }, Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - ManagementState: ManagementStateManaged, + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + ManagementState: common.ManagementStateManaged, Replicas: &one, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -137,7 +138,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Spec: OpenTelemetryCollectorSpec{ Mode: ModeSidecar, UpgradeStrategy: "adhoc", - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &five, }, }, @@ -151,10 +152,10 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Spec: OpenTelemetryCollectorSpec{ Mode: ModeSidecar, UpgradeStrategy: "adhoc", - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &five, - ManagementState: ManagementStateManaged, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + ManagementState: common.ManagementStateManaged, + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -170,9 +171,9 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Spec: OpenTelemetryCollectorSpec{ Mode: ModeSidecar, UpgradeStrategy: "adhoc", - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &five, - ManagementState: ManagementStateUnmanaged, + ManagementState: common.ManagementStateUnmanaged, }, }, }, @@ -185,10 +186,10 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Spec: OpenTelemetryCollectorSpec{ Mode: ModeSidecar, UpgradeStrategy: "adhoc", - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &five, - ManagementState: ManagementStateUnmanaged, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + ManagementState: common.ManagementStateUnmanaged, + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -202,8 +203,8 @@ func TestCollectorDefaultingWebhook(t *testing.T) { name: "Setting Autoscaler MaxReplicas", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Autoscaler: &AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &five, MinReplicas: &one, }, @@ -219,15 +220,15 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Spec: OpenTelemetryCollectorSpec{ Mode: ModeDeployment, UpgradeStrategy: UpgradeStrategyAutomatic, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &one, - ManagementState: ManagementStateManaged, - Autoscaler: &AutoscalerSpec{ + ManagementState: common.ManagementStateManaged, + Autoscaler: &common.AutoscalerSpec{ TargetCPUUtilization: &defaultCPUTarget, MaxReplicas: &five, MinReplicas: &one, }, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -255,10 +256,10 @@ func TestCollectorDefaultingWebhook(t *testing.T) { }, Spec: OpenTelemetryCollectorSpec{ Mode: ModeDeployment, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - ManagementState: ManagementStateManaged, + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + ManagementState: common.ManagementStateManaged, Replicas: &one, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -280,8 +281,8 @@ func TestCollectorDefaultingWebhook(t *testing.T) { otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ Mode: ModeDeployment, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MinAvailable: &intstr.IntOrString{ Type: intstr.String, StrVal: "10%", @@ -298,10 +299,10 @@ func TestCollectorDefaultingWebhook(t *testing.T) { }, Spec: OpenTelemetryCollectorSpec{ Mode: ModeDeployment, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &one, - ManagementState: ManagementStateManaged, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + ManagementState: common.ManagementStateManaged, + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MinAvailable: &intstr.IntOrString{ Type: intstr.String, StrVal: "10%", @@ -319,8 +320,8 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Mode: ModeDeployment, TargetAllocator: TargetAllocatorEmbedded{ Enabled: true, - AllocationStrategy: TargetAllocatorAllocationStrategyConsistentHashing, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + AllocationStrategy: common.TargetAllocatorAllocationStrategyConsistentHashing, + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MinAvailable: &intstr.IntOrString{ Type: intstr.String, StrVal: "10%", @@ -337,10 +338,10 @@ func TestCollectorDefaultingWebhook(t *testing.T) { }, Spec: OpenTelemetryCollectorSpec{ Mode: ModeDeployment, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &one, - ManagementState: ManagementStateManaged, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + ManagementState: common.ManagementStateManaged, + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -351,8 +352,8 @@ func TestCollectorDefaultingWebhook(t *testing.T) { TargetAllocator: TargetAllocatorEmbedded{ Enabled: true, Replicas: &one, - AllocationStrategy: TargetAllocatorAllocationStrategyConsistentHashing, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + AllocationStrategy: common.TargetAllocatorAllocationStrategyConsistentHashing, + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MinAvailable: &intstr.IntOrString{ Type: intstr.String, StrVal: "10%", @@ -370,7 +371,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) { TargetAllocator: TargetAllocatorEmbedded{ Enabled: true, Replicas: &one, - AllocationStrategy: TargetAllocatorAllocationStrategyConsistentHashing, + AllocationStrategy: common.TargetAllocatorAllocationStrategyConsistentHashing, }, }, }, @@ -382,10 +383,10 @@ func TestCollectorDefaultingWebhook(t *testing.T) { }, Spec: OpenTelemetryCollectorSpec{ Mode: ModeDeployment, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &one, - ManagementState: ManagementStateManaged, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + ManagementState: common.ManagementStateManaged, + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -396,8 +397,8 @@ func TestCollectorDefaultingWebhook(t *testing.T) { TargetAllocator: TargetAllocatorEmbedded{ Enabled: true, Replicas: &one, - AllocationStrategy: TargetAllocatorAllocationStrategyConsistentHashing, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + AllocationStrategy: common.TargetAllocatorAllocationStrategyConsistentHashing, + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -414,7 +415,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) { Mode: ModeDeployment, TargetAllocator: TargetAllocatorEmbedded{ Enabled: true, - AllocationStrategy: TargetAllocatorAllocationStrategyLeastWeighted, + AllocationStrategy: common.TargetAllocatorAllocationStrategyLeastWeighted, }, }, }, @@ -426,10 +427,10 @@ func TestCollectorDefaultingWebhook(t *testing.T) { }, Spec: OpenTelemetryCollectorSpec{ Mode: ModeDeployment, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &one, - ManagementState: ManagementStateManaged, - PodDisruptionBudget: &PodDisruptionBudgetSpec{ + ManagementState: common.ManagementStateManaged, + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -440,7 +441,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) { TargetAllocator: TargetAllocatorEmbedded{ Enabled: true, Replicas: &one, - AllocationStrategy: TargetAllocatorAllocationStrategyLeastWeighted, + AllocationStrategy: common.TargetAllocatorAllocationStrategyLeastWeighted, }, }, }, @@ -490,7 +491,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { three := int32(3) five := int32(5) - cfg := Config{} + cfg := common.Config{} err := yaml.Unmarshal([]byte(cfgYaml), &cfg) require.NoError(t, err) @@ -510,9 +511,9 @@ func TestOTELColValidatingWebhook(t *testing.T) { otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ Mode: ModeStatefulSet, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &three, - Autoscaler: &AutoscalerSpec{ + Autoscaler: &common.AutoscalerSpec{ MinReplicas: &one, MaxReplicas: &five, Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{ @@ -525,7 +526,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { }, TargetCPUUtilization: &five, }, - Ports: []PortsSpec{ + Ports: []common.PortsSpec{ { ServicePort: v1.ServicePort{ Name: "port1", @@ -555,9 +556,9 @@ func TestOTELColValidatingWebhook(t *testing.T) { otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ Mode: ModeStatefulSet, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &three, - Autoscaler: &AutoscalerSpec{ + Autoscaler: &common.AutoscalerSpec{ MinReplicas: &one, MaxReplicas: &five, Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{ @@ -570,7 +571,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { }, TargetCPUUtilization: &five, }, - Ports: []PortsSpec{ + Ports: []common.PortsSpec{ { ServicePort: v1.ServicePort{ Name: "port1", @@ -589,7 +590,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { UpgradeStrategy: "adhoc", TargetAllocator: TargetAllocatorEmbedded{ Enabled: true, - PrometheusCR: TargetAllocatorPrometheusCR{Enabled: true}, + PrometheusCR: common.TargetAllocatorPrometheusCR{Enabled: true}, }, Config: cfg, }, @@ -616,9 +617,9 @@ func TestOTELColValidatingWebhook(t *testing.T) { Spec: OpenTelemetryCollectorSpec{ Mode: ModeStatefulSet, UpgradeStrategy: "adhoc", - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &three, - Ports: []PortsSpec{ + Ports: []common.PortsSpec{ { ServicePort: v1.ServicePort{ Name: "port1", @@ -633,7 +634,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { }, }, }, - Autoscaler: &AutoscalerSpec{ + Autoscaler: &common.AutoscalerSpec{ Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{ ScaleDown: &autoscalingv2.HPAScalingRules{ StabilizationWindowSeconds: &three, @@ -647,7 +648,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { }, TargetAllocator: TargetAllocatorEmbedded{ Enabled: true, - PrometheusCR: TargetAllocatorPrometheusCR{Enabled: true}, + PrometheusCR: common.TargetAllocatorPrometheusCR{Enabled: true}, }, Config: cfg, }, @@ -658,7 +659,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ Mode: ModeSidecar, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ VolumeClaimTemplates: []v1.PersistentVolumeClaim{{}, {}}, }, }, @@ -670,7 +671,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ Mode: ModeSidecar, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Tolerations: []v1.Toleration{{}, {}}, }, }, @@ -708,7 +709,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { Mode: ModeDaemonSet, TargetAllocator: TargetAllocatorEmbedded{ Enabled: true, - AllocationStrategy: TargetAllocatorAllocationStrategyLeastWeighted, + AllocationStrategy: common.TargetAllocatorAllocationStrategyLeastWeighted, }, }, }, @@ -718,8 +719,8 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid port name", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Ports: []PortsSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Ports: []common.PortsSpec{ { ServicePort: v1.ServicePort{ // this port name contains a non alphanumeric character, which is invalid. @@ -738,8 +739,8 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid port name, too long", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Ports: []PortsSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Ports: []common.PortsSpec{ { ServicePort: v1.ServicePort{ Name: "aaaabbbbccccdddd", // len: 16, too long @@ -756,8 +757,8 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid port num", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Ports: []PortsSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Ports: []common.PortsSpec{ { ServicePort: v1.ServicePort{ Name: "aaaabbbbccccddd", // len: 15 @@ -774,8 +775,8 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid max replicas", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Autoscaler: &AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &zero, }, }, @@ -787,9 +788,9 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid replicas, greater than max", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &five, - Autoscaler: &AutoscalerSpec{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &three, }, }, @@ -801,8 +802,8 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid min replicas, greater than max", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Autoscaler: &AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &three, MinReplicas: &five, }, @@ -815,8 +816,8 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid min replicas, lesser than 1", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Autoscaler: &AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &three, MinReplicas: &zero, }, @@ -829,8 +830,8 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid autoscaler scale down", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Autoscaler: &AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &three, Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{ ScaleDown: &autoscalingv2.HPAScalingRules{ @@ -847,8 +848,8 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid autoscaler scale up", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Autoscaler: &AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &three, Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{ ScaleUp: &autoscalingv2.HPAScalingRules{ @@ -865,8 +866,8 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid autoscaler target cpu utilization", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Autoscaler: &AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &three, TargetCPUUtilization: &zero, }, @@ -879,8 +880,8 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "autoscaler minReplicas is less than maxReplicas", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Autoscaler: &AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &one, MinReplicas: &five, }, @@ -893,10 +894,10 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid autoscaler metric type", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Autoscaler: &AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &three, - Metrics: []MetricSpec{ + Metrics: []common.MetricSpec{ { Type: autoscalingv2.ResourceMetricSourceType, }, @@ -911,10 +912,10 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "invalid pod metric average value", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Autoscaler: &AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &three, - Metrics: []MetricSpec{ + Metrics: []common.MetricSpec{ { Type: autoscalingv2.PodsMetricSourceType, Pods: &autoscalingv2.PodsMetricSource{ @@ -938,10 +939,10 @@ func TestOTELColValidatingWebhook(t *testing.T) { name: "utilization target is not valid with pod metrics", otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ - Autoscaler: &AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MaxReplicas: &three, - Metrics: []MetricSpec{ + Metrics: []common.MetricSpec{ { Type: autoscalingv2.PodsMetricSourceType, Pods: &autoscalingv2.PodsMetricSource{ @@ -980,7 +981,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ Mode: ModeSidecar, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PriorityClassName: "test-class", }, }, @@ -992,7 +993,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ Mode: ModeSidecar, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Affinity: &v1.Affinity{ NodeAffinity: &v1.NodeAffinity{ RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{ @@ -1086,7 +1087,7 @@ func TestOTELColValidatingWebhook(t *testing.T) { otelcol: OpenTelemetryCollector{ Spec: OpenTelemetryCollectorSpec{ Mode: ModeSidecar, - OpenTelemetryCommonFields: OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ AdditionalContainers: []v1.Container{ { Name: "test", diff --git a/apis/v1beta1/opentelemetrycollector_types.go b/apis/v1beta1/opentelemetrycollector_types.go index f21637d7fe..6ad89a8f58 100644 --- a/apis/v1beta1/opentelemetrycollector_types.go +++ b/apis/v1beta1/opentelemetrycollector_types.go @@ -18,6 +18,8 @@ import ( appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/open-telemetry/opentelemetry-operator/apis/common" ) func init() { @@ -78,7 +80,7 @@ type OpenTelemetryCollectorStatus struct { // OpenTelemetryCollectorSpec defines the desired state of OpenTelemetryCollector. type OpenTelemetryCollectorSpec struct { // OpenTelemetryCommonFields are fields that are on all OpenTelemetry CRD workloads. - OpenTelemetryCommonFields `json:",inline"` + common.OpenTelemetryCommonFields `json:",inline"` // TargetAllocator indicates a value which determines whether to spawn a target allocation resource or not. // +optional TargetAllocator TargetAllocatorEmbedded `json:"targetAllocator,omitempty"` @@ -92,7 +94,7 @@ type OpenTelemetryCollectorSpec struct { // The empty objects e.g. batch: should be written as batch: {} otherwise they won't work with kustomize or kubectl edit. // +required // +kubebuilder:pruning:PreserveUnknownFields - Config Config `json:"config"` + Config common.Config `json:"config"` // Ingress is used to specify how OpenTelemetry Collector is exposed. This // functionality is only available if one of the valid modes is set. // Valid modes are: deployment, daemonset and statefulset. @@ -108,7 +110,7 @@ type OpenTelemetryCollectorSpec struct { // +optional // +kubebuilder:validation:Optional // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Observability" - Observability ObservabilitySpec `json:"observability,omitempty"` + Observability common.ObservabilitySpec `json:"observability,omitempty"` // ConfigMaps is a list of ConfigMaps in the same namespace as the OpenTelemetryCollector // object, which shall be mounted into the Collector Pods. @@ -146,13 +148,13 @@ type TargetAllocatorEmbedded struct { // WARNING: The per-node strategy currently ignores targets without a Node, like control plane components. // +optional // +kubebuilder:default:=consistent-hashing - AllocationStrategy TargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"` + AllocationStrategy common.TargetAllocatorAllocationStrategy `json:"allocationStrategy,omitempty"` // FilterStrategy determines how to filter targets before allocating them among the collectors. // The only current option is relabel-config (drops targets based on prom relabel_config). // The default is relabel-config. // +optional // +kubebuilder:default:=relabel-config - FilterStrategy TargetAllocatorFilterStrategy `json:"filterStrategy,omitempty"` + FilterStrategy common.TargetAllocatorFilterStrategy `json:"filterStrategy,omitempty"` // ServiceAccount indicates the name of an existing service account to use with this instance. When set, // the operator will not automatically create a ServiceAccount for the TargetAllocator. // +optional @@ -169,7 +171,7 @@ type TargetAllocatorEmbedded struct { // 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 TargetAllocatorPrometheusCR `json:"prometheusCR,omitempty"` + PrometheusCR common.TargetAllocatorPrometheusCR `json:"prometheusCR,omitempty"` // SecurityContext configures the container security context for // the targetallocator. // +optional @@ -197,12 +199,12 @@ type TargetAllocatorEmbedded struct { // +optional // +kubebuilder:validation:Optional // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Observability" - Observability ObservabilitySpec `json:"observability,omitempty"` + Observability common.ObservabilitySpec `json:"observability,omitempty"` // PodDisruptionBudget specifies the pod disruption budget configuration to use // for the target allocator workload. // // +optional - PodDisruptionBudget *PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"` + PodDisruptionBudget *common.PodDisruptionBudgetSpec `json:"podDisruptionBudget,omitempty"` } // Probe defines the OpenTelemetry's pod probe config. Only Liveness probe is supported currently. @@ -243,33 +245,6 @@ type Probe struct { TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"` } -// ObservabilitySpec defines how telemetry data gets handled. -type ObservabilitySpec struct { - // Metrics defines the metrics configuration for operands. - // - // +optional - // +kubebuilder:validation:Optional - // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Metrics Config" - Metrics MetricsConfigSpec `json:"metrics,omitempty"` -} - -// MetricsConfigSpec defines a metrics config. -type MetricsConfigSpec struct { - // EnableMetrics specifies if ServiceMonitor or PodMonitor(for sidecar mode) should be created for the service managed by the OpenTelemetry Operator. - // The operator.observability.prometheus feature gate must be enabled to use this feature. - // - // +optional - // +kubebuilder:validation:Optional - // +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Create ServiceMonitors for OpenTelemetry Collector" - EnableMetrics bool `json:"enableMetrics,omitempty"` - // DisablePrometheusAnnotations controls the automatic addition of default Prometheus annotations - // ('prometheus.io/scrape', 'prometheus.io/port', and 'prometheus.io/path') - // - // +optional - // +kubebuilder:validation:Optional - DisablePrometheusAnnotations bool `json:"disablePrometheusAnnotations,omitempty"` -} - // ScaleSubresourceStatus defines the observed state of the OpenTelemetryCollector's // scale subresource. type ScaleSubresourceStatus struct { diff --git a/apis/v1beta1/zz_generated.deepcopy.go b/apis/v1beta1/zz_generated.deepcopy.go index 80cddf7dd0..44643cdd4c 100644 --- a/apis/v1beta1/zz_generated.deepcopy.go +++ b/apis/v1beta1/zz_generated.deepcopy.go @@ -19,91 +19,12 @@ package v1beta1 import ( - "k8s.io/api/autoscaling/v2" - "k8s.io/api/core/v1" - networkingv1 "k8s.io/api/networking/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" + corev1 "k8s.io/api/core/v1" + "k8s.io/api/networking/v1" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/util/intstr" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AutoscalerSpec) DeepCopyInto(out *AutoscalerSpec) { - *out = *in - if in.MinReplicas != nil { - in, out := &in.MinReplicas, &out.MinReplicas - *out = new(int32) - **out = **in - } - if in.MaxReplicas != nil { - in, out := &in.MaxReplicas, &out.MaxReplicas - *out = new(int32) - **out = **in - } - if in.Behavior != nil { - in, out := &in.Behavior, &out.Behavior - *out = new(v2.HorizontalPodAutoscalerBehavior) - (*in).DeepCopyInto(*out) - } - if in.Metrics != nil { - in, out := &in.Metrics, &out.Metrics - *out = make([]MetricSpec, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.TargetCPUUtilization != nil { - in, out := &in.TargetCPUUtilization, &out.TargetCPUUtilization - *out = new(int32) - **out = **in - } - if in.TargetMemoryUtilization != nil { - in, out := &in.TargetMemoryUtilization, &out.TargetMemoryUtilization - *out = new(int32) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AutoscalerSpec. -func (in *AutoscalerSpec) DeepCopy() *AutoscalerSpec { - if in == nil { - return nil - } - out := new(AutoscalerSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Config) DeepCopyInto(out *Config) { - *out = *in - in.Receivers.DeepCopyInto(&out.Receivers) - in.Exporters.DeepCopyInto(&out.Exporters) - if in.Processors != nil { - in, out := &in.Processors, &out.Processors - *out = (*in).DeepCopy() - } - if in.Connectors != nil { - in, out := &in.Connectors, &out.Connectors - *out = (*in).DeepCopy() - } - if in.Extensions != nil { - in, out := &in.Extensions, &out.Extensions - *out = (*in).DeepCopy() - } - in.Service.DeepCopyInto(&out.Service) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Config. -func (in *Config) DeepCopy() *Config { - if in == nil { - return nil - } - out := new(Config) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ConfigMapsSpec) DeepCopyInto(out *ConfigMapsSpec) { *out = *in @@ -131,7 +52,7 @@ func (in *Ingress) DeepCopyInto(out *Ingress) { } if in.TLS != nil { in, out := &in.TLS, &out.TLS - *out = make([]networkingv1.IngressTLS, len(*in)) + *out = make([]v1.IngressTLS, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -154,72 +75,6 @@ func (in *Ingress) DeepCopy() *Ingress { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MetricSpec) DeepCopyInto(out *MetricSpec) { - *out = *in - if in.Pods != nil { - in, out := &in.Pods, &out.Pods - *out = new(v2.PodsMetricSource) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricSpec. -func (in *MetricSpec) DeepCopy() *MetricSpec { - if in == nil { - return nil - } - out := new(MetricSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MetricsConfig) DeepCopyInto(out *MetricsConfig) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricsConfig. -func (in *MetricsConfig) DeepCopy() *MetricsConfig { - if in == nil { - return nil - } - out := new(MetricsConfig) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MetricsConfigSpec) DeepCopyInto(out *MetricsConfigSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricsConfigSpec. -func (in *MetricsConfigSpec) DeepCopy() *MetricsConfigSpec { - if in == nil { - return nil - } - out := new(MetricsConfigSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ObservabilitySpec) DeepCopyInto(out *ObservabilitySpec) { - *out = *in - out.Metrics = in.Metrics -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ObservabilitySpec. -func (in *ObservabilitySpec) DeepCopy() *ObservabilitySpec { - if in == nil { - return nil - } - out := new(ObservabilitySpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OpenShiftRoute) DeepCopyInto(out *OpenShiftRoute) { *out = *in @@ -342,194 +197,6 @@ func (in *OpenTelemetryCollectorStatus) DeepCopy() *OpenTelemetryCollectorStatus return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *OpenTelemetryCommonFields) DeepCopyInto(out *OpenTelemetryCommonFields) { - *out = *in - in.Resources.DeepCopyInto(&out.Resources) - if in.NodeSelector != nil { - in, out := &in.NodeSelector, &out.NodeSelector - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - if in.Args != nil { - in, out := &in.Args, &out.Args - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - if in.Replicas != nil { - in, out := &in.Replicas, &out.Replicas - *out = new(int32) - **out = **in - } - if in.Autoscaler != nil { - in, out := &in.Autoscaler, &out.Autoscaler - *out = new(AutoscalerSpec) - (*in).DeepCopyInto(*out) - } - if in.PodDisruptionBudget != nil { - in, out := &in.PodDisruptionBudget, &out.PodDisruptionBudget - *out = new(PodDisruptionBudgetSpec) - (*in).DeepCopyInto(*out) - } - if in.SecurityContext != nil { - in, out := &in.SecurityContext, &out.SecurityContext - *out = new(v1.SecurityContext) - (*in).DeepCopyInto(*out) - } - if in.PodSecurityContext != nil { - in, out := &in.PodSecurityContext, &out.PodSecurityContext - *out = new(v1.PodSecurityContext) - (*in).DeepCopyInto(*out) - } - if in.PodAnnotations != nil { - in, out := &in.PodAnnotations, &out.PodAnnotations - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - if in.VolumeMounts != nil { - in, out := &in.VolumeMounts, &out.VolumeMounts - *out = make([]v1.VolumeMount, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Ports != nil { - in, out := &in.Ports, &out.Ports - *out = make([]PortsSpec, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Env != nil { - in, out := &in.Env, &out.Env - *out = make([]v1.EnvVar, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.EnvFrom != nil { - in, out := &in.EnvFrom, &out.EnvFrom - *out = make([]v1.EnvFromSource, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.VolumeClaimTemplates != nil { - in, out := &in.VolumeClaimTemplates, &out.VolumeClaimTemplates - *out = make([]v1.PersistentVolumeClaim, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Tolerations != nil { - in, out := &in.Tolerations, &out.Tolerations - *out = make([]v1.Toleration, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Volumes != nil { - in, out := &in.Volumes, &out.Volumes - *out = make([]v1.Volume, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.Affinity != nil { - in, out := &in.Affinity, &out.Affinity - *out = new(v1.Affinity) - (*in).DeepCopyInto(*out) - } - if in.Lifecycle != nil { - in, out := &in.Lifecycle, &out.Lifecycle - *out = new(v1.Lifecycle) - (*in).DeepCopyInto(*out) - } - if in.TerminationGracePeriodSeconds != nil { - in, out := &in.TerminationGracePeriodSeconds, &out.TerminationGracePeriodSeconds - *out = new(int64) - **out = **in - } - if in.TopologySpreadConstraints != nil { - in, out := &in.TopologySpreadConstraints, &out.TopologySpreadConstraints - *out = make([]v1.TopologySpreadConstraint, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.InitContainers != nil { - in, out := &in.InitContainers, &out.InitContainers - *out = make([]v1.Container, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.AdditionalContainers != nil { - in, out := &in.AdditionalContainers, &out.AdditionalContainers - *out = make([]v1.Container, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenTelemetryCommonFields. -func (in *OpenTelemetryCommonFields) DeepCopy() *OpenTelemetryCommonFields { - if in == nil { - return nil - } - out := new(OpenTelemetryCommonFields) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PodDisruptionBudgetSpec) DeepCopyInto(out *PodDisruptionBudgetSpec) { - *out = *in - if in.MinAvailable != nil { - in, out := &in.MinAvailable, &out.MinAvailable - *out = new(intstr.IntOrString) - **out = **in - } - if in.MaxUnavailable != nil { - in, out := &in.MaxUnavailable, &out.MaxUnavailable - *out = new(intstr.IntOrString) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodDisruptionBudgetSpec. -func (in *PodDisruptionBudgetSpec) DeepCopy() *PodDisruptionBudgetSpec { - if in == nil { - return nil - } - out := new(PodDisruptionBudgetSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PortsSpec) DeepCopyInto(out *PortsSpec) { - *out = *in - in.ServicePort.DeepCopyInto(&out.ServicePort) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PortsSpec. -func (in *PortsSpec) DeepCopy() *PortsSpec { - if in == nil { - return nil - } - out := new(PortsSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Probe) DeepCopyInto(out *Probe) { *out = *in @@ -590,62 +257,6 @@ func (in *ScaleSubresourceStatus) DeepCopy() *ScaleSubresourceStatus { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Service) DeepCopyInto(out *Service) { - *out = *in - if in.Extensions != nil { - in, out := &in.Extensions, &out.Extensions - *out = new([]string) - if **in != nil { - in, out := *in, *out - *out = make([]string, len(*in)) - copy(*out, *in) - } - } - if in.Telemetry != nil { - in, out := &in.Telemetry, &out.Telemetry - *out = (*in).DeepCopy() - } - in.Pipelines.DeepCopyInto(&out.Pipelines) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Service. -func (in *Service) DeepCopy() *Service { - if in == nil { - return nil - } - out := new(Service) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TargetAllocator) DeepCopyInto(out *TargetAllocator) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocator. -func (in *TargetAllocator) DeepCopy() *TargetAllocator { - if in == nil { - return nil - } - out := new(TargetAllocator) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *TargetAllocator) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TargetAllocatorEmbedded) DeepCopyInto(out *TargetAllocatorEmbedded) { *out = *in @@ -664,37 +275,37 @@ func (in *TargetAllocatorEmbedded) DeepCopyInto(out *TargetAllocatorEmbedded) { in.Resources.DeepCopyInto(&out.Resources) if in.Affinity != nil { in, out := &in.Affinity, &out.Affinity - *out = new(v1.Affinity) + *out = new(corev1.Affinity) (*in).DeepCopyInto(*out) } in.PrometheusCR.DeepCopyInto(&out.PrometheusCR) if in.SecurityContext != nil { in, out := &in.SecurityContext, &out.SecurityContext - *out = new(v1.SecurityContext) + *out = new(corev1.SecurityContext) (*in).DeepCopyInto(*out) } if in.PodSecurityContext != nil { in, out := &in.PodSecurityContext, &out.PodSecurityContext - *out = new(v1.PodSecurityContext) + *out = new(corev1.PodSecurityContext) (*in).DeepCopyInto(*out) } if in.TopologySpreadConstraints != nil { in, out := &in.TopologySpreadConstraints, &out.TopologySpreadConstraints - *out = make([]v1.TopologySpreadConstraint, len(*in)) + *out = make([]corev1.TopologySpreadConstraint, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.Tolerations != nil { in, out := &in.Tolerations, &out.Tolerations - *out = make([]v1.Toleration, len(*in)) + *out = make([]corev1.Toleration, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.Env != nil { in, out := &in.Env, &out.Env - *out = make([]v1.EnvVar, len(*in)) + *out = make([]corev1.EnvVar, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -702,7 +313,7 @@ func (in *TargetAllocatorEmbedded) DeepCopyInto(out *TargetAllocatorEmbedded) { out.Observability = in.Observability if in.PodDisruptionBudget != nil { in, out := &in.PodDisruptionBudget, &out.PodDisruptionBudget - *out = new(PodDisruptionBudgetSpec) + *out = new(common.PodDisruptionBudgetSpec) (*in).DeepCopyInto(*out) } } @@ -716,138 +327,3 @@ func (in *TargetAllocatorEmbedded) DeepCopy() *TargetAllocatorEmbedded { in.DeepCopyInto(out) return out } - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TargetAllocatorList) DeepCopyInto(out *TargetAllocatorList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]OpenTelemetryCollector, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocatorList. -func (in *TargetAllocatorList) DeepCopy() *TargetAllocatorList { - if in == nil { - return nil - } - out := new(TargetAllocatorList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *TargetAllocatorList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TargetAllocatorPrometheusCR) DeepCopyInto(out *TargetAllocatorPrometheusCR) { - *out = *in - if in.ScrapeInterval != nil { - in, out := &in.ScrapeInterval, &out.ScrapeInterval - *out = new(metav1.Duration) - **out = **in - } - if in.PodMonitorSelector != nil { - in, out := &in.PodMonitorSelector, &out.PodMonitorSelector - *out = new(metav1.LabelSelector) - (*in).DeepCopyInto(*out) - } - if in.ServiceMonitorSelector != nil { - in, out := &in.ServiceMonitorSelector, &out.ServiceMonitorSelector - *out = new(metav1.LabelSelector) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocatorPrometheusCR. -func (in *TargetAllocatorPrometheusCR) DeepCopy() *TargetAllocatorPrometheusCR { - if in == nil { - return nil - } - out := new(TargetAllocatorPrometheusCR) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TargetAllocatorSpec) DeepCopyInto(out *TargetAllocatorSpec) { - *out = *in - in.OpenTelemetryCommonFields.DeepCopyInto(&out.OpenTelemetryCommonFields) - in.CollectorSelector.DeepCopyInto(&out.CollectorSelector) - if in.ScrapeConfigs != nil { - in, out := &in.ScrapeConfigs, &out.ScrapeConfigs - *out = make([]AnyConfig, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - in.PrometheusCR.DeepCopyInto(&out.PrometheusCR) - out.Observability = in.Observability -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocatorSpec. -func (in *TargetAllocatorSpec) DeepCopy() *TargetAllocatorSpec { - if in == nil { - return nil - } - out := new(TargetAllocatorSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TargetAllocatorStatus) DeepCopyInto(out *TargetAllocatorStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetAllocatorStatus. -func (in *TargetAllocatorStatus) DeepCopy() *TargetAllocatorStatus { - if in == nil { - return nil - } - out := new(TargetAllocatorStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Telemetry) DeepCopyInto(out *Telemetry) { - *out = *in - out.Metrics = in.Metrics - if in.Resource != nil { - in, out := &in.Resource, &out.Resource - *out = make(map[string]*string, len(*in)) - for key, val := range *in { - var outVal *string - if val == nil { - (*out)[key] = nil - } else { - inVal := (*in)[key] - in, out := &inVal, &outVal - *out = new(string) - **out = **in - } - (*out)[key] = outVal - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Telemetry. -func (in *Telemetry) DeepCopy() *Telemetry { - if in == nil { - return nil - } - out := new(Telemetry) - in.DeepCopyInto(out) - return out -} diff --git a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml index 9facf2f1aa..2310cc5400 100644 --- a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -2921,6 +2921,9 @@ spec: type: array filterStrategy: default: relabel-config + enum: + - "" + - relabel-config type: string image: type: string diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index b17a8dede1..b3729cdcc4 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -2907,6 +2907,9 @@ spec: type: array filterStrategy: default: relabel-config + enum: + - "" + - relabel-config type: string image: type: string diff --git a/config/crd/bases/opentelemetry.io_targetallocators.yaml b/config/crd/bases/opentelemetry.io_targetallocators.yaml index 7d59d689c6..30346ed44f 100644 --- a/config/crd/bases/opentelemetry.io_targetallocators.yaml +++ b/config/crd/bases/opentelemetry.io_targetallocators.yaml @@ -14,7 +14,7 @@ spec: singular: targetallocator scope: Namespaced versions: - - name: v1beta1 + - name: v1alpha1 schema: openAPIV3Schema: properties: diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 5614b3fc80..6f94dcc69b 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -32,6 +32,7 @@ import ( "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" @@ -83,7 +84,7 @@ service: exporters: [logging] ` - goodConfig := v1beta1.Config{} + goodConfig := common.Config{} err := go_yaml.Unmarshal([]byte(goodConfigYaml), &goodConfig) require.NoError(t, err) one := int32(1) @@ -105,7 +106,7 @@ service: Namespace: "test", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Image: "test", Replicas: &one, }, @@ -345,7 +346,7 @@ service: Namespace: "test", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Image: "test", Replicas: &one, }, @@ -634,7 +635,7 @@ service: Namespace: "test", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Image: "test", Replicas: &one, ServiceAccount: "my-special-sa", @@ -1126,7 +1127,7 @@ service: exporters: [logging] ` - goodConfig := v1beta1.Config{} + goodConfig := common.Config{} err := go_yaml.Unmarshal([]byte(goodConfigYaml), &goodConfig) require.NoError(t, err) one := int32(1) @@ -1149,7 +1150,7 @@ service: Namespace: "test", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Image: "test", Replicas: &one, }, @@ -1158,7 +1159,7 @@ service: TargetAllocator: v1beta1.TargetAllocatorEmbedded{ Enabled: true, FilterStrategy: "relabel-config", - PrometheusCR: v1beta1.TargetAllocatorPrometheusCR{ + PrometheusCR: common.TargetAllocatorPrometheusCR{ Enabled: true, }, }, @@ -1538,7 +1539,7 @@ prometheus_cr: Namespace: "test", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Image: "test", Replicas: &one, }, @@ -1546,12 +1547,12 @@ prometheus_cr: Config: goodConfig, TargetAllocator: v1beta1.TargetAllocatorEmbedded{ Enabled: true, - PrometheusCR: v1beta1.TargetAllocatorPrometheusCR{ + PrometheusCR: common.TargetAllocatorPrometheusCR{ Enabled: true, }, FilterStrategy: "relabel-config", - Observability: v1beta1.ObservabilitySpec{ - Metrics: v1beta1.MetricsConfigSpec{ + Observability: common.ObservabilitySpec{ + Metrics: common.MetricsConfigSpec{ EnableMetrics: true, }, }, diff --git a/controllers/opentelemetrycollector_controller.go b/controllers/opentelemetrycollector_controller.go index 258c5fadfc..1d39abbd6b 100644 --- a/controllers/opentelemetrycollector_controller.go +++ b/controllers/opentelemetrycollector_controller.go @@ -36,6 +36,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift" "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus" @@ -197,7 +198,7 @@ func (r *OpenTelemetryCollectorReconciler) Reconcile(ctx context.Context, req ct return ctrl.Result{}, nil } - if instance.Spec.ManagementState == v1beta1.ManagementStateUnmanaged { + if instance.Spec.ManagementState == common.ManagementStateUnmanaged { log.Info("Skipping reconciliation for unmanaged OpenTelemetryCollector resource", "name", req.String()) // Stop requeueing for unmanaged OpenTelemetryCollector custom resources return ctrl.Result{}, nil diff --git a/docs/api.md b/docs/api.md index 8235f45406..7ca5859069 100644 --- a/docs/api.md +++ b/docs/api.md @@ -21589,12 +21589,13 @@ consumed in the config file for the TargetAllocator.
false filterStrategy - string + enum FilterStrategy determines how to filter targets before allocating them among the collectors. The only current option is relabel-config (drops targets based on prom relabel_config). The default is relabel-config.

+ Enum: , relabel-config
Default: relabel-config
false diff --git a/internal/manifests/collector/container.go b/internal/manifests/collector/container.go index d0585ff9d8..67aa98c9a5 100644 --- a/internal/manifests/collector/container.go +++ b/internal/manifests/collector/container.go @@ -25,6 +25,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/validation" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/adapters" @@ -169,7 +170,7 @@ func Container(cfg config.Config, logger logr.Logger, otelcol v1beta1.OpenTeleme } } -func getConfigContainerPorts(logger logr.Logger, cfgYaml string, conf v1beta1.Config) (map[string]corev1.ContainerPort, error) { +func getConfigContainerPorts(logger logr.Logger, cfgYaml string, conf common.Config) (map[string]corev1.ContainerPort, error) { ports := map[string]corev1.ContainerPort{} c, err := adapters.ConfigFromString(cfgYaml) if err != nil { diff --git a/internal/manifests/collector/container_test.go b/internal/manifests/collector/container_test.go index e2cd24639d..f36d82b295 100644 --- a/internal/manifests/collector/container_test.go +++ b/internal/manifests/collector/container_test.go @@ -25,6 +25,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" logf "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" . "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector" @@ -54,8 +55,8 @@ func TestContainerNewDefault(t *testing.T) { exporters: [debug]` otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Ports: []v1beta1.PortsSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Ports: []common.PortsSpec{ { ServicePort: corev1.ServicePort{ Name: "metrics", @@ -82,7 +83,7 @@ func TestContainerWithImageOverridden(t *testing.T) { // prepare otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Image: "overridden-image", }, }, @@ -111,13 +112,13 @@ service: tests := []struct { description string specConfig string - specPorts []v1beta1.PortsSpec + specPorts []common.PortsSpec expectedPorts []corev1.ContainerPort }{ { description: "couldn't build ports from spec config", specConfig: "", - specPorts: []v1beta1.PortsSpec{ + specPorts: []common.PortsSpec{ { ServicePort: corev1.ServicePort{ Name: "metrics", @@ -142,7 +143,7 @@ service: }, { description: "ports in spec ContainerPorts", - specPorts: []v1beta1.PortsSpec{ + specPorts: []common.PortsSpec{ { ServicePort: corev1.ServicePort{ Name: "metrics", @@ -168,7 +169,7 @@ service: { description: "ports in spec Config and ContainerPorts", specConfig: goodConfig, - specPorts: []v1beta1.PortsSpec{ + specPorts: []common.PortsSpec{ { ServicePort: corev1.ServicePort{ Name: "testport1", @@ -203,7 +204,7 @@ service: { description: "duplicate port name", specConfig: goodConfig, - specPorts: []v1beta1.PortsSpec{ + specPorts: []common.PortsSpec{ { ServicePort: corev1.ServicePort{ Name: "testport1", @@ -241,7 +242,7 @@ service: receivers: [otlp] exporters: [prometheus, debug] `, - specPorts: []v1beta1.PortsSpec{ + specPorts: []common.PortsSpec{ { ServicePort: corev1.ServicePort{ Name: "metrics", @@ -281,7 +282,7 @@ service: metrics: exporters: [prometheus/prod, prometheus/dev, debug] `, - specPorts: []v1beta1.PortsSpec{ + specPorts: []common.PortsSpec{ { ServicePort: corev1.ServicePort{ Name: "metrics", @@ -319,7 +320,7 @@ service: specConfig: `exporters: prometheusremotewrite/prometheus: endpoint: http://prometheus-server.monitoring/api/v1/write`, - specPorts: []v1beta1.PortsSpec{ + specPorts: []common.PortsSpec{ { ServicePort: corev1.ServicePort{ Name: "metrics", @@ -345,7 +346,7 @@ service: pipelines: metrics: exporters: [prometheus/prod, prometheus/dev, prometheusremotewrite/prometheus, debug]`, - specPorts: []v1beta1.PortsSpec{ + specPorts: []common.PortsSpec{ { ServicePort: corev1.ServicePort{ Name: "metrics", @@ -386,7 +387,7 @@ service: otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ Config: mustUnmarshalToConfig(t, testCase.specConfig), - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Ports: testCase.specPorts, }, }, @@ -406,7 +407,7 @@ func TestContainerConfigFlagIsIgnored(t *testing.T) { // prepare otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Args: map[string]string{ "key": "value", "config": "/some-custom-file.yaml", @@ -429,7 +430,7 @@ func TestContainerCustomVolumes(t *testing.T) { // prepare otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ VolumeMounts: []corev1.VolumeMount{{ Name: "custom-volume-mount", }}, @@ -486,7 +487,7 @@ func TestContainerCustomSecurityContext(t *testing.T) { // test c2 := Container(config.New(), logger, v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ SecurityContext: &corev1.SecurityContext{ Privileged: &isPrivileged, @@ -505,7 +506,7 @@ func TestContainerCustomSecurityContext(t *testing.T) { func TestContainerEnvVarsOverridden(t *testing.T) { otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Env: []corev1.EnvVar{ { Name: "foo", @@ -565,7 +566,7 @@ func TestContainerProxyEnvVars(t *testing.T) { func TestContainerResourceRequirements(t *testing.T) { otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("100m"), @@ -610,7 +611,7 @@ func TestContainerArgs(t *testing.T) { // prepare otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Args: map[string]string{ "metrics-level": "detailed", "log-level": "debug", @@ -632,7 +633,7 @@ func TestContainerOrderedArgs(t *testing.T) { // prepare a scenario where the debug level and a feature gate has been enabled otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Args: map[string]string{ "log-level": "debug", "feature-gates": "+random-feature", @@ -656,7 +657,7 @@ func TestContainerImagePullPolicy(t *testing.T) { // prepare otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ ImagePullPolicy: corev1.PullIfNotPresent, }, }, @@ -688,7 +689,7 @@ func TestContainerEnvFrom(t *testing.T) { } otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ EnvFrom: []corev1.EnvFromSource{ envFrom1, envFrom2, @@ -796,7 +797,7 @@ func TestContainerLifecycle(t *testing.T) { // prepare otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Lifecycle: &corev1.Lifecycle{ PostStart: &corev1.LifecycleHandler{ Exec: &corev1.ExecAction{Command: []string{"sh", "sleep 100"}}, @@ -826,8 +827,8 @@ func TestContainerLifecycle(t *testing.T) { assert.Equal(t, expectedLifecycleHooks, *c.Lifecycle) } -func mustUnmarshalToConfig(t *testing.T, config string) v1beta1.Config { - cfg := v1beta1.Config{} +func mustUnmarshalToConfig(t *testing.T, config string) common.Config { + cfg := common.Config{} if err := yaml.Unmarshal([]byte(config), &cfg); err != nil { t.Fatal(err) } diff --git a/internal/manifests/collector/daemonset_test.go b/internal/manifests/collector/daemonset_test.go index 778c3791f6..7877a23915 100644 --- a/internal/manifests/collector/daemonset_test.go +++ b/internal/manifests/collector/daemonset_test.go @@ -24,6 +24,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" @@ -40,7 +41,7 @@ func TestDaemonSetNewDefault(t *testing.T) { Namespace: "my-namespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Tolerations: testTolerationValues, }, }, @@ -122,7 +123,7 @@ func TestDaemonsetHostNetwork(t *testing.T) { Namespace: "my-namespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ HostNetwork: true, }, }, @@ -143,7 +144,7 @@ func TestDaemonsetPodAnnotations(t *testing.T) { Name: "my-instance", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PodAnnotations: testPodAnnotationValues, }, }, @@ -187,7 +188,7 @@ func TestDaemonstPodSecurityContext(t *testing.T) { Name: "my-instance", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PodSecurityContext: &v1.PodSecurityContext{ RunAsNonRoot: &runAsNonRoot, RunAsUser: &runAsUser, @@ -302,7 +303,7 @@ func TestDaemonSetNodeSelector(t *testing.T) { Name: "my-instance-nodeselector", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ HostNetwork: true, NodeSelector: map[string]string{ "node-key": "node-value", @@ -350,7 +351,7 @@ func TestDaemonSetPriorityClassName(t *testing.T) { Name: "my-instance-priortyClassName", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PriorityClassName: priorityClassName, }, }, @@ -393,7 +394,7 @@ func TestDaemonSetAffinity(t *testing.T) { Name: "my-instance-priortyClassName", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Affinity: testAffinityValue, }, }, @@ -421,7 +422,7 @@ func TestDaemonSetInitContainer(t *testing.T) { Namespace: "my-namespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ InitContainers: []v1.Container{ { Name: "test", @@ -457,7 +458,7 @@ func TestDaemonSetAdditionalContainer(t *testing.T) { Namespace: "my-namespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ AdditionalContainers: []v1.Container{ { Name: "test", @@ -580,7 +581,7 @@ func TestDaemonsetShareProcessNamespace(t *testing.T) { Name: "my-instance-with-shareprocessnamespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ ShareProcessNamespace: true, }, }, diff --git a/internal/manifests/collector/deployment_test.go b/internal/manifests/collector/deployment_test.go index 0523a214b6..ac9ab337e8 100644 --- a/internal/manifests/collector/deployment_test.go +++ b/internal/manifests/collector/deployment_test.go @@ -24,6 +24,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" @@ -77,7 +78,7 @@ func TestDeploymentNewDefault(t *testing.T) { Namespace: "my-namespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Tolerations: testTolerationValues, }, }, @@ -145,7 +146,7 @@ func TestDeploymentPodAnnotations(t *testing.T) { Name: "my-instance", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PodAnnotations: testPodAnnotationValues, }, }, @@ -189,7 +190,7 @@ func TestDeploymenttPodSecurityContext(t *testing.T) { Name: "my-instance", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PodSecurityContext: &v1.PodSecurityContext{ RunAsNonRoot: &runAsNonRoot, RunAsUser: &runAsUser, @@ -275,7 +276,7 @@ func TestDeploymentHostNetwork(t *testing.T) { Name: "my-instance-hostnetwork", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ HostNetwork: true, }, }, @@ -384,7 +385,7 @@ func TestDeploymentNodeSelector(t *testing.T) { Name: "my-instance-nodeselector", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ HostNetwork: true, NodeSelector: map[string]string{ "node-key": "node-value", @@ -432,7 +433,7 @@ func TestDeploymentPriorityClassName(t *testing.T) { Name: "my-instance-priortyClassName", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PriorityClassName: priorityClassName, }, }, @@ -475,7 +476,7 @@ func TestDeploymentAffinity(t *testing.T) { Name: "my-instance-priortyClassName", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Affinity: testAffinityValue, }, }, @@ -521,7 +522,7 @@ func TestDeploymentTerminationGracePeriodSeconds(t *testing.T) { Name: "my-instance-terminationGracePeriodSeconds", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ TerminationGracePeriodSeconds: &gracePeriodSec, }, }, @@ -549,7 +550,7 @@ func TestDeploymentSetInitContainer(t *testing.T) { Namespace: "my-namespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ InitContainers: []v1.Container{ { Name: "test", @@ -603,7 +604,7 @@ func TestDeploymentTopologySpreadConstraints(t *testing.T) { Name: "my-instance-topologyspreadconstraint", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ TopologySpreadConstraints: testTopologySpreadConstraintValue, }, }, @@ -632,7 +633,7 @@ func TestDeploymentAdditionalContainers(t *testing.T) { Namespace: "my-namespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ AdditionalContainers: []v1.Container{ { Name: "test", @@ -687,7 +688,7 @@ func TestDeploymentShareProcessNamespace(t *testing.T) { Name: "my-instance-with-shareprocessnamespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ ShareProcessNamespace: true, }, }, diff --git a/internal/manifests/collector/horizontalpodautoscaler_test.go b/internal/manifests/collector/horizontalpodautoscaler_test.go index 29134197bb..0288a5c92c 100644 --- a/internal/manifests/collector/horizontalpodautoscaler_test.go +++ b/internal/manifests/collector/horizontalpodautoscaler_test.go @@ -22,6 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" @@ -46,8 +47,8 @@ func TestHPA(t *testing.T) { Name: "my-instance", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Autoscaler: &v1beta1.AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MinReplicas: &minReplicas, MaxReplicas: &maxReplicas, TargetCPUUtilization: &cpuUtilization, @@ -61,8 +62,8 @@ func TestHPA(t *testing.T) { Name: "my-instance", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Autoscaler: &v1beta1.AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MinReplicas: &minReplicas, MaxReplicas: &maxReplicas, TargetCPUUtilization: &cpuUtilization, @@ -82,8 +83,8 @@ func TestHPA(t *testing.T) { OtelCol: v1beta1.OpenTelemetryCollector{ ObjectMeta: otelcol.ObjectMeta, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Autoscaler: &v1beta1.AutoscalerSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Autoscaler: &common.AutoscalerSpec{ MinReplicas: otelcol.Spec.Autoscaler.MinReplicas, MaxReplicas: otelcol.Spec.Autoscaler.MaxReplicas, TargetCPUUtilization: otelcol.Spec.OpenTelemetryCommonFields.Autoscaler.TargetCPUUtilization, diff --git a/internal/manifests/collector/ingress.go b/internal/manifests/collector/ingress.go index e646a5446d..428513cbc4 100644 --- a/internal/manifests/collector/ingress.go +++ b/internal/manifests/collector/ingress.go @@ -22,6 +22,7 @@ import ( networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/adapters" @@ -174,7 +175,7 @@ func servicePortsFromCfg(logger logr.Logger, otelcol v1beta1.OpenTelemetryCollec return ports, nil } -func toServicePorts(spec []v1beta1.PortsSpec) []corev1.ServicePort { +func toServicePorts(spec []common.PortsSpec) []corev1.ServicePort { var ports []corev1.ServicePort for _, p := range spec { ports = append(ports, p.ServicePort) diff --git a/internal/manifests/collector/ingress_test.go b/internal/manifests/collector/ingress_test.go index 40e736b7bb..778cab7a36 100644 --- a/internal/manifests/collector/ingress_test.go +++ b/internal/manifests/collector/ingress_test.go @@ -23,6 +23,7 @@ import ( networkingv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" @@ -72,7 +73,7 @@ func TestDesiredIngresses(t *testing.T) { Log: logger, OtelCol: v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - Config: v1beta1.Config{}, + Config: common.Config{}, Ingress: v1beta1.Ingress{ Type: v1beta1.IngressTypeIngress, }, diff --git a/internal/manifests/collector/poddisruptionbudget_test.go b/internal/manifests/collector/poddisruptionbudget_test.go index 7bf709a6be..6a8a818cb2 100644 --- a/internal/manifests/collector/poddisruptionbudget_test.go +++ b/internal/manifests/collector/poddisruptionbudget_test.go @@ -22,6 +22,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" @@ -76,7 +77,7 @@ func TestPDB(t *testing.T) { for _, otelcol := range otelcols { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - otelcol.Spec.PodDisruptionBudget = &v1beta1.PodDisruptionBudgetSpec{ + otelcol.Spec.PodDisruptionBudget = &common.PodDisruptionBudgetSpec{ MinAvailable: test.MinAvailable, MaxUnavailable: test.MaxUnavailable, } diff --git a/internal/manifests/collector/route_test.go b/internal/manifests/collector/route_test.go index b7ec294e7b..7641703812 100644 --- a/internal/manifests/collector/route_test.go +++ b/internal/manifests/collector/route_test.go @@ -25,6 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" @@ -56,7 +57,7 @@ func TestDesiredRoutes(t *testing.T) { Log: logger, OtelCol: v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - Config: v1beta1.Config{}, + Config: common.Config{}, Ingress: v1beta1.Ingress{ Type: v1beta1.IngressTypeRoute, Route: v1beta1.OpenShiftRoute{ diff --git a/internal/manifests/collector/service.go b/internal/manifests/collector/service.go index 10d3ae15ab..cc81250d00 100644 --- a/internal/manifests/collector/service.go +++ b/internal/manifests/collector/service.go @@ -22,6 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/adapters" @@ -206,7 +207,7 @@ func filterPort(logger logr.Logger, candidate corev1.ServicePort, portNumbers ma return &candidate } -func extractPortNumbersAndNames(ports []v1beta1.PortsSpec) (map[PortNumberKey]bool, map[string]bool) { +func extractPortNumbersAndNames(ports []common.PortsSpec) (map[PortNumberKey]bool, map[string]bool) { numbers := map[PortNumberKey]bool{} names := map[string]bool{} diff --git a/internal/manifests/collector/service_test.go b/internal/manifests/collector/service_test.go index 0e3c125be5..2c1ae1fd1c 100644 --- a/internal/manifests/collector/service_test.go +++ b/internal/manifests/collector/service_test.go @@ -21,6 +21,7 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" @@ -29,7 +30,7 @@ import ( func TestExtractPortNumbersAndNames(t *testing.T) { t.Run("should return extracted port names and numbers", func(t *testing.T) { - ports := []v1beta1.PortsSpec{ + ports := []common.PortsSpec{ {ServicePort: v1.ServicePort{Name: "web", Port: 8080}}, {ServicePort: v1.ServicePort{Name: "tcp", Port: 9200}}, {ServicePort: v1.ServicePort{Name: "web-explicit", Port: 80, Protocol: v1.ProtocolTCP}}, @@ -156,7 +157,7 @@ func TestDesiredService(t *testing.T) { Config: config.Config{}, Log: logger, OtelCol: v1beta1.OpenTelemetryCollector{ - Spec: v1beta1.OpenTelemetryCollectorSpec{Config: v1beta1.Config{}}, + Spec: v1beta1.OpenTelemetryCollectorSpec{Config: common.Config{}}, }, } @@ -167,7 +168,7 @@ func TestDesiredService(t *testing.T) { t.Run("should return service with port mentioned in OtelCol.Spec.Ports and inferred ports", func(t *testing.T) { grpc := "grpc" - jaegerPorts := v1beta1.PortsSpec{ + jaegerPorts := common.PortsSpec{ ServicePort: v1.ServicePort{ Name: "jaeger-grpc", Protocol: "TCP", @@ -186,7 +187,7 @@ func TestDesiredService(t *testing.T) { t.Run("on OpenShift gRPC appProtocol should be h2c", func(t *testing.T) { h2c := "h2c" - jaegerPort := v1beta1.PortsSpec{ + jaegerPort := common.PortsSpec{ ServicePort: v1.ServicePort{ Name: "jaeger-grpc", Protocol: "TCP", @@ -209,7 +210,7 @@ func TestDesiredService(t *testing.T) { t.Run("should return service with local internal traffic policy", func(t *testing.T) { grpc := "grpc" - jaegerPorts := v1beta1.PortsSpec{ + jaegerPorts := common.PortsSpec{ ServicePort: v1.ServicePort{ Name: "jaeger-grpc", Protocol: "TCP", @@ -258,9 +259,9 @@ func TestMonitoringService(t *testing.T) { Port: 9090, }} params := deploymentParams() - params.OtelCol.Spec.Config = v1beta1.Config{ - Service: v1beta1.Service{ - Telemetry: &v1beta1.AnyConfig{ + params.OtelCol.Spec.Config = common.Config{ + Service: common.Service{ + Telemetry: &common.AnyConfig{ Object: map[string]interface{}{ "metrics": map[string]interface{}{ "level": "detailed", @@ -279,11 +280,11 @@ func TestMonitoringService(t *testing.T) { }) } -func service(name string, ports []v1beta1.PortsSpec) v1.Service { +func service(name string, ports []common.PortsSpec) v1.Service { return serviceWithInternalTrafficPolicy(name, ports, v1.ServiceInternalTrafficPolicyCluster) } -func serviceWithInternalTrafficPolicy(name string, ports []v1beta1.PortsSpec, internalTrafficPolicy v1.ServiceInternalTrafficPolicyType) v1.Service { +func serviceWithInternalTrafficPolicy(name string, ports []common.PortsSpec, internalTrafficPolicy v1.ServiceInternalTrafficPolicyType) v1.Service { params := deploymentParams() labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{}) diff --git a/internal/manifests/collector/serviceaccount_test.go b/internal/manifests/collector/serviceaccount_test.go index 3a7c3ec351..f273526c92 100644 --- a/internal/manifests/collector/serviceaccount_test.go +++ b/internal/manifests/collector/serviceaccount_test.go @@ -20,6 +20,7 @@ import ( "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" . "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector" ) @@ -46,7 +47,7 @@ func TestServiceAccountOverride(t *testing.T) { Name: "my-instance", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ ServiceAccount: "my-special-sa", }, }, diff --git a/internal/manifests/collector/statefulset_test.go b/internal/manifests/collector/statefulset_test.go index 5e0af9d110..c2fe017534 100644 --- a/internal/manifests/collector/statefulset_test.go +++ b/internal/manifests/collector/statefulset_test.go @@ -25,6 +25,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" @@ -40,7 +41,7 @@ func TestStatefulSetNewDefault(t *testing.T) { }, Spec: v1beta1.OpenTelemetryCollectorSpec{ Mode: "statefulset", - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Tolerations: testTolerationValues, }, }, @@ -115,7 +116,7 @@ func TestStatefulSetReplicas(t *testing.T) { }, Spec: v1beta1.OpenTelemetryCollectorSpec{ Mode: "statefulset", - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &replicaInt, }, }, @@ -144,7 +145,7 @@ func TestStatefulSetVolumeClaimTemplates(t *testing.T) { }, Spec: v1beta1.OpenTelemetryCollectorSpec{ Mode: "statefulset", - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{ ObjectMeta: metav1.ObjectMeta{ Name: "added-volume", @@ -189,7 +190,7 @@ func TestStatefulSetPodAnnotations(t *testing.T) { Name: "my-instance", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PodAnnotations: testPodAnnotationValues, }, }, @@ -231,7 +232,7 @@ func TestStatefulSetPodSecurityContext(t *testing.T) { Name: "my-instance", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PodSecurityContext: &v1.PodSecurityContext{ RunAsNonRoot: &runAsNonRoot, RunAsUser: &runAsUser, @@ -285,7 +286,7 @@ func TestStatefulSetHostNetwork(t *testing.T) { Name: "my-instance-hostnetwork", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ HostNetwork: true, }, }, @@ -394,7 +395,7 @@ func TestStatefulSetNodeSelector(t *testing.T) { Name: "my-instance-nodeselector", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ HostNetwork: true, NodeSelector: map[string]string{ "node-key": "node-value", @@ -442,7 +443,7 @@ func TestStatefulSetPriorityClassName(t *testing.T) { Name: "my-instance-priortyClassName", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PriorityClassName: priorityClassName, }, }, @@ -485,7 +486,7 @@ func TestStatefulSetAffinity(t *testing.T) { Name: "my-instance-priortyClassName", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Affinity: testAffinityValue, }, }, @@ -513,7 +514,7 @@ func TestStatefulSetInitContainer(t *testing.T) { Namespace: "my-namespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ InitContainers: []v1.Container{ { Name: "test", @@ -567,7 +568,7 @@ func TestStatefulSetTopologySpreadConstraints(t *testing.T) { Name: "my-instance-topologyspreadconstraint", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ TopologySpreadConstraints: testTopologySpreadConstraintValue, }, }, @@ -597,7 +598,7 @@ func TestStatefulSetAdditionalContainers(t *testing.T) { Namespace: "my-namespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ AdditionalContainers: []v1.Container{ { Name: "test", @@ -652,7 +653,7 @@ func TestStatefulSetShareProcessNamespace(t *testing.T) { Name: "my-instance-with-shareprocessnamespace", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ ShareProcessNamespace: true, }, }, diff --git a/internal/manifests/collector/suite_test.go b/internal/manifests/collector/suite_test.go index 1f2654ba60..c7a225490c 100644 --- a/internal/manifests/collector/suite_test.go +++ b/internal/manifests/collector/suite_test.go @@ -26,6 +26,7 @@ import ( "k8s.io/client-go/tools/record" logf "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/openshift" "github.com/open-telemetry/opentelemetry-operator/internal/autodetect/prometheus" @@ -53,7 +54,7 @@ func paramsWithMode(mode v1beta1.Mode) manifests.Params { if err != nil { fmt.Printf("Error getting yaml file: %v", err) } - cfg := v1beta1.Config{} + cfg := common.Config{} err = go_yaml.Unmarshal(configYAML, &cfg) if err != nil { fmt.Printf("Error unmarshalling YAML: %v", err) @@ -75,10 +76,10 @@ func paramsWithMode(mode v1beta1.Mode) manifests.Params { UID: instanceUID, }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Image: "ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.47.0", - Ports: []v1beta1.PortsSpec{ + Ports: []common.PortsSpec{ { ServicePort: v1.ServicePort{ Name: "web", @@ -116,7 +117,7 @@ func newParams(taContainerImage string, file string, options ...config.Option) ( return manifests.Params{}, fmt.Errorf("error getting yaml file: %w", err) } - colCfg := v1beta1.Config{} + colCfg := common.Config{} err = go_yaml.Unmarshal(configYAML, &colCfg) if err != nil { return manifests.Params{}, fmt.Errorf("failed to unmarshal config: %w", err) @@ -142,8 +143,8 @@ func newParams(taContainerImage string, file string, options ...config.Option) ( UID: instanceUID, }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Ports: []v1beta1.PortsSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Ports: []common.PortsSpec{ { ServicePort: v1.ServicePort{ Name: "web", diff --git a/internal/manifests/collector/targetallocator.go b/internal/manifests/collector/targetallocator.go index 4083d4c3f7..ffcc111127 100644 --- a/internal/manifests/collector/targetallocator.go +++ b/internal/manifests/collector/targetallocator.go @@ -17,14 +17,15 @@ package collector import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters" ) // TargetAllocator builds the TargetAllocator CR for the given instance. -func TargetAllocator(params manifests.Params) (*v1beta1.TargetAllocator, error) { +func TargetAllocator(params manifests.Params) (*v1alpha1.TargetAllocator, error) { taSpec := params.OtelCol.Spec.TargetAllocator if !taSpec.Enabled { @@ -44,15 +45,15 @@ func TargetAllocator(params manifests.Params) (*v1beta1.TargetAllocator, error) return nil, err } - return &v1beta1.TargetAllocator{ + return &v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: params.OtelCol.Name, Namespace: params.OtelCol.Namespace, Annotations: params.OtelCol.Annotations, Labels: params.OtelCol.Labels, }, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: taSpec.Replicas, NodeSelector: taSpec.NodeSelector, Resources: taSpec.Resources, @@ -77,7 +78,7 @@ func TargetAllocator(params manifests.Params) (*v1beta1.TargetAllocator, error) }, nil } -func getScrapeConfigs(otelcolConfig string) ([]v1beta1.AnyConfig, error) { +func getScrapeConfigs(otelcolConfig string) ([]common.AnyConfig, error) { // Collector supports environment variable substitution, but the TA does not. // TA Scrape Configs should have a single "$", as it does not support env var substitution prometheusReceiverConfig, err := adapters.UnescapeDollarSignsInPromConfig(otelcolConfig) @@ -90,10 +91,10 @@ func getScrapeConfigs(otelcolConfig string) ([]v1beta1.AnyConfig, error) { return nil, err } - v1beta1scrapeConfigs := make([]v1beta1.AnyConfig, len(scrapeConfigs)) + v1beta1scrapeConfigs := make([]common.AnyConfig, len(scrapeConfigs)) for i, config := range scrapeConfigs { - v1beta1scrapeConfigs[i] = v1beta1.AnyConfig{Object: config} + v1beta1scrapeConfigs[i] = common.AnyConfig{Object: config} } return v1beta1scrapeConfigs, nil diff --git a/internal/manifests/collector/targetallocator_test.go b/internal/manifests/collector/targetallocator_test.go index 76a51b66ef..1413aa3f8e 100644 --- a/internal/manifests/collector/targetallocator_test.go +++ b/internal/manifests/collector/targetallocator_test.go @@ -26,6 +26,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" + "github.com/open-telemetry/opentelemetry-operator/apis/common" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" @@ -47,8 +49,8 @@ func TestTargetAllocator(t *testing.T) { privileged := true runAsUser := int64(1337) runasGroup := int64(1338) - otelcolConfig := v1beta1.Config{ - Receivers: v1beta1.AnyConfig{ + otelcolConfig := common.Config{ + Receivers: common.AnyConfig{ Object: map[string]interface{}{ "prometheus": map[string]any{ "config": map[string]any{ @@ -62,7 +64,7 @@ func TestTargetAllocator(t *testing.T) { testCases := []struct { name string input v1beta1.OpenTelemetryCollector - want *v1beta1.TargetAllocator + want *v1alpha1.TargetAllocator wantErr error }{ { @@ -87,13 +89,13 @@ func TestTargetAllocator(t *testing.T) { }, }, }, - want: &v1beta1.TargetAllocator{ + want: &v1alpha1.TargetAllocator{ ObjectMeta: objectMetadata, - Spec: v1beta1.TargetAllocatorSpec{ + Spec: v1alpha1.TargetAllocatorSpec{ CollectorSelector: metav1.LabelSelector{ MatchLabels: manifestutils.SelectorLabels(objectMetadata, ComponentOpenTelemetryCollector), }, - ScrapeConfigs: []v1beta1.AnyConfig{}, + ScrapeConfigs: []common.AnyConfig{}, }, }, }, @@ -115,7 +117,7 @@ func TestTargetAllocator(t *testing.T) { v1.ResourceMemory: resource.MustParse("128Mi"), }, }, - AllocationStrategy: v1beta1.TargetAllocatorAllocationStrategyConsistentHashing, + AllocationStrategy: common.TargetAllocatorAllocationStrategyConsistentHashing, FilterStrategy: "relabel-config", ServiceAccount: "serviceAccountName", Image: "custom_image", @@ -137,7 +139,7 @@ func TestTargetAllocator(t *testing.T) { }, }, }, - PrometheusCR: v1beta1.TargetAllocatorPrometheusCR{ + PrometheusCR: common.TargetAllocatorPrometheusCR{ Enabled: true, ScrapeInterval: &metav1.Duration{Duration: time.Second}, PodMonitorSelector: &metav1.LabelSelector{ @@ -185,12 +187,12 @@ func TestTargetAllocator(t *testing.T) { }, }, }, - Observability: v1beta1.ObservabilitySpec{ - Metrics: v1beta1.MetricsConfigSpec{ + Observability: common.ObservabilitySpec{ + Metrics: common.MetricsConfigSpec{ EnableMetrics: true, }, }, - PodDisruptionBudget: &v1beta1.PodDisruptionBudgetSpec{ + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -200,10 +202,10 @@ func TestTargetAllocator(t *testing.T) { Config: otelcolConfig, }, }, - want: &v1beta1.TargetAllocator{ + want: &v1alpha1.TargetAllocator{ ObjectMeta: objectMetadata, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Replicas: &replicas, NodeSelector: map[string]string{"key": "value"}, Resources: v1.ResourceRequirements{ @@ -274,7 +276,7 @@ func TestTargetAllocator(t *testing.T) { }, }, - PodDisruptionBudget: &v1beta1.PodDisruptionBudgetSpec{ + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MaxUnavailable: &intstr.IntOrString{ Type: intstr.Int, IntVal: 1, @@ -284,9 +286,9 @@ func TestTargetAllocator(t *testing.T) { CollectorSelector: metav1.LabelSelector{ MatchLabels: manifestutils.SelectorLabels(objectMetadata, ComponentOpenTelemetryCollector), }, - AllocationStrategy: v1beta1.TargetAllocatorAllocationStrategyConsistentHashing, - FilterStrategy: v1beta1.TargetAllocatorFilterStrategyRelabelConfig, - PrometheusCR: v1beta1.TargetAllocatorPrometheusCR{ + AllocationStrategy: common.TargetAllocatorAllocationStrategyConsistentHashing, + FilterStrategy: common.TargetAllocatorFilterStrategyRelabelConfig, + PrometheusCR: common.TargetAllocatorPrometheusCR{ Enabled: true, ScrapeInterval: &metav1.Duration{Duration: time.Second}, PodMonitorSelector: &metav1.LabelSelector{ @@ -296,9 +298,9 @@ func TestTargetAllocator(t *testing.T) { MatchLabels: map[string]string{"servicemonitorkey": "servicemonitorkey"}, }, }, - ScrapeConfigs: []v1beta1.AnyConfig{}, - Observability: v1beta1.ObservabilitySpec{ - Metrics: v1beta1.MetricsConfigSpec{ + ScrapeConfigs: []common.AnyConfig{}, + Observability: common.ObservabilitySpec{ + Metrics: common.MetricsConfigSpec{ EnableMetrics: true, }, }, @@ -323,14 +325,14 @@ func TestTargetAllocator(t *testing.T) { func TestGetScrapeConfigs(t *testing.T) { testCases := []struct { name string - input v1beta1.Config - want []v1beta1.AnyConfig + input common.Config + want []common.AnyConfig wantErr error }{ { name: "empty scrape configs list", - input: v1beta1.Config{ - Receivers: v1beta1.AnyConfig{ + input: common.Config{ + Receivers: common.AnyConfig{ Object: map[string]interface{}{ "prometheus": map[string]any{ "config": map[string]any{ @@ -340,12 +342,12 @@ func TestGetScrapeConfigs(t *testing.T) { }, }, }, - want: []v1beta1.AnyConfig{}, + want: []common.AnyConfig{}, }, { name: "no scrape configs key", - input: v1beta1.Config{ - Receivers: v1beta1.AnyConfig{ + input: common.Config{ + Receivers: common.AnyConfig{ Object: map[string]interface{}{ "prometheus": map[string]any{ "config": map[string]any{}, @@ -357,8 +359,8 @@ func TestGetScrapeConfigs(t *testing.T) { }, { name: "one scrape config", - input: v1beta1.Config{ - Receivers: v1beta1.AnyConfig{ + input: common.Config{ + Receivers: common.AnyConfig{ Object: map[string]interface{}{ "prometheus": map[string]any{ "config": map[string]any{ @@ -372,14 +374,14 @@ func TestGetScrapeConfigs(t *testing.T) { }, }, }, - want: []v1beta1.AnyConfig{ + want: []common.AnyConfig{ {Object: map[string]interface{}{"job": "somejob"}}, }, }, { name: "regex substitution", - input: v1beta1.Config{ - Receivers: v1beta1.AnyConfig{ + input: common.Config{ + Receivers: common.AnyConfig{ Object: map[string]interface{}{ "prometheus": map[string]any{ "config": map[string]any{ @@ -400,7 +402,7 @@ func TestGetScrapeConfigs(t *testing.T) { }, }, }, - want: []v1beta1.AnyConfig{ + want: []common.AnyConfig{ {Object: map[string]interface{}{ "job": "somejob", "metric_relabel_configs": []any{ diff --git a/internal/manifests/collector/volume_test.go b/internal/manifests/collector/volume_test.go index 06832e6314..37f4b611ec 100644 --- a/internal/manifests/collector/volume_test.go +++ b/internal/manifests/collector/volume_test.go @@ -20,6 +20,7 @@ import ( "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" . "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector" @@ -45,7 +46,7 @@ func TestVolumeAllowsMoreToBeAdded(t *testing.T) { // prepare otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Volumes: []corev1.Volume{{ Name: "my-volume", }}, diff --git a/internal/manifests/collector/volumeclaim_test.go b/internal/manifests/collector/volumeclaim_test.go index df34a41ab0..1a194bfed8 100644 --- a/internal/manifests/collector/volumeclaim_test.go +++ b/internal/manifests/collector/volumeclaim_test.go @@ -22,6 +22,7 @@ import ( "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" . "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector" ) @@ -31,7 +32,7 @@ func TestVolumeClaimAllowsUserToAdd(t *testing.T) { otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ Mode: "statefulset", - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{ ObjectMeta: metav1.ObjectMeta{ Name: "added-volume", @@ -68,7 +69,7 @@ func TestVolumeClaimChecksForStatefulset(t *testing.T) { otelcol := v1beta1.OpenTelemetryCollector{ Spec: v1beta1.OpenTelemetryCollectorSpec{ Mode: "daemonset", - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ VolumeClaimTemplates: []corev1.PersistentVolumeClaim{{ ObjectMeta: metav1.ObjectMeta{ Name: "added-volume", diff --git a/internal/manifests/manifestutils/annotations.go b/internal/manifests/manifestutils/annotations.go index 06f1baed81..7291c96b7e 100644 --- a/internal/manifests/manifestutils/annotations.go +++ b/internal/manifests/manifestutils/annotations.go @@ -19,6 +19,7 @@ import ( "encoding/json" "fmt" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" ) @@ -88,7 +89,7 @@ func PodAnnotations(instance v1beta1.OpenTelemetryCollector, filterAnnotations [ return podAnnotations, nil } -func getConfigMapSHA(config v1beta1.Config) (string, error) { +func getConfigMapSHA(config common.Config) (string, error) { b, err := json.Marshal(&config) if err != nil { return "", err diff --git a/internal/manifests/manifestutils/annotations_test.go b/internal/manifests/manifestutils/annotations_test.go index 3d1926eeae..a436080fce 100644 --- a/internal/manifests/manifestutils/annotations_test.go +++ b/internal/manifests/manifestutils/annotations_test.go @@ -21,6 +21,7 @@ import ( "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" ) @@ -32,8 +33,8 @@ func TestDefaultAnnotations(t *testing.T) { Namespace: "my-ns", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - Config: v1beta1.Config{ - Service: v1beta1.Service{ + Config: common.Config{ + Service: common.Service{ Extensions: func() *[]string { res := []string{"test"} return &res @@ -69,8 +70,8 @@ func TestNonDefaultPodAnnotation(t *testing.T) { Namespace: "my-ns", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - Observability: v1beta1.ObservabilitySpec{ - Metrics: v1beta1.MetricsConfigSpec{ + Observability: common.ObservabilitySpec{ + Metrics: common.MetricsConfigSpec{ DisablePrometheusAnnotations: true, }, }, @@ -108,8 +109,8 @@ func TestUserAnnotations(t *testing.T) { }, }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - Config: v1beta1.Config{ - Service: v1beta1.Service{ + Config: common.Config{ + Service: common.Service{ Extensions: func() *[]string { res := []string{"test2"} return &res @@ -140,7 +141,7 @@ func TestAnnotationsPropagateDown(t *testing.T) { Annotations: map[string]string{"myapp": "mycomponent"}, }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PodAnnotations: map[string]string{"pod_annotation": "pod_annotation_value"}, }, }, diff --git a/internal/manifests/manifestutils/labels.go b/internal/manifests/manifestutils/labels.go index b31fd8ff92..2e335b8456 100644 --- a/internal/manifests/manifestutils/labels.go +++ b/internal/manifests/manifestutils/labels.go @@ -20,7 +20,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) @@ -84,7 +84,7 @@ func SelectorLabels(instance metav1.ObjectMeta, component string) map[string]str } // SelectorLabels return the selector labels for Target Allocator Pods. -func TASelectorLabels(instance v1beta1.TargetAllocator, component string) map[string]string { +func TASelectorLabels(instance v1alpha1.TargetAllocator, component string) map[string]string { selectorLabels := SelectorLabels(instance.ObjectMeta, component) // TargetAllocator uses the name label as well for selection diff --git a/internal/manifests/manifestutils/labels_test.go b/internal/manifests/manifestutils/labels_test.go index 22fc5eb33d..90faf23adc 100644 --- a/internal/manifests/manifestutils/labels_test.go +++ b/internal/manifests/manifestutils/labels_test.go @@ -21,7 +21,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) @@ -163,7 +162,7 @@ func TestSelectorLabels(t *testing.T) { "app.kubernetes.io/name": "my-opentelemetry-collector-targetallocator", "app.kubernetes.io/part-of": "opentelemetry", } - tainstance := v1beta1.TargetAllocator{ + tainstance := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{Name: "my-opentelemetry-collector", Namespace: "my-namespace"}, } @@ -176,7 +175,7 @@ func TestSelectorLabels(t *testing.T) { func TestLabelsTACommonSet(t *testing.T) { // prepare - tainstance := v1beta1.TargetAllocator{ + tainstance := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: taname, Namespace: tanamespace, @@ -195,7 +194,7 @@ func TestLabelsTACommonSet(t *testing.T) { func TestLabelsTAPropagateDown(t *testing.T) { // prepare - tainstance := v1beta1.TargetAllocator{ + tainstance := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ "myapp": "mycomponent", @@ -218,7 +217,7 @@ func TestLabelsTAPropagateDown(t *testing.T) { func TestSelectorTALabels(t *testing.T) { // prepare - tainstance := v1beta1.TargetAllocator{ + tainstance := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: taname, Namespace: tanamespace, diff --git a/internal/manifests/params.go b/internal/manifests/params.go index de80cbc966..7e12a74b4d 100644 --- a/internal/manifests/params.go +++ b/internal/manifests/params.go @@ -32,7 +32,7 @@ type Params struct { Scheme *runtime.Scheme Log logr.Logger OtelCol v1beta1.OpenTelemetryCollector - TargetAllocator v1beta1.TargetAllocator + TargetAllocator v1alpha1.TargetAllocator OpAMPBridge v1alpha1.OpAMPBridge Config config.Config } diff --git a/internal/manifests/targetallocator/annotations.go b/internal/manifests/targetallocator/annotations.go index 7666bd64ab..263b6234b1 100644 --- a/internal/manifests/targetallocator/annotations.go +++ b/internal/manifests/targetallocator/annotations.go @@ -20,14 +20,14 @@ import ( v1 "k8s.io/api/core/v1" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" ) const configMapHashAnnotationKey = "opentelemetry-targetallocator-config/hash" // Annotations returns the annotations for the TargetAllocator Pod. -func Annotations(instance v1beta1.TargetAllocator, configMap *v1.ConfigMap, filterAnnotations []string) map[string]string { +func Annotations(instance v1alpha1.TargetAllocator, configMap *v1.ConfigMap, filterAnnotations []string) map[string]string { // Make a copy of PodAnnotations to be safe annotations := make(map[string]string, len(instance.Spec.PodAnnotations)) for key, value := range instance.Spec.PodAnnotations { diff --git a/internal/manifests/targetallocator/configmap.go b/internal/manifests/targetallocator/configmap.go index 09a3c5f48f..923f95bf07 100644 --- a/internal/manifests/targetallocator/configmap.go +++ b/internal/manifests/targetallocator/configmap.go @@ -19,7 +19,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/naming" @@ -49,7 +49,7 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) { if len(taSpec.AllocationStrategy) > 0 { taConfig["allocation_strategy"] = taSpec.AllocationStrategy } else { - taConfig["allocation_strategy"] = v1beta1.TargetAllocatorAllocationStrategyConsistentHashing + taConfig["allocation_strategy"] = common.TargetAllocatorAllocationStrategyConsistentHashing } taConfig["filter_strategy"] = taSpec.FilterStrategy diff --git a/internal/manifests/targetallocator/configmap_test.go b/internal/manifests/targetallocator/configmap_test.go index 05992196cc..84202118b0 100644 --- a/internal/manifests/targetallocator/configmap_test.go +++ b/internal/manifests/targetallocator/configmap_test.go @@ -23,7 +23,7 @@ import ( "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" ) @@ -101,7 +101,7 @@ prometheus_cr: } collector := collectorInstance() targetAllocator := targetAllocatorInstance() - targetAllocator.Spec.ScrapeConfigs = []v1beta1.AnyConfig{} + targetAllocator.Spec.ScrapeConfigs = []common.AnyConfig{} cfg := config.New() params := manifests.Params{ OtelCol: collector, diff --git a/internal/manifests/targetallocator/container.go b/internal/manifests/targetallocator/container.go index 17e8d3772f..f23bae177b 100644 --- a/internal/manifests/targetallocator/container.go +++ b/internal/manifests/targetallocator/container.go @@ -20,13 +20,13 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) // Container builds a container for the given TargetAllocator. -func Container(cfg config.Config, logger logr.Logger, instance v1beta1.TargetAllocator) corev1.Container { +func Container(cfg config.Config, logger logr.Logger, instance v1alpha1.TargetAllocator) corev1.Container { image := instance.Spec.Image if len(image) == 0 { image = cfg.TargetAllocatorImage() diff --git a/internal/manifests/targetallocator/container_test.go b/internal/manifests/targetallocator/container_test.go index fb9ef9fe2d..42a3f36285 100644 --- a/internal/manifests/targetallocator/container_test.go +++ b/internal/manifests/targetallocator/container_test.go @@ -25,7 +25,8 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" logf "sigs.k8s.io/controller-runtime/pkg/log" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) @@ -34,7 +35,7 @@ var logger = logf.Log.WithName("unit-tests") func TestContainerNewDefault(t *testing.T) { // prepare - targetAllocator := v1beta1.TargetAllocator{} + targetAllocator := v1alpha1.TargetAllocator{} cfg := config.New(config.WithTargetAllocatorImage("default-image")) // test @@ -46,9 +47,9 @@ func TestContainerNewDefault(t *testing.T) { func TestContainerWithImageOverridden(t *testing.T) { // prepare - targetAllocator := v1beta1.TargetAllocator{ - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + targetAllocator := v1alpha1.TargetAllocator{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Image: "overridden-image", }, }, @@ -64,7 +65,7 @@ func TestContainerWithImageOverridden(t *testing.T) { func TestContainerPorts(t *testing.T) { // prepare - targetAllocator := v1beta1.TargetAllocator{} + targetAllocator := v1alpha1.TargetAllocator{} cfg := config.New() // test @@ -78,7 +79,7 @@ func TestContainerPorts(t *testing.T) { func TestContainerVolumes(t *testing.T) { // prepare - targetAllocator := v1beta1.TargetAllocator{} + targetAllocator := v1alpha1.TargetAllocator{} cfg := config.New() // test @@ -90,9 +91,9 @@ func TestContainerVolumes(t *testing.T) { } func TestContainerResourceRequirements(t *testing.T) { - targetAllocator := v1beta1.TargetAllocator{ - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + targetAllocator := v1alpha1.TargetAllocator{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ corev1.ResourceCPU: resource.MustParse("100m"), @@ -128,9 +129,9 @@ func TestContainerResourceRequirements(t *testing.T) { func TestContainerHasEnvVars(t *testing.T) { // prepare - targetAllocator := v1beta1.TargetAllocator{ - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + targetAllocator := v1alpha1.TargetAllocator{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Env: []corev1.EnvVar{ { Name: "TEST_ENV", @@ -212,9 +213,9 @@ func TestContainerHasProxyEnvVars(t *testing.T) { defer os.Unsetenv("NO_PROXY") // prepare - targetAllocator := v1beta1.TargetAllocator{ - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + targetAllocator := v1alpha1.TargetAllocator{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Env: []corev1.EnvVar{ { Name: "TEST_ENV", @@ -237,9 +238,9 @@ func TestContainerHasProxyEnvVars(t *testing.T) { func TestContainerDoesNotOverrideEnvVars(t *testing.T) { // prepare - targetAllocator := v1beta1.TargetAllocator{ - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + targetAllocator := v1alpha1.TargetAllocator{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Env: []corev1.EnvVar{ { Name: "OTELCOL_NAMESPACE", @@ -302,7 +303,7 @@ func TestContainerDoesNotOverrideEnvVars(t *testing.T) { assert.Equal(t, expected, c) } func TestReadinessProbe(t *testing.T) { - targetAllocator := v1beta1.TargetAllocator{} + targetAllocator := v1alpha1.TargetAllocator{} cfg := config.New() expected := &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ @@ -321,7 +322,7 @@ func TestReadinessProbe(t *testing.T) { } func TestLivenessProbe(t *testing.T) { // prepare - targetAllocator := v1beta1.TargetAllocator{} + targetAllocator := v1alpha1.TargetAllocator{} cfg := config.New() expected := &corev1.Probe{ ProbeHandler: corev1.ProbeHandler{ @@ -345,9 +346,9 @@ func TestSecurityContext(t *testing.T) { RunAsNonRoot: &runAsNonRoot, } // prepare - targetAllocator := v1beta1.TargetAllocator{ - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + targetAllocator := v1alpha1.TargetAllocator{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ SecurityContext: securityContext, }, }, diff --git a/internal/manifests/targetallocator/deployment_test.go b/internal/manifests/targetallocator/deployment_test.go index 1767696fdb..a7a72dcd30 100644 --- a/internal/manifests/targetallocator/deployment_test.go +++ b/internal/manifests/targetallocator/deployment_test.go @@ -24,6 +24,8 @@ import ( v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" @@ -79,7 +81,7 @@ var testSecurityContextValue = &v1.PodSecurityContext{ func TestDeploymentSecurityContext(t *testing.T) { // Test default - targetallocator11 := v1beta1.TargetAllocator{ + targetallocator11 := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -99,12 +101,12 @@ func TestDeploymentSecurityContext(t *testing.T) { assert.Empty(t, d1.Spec.Template.Spec.SecurityContext) // Test SecurityContext - targetAllocator2 := v1beta1.TargetAllocator{ + targetAllocator2 := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-securitycontext", }, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ PodSecurityContext: testSecurityContextValue, }, }, @@ -185,7 +187,7 @@ func collectorInstance() v1beta1.OpenTelemetryCollector { if err != nil { fmt.Printf("Error getting yaml file: %v", err) } - cfg := v1beta1.Config{} + cfg := common.Config{} err = go_yaml.Unmarshal(configYAML, &cfg) if err != nil { fmt.Printf("Error unmarshalling YAML: %v", err) @@ -196,7 +198,7 @@ func collectorInstance() v1beta1.OpenTelemetryCollector { Namespace: "default", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Image: "ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.47.0", }, Config: cfg, @@ -208,7 +210,7 @@ func collectorInstance() v1beta1.OpenTelemetryCollector { } } -func targetAllocatorInstance() v1beta1.TargetAllocator { +func targetAllocatorInstance() v1alpha1.TargetAllocator { collectorInstance := collectorInstance() collectorInstance.Spec.TargetAllocator.Enabled = true params := manifests.Params{OtelCol: collectorInstance} @@ -219,7 +221,7 @@ func targetAllocatorInstance() v1beta1.TargetAllocator { func TestDeploymentNodeSelector(t *testing.T) { // Test default - targetAllocator1 := v1beta1.TargetAllocator{} + targetAllocator1 := v1alpha1.TargetAllocator{} cfg := config.New() @@ -233,12 +235,12 @@ func TestDeploymentNodeSelector(t *testing.T) { assert.Empty(t, d1.Spec.Template.Spec.NodeSelector) // Test nodeSelector - targetAllocator2 := v1beta1.TargetAllocator{ + targetAllocator2 := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-nodeselector", }, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ NodeSelector: map[string]string{ "node-key": "node-value", }, @@ -261,7 +263,7 @@ func TestDeploymentNodeSelector(t *testing.T) { func TestDeploymentAffinity(t *testing.T) { // Test default - targetAllocator1 := v1beta1.TargetAllocator{} + targetAllocator1 := v1alpha1.TargetAllocator{} cfg := config.New() @@ -275,12 +277,12 @@ func TestDeploymentAffinity(t *testing.T) { assert.Empty(t, d1.Spec.Template.Spec.Affinity) // Test affinity - targetAllocator2 := v1beta1.TargetAllocator{ + targetAllocator2 := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-affinity", }, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Affinity: testAffinityValue, }, }, @@ -301,7 +303,7 @@ func TestDeploymentAffinity(t *testing.T) { func TestDeploymentTolerations(t *testing.T) { // Test default - targetAllocator1 := v1beta1.TargetAllocator{ + targetAllocator1 := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -319,12 +321,12 @@ func TestDeploymentTolerations(t *testing.T) { assert.Empty(t, d1.Spec.Template.Spec.Tolerations) // Test Tolerations - targetAllocator2 := v1beta1.TargetAllocator{ + targetAllocator2 := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-toleration", }, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Tolerations: testTolerationValues, }, }, @@ -345,7 +347,7 @@ func TestDeploymentTolerations(t *testing.T) { func TestDeploymentTopologySpreadConstraints(t *testing.T) { // Test default - targetAllocator1 := v1beta1.TargetAllocator{ + targetAllocator1 := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -364,12 +366,12 @@ func TestDeploymentTopologySpreadConstraints(t *testing.T) { assert.Empty(t, d1.Spec.Template.Spec.TopologySpreadConstraints) // Test TopologySpreadConstraints - targetAllocator2 := v1beta1.TargetAllocator{ + targetAllocator2 := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance-topologyspreadconstraint", }, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ TopologySpreadConstraints: testTopologySpreadConstraintValue, }, }, diff --git a/internal/manifests/targetallocator/poddisruptionbudget.go b/internal/manifests/targetallocator/poddisruptionbudget.go index 695f4ed0fd..fa0b666657 100644 --- a/internal/manifests/targetallocator/poddisruptionbudget.go +++ b/internal/manifests/targetallocator/poddisruptionbudget.go @@ -20,7 +20,7 @@ import ( policyV1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/naming" @@ -36,7 +36,7 @@ func PodDisruptionBudget(params manifests.Params) (*policyV1.PodDisruptionBudget // defaulter doesn't set PodDisruptionBudget if the strategy isn't valid, // if PodDisruptionBudget != nil and stategy isn't correct, users have set // it wrongly - if params.TargetAllocator.Spec.AllocationStrategy != v1beta1.TargetAllocatorAllocationStrategyConsistentHashing { + if params.TargetAllocator.Spec.AllocationStrategy != common.TargetAllocatorAllocationStrategyConsistentHashing { params.Log.V(4).Info("current allocation strategy not compatible, skipping podDisruptionBudget creation") return nil, fmt.Errorf("target allocator pdb has been configured but the allocation strategy isn't not compatible") } diff --git a/internal/manifests/targetallocator/poddisruptionbudget_test.go b/internal/manifests/targetallocator/poddisruptionbudget_test.go index 3beb7d1ee3..b30889571c 100644 --- a/internal/manifests/targetallocator/poddisruptionbudget_test.go +++ b/internal/manifests/targetallocator/poddisruptionbudget_test.go @@ -21,7 +21,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" ) @@ -66,18 +67,18 @@ var tests = []test{ func TestPDBWithValidStrategy(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - targetAllocator := v1beta1.TargetAllocator{ + targetAllocator := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - PodDisruptionBudget: &v1beta1.PodDisruptionBudgetSpec{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MinAvailable: test.MinAvailable, MaxUnavailable: test.MaxUnavailable, }, }, - AllocationStrategy: v1beta1.TargetAllocatorAllocationStrategyConsistentHashing, + AllocationStrategy: common.TargetAllocatorAllocationStrategyConsistentHashing, }, } configuration := config.New() @@ -100,18 +101,18 @@ func TestPDBWithValidStrategy(t *testing.T) { func TestPDBWithNotValidStrategy(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - targetAllocator := v1beta1.TargetAllocator{ + targetAllocator := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - PodDisruptionBudget: &v1beta1.PodDisruptionBudgetSpec{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + PodDisruptionBudget: &common.PodDisruptionBudgetSpec{ MinAvailable: test.MinAvailable, MaxUnavailable: test.MaxUnavailable, }, }, - AllocationStrategy: v1beta1.TargetAllocatorAllocationStrategyLeastWeighted, + AllocationStrategy: common.TargetAllocatorAllocationStrategyLeastWeighted, }, } configuration := config.New() @@ -129,9 +130,9 @@ func TestPDBWithNotValidStrategy(t *testing.T) { } func TestNoPDB(t *testing.T) { - targetAllocator := v1beta1.TargetAllocator{ - Spec: v1beta1.TargetAllocatorSpec{ - AllocationStrategy: v1beta1.TargetAllocatorAllocationStrategyLeastWeighted, + targetAllocator := v1alpha1.TargetAllocator{ + Spec: v1alpha1.TargetAllocatorSpec{ + AllocationStrategy: common.TargetAllocatorAllocationStrategyLeastWeighted, }, } configuration := config.New() diff --git a/internal/manifests/targetallocator/serviceaccount.go b/internal/manifests/targetallocator/serviceaccount.go index e38e64b557..05ae797ef1 100644 --- a/internal/manifests/targetallocator/serviceaccount.go +++ b/internal/manifests/targetallocator/serviceaccount.go @@ -18,14 +18,14 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) // ServiceAccountName returns the name of the existing or self-provisioned service account to use for the given instance. -func ServiceAccountName(instance v1beta1.TargetAllocator) string { +func ServiceAccountName(instance v1alpha1.TargetAllocator) string { if len(instance.Spec.ServiceAccount) == 0 { return naming.TargetAllocatorServiceAccount(instance.Name) } diff --git a/internal/manifests/targetallocator/serviceaccount_test.go b/internal/manifests/targetallocator/serviceaccount_test.go index f8bd532f9e..66a87c4164 100644 --- a/internal/manifests/targetallocator/serviceaccount_test.go +++ b/internal/manifests/targetallocator/serviceaccount_test.go @@ -21,14 +21,15 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" ) func TestServiceAccountDefaultName(t *testing.T) { // prepare - targetAllocator := v1beta1.TargetAllocator{ + targetAllocator := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -43,12 +44,12 @@ func TestServiceAccountDefaultName(t *testing.T) { func TestServiceAccountOverrideName(t *testing.T) { // prepare - targetAllocator := v1beta1.TargetAllocator{ + targetAllocator := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ ServiceAccount: "my-special-sa", }, }, @@ -63,7 +64,7 @@ func TestServiceAccountOverrideName(t *testing.T) { func TestServiceAccountDefault(t *testing.T) { params := manifests.Params{ - TargetAllocator: v1beta1.TargetAllocator{ + TargetAllocator: v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, @@ -87,12 +88,12 @@ func TestServiceAccountDefault(t *testing.T) { func TestServiceAccountOverride(t *testing.T) { params := manifests.Params{ - TargetAllocator: v1beta1.TargetAllocator{ + TargetAllocator: v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", }, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ ServiceAccount: "my-special-sa", }, }, diff --git a/internal/manifests/targetallocator/servicemonitor_test.go b/internal/manifests/targetallocator/servicemonitor_test.go index a39c5aec46..5b7ccf6db9 100644 --- a/internal/manifests/targetallocator/servicemonitor_test.go +++ b/internal/manifests/targetallocator/servicemonitor_test.go @@ -21,19 +21,20 @@ import ( "github.com/stretchr/testify/assert" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/common" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" ) func TestDesiredServiceMonitors(t *testing.T) { - ta := v1beta1.TargetAllocator{ + ta := v1alpha1.TargetAllocator{ ObjectMeta: metav1.ObjectMeta{ Name: "my-instance", Namespace: "my-namespace", }, - Spec: v1beta1.TargetAllocatorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ + Spec: v1alpha1.TargetAllocatorSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ Tolerations: testTolerationValues, }, }, diff --git a/internal/manifests/targetallocator/volume.go b/internal/manifests/targetallocator/volume.go index 3651a9d3ae..2da3a961b2 100644 --- a/internal/manifests/targetallocator/volume.go +++ b/internal/manifests/targetallocator/volume.go @@ -17,13 +17,13 @@ package targetallocator import ( corev1 "k8s.io/api/core/v1" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) // Volumes builds the volumes for the given instance, including the config map volume. -func Volumes(cfg config.Config, instance v1beta1.TargetAllocator) []corev1.Volume { +func Volumes(cfg config.Config, instance v1alpha1.TargetAllocator) []corev1.Volume { volumes := []corev1.Volume{{ Name: naming.TAConfigMapVolume(), VolumeSource: corev1.VolumeSource{ diff --git a/internal/manifests/targetallocator/volume_test.go b/internal/manifests/targetallocator/volume_test.go index 052e1fb20d..6d255e849c 100644 --- a/internal/manifests/targetallocator/volume_test.go +++ b/internal/manifests/targetallocator/volume_test.go @@ -19,14 +19,14 @@ import ( "github.com/stretchr/testify/assert" - "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" + "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) func TestVolumeNewDefault(t *testing.T) { // prepare - otelcol := v1beta1.TargetAllocator{} + otelcol := v1alpha1.TargetAllocator{} cfg := config.New() // test diff --git a/pkg/collector/upgrade/upgrade.go b/pkg/collector/upgrade/upgrade.go index 971689169d..a25512f062 100644 --- a/pkg/collector/upgrade/upgrade.go +++ b/pkg/collector/upgrade/upgrade.go @@ -20,11 +20,12 @@ import ( "fmt" "reflect" - semver "github.com/Masterminds/semver/v3" + "github.com/Masterminds/semver/v3" "github.com/go-logr/logr" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/version" @@ -57,7 +58,7 @@ func (u VersionUpgrade) ManagedInstances(ctx context.Context) error { original := list.Items[i] itemLogger := u.Log.WithValues("name", original.Name, "namespace", original.Namespace) - if original.Spec.ManagementState == v1beta1.ManagementStateUnmanaged { + if original.Spec.ManagementState == common.ManagementStateUnmanaged { itemLogger.Info("skipping upgrade because instance is not managed") continue } diff --git a/pkg/sidecar/pod_test.go b/pkg/sidecar/pod_test.go index c941961181..c892e44ad6 100644 --- a/pkg/sidecar/pod_test.go +++ b/pkg/sidecar/pod_test.go @@ -23,6 +23,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" logf "sigs.k8s.io/controller-runtime/pkg/log" + "github.com/open-telemetry/opentelemetry-operator/apis/common" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/naming" @@ -53,8 +54,8 @@ func TestAddSidecarWhenNoSidecarExists(t *testing.T) { Namespace: "some-app", }, Spec: v1beta1.OpenTelemetryCollectorSpec{ - OpenTelemetryCommonFields: v1beta1.OpenTelemetryCommonFields{ - Ports: []v1beta1.PortsSpec{ + OpenTelemetryCommonFields: common.OpenTelemetryCommonFields{ + Ports: []common.PortsSpec{ { ServicePort: corev1.ServicePort{ Name: "metrics",