Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary instances of app.kubernetes.io/managed-by #3074

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .chloggen/fix-managed-by-gross.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: breaking

# 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: collector, auto-instrumentation, opamp

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: This removes the static label app.kubernetes.io/managed-by from user applied CRs (collector, instrumentation, bridge)

# One or more tracking issues related to the change
issues: [3014]

# (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: |
The existence of app.kubernetes.io/managed-by=opentelemetry-operator was preventing the helm managed-by
labels from persisting correctly. this resulted in unnecessary conflicts while also resulting in an
operator failure to pull the correct images for auto-instrumentation.
4 changes: 0 additions & 4 deletions apis/v1alpha1/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ func (w InstrumentationWebhook) defaulter(r *Instrumentation) error {
if r.Labels == nil {
r.Labels = map[string]string{}
}
if r.Labels["app.kubernetes.io/managed-by"] == "" {
r.Labels["app.kubernetes.io/managed-by"] = "opentelemetry-operator"
}

if r.Spec.Java.Image == "" {
r.Spec.Java.Image = w.cfg.AutoInstrumentationJavaImage()
}
Expand Down
18 changes: 7 additions & 11 deletions apis/v1alpha1/opampbridge_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,42 +52,38 @@ func (o *OpAMPBridgeWebhook) Default(ctx context.Context, obj runtime.Object) er
return o.defaulter(opampBridge)
}

func (c OpAMPBridgeWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
func (o *OpAMPBridgeWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
opampBridge, ok := obj.(*OpAMPBridge)
if !ok {
return nil, fmt.Errorf("expected an OpAMPBridge, received %T", obj)
}
return c.validate(opampBridge)
return o.validate(opampBridge)
}

func (c OpAMPBridgeWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
func (o *OpAMPBridgeWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
opampBridge, ok := newObj.(*OpAMPBridge)
if !ok {
return nil, fmt.Errorf("expected an OpAMPBridge, received %T", newObj)
}
return c.validate(opampBridge)
return o.validate(opampBridge)
}

func (o OpAMPBridgeWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
func (o *OpAMPBridgeWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
opampBridge, ok := obj.(*OpAMPBridge)
if !ok || opampBridge == nil {
return nil, fmt.Errorf("expected an OpAMPBridge, received %T", obj)
}
return o.validate(opampBridge)
}

func (o OpAMPBridgeWebhook) defaulter(r *OpAMPBridge) error {
func (o *OpAMPBridgeWebhook) defaulter(r *OpAMPBridge) error {
if len(r.Spec.UpgradeStrategy) == 0 {
r.Spec.UpgradeStrategy = UpgradeStrategyAutomatic
}

if r.Labels == nil {
r.Labels = map[string]string{}
}
if r.Labels["app.kubernetes.io/managed-by"] == "" {
r.Labels["app.kubernetes.io/managed-by"] = "opentelemetry-operator"
}

one := int32(1)
if r.Spec.Replicas == nil {
r.Spec.Replicas = &one
Expand All @@ -104,7 +100,7 @@ func (o OpAMPBridgeWebhook) defaulter(r *OpAMPBridge) error {
return nil
}

func (o OpAMPBridgeWebhook) validate(r *OpAMPBridge) (admission.Warnings, error) {
func (o *OpAMPBridgeWebhook) validate(r *OpAMPBridge) (admission.Warnings, error) {
warnings := admission.Warnings{}

// validate OpAMP server endpoint
Expand Down
12 changes: 3 additions & 9 deletions apis/v1alpha1/opampbridge_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ func TestOpAMPBridgeDefaultingWebhook(t *testing.T) {
opampBridge: OpAMPBridge{},
expected: OpAMPBridge{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpAMPBridgeSpec{
Replicas: &one,
Expand All @@ -71,9 +69,7 @@ func TestOpAMPBridgeDefaultingWebhook(t *testing.T) {
},
expected: OpAMPBridge{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpAMPBridgeSpec{
Replicas: &five,
Expand All @@ -93,9 +89,7 @@ func TestOpAMPBridgeDefaultingWebhook(t *testing.T) {
},
expected: OpAMPBridge{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpAMPBridgeSpec{
Replicas: &one,
Expand Down
3 changes: 0 additions & 3 deletions apis/v1beta1/collector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ func (c CollectorWebhook) Default(_ context.Context, obj runtime.Object) error {
if otelcol.Labels == nil {
otelcol.Labels = map[string]string{}
}
if otelcol.Labels["app.kubernetes.io/managed-by"] == "" {
otelcol.Labels["app.kubernetes.io/managed-by"] = "opentelemetry-operator"
}

// We can default to one because dependent objects Deployment and HorizontalPodAutoScaler
// default to 1 as well.
Expand Down
40 changes: 10 additions & 30 deletions apis/v1beta1/collector_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
otelcol: OpenTelemetryCollector{},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jaronoff97 ,
Just curious, after removing the filtering logic. For resources with label "app.kubernetes.io/managed-by": "Helm", could it be possible that both the helm chart and the OTel operator are managed at the same time resulting in a common modification of a resource (e.g., operator modifies the resource first, helm upgrade modifies it again)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different applications making changes to the same resource is a normal occurence in K8s, that by itself is not an issue. What we're fixing here is that the value of this label is a lie currently. The operator does not manage its own CRs in general, it only manages the ones it creates.

Copy link
Contributor Author

@jaronoff97 jaronoff97 Jun 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the issue today is that a collector or instrumentation created by helm will not be upgraded correctly by the operator because the label we filter isn't accurate

},
Spec: OpenTelemetryCollectorSpec{
OpenTelemetryCommonFields: OpenTelemetryCommonFields{
Expand Down Expand Up @@ -144,9 +142,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeSidecar,
Expand Down Expand Up @@ -178,9 +174,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeSidecar,
Expand Down Expand Up @@ -210,9 +204,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
Expand Down Expand Up @@ -247,9 +239,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
Expand Down Expand Up @@ -290,9 +280,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
Expand Down Expand Up @@ -329,9 +317,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
Expand Down Expand Up @@ -379,9 +365,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
Expand Down Expand Up @@ -424,9 +408,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
Expand Down Expand Up @@ -468,9 +450,7 @@ func TestCollectorDefaultingWebhook(t *testing.T) {
},
expected: OpenTelemetryCollector{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
},
Labels: map[string]string{},
},
Spec: OpenTelemetryCollectorSpec{
Mode: ModeDeployment,
Expand Down
7 changes: 1 addition & 6 deletions apis/v1beta1/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,8 @@ func NewMetrics(prv metric.MeterProvider, ctx context.Context, cl client.Reader)

// Init metrics from the first time the operator starts.
func (m *Metrics) init(ctx context.Context, cl client.Reader) error {
opts := []client.ListOption{
client.MatchingLabels(map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
}),
}
list := &OpenTelemetryCollectorList{}
if err := cl.List(ctx, list, opts...); err != nil {
if err := cl.List(ctx, list); err != nil {
return fmt.Errorf("failed to list: %w", err)
}

Expand Down
8 changes: 1 addition & 7 deletions pkg/collector/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,8 @@ const RecordBufferSize int = 10
// ManagedInstances finds all the otelcol instances for the current operator and upgrades them, if necessary.
func (u VersionUpgrade) ManagedInstances(ctx context.Context) error {
u.Log.Info("looking for managed instances to upgrade")

opts := []client.ListOption{
client.MatchingLabels(map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
}),
}
list := &v1beta1.OpenTelemetryCollectorList{}
if err := u.Client.List(ctx, list, opts...); err != nil {
if err := u.Client.List(ctx, list); err != nil {
return fmt.Errorf("failed to list: %w", err)
}

Expand Down
8 changes: 1 addition & 7 deletions pkg/instrumentation/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,8 @@ func NewInstrumentationUpgrade(client client.Client, logger logr.Logger, recorde
// ManagedInstances upgrades managed instances by the opentelemetry-operator.
func (u *InstrumentationUpgrade) ManagedInstances(ctx context.Context) error {
u.Logger.Info("looking for managed Instrumentation instances to upgrade")

opts := []client.ListOption{
client.MatchingLabels(map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
}),
}
list := &v1alpha1.InstrumentationList{}
if err := u.Client.List(ctx, list, opts...); err != nil {
if err := u.Client.List(ctx, list); err != nil {
return fmt.Errorf("failed to list: %w", err)
}

Expand Down
Loading