From 377b51f0f89a45c4f1766f1d4c69405146b316a6 Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Fri, 22 Mar 2024 19:04:17 +0800 Subject: [PATCH 01/13] Instrumentations support select --- .chloggen/instrumentation-support-select.yaml | 16 ++++++++++ apis/v1alpha1/instrumentation_types.go | 4 +++ apis/v1alpha1/zz_generated.deepcopy.go | 7 +++++ .../opentelemetry.io_instrumentations.yaml | 4 +++ .../opentelemetry.io_instrumentations.yaml | 4 +++ docs/api.md | 7 +++++ pkg/instrumentation/podmutator.go | 29 ++++++++++++++----- 7 files changed, 63 insertions(+), 8 deletions(-) create mode 100755 .chloggen/instrumentation-support-select.yaml diff --git a/.chloggen/instrumentation-support-select.yaml b/.chloggen/instrumentation-support-select.yaml new file mode 100755 index 0000000000..82ffc060ed --- /dev/null +++ b/.chloggen/instrumentation-support-select.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) +component: auto-instrumentation + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Instrumentations support select + +# One or more tracking issues related to the change +issues: [2744] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/apis/v1alpha1/instrumentation_types.go b/apis/v1alpha1/instrumentation_types.go index 0f3abf4203..44e047b376 100644 --- a/apis/v1alpha1/instrumentation_types.go +++ b/apis/v1alpha1/instrumentation_types.go @@ -22,6 +22,10 @@ import ( // InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumentation. type InstrumentationSpec struct { + // Selector is the selector label of injected Object + // +optional + Selector map[string]string `json:"selector,omitempty"` + // Exporter defines exporter configuration. // +optional Exporter `json:"exporter,omitempty"` diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 8db7c841b4..125f33b70d 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -292,6 +292,13 @@ func (in *InstrumentationList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *InstrumentationSpec) DeepCopyInto(out *InstrumentationSpec) { *out = *in + if in.Selector != nil { + in, out := &in.Selector, &out.Selector + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } out.Exporter = in.Exporter in.Resource.DeepCopyInto(&out.Resource) if in.Propagators != nil { diff --git a/bundle/manifests/opentelemetry.io_instrumentations.yaml b/bundle/manifests/opentelemetry.io_instrumentations.yaml index f85883f3ef..3e0dbecbb9 100644 --- a/bundle/manifests/opentelemetry.io_instrumentations.yaml +++ b/bundle/manifests/opentelemetry.io_instrumentations.yaml @@ -1027,6 +1027,10 @@ spec: - xray type: string type: object + selector: + additionalProperties: + type: string + type: object type: object status: type: object diff --git a/config/crd/bases/opentelemetry.io_instrumentations.yaml b/config/crd/bases/opentelemetry.io_instrumentations.yaml index 1d9afa606b..3be545d7f1 100644 --- a/config/crd/bases/opentelemetry.io_instrumentations.yaml +++ b/config/crd/bases/opentelemetry.io_instrumentations.yaml @@ -1025,6 +1025,10 @@ spec: - xray type: string type: object + selector: + additionalProperties: + type: string + type: object type: object status: type: object diff --git a/docs/api.md b/docs/api.md index 0fdbb73b92..63cf6b26be 100644 --- a/docs/api.md +++ b/docs/api.md @@ -172,6 +172,13 @@ Resource Types:
false + + selector + map[string]string + +
+ + false diff --git a/pkg/instrumentation/podmutator.go b/pkg/instrumentation/podmutator.go index 0a4fbde291..c1f206945b 100644 --- a/pkg/instrumentation/podmutator.go +++ b/pkg/instrumentation/podmutator.go @@ -33,8 +33,7 @@ import ( ) var ( - errMultipleInstancesPossible = errors.New("multiple OpenTelemetry Instrumentation instances available, cannot determine which one to select") - errNoInstancesAvailable = errors.New("no OpenTelemetry Instrumentation instances available") + errNoInstancesAvailable = errors.New("no OpenTelemetry Instrumentation instances available") ) type instPodMutator struct { @@ -373,7 +372,7 @@ func (pm *instPodMutator) getInstrumentationInstance(ctx context.Context, ns cor } if strings.EqualFold(instValue, "true") { - return pm.selectInstrumentationInstanceFromNamespace(ctx, ns) + return pm.selectInstrumentationInstanceFromNamespace(ctx, ns, pod) } var instNamespacedName types.NamespacedName @@ -392,18 +391,32 @@ func (pm *instPodMutator) getInstrumentationInstance(ctx context.Context, ns cor return otelInst, nil } -func (pm *instPodMutator) selectInstrumentationInstanceFromNamespace(ctx context.Context, ns corev1.Namespace) (*v1alpha1.Instrumentation, error) { +func (pm *instPodMutator) selectInstrumentationInstanceFromNamespace(ctx context.Context, ns corev1.Namespace, pod corev1.Pod) (*v1alpha1.Instrumentation, error) { var otelInsts v1alpha1.InstrumentationList if err := pm.Client.List(ctx, &otelInsts, client.InNamespace(ns.Name)); err != nil { return nil, err } - switch s := len(otelInsts.Items); { + // selector + var availableInstrument []v1alpha1.Instrumentation + for _, ins := range otelInsts.Items { + isMatch := true + if len(ins.Spec.Selector) != 0 { + for k, v := range ins.Spec.Selector { + if !strings.EqualFold(v, pod.Labels[k]) { + isMatch = false + } + } + } + if isMatch { + availableInstrument = append(availableInstrument, ins) + } + } + + switch s := len(availableInstrument); { case s == 0: return nil, errNoInstancesAvailable - case s > 1: - return nil, errMultipleInstancesPossible default: - return &otelInsts.Items[0], nil + return &availableInstrument[len(availableInstrument)-1], nil } } From 686f1c67b50822ad276dcde4d16fcf7a95c86173 Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Mon, 25 Mar 2024 18:39:45 +0800 Subject: [PATCH 02/13] use LabelSelector instead of map --- apis/v1alpha1/instrumentation_types.go | 2 +- apis/v1alpha1/zz_generated.deepcopy.go | 92 +++++++++---------- ...emetry-operator.clusterserviceversion.yaml | 4 +- .../opentelemetry.io_instrumentations.yaml | 24 ++++- .../opentelemetry.io_instrumentations.yaml | 24 ++++- docs/api.md | 79 +++++++++++++++- pkg/instrumentation/podmutator.go | 18 +++- .../00-install-collector.yaml | 23 +++++ .../00-install-instrumentation-select.yaml | 37 ++++++++ .../01-assert-select.yaml | 69 ++++++++++++++ .../01-install-app-select.yaml | 28 ++++++ .../instrumentation-select/chainsaw-test.yaml | 40 ++++++++ 12 files changed, 380 insertions(+), 60 deletions(-) create mode 100644 tests/e2e-instrumentation/instrumentation-select/00-install-collector.yaml create mode 100644 tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml create mode 100644 tests/e2e-instrumentation/instrumentation-select/01-assert-select.yaml create mode 100644 tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml create mode 100755 tests/e2e-instrumentation/instrumentation-select/chainsaw-test.yaml diff --git a/apis/v1alpha1/instrumentation_types.go b/apis/v1alpha1/instrumentation_types.go index 44e047b376..f2ca94d40a 100644 --- a/apis/v1alpha1/instrumentation_types.go +++ b/apis/v1alpha1/instrumentation_types.go @@ -24,7 +24,7 @@ import ( type InstrumentationSpec struct { // Selector is the selector label of injected Object // +optional - Selector map[string]string `json:"selector,omitempty"` + Selector *metav1.LabelSelector `json:"selector,omitempty"` // Exporter defines exporter configuration. // +optional diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 125f33b70d..1679c59a5d 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -20,9 +20,9 @@ package v1alpha1 import ( "k8s.io/api/autoscaling/v2" - "k8s.io/api/core/v1" + corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -37,14 +37,14 @@ func (in *ApacheHttpd) DeepCopyInto(out *ApacheHttpd) { } 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]) } } if in.Attrs != nil { in, out := &in.Attrs, &out.Attrs - *out = make([]v1.EnvVar, len(*in)) + *out = make([]corev1.EnvVar, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -134,7 +134,7 @@ func (in *DotNet) DeepCopyInto(out *DotNet) { } 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]) } @@ -177,7 +177,7 @@ func (in *Go) DeepCopyInto(out *Go) { } 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]) } @@ -294,10 +294,8 @@ func (in *InstrumentationSpec) DeepCopyInto(out *InstrumentationSpec) { *out = *in if in.Selector != nil { in, out := &in.Selector, &out.Selector - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) } out.Exporter = in.Exporter in.Resource.DeepCopyInto(&out.Resource) @@ -309,7 +307,7 @@ func (in *InstrumentationSpec) DeepCopyInto(out *InstrumentationSpec) { out.Sampler = in.Sampler 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]) } @@ -358,7 +356,7 @@ func (in *Java) DeepCopyInto(out *Java) { } 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]) } @@ -421,14 +419,14 @@ func (in *Nginx) DeepCopyInto(out *Nginx) { } 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]) } } if in.Attrs != nil { in, out := &in.Attrs, &out.Attrs - *out = make([]v1.EnvVar, len(*in)) + *out = make([]corev1.EnvVar, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -456,7 +454,7 @@ func (in *NodeJS) DeepCopyInto(out *NodeJS) { } 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]) } @@ -597,12 +595,12 @@ func (in *OpAMPBridgeSpec) DeepCopyInto(out *OpAMPBridgeSpec) { } 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.PodAnnotations != nil { @@ -614,54 +612,54 @@ func (in *OpAMPBridgeSpec) DeepCopyInto(out *OpAMPBridgeSpec) { } if in.VolumeMounts != nil { in, out := &in.VolumeMounts, &out.VolumeMounts - *out = make([]v1.VolumeMount, len(*in)) + *out = make([]corev1.VolumeMount, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.Ports != nil { in, out := &in.Ports, &out.Ports - *out = make([]v1.ServicePort, len(*in)) + *out = make([]corev1.ServicePort, 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]) } } if in.EnvFrom != nil { in, out := &in.EnvFrom, &out.EnvFrom - *out = make([]v1.EnvFromSource, len(*in)) + *out = make([]corev1.EnvFromSource, 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.Volumes != nil { in, out := &in.Volumes, &out.Volumes - *out = make([]v1.Volume, len(*in)) + *out = make([]corev1.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) + *out = new(corev1.Affinity) (*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]) } @@ -812,12 +810,12 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp } 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.PodAnnotations != nil { @@ -830,49 +828,49 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp in.TargetAllocator.DeepCopyInto(&out.TargetAllocator) if in.VolumeMounts != nil { in, out := &in.VolumeMounts, &out.VolumeMounts - *out = make([]v1.VolumeMount, len(*in)) + *out = make([]corev1.VolumeMount, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.Ports != nil { in, out := &in.Ports, &out.Ports - *out = make([]v1.ServicePort, len(*in)) + *out = make([]corev1.ServicePort, 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]) } } if in.EnvFrom != nil { in, out := &in.EnvFrom, &out.EnvFrom - *out = make([]v1.EnvFromSource, len(*in)) + *out = make([]corev1.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)) + *out = make([]corev1.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)) + *out = make([]corev1.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)) + *out = make([]corev1.Volume, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -880,12 +878,12 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp in.Ingress.DeepCopyInto(&out.Ingress) if in.Affinity != nil { in, out := &in.Affinity, &out.Affinity - *out = new(v1.Affinity) + *out = new(corev1.Affinity) (*in).DeepCopyInto(*out) } if in.Lifecycle != nil { in, out := &in.Lifecycle, &out.Lifecycle - *out = new(v1.Lifecycle) + *out = new(corev1.Lifecycle) (*in).DeepCopyInto(*out) } if in.TerminationGracePeriodSeconds != nil { @@ -900,14 +898,14 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp } if in.InitContainers != nil { in, out := &in.InitContainers, &out.InitContainers - *out = make([]v1.Container, len(*in)) + *out = make([]corev1.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)) + *out = make([]corev1.Container, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -915,7 +913,7 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp out.Observability = in.Observability 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]) } @@ -978,37 +976,37 @@ func (in *OpenTelemetryTargetAllocator) DeepCopyInto(out *OpenTelemetryTargetAll 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]) } @@ -1036,7 +1034,7 @@ func (in *OpenTelemetryTargetAllocatorPrometheusCR) DeepCopyInto(out *OpenTeleme *out = *in if in.ScrapeInterval != nil { in, out := &in.ScrapeInterval, &out.ScrapeInterval - *out = new(metav1.Duration) + *out = new(v1.Duration) **out = **in } if in.PodMonitorSelector != nil { @@ -1145,7 +1143,7 @@ func (in *Python) DeepCopyInto(out *Python) { } 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]) } diff --git a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml index eaa0bc7aa2..3426199cad 100644 --- a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -99,7 +99,7 @@ metadata: categories: Logging & Tracing,Monitoring certified: "false" containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator - createdAt: "2024-03-11T13:32:19Z" + createdAt: "2024-03-25T10:35:29Z" description: Provides the OpenTelemetry components, including the Collector operators.operatorframework.io/builder: operator-sdk-v1.29.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 @@ -488,6 +488,8 @@ spec: - --zap-log-level=info - --zap-time-encoding=rfc3339nano - --feature-gates=+operator.autoinstrumentation.go,+operator.autoinstrumentation.nginx + - --target-allocator-image=ghcr.io/open-telemetry/opentelemetry-operator/target-allocator:v0.96.0-18-g377b51f + - --operator-opamp-bridge-image=ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:v0.96.0-18-g377b51f image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.96.0 livenessProbe: httpGet: diff --git a/bundle/manifests/opentelemetry.io_instrumentations.yaml b/bundle/manifests/opentelemetry.io_instrumentations.yaml index 3e0dbecbb9..ff5ae110f2 100644 --- a/bundle/manifests/opentelemetry.io_instrumentations.yaml +++ b/bundle/manifests/opentelemetry.io_instrumentations.yaml @@ -1028,9 +1028,29 @@ spec: type: string type: object selector: - additionalProperties: - type: string + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object type: object + x-kubernetes-map-type: atomic type: object status: type: object diff --git a/config/crd/bases/opentelemetry.io_instrumentations.yaml b/config/crd/bases/opentelemetry.io_instrumentations.yaml index 3be545d7f1..69c4d43f1a 100644 --- a/config/crd/bases/opentelemetry.io_instrumentations.yaml +++ b/config/crd/bases/opentelemetry.io_instrumentations.yaml @@ -1026,9 +1026,29 @@ spec: type: string type: object selector: - additionalProperties: - type: string + properties: + matchExpressions: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array + matchLabels: + additionalProperties: + type: string + type: object type: object + x-kubernetes-map-type: atomic type: object status: type: object diff --git a/docs/api.md b/docs/api.md index 63cf6b26be..e69f87ad53 100644 --- a/docs/api.md +++ b/docs/api.md @@ -173,8 +173,8 @@ Resource Types: false - selector - map[string]string + selector + object
@@ -3586,6 +3586,81 @@ Resource Types: + +### Instrumentation.spec.selector +[↩ Parent](#instrumentationspec) + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
matchExpressions[]object +
+
false
matchLabelsmap[string]string +
+
false
+ + +### Instrumentation.spec.selector.matchExpressions[index] +[↩ Parent](#instrumentationspecselector) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
keystring +
+
true
operatorstring +
+
true
values[]string +
+
false
+ ## OpAMPBridge [↩ Parent](#opentelemetryiov1alpha1 ) diff --git a/pkg/instrumentation/podmutator.go b/pkg/instrumentation/podmutator.go index c1f206945b..fe59f81e96 100644 --- a/pkg/instrumentation/podmutator.go +++ b/pkg/instrumentation/podmutator.go @@ -20,8 +20,11 @@ import ( "fmt" "strings" + "k8s.io/apimachinery/pkg/labels" + "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" @@ -401,13 +404,18 @@ func (pm *instPodMutator) selectInstrumentationInstanceFromNamespace(ctx context var availableInstrument []v1alpha1.Instrumentation for _, ins := range otelInsts.Items { isMatch := true - if len(ins.Spec.Selector) != 0 { - for k, v := range ins.Spec.Selector { - if !strings.EqualFold(v, pod.Labels[k]) { - isMatch = false - } + if ins.Spec.Selector != nil { + labelSelector, err := v1.LabelSelectorAsSelector(ins.Spec.Selector) + if err != nil { + return nil, err + } + set := labels.Set(pod.GetLabels()) + // selector not match + if !labelSelector.Matches(set) { + isMatch = false } } + if isMatch { availableInstrument = append(availableInstrument, ins) } diff --git a/tests/e2e-instrumentation/instrumentation-select/00-install-collector.yaml b/tests/e2e-instrumentation/instrumentation-select/00-install-collector.yaml new file mode 100644 index 0000000000..fe390c6cae --- /dev/null +++ b/tests/e2e-instrumentation/instrumentation-select/00-install-collector.yaml @@ -0,0 +1,23 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: OpenTelemetryCollector +metadata: + name: sidecar +spec: + config: | + receivers: + otlp: + protocols: + grpc: + http: + processors: + + exporters: + debug: + + service: + pipelines: + traces: + receivers: [otlp] + processors: [] + exporters: [debug] + mode: sidecar diff --git a/tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml b/tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml new file mode 100644 index 0000000000..84b213ab8a --- /dev/null +++ b/tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml @@ -0,0 +1,37 @@ +apiVersion: opentelemetry.io/v1alpha1 +kind: Instrumentation +metadata: + name: java-select +spec: + selector: + matchLabels: + app: my-java-select + env: + - name: OTEL_TRACES_EXPORTER + value: otlp + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" + - name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED + value: "true" + exporter: + endpoint: http://localhost:4317 + propagators: + - jaeger + - b3 + sampler: + type: parentbased_traceidratio + argument: "0.25" + java: + env: + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" + - name: SPLUNK_PROFILER_ENABLED + value: "false" diff --git a/tests/e2e-instrumentation/instrumentation-select/01-assert-select.yaml b/tests/e2e-instrumentation/instrumentation-select/01-assert-select.yaml new file mode 100644 index 0000000000..c5e61791ef --- /dev/null +++ b/tests/e2e-instrumentation/instrumentation-select/01-assert-select.yaml @@ -0,0 +1,69 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + instrumentation.opentelemetry.io/inject-java: "true" + sidecar.opentelemetry.io/inject: "true" + labels: + app: my-java-select +spec: + containers: + - env: + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" + - name: SPLUNK_PROFILER_ENABLED + value: "false" + - name: JAVA_TOOL_OPTIONS + value: ' -javaagent:/otel-auto-instrumentation-java/javaagent.jar' + - name: OTEL_TRACES_EXPORTER + value: otlp + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" + - name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED + value: "true" + - name: OTEL_SERVICE_NAME + value: my-java-select + - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: OTEL_PROPAGATORS + value: jaeger,b3 + - name: OTEL_RESOURCE_ATTRIBUTES + name: myapp + volumeMounts: + - mountPath: /var/run/secrets/kubernetes.io/serviceaccount + readOnly: true + - mountPath: /otel-auto-instrumentation-java + name: opentelemetry-auto-instrumentation-java + - args: + - --config=env:OTEL_CONFIG + name: otc-container + initContainers: + - name: opentelemetry-auto-instrumentation-java +status: + containerStatuses: + - name: myapp + ready: true + started: true + - name: otc-container + ready: true + started: true + initContainerStatuses: + - name: opentelemetry-auto-instrumentation-java + ready: true + phase: Running diff --git a/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml b/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml new file mode 100644 index 0000000000..bf42bc65dd --- /dev/null +++ b/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml @@ -0,0 +1,28 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-java-select +spec: + selector: + matchLabels: + app: my-java-select + replicas: 1 + template: + metadata: + labels: + app: my-java-select + annotations: + sidecar.opentelemetry.io/inject: "true" + instrumentation.opentelemetry.io/inject-java: "true" + spec: + securityContext: + runAsUser: 1000 + runAsGroup: 3000 + fsGroup: 3000 + containers: + - name: myapp + image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-java:main + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ["ALL"] diff --git a/tests/e2e-instrumentation/instrumentation-select/chainsaw-test.yaml b/tests/e2e-instrumentation/instrumentation-select/chainsaw-test.yaml new file mode 100755 index 0000000000..6bd8dbe4f7 --- /dev/null +++ b/tests/e2e-instrumentation/instrumentation-select/chainsaw-test.yaml @@ -0,0 +1,40 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + creationTimestamp: null + name: instrumentation-java +spec: + steps: + - name: step-00 + try: + # In OpenShift, when a namespace is created, all necessary SCC annotations are automatically added. However, if a namespace is created using a resource file with only selected SCCs, the other auto-added SCCs are not included. Therefore, the UID-range and supplemental groups SCC annotations must be set after the namespace is created. + - command: + entrypoint: kubectl + args: + - annotate + - namespace + - ${NAMESPACE} + - openshift.io/sa.scc.uid-range=1000/1000 + - --overwrite + - command: + entrypoint: kubectl + args: + - annotate + - namespace + - ${NAMESPACE} + - openshift.io/sa.scc.supplemental-groups=3000/3000 + - --overwrite + - apply: + file: 00-install-collector.yaml + - apply: + file: 00-install-instrumentation-select.yaml + - name: step-01 + try: + - apply: + file: 01-install-app-select.yaml + - assert: + file: 01-assert-select.yaml + catch: + - podLogs: + selector: app=my-java-select \ No newline at end of file From 4f69d5b856a18e1ae2a38a09dec514308f9acc8b Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Mon, 25 Mar 2024 18:42:13 +0800 Subject: [PATCH 03/13] reset --- .../opentelemetry-operator.clusterserviceversion.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml index 3426199cad..819893bac7 100644 --- a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -99,7 +99,7 @@ metadata: categories: Logging & Tracing,Monitoring certified: "false" containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator - createdAt: "2024-03-25T10:35:29Z" + createdAt: "2024-03-25T10:41:54Z" description: Provides the OpenTelemetry components, including the Collector operators.operatorframework.io/builder: operator-sdk-v1.29.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 @@ -488,8 +488,6 @@ spec: - --zap-log-level=info - --zap-time-encoding=rfc3339nano - --feature-gates=+operator.autoinstrumentation.go,+operator.autoinstrumentation.nginx - - --target-allocator-image=ghcr.io/open-telemetry/opentelemetry-operator/target-allocator:v0.96.0-18-g377b51f - - --operator-opamp-bridge-image=ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:v0.96.0-18-g377b51f image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.96.0 livenessProbe: httpGet: From 1a5310814543e53ef201efd4c753f2df8be324e0 Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Mon, 25 Mar 2024 23:02:09 +0800 Subject: [PATCH 04/13] fix cr --- ...emetry-operator.clusterserviceversion.yaml | 4 ++- pkg/instrumentation/podmutator.go | 7 +++-- .../01-assert-without-select.yaml | 17 +++++++++++ .../01-install-app-select.yaml | 29 +++++++++++++++++++ .../instrumentation-select/chainsaw-test.yaml | 2 +- 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 tests/e2e-instrumentation/instrumentation-select/01-assert-without-select.yaml diff --git a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml index 819893bac7..80334911de 100644 --- a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -99,7 +99,7 @@ metadata: categories: Logging & Tracing,Monitoring certified: "false" containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator - createdAt: "2024-03-25T10:41:54Z" + createdAt: "2024-03-25T15:01:37Z" description: Provides the OpenTelemetry components, including the Collector operators.operatorframework.io/builder: operator-sdk-v1.29.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 @@ -488,6 +488,8 @@ spec: - --zap-log-level=info - --zap-time-encoding=rfc3339nano - --feature-gates=+operator.autoinstrumentation.go,+operator.autoinstrumentation.nginx + - --target-allocator-image=ghcr.io/open-telemetry/opentelemetry-operator/target-allocator:v0.96.0-20-g4f69d5b + - --operator-opamp-bridge-image=ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:v0.96.0-20-g4f69d5b image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.96.0 livenessProbe: httpGet: diff --git a/pkg/instrumentation/podmutator.go b/pkg/instrumentation/podmutator.go index fe59f81e96..34bcf64243 100644 --- a/pkg/instrumentation/podmutator.go +++ b/pkg/instrumentation/podmutator.go @@ -36,7 +36,8 @@ import ( ) var ( - errNoInstancesAvailable = errors.New("no OpenTelemetry Instrumentation instances available") + errMultipleInstancesPossible = errors.New("multiple OpenTelemetry Instrumentation instances available, cannot determine which one to select") + errNoInstancesAvailable = errors.New("no OpenTelemetry Instrumentation instances available") ) type instPodMutator struct { @@ -424,7 +425,9 @@ func (pm *instPodMutator) selectInstrumentationInstanceFromNamespace(ctx context switch s := len(availableInstrument); { case s == 0: return nil, errNoInstancesAvailable + case s > 1: + return nil, errMultipleInstancesPossible default: - return &availableInstrument[len(availableInstrument)-1], nil + return &otelInsts.Items[0], nil } } diff --git a/tests/e2e-instrumentation/instrumentation-select/01-assert-without-select.yaml b/tests/e2e-instrumentation/instrumentation-select/01-assert-without-select.yaml new file mode 100644 index 0000000000..ea8bdf33d9 --- /dev/null +++ b/tests/e2e-instrumentation/instrumentation-select/01-assert-without-select.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + instrumentation.opentelemetry.io/inject-java: "true" + sidecar.opentelemetry.io/inject: "true" + labels: + app: my-java-without-select +spec: + containers: + - name: myapp + image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-java:main + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: [ "ALL" ] + diff --git a/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml b/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml index bf42bc65dd..31f1667641 100644 --- a/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml +++ b/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml @@ -26,3 +26,32 @@ spec: allowPrivilegeEscalation: false capabilities: drop: ["ALL"] +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-java-without-select +spec: + selector: + matchLabels: + app: my-java-without-select + replicas: 1 + template: + metadata: + labels: + app: my-java-without-select + annotations: + sidecar.opentelemetry.io/inject: "true" + instrumentation.opentelemetry.io/inject-java: "true" + spec: + securityContext: + runAsUser: 1000 + runAsGroup: 3000 + fsGroup: 3000 + containers: + - name: myapp + image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-java:main + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ["ALL"] diff --git a/tests/e2e-instrumentation/instrumentation-select/chainsaw-test.yaml b/tests/e2e-instrumentation/instrumentation-select/chainsaw-test.yaml index 6bd8dbe4f7..3631d6e7d8 100755 --- a/tests/e2e-instrumentation/instrumentation-select/chainsaw-test.yaml +++ b/tests/e2e-instrumentation/instrumentation-select/chainsaw-test.yaml @@ -34,7 +34,7 @@ spec: - apply: file: 01-install-app-select.yaml - assert: - file: 01-assert-select.yaml + file: 01-assert*.yaml catch: - podLogs: selector: app=my-java-select \ No newline at end of file From 04badc2aefa3e60196079ece36f32c79b990c999 Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Mon, 25 Mar 2024 23:03:13 +0800 Subject: [PATCH 05/13] reset --- .../opentelemetry-operator.clusterserviceversion.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml index 80334911de..2cbdfa594f 100644 --- a/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml +++ b/bundle/manifests/opentelemetry-operator.clusterserviceversion.yaml @@ -99,7 +99,7 @@ metadata: categories: Logging & Tracing,Monitoring certified: "false" containerImage: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator - createdAt: "2024-03-25T15:01:37Z" + createdAt: "2024-03-25T15:02:49Z" description: Provides the OpenTelemetry components, including the Collector operators.operatorframework.io/builder: operator-sdk-v1.29.0 operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 @@ -488,8 +488,6 @@ spec: - --zap-log-level=info - --zap-time-encoding=rfc3339nano - --feature-gates=+operator.autoinstrumentation.go,+operator.autoinstrumentation.nginx - - --target-allocator-image=ghcr.io/open-telemetry/opentelemetry-operator/target-allocator:v0.96.0-20-g4f69d5b - - --operator-opamp-bridge-image=ghcr.io/open-telemetry/opentelemetry-operator/operator-opamp-bridge:v0.96.0-20-g4f69d5b image: ghcr.io/open-telemetry/opentelemetry-operator/opentelemetry-operator:0.96.0 livenessProbe: httpGet: From 4025131fb2c6085dfcc7ef563fc70b66b9fbd9f7 Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Mon, 25 Mar 2024 23:26:47 +0800 Subject: [PATCH 06/13] Update .chloggen/instrumentation-support-select.yaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mikołaj Świątek --- .chloggen/instrumentation-support-select.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/instrumentation-support-select.yaml b/.chloggen/instrumentation-support-select.yaml index 82ffc060ed..d7f01ed563 100755 --- a/.chloggen/instrumentation-support-select.yaml +++ b/.chloggen/instrumentation-support-select.yaml @@ -5,7 +5,7 @@ change_type: enhancement component: auto-instrumentation # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Instrumentations support select +note: Support label selectors in the Instrumentation CR # One or more tracking issues related to the change issues: [2744] From bac91bfb97dd04b9c47e4c53e9193a3b1d3688ba Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Tue, 2 Apr 2024 17:14:58 +0800 Subject: [PATCH 07/13] Update apis/v1alpha1/instrumentation_types.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mikołaj Świątek --- apis/v1alpha1/instrumentation_types.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apis/v1alpha1/instrumentation_types.go b/apis/v1alpha1/instrumentation_types.go index f2ca94d40a..3cd9c94567 100644 --- a/apis/v1alpha1/instrumentation_types.go +++ b/apis/v1alpha1/instrumentation_types.go @@ -22,7 +22,9 @@ import ( // InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumentation. type InstrumentationSpec struct { - // Selector is the selector label of injected Object + // Selector is the label selector for affected Pods. + // Unlike standard label selectors, `nil` means `everything`, and this is also the default. + // This may change in a future CRD version. // +optional Selector *metav1.LabelSelector `json:"selector,omitempty"` From 60540f03a6d458afdc34b17b39e35c27a32d1e7a Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Tue, 2 Apr 2024 23:59:14 +0800 Subject: [PATCH 08/13] fix wrong Inst when having multi Inst --- pkg/instrumentation/podmutator.go | 2 +- .../00-install-instrumentation-select.yaml | 38 ++++++++++ .../01-assert-select-multi.yaml | 69 +++++++++++++++++++ .../01-install-app-select.yaml | 29 ++++++++ 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml diff --git a/pkg/instrumentation/podmutator.go b/pkg/instrumentation/podmutator.go index bb1557b71c..e3c3b1d673 100644 --- a/pkg/instrumentation/podmutator.go +++ b/pkg/instrumentation/podmutator.go @@ -428,6 +428,6 @@ func (pm *instPodMutator) selectInstrumentationInstanceFromNamespace(ctx context case s > 1: return nil, errMultipleInstancesPossible default: - return &otelInsts.Items[0], nil + return &availableInstrument[0], nil } } diff --git a/tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml b/tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml index 84b213ab8a..74f5aa10f3 100644 --- a/tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml +++ b/tests/e2e-instrumentation/instrumentation-select/00-install-instrumentation-select.yaml @@ -35,3 +35,41 @@ spec: value: "false" - name: SPLUNK_PROFILER_ENABLED value: "false" +--- +apiVersion: opentelemetry.io/v1alpha1 +kind: Instrumentation +metadata: + name: my-java-multi +spec: + selector: + matchLabels: + app: my-java-multi + env: + - name: OTEL_TRACES_EXPORTER + value: otlp + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" + - name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED + value: "true" + exporter: + endpoint: http://localhost:4317 + propagators: + - jaeger + - b3 + sampler: + type: parentbased_traceidratio + argument: "0.25" + java: + env: + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" + - name: SPLUNK_PROFILER_ENABLED + value: "false" diff --git a/tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml b/tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml new file mode 100644 index 0000000000..f8ce8b1ae5 --- /dev/null +++ b/tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml @@ -0,0 +1,69 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + instrumentation.opentelemetry.io/inject-java: "true" + sidecar.opentelemetry.io/inject: "true" + labels: + app: my-java-multi +spec: + containers: + - env: + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" + - name: SPLUNK_PROFILER_ENABLED + value: "false" + - name: JAVA_TOOL_OPTIONS + value: ' -javaagent:/otel-auto-instrumentation-java/javaagent.jar' + - name: OTEL_TRACES_EXPORTER + value: otlp + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" + - name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED + value: "true" + - name: OTEL_SERVICE_NAME + value: my-java-multi + - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: OTEL_PROPAGATORS + value: jaeger,b3 + - name: OTEL_RESOURCE_ATTRIBUTES + name: myapp + volumeMounts: + - mountPath: /var/run/secrets/kubernetes.io/serviceaccount + readOnly: true + - mountPath: /otel-auto-instrumentation-java + name: opentelemetry-auto-instrumentation-java + - args: + - --config=env:OTEL_CONFIG + name: otc-container + initContainers: + - name: opentelemetry-auto-instrumentation-java +status: + containerStatuses: + - name: myapp + ready: true + started: true + - name: otc-container + ready: true + started: true + initContainerStatuses: + - name: opentelemetry-auto-instrumentation-java + ready: true + phase: Running diff --git a/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml b/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml index 31f1667641..145bd6bed8 100644 --- a/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml +++ b/tests/e2e-instrumentation/instrumentation-select/01-install-app-select.yaml @@ -55,3 +55,32 @@ spec: allowPrivilegeEscalation: false capabilities: drop: ["ALL"] +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: my-java-multi +spec: + selector: + matchLabels: + app: my-java-multi + replicas: 1 + template: + metadata: + labels: + app: my-java-multi + annotations: + sidecar.opentelemetry.io/inject: "true" + instrumentation.opentelemetry.io/inject-java: "true" + spec: + securityContext: + runAsUser: 1000 + runAsGroup: 3000 + fsGroup: 3000 + containers: + - name: myapp + image: ghcr.io/open-telemetry/opentelemetry-operator/e2e-test-app-java:main + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: ["ALL"] From 8d258537795132c8293c8909d64213d9b53e0a6e Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Sun, 7 Apr 2024 15:04:48 +0800 Subject: [PATCH 09/13] fix import --- pkg/instrumentation/podmutator.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/instrumentation/podmutator.go b/pkg/instrumentation/podmutator.go index e3c3b1d673..4db22c45be 100644 --- a/pkg/instrumentation/podmutator.go +++ b/pkg/instrumentation/podmutator.go @@ -20,11 +20,10 @@ import ( "fmt" "strings" - "k8s.io/apimachinery/pkg/labels" - "github.com/go-logr/logr" corev1 "k8s.io/api/core/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" From 0a7d64056eb89877ee16e3ce0bc3a63d1bca3d25 Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Tue, 9 Apr 2024 13:43:27 +0800 Subject: [PATCH 10/13] fix select document. --- apis/v1alpha1/instrumentation_types.go | 1 + .../opentelemetry.io_instrumentations.yaml | 18 +++++++++++++++ .../opentelemetry.io_instrumentations.yaml | 18 +++++++++++++++ docs/api.md | 22 ++++++++++++------- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/apis/v1alpha1/instrumentation_types.go b/apis/v1alpha1/instrumentation_types.go index 3cd9c94567..eb7f616387 100644 --- a/apis/v1alpha1/instrumentation_types.go +++ b/apis/v1alpha1/instrumentation_types.go @@ -23,6 +23,7 @@ import ( // InstrumentationSpec defines the desired state of OpenTelemetry SDK and instrumentation. type InstrumentationSpec struct { // Selector is the label selector for affected Pods. + // This selector only takes effect when annotation: instrumentation.opentelemetry.io/inject-xx equal true. // Unlike standard label selectors, `nil` means `everything`, and this is also the default. // This may change in a future CRD version. // +optional diff --git a/bundle/manifests/opentelemetry.io_instrumentations.yaml b/bundle/manifests/opentelemetry.io_instrumentations.yaml index bb0aa1052f..12f825af89 100644 --- a/bundle/manifests/opentelemetry.io_instrumentations.yaml +++ b/bundle/manifests/opentelemetry.io_instrumentations.yaml @@ -1677,15 +1677,32 @@ spec: type: string type: object selector: + description: |- + Selector is the label selector for affected Pods. + This selector only takes effect when annotation: instrumentation.opentelemetry.io/inject-xx equal true. properties: matchExpressions: + description: matchExpressions is a list of label selector requirements. + The requirements are ANDed. items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. properties: key: + description: key is the label key that the selector applies + to. type: string operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. type: string values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. items: type: string type: array @@ -1697,6 +1714,7 @@ spec: matchLabels: additionalProperties: type: string + description: matchLabels is a map of {key,value} pairs. type: object type: object x-kubernetes-map-type: atomic diff --git a/config/crd/bases/opentelemetry.io_instrumentations.yaml b/config/crd/bases/opentelemetry.io_instrumentations.yaml index 068e26f995..3518f67d5f 100644 --- a/config/crd/bases/opentelemetry.io_instrumentations.yaml +++ b/config/crd/bases/opentelemetry.io_instrumentations.yaml @@ -1675,15 +1675,32 @@ spec: type: string type: object selector: + description: |- + Selector is the label selector for affected Pods. + This selector only takes effect when annotation: instrumentation.opentelemetry.io/inject-xx equal true. properties: matchExpressions: + description: matchExpressions is a list of label selector requirements. + The requirements are ANDed. items: + description: |- + A label selector requirement is a selector that contains values, a key, and an operator that + relates the key and values. properties: key: + description: key is the label key that the selector applies + to. type: string operator: + description: |- + operator represents a key's relationship to a set of values. + Valid operators are In, NotIn, Exists and DoesNotExist. type: string values: + description: |- + values is an array of string values. If the operator is In or NotIn, + the values array must be non-empty. If the operator is Exists or DoesNotExist, + the values array must be empty. items: type: string type: array @@ -1695,6 +1712,7 @@ spec: matchLabels: additionalProperties: type: string + description: matchLabels is a map of {key,value} pairs. type: object type: object x-kubernetes-map-type: atomic diff --git a/docs/api.md b/docs/api.md index bf3700cc2c..ddfcbac5c0 100644 --- a/docs/api.md +++ b/docs/api.md @@ -177,7 +177,8 @@ Enum=tracecontext;baggage;b3;b3multi;jaeger;xray;ottrace;none
selector object -
+ Selector is the label selector for affected Pods. +This selector only takes effect when annotation: instrumentation.opentelemetry.io/inject-xx equal true.
false @@ -3767,7 +3768,8 @@ The value can be for instance parentbased_always_on, parentbased_always_off, par - +Selector is the label selector for affected Pods. +This selector only takes effect when annotation: instrumentation.opentelemetry.io/inject-xx equal true. @@ -3782,14 +3784,14 @@ The value can be for instance parentbased_always_on, parentbased_always_off, par @@ -3801,7 +3803,8 @@ The value can be for instance parentbased_always_on, parentbased_always_off, par - +A label selector requirement is a selector that contains values, a key, and an operator that +relates the key and values.
matchExpressions []object -
+ matchExpressions is a list of label selector requirements. The requirements are ANDed.
false
matchLabels map[string]string -
+ matchLabels is a map of {key,value} pairs.
false
@@ -3816,21 +3819,24 @@ The value can be for instance parentbased_always_on, parentbased_always_off, par From 8b7609ae5321f444902239b08d6001d1952a2598 Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Wed, 10 Apr 2024 01:12:42 +0800 Subject: [PATCH 11/13] fix e2e test --- .../01-assert-select-multi.yaml | 116 ++++++++++-------- .../01-assert-select.yaml | 116 ++++++++++-------- 2 files changed, 124 insertions(+), 108 deletions(-) diff --git a/tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml b/tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml index f8ce8b1ae5..be4bcdec4e 100644 --- a/tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml +++ b/tests/e2e-instrumentation/instrumentation-select/01-assert-select-multi.yaml @@ -8,62 +8,70 @@ metadata: app: my-java-multi spec: containers: - - env: - - name: OTEL_JAVAAGENT_DEBUG - value: "true" - - name: OTEL_INSTRUMENTATION_JDBC_ENABLED - value: "false" - - name: SPLUNK_PROFILER_ENABLED - value: "false" - - name: JAVA_TOOL_OPTIONS - value: ' -javaagent:/otel-auto-instrumentation-java/javaagent.jar' - - name: OTEL_TRACES_EXPORTER - value: otlp - - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: http://localhost:4317 - - name: OTEL_EXPORTER_OTLP_TIMEOUT - value: "20" - - name: OTEL_TRACES_SAMPLER - value: parentbased_traceidratio - - name: OTEL_TRACES_SAMPLER_ARG - value: "0.85" - - name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED - value: "true" - - name: OTEL_SERVICE_NAME - value: my-java-multi - - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.name - - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: spec.nodeName - - name: OTEL_PROPAGATORS - value: jaeger,b3 - - name: OTEL_RESOURCE_ATTRIBUTES - name: myapp - volumeMounts: - - mountPath: /var/run/secrets/kubernetes.io/serviceaccount - readOnly: true - - mountPath: /otel-auto-instrumentation-java - name: opentelemetry-auto-instrumentation-java - - args: - - --config=env:OTEL_CONFIG - name: otc-container + - env: + - name: OTEL_NODE_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP + - name: OTEL_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" + - name: SPLUNK_PROFILER_ENABLED + value: "false" + - name: JAVA_TOOL_OPTIONS + value: ' -javaagent:/otel-auto-instrumentation-java/javaagent.jar' + - name: OTEL_TRACES_EXPORTER + value: otlp + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" + - name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED + value: "true" + - name: OTEL_SERVICE_NAME + value: my-java-multi + - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: OTEL_PROPAGATORS + value: jaeger,b3 + - name: OTEL_RESOURCE_ATTRIBUTES + name: myapp + volumeMounts: + - mountPath: /var/run/secrets/kubernetes.io/serviceaccount + readOnly: true + - mountPath: /otel-auto-instrumentation-java + name: opentelemetry-auto-instrumentation-java + - args: + - --config=env:OTEL_CONFIG + name: otc-container initContainers: - - name: opentelemetry-auto-instrumentation-java + - name: opentelemetry-auto-instrumentation-java status: containerStatuses: - - name: myapp - ready: true - started: true - - name: otc-container - ready: true - started: true + - name: myapp + ready: true + started: true + - name: otc-container + ready: true + started: true initContainerStatuses: - - name: opentelemetry-auto-instrumentation-java - ready: true + - name: opentelemetry-auto-instrumentation-java + ready: true phase: Running diff --git a/tests/e2e-instrumentation/instrumentation-select/01-assert-select.yaml b/tests/e2e-instrumentation/instrumentation-select/01-assert-select.yaml index c5e61791ef..bf96c2b522 100644 --- a/tests/e2e-instrumentation/instrumentation-select/01-assert-select.yaml +++ b/tests/e2e-instrumentation/instrumentation-select/01-assert-select.yaml @@ -8,62 +8,70 @@ metadata: app: my-java-select spec: containers: - - env: - - name: OTEL_JAVAAGENT_DEBUG - value: "true" - - name: OTEL_INSTRUMENTATION_JDBC_ENABLED - value: "false" - - name: SPLUNK_PROFILER_ENABLED - value: "false" - - name: JAVA_TOOL_OPTIONS - value: ' -javaagent:/otel-auto-instrumentation-java/javaagent.jar' - - name: OTEL_TRACES_EXPORTER - value: otlp - - name: OTEL_EXPORTER_OTLP_ENDPOINT - value: http://localhost:4317 - - name: OTEL_EXPORTER_OTLP_TIMEOUT - value: "20" - - name: OTEL_TRACES_SAMPLER - value: parentbased_traceidratio - - name: OTEL_TRACES_SAMPLER_ARG - value: "0.85" - - name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED - value: "true" - - name: OTEL_SERVICE_NAME - value: my-java-select - - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.name - - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: spec.nodeName - - name: OTEL_PROPAGATORS - value: jaeger,b3 - - name: OTEL_RESOURCE_ATTRIBUTES - name: myapp - volumeMounts: - - mountPath: /var/run/secrets/kubernetes.io/serviceaccount - readOnly: true - - mountPath: /otel-auto-instrumentation-java - name: opentelemetry-auto-instrumentation-java - - args: - - --config=env:OTEL_CONFIG - name: otc-container + - env: + - name: OTEL_NODE_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP + - name: OTEL_POD_IP + valueFrom: + fieldRef: + fieldPath: status.podIP + - name: OTEL_JAVAAGENT_DEBUG + value: "true" + - name: OTEL_INSTRUMENTATION_JDBC_ENABLED + value: "false" + - name: SPLUNK_PROFILER_ENABLED + value: "false" + - name: JAVA_TOOL_OPTIONS + value: ' -javaagent:/otel-auto-instrumentation-java/javaagent.jar' + - name: OTEL_TRACES_EXPORTER + value: otlp + - name: OTEL_EXPORTER_OTLP_ENDPOINT + value: http://localhost:4317 + - name: OTEL_EXPORTER_OTLP_TIMEOUT + value: "20" + - name: OTEL_TRACES_SAMPLER + value: parentbased_traceidratio + - name: OTEL_TRACES_SAMPLER_ARG + value: "0.85" + - name: SPLUNK_TRACE_RESPONSE_HEADER_ENABLED + value: "true" + - name: OTEL_SERVICE_NAME + value: my-java-select + - name: OTEL_RESOURCE_ATTRIBUTES_POD_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.name + - name: OTEL_RESOURCE_ATTRIBUTES_NODE_NAME + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: spec.nodeName + - name: OTEL_PROPAGATORS + value: jaeger,b3 + - name: OTEL_RESOURCE_ATTRIBUTES + name: myapp + volumeMounts: + - mountPath: /var/run/secrets/kubernetes.io/serviceaccount + readOnly: true + - mountPath: /otel-auto-instrumentation-java + name: opentelemetry-auto-instrumentation-java + - args: + - --config=env:OTEL_CONFIG + name: otc-container initContainers: - - name: opentelemetry-auto-instrumentation-java + - name: opentelemetry-auto-instrumentation-java status: containerStatuses: - - name: myapp - ready: true - started: true - - name: otc-container - ready: true - started: true + - name: myapp + ready: true + started: true + - name: otc-container + ready: true + started: true initContainerStatuses: - - name: opentelemetry-auto-instrumentation-java - ready: true + - name: opentelemetry-auto-instrumentation-java + ready: true phase: Running From b11cb13355272f01b56d6144fad851294a7e9c69 Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Wed, 10 Apr 2024 01:25:52 +0800 Subject: [PATCH 12/13] merge main to current branch --- apis/v1alpha1/zz_generated.deepcopy.go | 89 ++++++++++++++------------ 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/apis/v1alpha1/zz_generated.deepcopy.go b/apis/v1alpha1/zz_generated.deepcopy.go index 92911cd336..e54fa486ee 100644 --- a/apis/v1alpha1/zz_generated.deepcopy.go +++ b/apis/v1alpha1/zz_generated.deepcopy.go @@ -20,9 +20,9 @@ package v1alpha1 import ( "k8s.io/api/autoscaling/v2" - "k8s.io/api/core/v1" + corev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/intstr" ) @@ -37,14 +37,14 @@ func (in *ApacheHttpd) DeepCopyInto(out *ApacheHttpd) { } 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]) } } if in.Attrs != nil { in, out := &in.Attrs, &out.Attrs - *out = make([]v1.EnvVar, len(*in)) + *out = make([]corev1.EnvVar, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -134,7 +134,7 @@ func (in *DotNet) DeepCopyInto(out *DotNet) { } 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]) } @@ -177,7 +177,7 @@ func (in *Go) DeepCopyInto(out *Go) { } 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]) } @@ -292,6 +292,11 @@ func (in *InstrumentationList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *InstrumentationSpec) DeepCopyInto(out *InstrumentationSpec) { *out = *in + if in.Selector != nil { + in, out := &in.Selector, &out.Selector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } out.Exporter = in.Exporter in.Resource.DeepCopyInto(&out.Resource) if in.Propagators != nil { @@ -302,7 +307,7 @@ func (in *InstrumentationSpec) DeepCopyInto(out *InstrumentationSpec) { out.Sampler = in.Sampler 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]) } @@ -351,7 +356,7 @@ func (in *Java) DeepCopyInto(out *Java) { } 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]) } @@ -414,14 +419,14 @@ func (in *Nginx) DeepCopyInto(out *Nginx) { } 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]) } } if in.Attrs != nil { in, out := &in.Attrs, &out.Attrs - *out = make([]v1.EnvVar, len(*in)) + *out = make([]corev1.EnvVar, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -449,7 +454,7 @@ func (in *NodeJS) DeepCopyInto(out *NodeJS) { } 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]) } @@ -590,12 +595,12 @@ func (in *OpAMPBridgeSpec) DeepCopyInto(out *OpAMPBridgeSpec) { } 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.PodAnnotations != nil { @@ -607,54 +612,54 @@ func (in *OpAMPBridgeSpec) DeepCopyInto(out *OpAMPBridgeSpec) { } if in.VolumeMounts != nil { in, out := &in.VolumeMounts, &out.VolumeMounts - *out = make([]v1.VolumeMount, len(*in)) + *out = make([]corev1.VolumeMount, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.Ports != nil { in, out := &in.Ports, &out.Ports - *out = make([]v1.ServicePort, len(*in)) + *out = make([]corev1.ServicePort, 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]) } } if in.EnvFrom != nil { in, out := &in.EnvFrom, &out.EnvFrom - *out = make([]v1.EnvFromSource, len(*in)) + *out = make([]corev1.EnvFromSource, 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.Volumes != nil { in, out := &in.Volumes, &out.Volumes - *out = make([]v1.Volume, len(*in)) + *out = make([]corev1.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) + *out = new(corev1.Affinity) (*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]) } @@ -805,12 +810,12 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp } 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.PodAnnotations != nil { @@ -823,7 +828,7 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp in.TargetAllocator.DeepCopyInto(&out.TargetAllocator) if in.VolumeMounts != nil { in, out := &in.VolumeMounts, &out.VolumeMounts - *out = make([]v1.VolumeMount, len(*in)) + *out = make([]corev1.VolumeMount, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -837,35 +842,35 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp } 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]) } } if in.EnvFrom != nil { in, out := &in.EnvFrom, &out.EnvFrom - *out = make([]v1.EnvFromSource, len(*in)) + *out = make([]corev1.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)) + *out = make([]corev1.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)) + *out = make([]corev1.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)) + *out = make([]corev1.Volume, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -873,12 +878,12 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp in.Ingress.DeepCopyInto(&out.Ingress) if in.Affinity != nil { in, out := &in.Affinity, &out.Affinity - *out = new(v1.Affinity) + *out = new(corev1.Affinity) (*in).DeepCopyInto(*out) } if in.Lifecycle != nil { in, out := &in.Lifecycle, &out.Lifecycle - *out = new(v1.Lifecycle) + *out = new(corev1.Lifecycle) (*in).DeepCopyInto(*out) } if in.TerminationGracePeriodSeconds != nil { @@ -893,14 +898,14 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp } if in.InitContainers != nil { in, out := &in.InitContainers, &out.InitContainers - *out = make([]v1.Container, len(*in)) + *out = make([]corev1.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)) + *out = make([]corev1.Container, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -908,7 +913,7 @@ func (in *OpenTelemetryCollectorSpec) DeepCopyInto(out *OpenTelemetryCollectorSp out.Observability = in.Observability 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]) } @@ -971,37 +976,37 @@ func (in *OpenTelemetryTargetAllocator) DeepCopyInto(out *OpenTelemetryTargetAll 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]) } @@ -1029,7 +1034,7 @@ func (in *OpenTelemetryTargetAllocatorPrometheusCR) DeepCopyInto(out *OpenTeleme *out = *in if in.ScrapeInterval != nil { in, out := &in.ScrapeInterval, &out.ScrapeInterval - *out = new(metav1.Duration) + *out = new(v1.Duration) **out = **in } if in.PodMonitorSelector != nil { @@ -1154,7 +1159,7 @@ func (in *Python) DeepCopyInto(out *Python) { } 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]) } From 73eb99e8c097922b75824197cd092843c8ee3870 Mon Sep 17 00:00:00 2001 From: crossoverJie Date: Wed, 8 May 2024 21:51:11 +0800 Subject: [PATCH 13/13] merge main to current branch --- .../opentelemetry.io_instrumentations.yaml | 18 ------------------ .../opentelemetry.io_instrumentations.yaml | 18 ------------------ docs/api.md | 13 ++++++++++--- 3 files changed, 10 insertions(+), 39 deletions(-) diff --git a/bundle/manifests/opentelemetry.io_instrumentations.yaml b/bundle/manifests/opentelemetry.io_instrumentations.yaml index a3cbd416ff..4829733363 100644 --- a/bundle/manifests/opentelemetry.io_instrumentations.yaml +++ b/bundle/manifests/opentelemetry.io_instrumentations.yaml @@ -1040,32 +1040,15 @@ spec: type: string type: object selector: - description: |- - Selector is the label selector for affected Pods. - This selector only takes effect when annotation: instrumentation.opentelemetry.io/inject-xx equal true. properties: matchExpressions: - description: matchExpressions is a list of label selector requirements. - The requirements are ANDed. items: - description: |- - A label selector requirement is a selector that contains values, a key, and an operator that - relates the key and values. properties: key: - description: key is the label key that the selector applies - to. type: string operator: - description: |- - operator represents a key's relationship to a set of values. - Valid operators are In, NotIn, Exists and DoesNotExist. type: string values: - description: |- - values is an array of string values. If the operator is In or NotIn, - the values array must be non-empty. If the operator is Exists or DoesNotExist, - the values array must be empty. items: type: string type: array @@ -1077,7 +1060,6 @@ spec: matchLabels: additionalProperties: type: string - description: matchLabels is a map of {key,value} pairs. type: object type: object x-kubernetes-map-type: atomic diff --git a/config/crd/bases/opentelemetry.io_instrumentations.yaml b/config/crd/bases/opentelemetry.io_instrumentations.yaml index 315d661ee1..b10a5eaf4d 100644 --- a/config/crd/bases/opentelemetry.io_instrumentations.yaml +++ b/config/crd/bases/opentelemetry.io_instrumentations.yaml @@ -1038,32 +1038,15 @@ spec: type: string type: object selector: - description: |- - Selector is the label selector for affected Pods. - This selector only takes effect when annotation: instrumentation.opentelemetry.io/inject-xx equal true. properties: matchExpressions: - description: matchExpressions is a list of label selector requirements. - The requirements are ANDed. items: - description: |- - A label selector requirement is a selector that contains values, a key, and an operator that - relates the key and values. properties: key: - description: key is the label key that the selector applies - to. type: string operator: - description: |- - operator represents a key's relationship to a set of values. - Valid operators are In, NotIn, Exists and DoesNotExist. type: string values: - description: |- - values is an array of string values. If the operator is In or NotIn, - the values array must be non-empty. If the operator is Exists or DoesNotExist, - the values array must be empty. items: type: string type: array @@ -1075,7 +1058,6 @@ spec: matchLabels: additionalProperties: type: string - description: matchLabels is a map of {key,value} pairs. type: object type: object x-kubernetes-map-type: atomic diff --git a/docs/api.md b/docs/api.md index 40bbf26410..06494cbf29 100644 --- a/docs/api.md +++ b/docs/api.md @@ -184,7 +184,9 @@ Enum=tracecontext;baggage;b3;b3multi;jaeger;xray;ottrace;none
@@ -3938,6 +3940,8 @@ The value can be for instance parentbased_always_on, parentbased_always_off, par Selector is the label selector for affected Pods. This selector only takes effect when annotation: instrumentation.opentelemetry.io/inject-xx equal true. +Unlike standard label selectors, `nil` means `everything`, and this is also the default. +This may change in a future CRD version.
key string -
+ key is the label key that the selector applies to.
true
operator string -
+ operator represents a key's relationship to a set of values. +Valid operators are In, NotIn, Exists and DoesNotExist.
true
values []string -
+ values is an array of string values. If the operator is In or NotIn, +the values array must be non-empty. If the operator is Exists or DoesNotExist, +the values array must be empty.
false
object Selector is the label selector for affected Pods. -This selector only takes effect when annotation: instrumentation.opentelemetry.io/inject-xx equal true.
+This selector only takes effect when annotation: instrumentation.opentelemetry.io/inject-xx equal true. +Unlike standard label selectors, `nil` means `everything`, and this is also the default. +This may change in a future CRD version.
false
@@ -3959,7 +3963,9 @@ This selector only takes effect when annotation: instrumentation.opentelemetry.i @@ -4004,7 +4010,8 @@ Valid operators are In, NotIn, Exists and DoesNotExist.
matchLabels map[string]string - matchLabels is a map of {key,value} pairs.
+ matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels +map is equivalent to an element of matchExpressions, whose key field is "key", the +operator is "In", and the values array contains only "value". The requirements are ANDed.
false
values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, -the values array must be empty.
+the values array must be empty. This array is replaced during a strategic +merge patch.
false