Skip to content

Commit

Permalink
wip: change default otel image
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm committed Apr 25, 2024
1 parent 2504f5b commit 07f34b3
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 2 deletions.
60 changes: 59 additions & 1 deletion apis/v1alpha1/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/conversion"

"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
"github.com/open-telemetry/opentelemetry-operator/internal/distros"
"github.com/open-telemetry/opentelemetry-operator/internal/version"
)

var _ conversion.Convertible = &OpenTelemetryCollector{}
Expand Down Expand Up @@ -94,7 +96,7 @@ func tov1beta1(in OpenTelemetryCollector) (v1beta1.OpenTelemetryCollector, error
PodSecurityContext: copy.Spec.PodSecurityContext,
PodAnnotations: copy.Spec.PodAnnotations,
ServiceAccount: copy.Spec.ServiceAccount,
Image: copy.Spec.Image,
Image: tov1beta1Image(copy.Spec.Image, *cfg),
ImagePullPolicy: copy.Spec.ImagePullPolicy,
VolumeMounts: copy.Spec.VolumeMounts,
Ports: tov1beta1Ports(copy.Spec.Ports),
Expand Down Expand Up @@ -270,6 +272,34 @@ func tov1beta1ConfigMaps(in []ConfigMapsSpec) []v1beta1.ConfigMapsSpec {
return mapsSpecs
}

func tov1beta1Image(image string, otelcolConfig v1beta1.Config) string {
if image != "" {
return image
}

config := distros.OtelcolConfig{
Receivers: otelcolConfig.Receivers.Object,
Exporters: otelcolConfig.Exporters.Object,
}
if otelcolConfig.Connectors != nil {
config.Connectors = otelcolConfig.Connectors.Object
}
if otelcolConfig.Processors != nil {
config.Connectors = otelcolConfig.Processors.Object
}
if otelcolConfig.Extensions != nil {
config.Connectors = otelcolConfig.Extensions.Object
}

if distros.IsValidConfigK8sDistro(config) {
return ""
}

return fmt.Sprintf(
"ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector:%s",
version.OpenTelemetryCollector())
}

func tov1alpha1Ports(in []v1beta1.PortsSpec) []PortsSpec {
var ports []PortsSpec

Expand Down Expand Up @@ -466,3 +496,31 @@ func tov1alpha1TA(in v1beta1.TargetAllocatorEmbedded) OpenTelemetryTargetAllocat
PodDisruptionBudget: tov1alpha1PodDisruptionBudget(in.PodDisruptionBudget),
}
}

func tov1alpha1Image(image string, otelcolConfig v1beta1.Config) string {

Check failure on line 500 in apis/v1alpha1/convert.go

View workflow job for this annotation

GitHub Actions / Code standards (linting)

func `tov1alpha1Image` is unused (unused)
if image != "" {
return image
}

config := distros.OtelcolConfig{
Receivers: otelcolConfig.Receivers.Object,
Exporters: otelcolConfig.Exporters.Object,
}
if otelcolConfig.Connectors != nil {
config.Connectors = otelcolConfig.Connectors.Object
}
if otelcolConfig.Processors != nil {
config.Connectors = otelcolConfig.Processors.Object
}
if otelcolConfig.Extensions != nil {
config.Connectors = otelcolConfig.Extensions.Object
}

if distros.IsValidConfigCoreDistro(config) {
return ""
}

return fmt.Sprintf(
"ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-k8s:%s",
version.OpenTelemetryCollector())
}
13 changes: 13 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator
newTag: 0.98.0-5-g8b43fa01
patches:
- patch: '[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--target-allocator-image=ghcr.io/open-telemetry/opentelemetry-operator/target-allocator:v0.98.0-5-g8b43fa01"}]'
target:
kind: Deployment
- patch: '[{"op":"add","path":"/spec/template/spec/containers/0/args/-","value":"--operator-opamp-bridge-image=ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:v0.98.0-5-g8b43fa01"}]'
target:
kind: Deployment
45 changes: 45 additions & 0 deletions internal/distros/coredistro.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package distros

var CoreReceivers = []string{
"hostmetrics",
"jaeger",
"kafka",
"nop",
"opencensus",
"otlp",
"prometheus",
"zipkin",
}
var CoreProcessors = []string{
"attributes",
"batch",
"filter",
"memory_limiter",
"probabilistic_sampler",
"resource",
"span",
}
var CoreExporters = []string{
"debug",
"file",
"kafka",
"logging",
"nop",
"opencensus",
"otlp",
"otlphttp",
"prometheus",
"prometheusremotewrite",
"zipkin",
}

var CoreExtensions = []string{
"health_check",
"memory_ballast",
"pprof",
"zpages",
}

var CoreConnectors = []string{
"forward",
}
88 changes: 88 additions & 0 deletions internal/distros/image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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 distros

import "k8s.io/utils/strings/slices"

type OtelcolConfig struct {
// +kubebuilder:pruning:PreserveUnknownFields
Receivers map[string]any `json:"receivers" yaml:"receivers"`
// +kubebuilder:pruning:PreserveUnknownFields
Exporters map[string]any `json:"exporters" yaml:"exporters"`
// +kubebuilder:pruning:PreserveUnknownFields
Processors map[string]any `json:"processors,omitempty" yaml:"processors,omitempty"`
// +kubebuilder:pruning:PreserveUnknownFields
Connectors map[string]any `json:"connectors,omitempty" yaml:"connectors,omitempty"`
// +kubebuilder:pruning:PreserveUnknownFields
Extensions map[string]any `json:"extensions,omitempty" yaml:"extensions,omitempty"`
}

func IsValidConfigK8sDistro(config OtelcolConfig) bool {
for receiver, _ := range config.Receivers {

Check failure on line 33 in internal/distros/image.go

View workflow job for this annotation

GitHub Actions / Code standards (linting)

S1005: unnecessary assignment to the blank identifier (gosimple)
if !slices.Contains(K8sReceivers, receiver) {
return false
}
}
for exporter, _ := range config.Exporters {

Check failure on line 38 in internal/distros/image.go

View workflow job for this annotation

GitHub Actions / Code standards (linting)

S1005: unnecessary assignment to the blank identifier (gosimple)
if !slices.Contains(K8sExporters, exporter) {
return false
}
}
for processor, _ := range config.Processors {

Check failure on line 43 in internal/distros/image.go

View workflow job for this annotation

GitHub Actions / Code standards (linting)

S1005: unnecessary assignment to the blank identifier (gosimple)
if !slices.Contains(K8sProcessors, processor) {
return false
}
}
for connector, _ := range config.Connectors {
if !slices.Contains(K8sConnectors, connector) {
return false
}
}
for extension, _ := range config.Extensions {
if !slices.Contains(K8sConnectors, extension) {
return false
}
}
return true
}

func IsValidConfigCoreDistro(config OtelcolConfig) bool {
for receiver, _ := range config.Receivers {
if !slices.Contains(CoreReceivers, receiver) {
return false
}
}
for exporter, _ := range config.Exporters {
if !slices.Contains(CoreExporters, exporter) {
return false
}
}
for processor, _ := range config.Processors {
if !slices.Contains(CoreProcessors, processor) {
return false
}
}
for connector, _ := range config.Connectors {
if !slices.Contains(CoreConnectors, connector) {
return false
}
}
for extension, _ := range config.Extensions {
if !slices.Contains(CoreConnectors, extension) {
return false
}
}
return true
}
67 changes: 67 additions & 0 deletions internal/distros/k8sdistro.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package distros

var K8sReceivers = []string{
"filelog",
"fluentforward",
"hostmetrics",
"httpcheck",
"jaeger",
"journald",
"k8s_cluster",
"k8s_events",
"k8sobjects",
"kubeletstats",
"opencensus",
"otlp",
"prometheus",
"receiver_creator",
"zipkin",
}
var K8sProcessors = []string{
"attributes",
"batch",
"cumulativetodelta",
"deltatorate",
"filter",
"groupbyattrs",
"groupbytrace",
"k8sattributes",
"memory_limiter",
"metricstransform",
"probabilistic_sampler",
"redaction",
"remotetap",
"resource",
"resourcedetection",
"tail_sampling",
"transform",
}
var K8sExporters = []string{
"debug",
"file",
"loadbalancing",
"otlp",
"otlphttp",
}

var K8sExtensions = []string{
"basicauth",
"bearertokenauth",
"file_storage",
"headers_setter",
"health_check",
"host_observer",
"k8s_observer",
"oauth2client",
"oidc",
"pprof",
"zpages",
}

var K8sConnectors = []string{
"count",
"forward",
"routing",
"servicegraph",
"spanmetrics",
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func main() {
pflag.BoolVar(&enablePythonInstrumentation, constants.FlagPython, true, "Controls whether the operator supports python auto-instrumentation")
pflag.BoolVar(&enableNginxInstrumentation, constants.FlagNginx, false, "Controls whether the operator supports nginx auto-instrumentation")
pflag.BoolVar(&enableJavaInstrumentation, constants.FlagJava, true, "Controls whether the operator supports java auto-instrumentation")
stringFlagOrEnv(&collectorImage, "collector-image", "RELATED_IMAGE_COLLECTOR", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector:%s", v.OpenTelemetryCollector), "The default OpenTelemetry collector image. This image is used when no image is specified in the CustomResource.")
stringFlagOrEnv(&collectorImage, "collector-image", "RELATED_IMAGE_COLLECTOR", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector-k8s:%s", v.OpenTelemetryCollector), "The default OpenTelemetry collector image. This image is used when no image is specified in the CustomResource.")
stringFlagOrEnv(&targetAllocatorImage, "target-allocator-image", "RELATED_IMAGE_TARGET_ALLOCATOR", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/target-allocator:%s", v.TargetAllocator), "The default OpenTelemetry target allocator image. This image is used when no image is specified in the CustomResource.")
stringFlagOrEnv(&operatorOpAMPBridgeImage, "operator-opamp-bridge-image", "RELATED_IMAGE_OPERATOR_OPAMP_BRIDGE", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:%s", v.OperatorOpAMPBridge), "The default OpenTelemetry Operator OpAMP Bridge image. This image is used when no image is specified in the CustomResource.")
stringFlagOrEnv(&autoInstrumentationJava, "auto-instrumentation-java-image", "RELATED_IMAGE_AUTO_INSTRUMENTATION_JAVA", fmt.Sprintf("ghcr.io/open-telemetry/opentelemetry-operator/autoinstrumentation-java:%s", v.AutoInstrumentationJava), "The default OpenTelemetry Java instrumentation image. This image is used when no image is specified in the CustomResource.")
Expand Down

0 comments on commit 07f34b3

Please sign in to comment.