Skip to content

Commit

Permalink
Fixes reconciling Internal Traffic Policy changes and adds test (#2060)
Browse files Browse the repository at this point in the history
* Fixes reconciling Internal Traffic Policy changes and add tests

* add changelog

* issue in changelog
  • Loading branch information
cmergenthaler authored Sep 5, 2023
1 parent 8d3000e commit a7a9c95
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .chloggen/fix-otel-collector-service-reconciliation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixes reconciling otel-collector service's internal traffic policy changes.

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

# (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:
1 change: 1 addition & 0 deletions pkg/collector/reconcile/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func expectedServices(ctx context.Context, params manifests.Params, expected []*
}
updated.Spec.Ports = desired.Spec.Ports
updated.Spec.Selector = desired.Spec.Selector
updated.Spec.InternalTrafficPolicy = desired.Spec.InternalTrafficPolicy

patch := client.MergeFrom(existing)

Expand Down
16 changes: 16 additions & 0 deletions pkg/collector/reconcile/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ func TestExpectedServices(t *testing.T) {
assert.Equal(t, instanceUID, actual.OwnerReferences[0].UID)
assert.Equal(t, "Newest", actual.Spec.Selector["app.kubernetes.io/version"])
})
t.Run("should update service on internal traffic policy change", func(t *testing.T) {
serviceInstance := service("test-collector", params().Instance.Spec.Ports)
createObjectIfNotExists(t, "test-collector", serviceInstance)

newService := serviceWithInternalTrafficPolicy("test-collector", params().Instance.Spec.Ports, v1.ServiceInternalTrafficPolicyLocal)
err := expectedServices(context.Background(), params(), []*v1.Service{newService})
assert.NoError(t, err)

actual := v1.Service{}
exists, err := populateObjectIfExists(t, &actual, types.NamespacedName{Namespace: "default", Name: "test-collector"})

assert.NoError(t, err)
assert.True(t, exists)
assert.Equal(t, instanceUID, actual.OwnerReferences[0].UID)
assert.Equal(t, v1.ServiceInternalTrafficPolicyLocal, *actual.Spec.InternalTrafficPolicy)
})
}

func TestDeleteServices(t *testing.T) {
Expand Down

0 comments on commit a7a9c95

Please sign in to comment.