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

Merged
merged 12 commits into from
Sep 5, 2024
20 changes: 20 additions & 0 deletions .chloggen/fix-managed-by-gross-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# 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: Fixes a bug that was preventing auto instrumentation from getting correct images.

# 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: |
This PR removes the restriction on the operator to only upgrade manually applied CRDs. This meant
that resources applied by helm were not upgraded at all. The solution was to remove the restriction
we had on querying the label app.kubernetes.io/managed-by=opentelemetry-operator, thereby upgrading
ALL CRDs in the cluster.
18 changes: 18 additions & 0 deletions .chloggen/fix-managed-by-gross.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# 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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixes a bug that was preventing upgrade patches from reliably applying.

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

# (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: |
A bug was discovered in the process of testing the PR that was failing to remove the environment
variables introduced in the 0.104.0 upgrade. The fix was to take a deepcopy of the object and update that.
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"
jaronoff97 marked this conversation as resolved.
Show resolved Hide resolved
}

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 @@ -64,9 +64,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{},
jaronoff97 marked this conversation as resolved.
Show resolved Hide resolved
},
Spec: OpenTelemetryCollectorSpec{
OpenTelemetryCommonFields: OpenTelemetryCommonFields{
Expand All @@ -139,9 +137,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 All @@ -168,9 +164,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 All @@ -195,9 +189,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 @@ -227,9 +219,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 @@ -265,9 +255,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 @@ -305,9 +293,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 @@ -350,9 +336,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 @@ -390,9 +374,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 @@ -423,9 +405,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
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/tools/record"
k8sapiflag "k8s.io/component-base/cli/flag"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
Expand Down Expand Up @@ -454,7 +453,7 @@ func addDependencies(_ context.Context, mgr ctrl.Manager, cfg config.Config, v v
Log: ctrl.Log.WithName("collector-upgrade"),
Version: v,
Client: mgr.GetClient(),
Recorder: record.NewFakeRecorder(collectorupgrade.RecordBufferSize),
Recorder: mgr.GetEventRecorderFor("opentelemetry-operator"),
}
return up.ManagedInstances(c)
}))
Expand Down
Loading
Loading