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

Update the target allocator on any manifest change #1027

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions pkg/collector/parser/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func singlePortFromConfigEndpoint(logger logr.Logger, name string, config map[in
case name == "kubeletstats":
return nil

// ignore prometheus receiver as it has no listening endpoint
case name == "prometheus":
return nil

default:
endpoint = getAddressFromConfig(logger, name, endpointKey, config)
}
Expand Down
6 changes: 1 addition & 5 deletions pkg/collector/reconcile/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ func expectedDeployments(ctx context.Context, params Params, expected []appsv1.D
updated.Labels = map[string]string{}
}

if desired.Labels["app.kubernetes.io/component"] == "opentelemetry-targetallocator" {
updated.Spec.Template.Spec.Containers[0].Image = desired.Spec.Template.Spec.Containers[0].Image
} else {
updated.Spec = desired.Spec
}
updated.Spec = desired.Spec
updated.ObjectMeta.OwnerReferences = desired.ObjectMeta.OwnerReferences

for k, v := range desired.ObjectMeta.Annotations {
Expand Down
15 changes: 8 additions & 7 deletions pkg/collector/reconcile/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,14 @@ func TestExpectedDeployments(t *testing.T) {
assert.Equal(t, int32(2), *actual.Spec.Replicas)
})

t.Run("should not update target allocator deployment when the container image is not updated", func(t *testing.T) {
t.Run("should update target allocator deployment when the container image is updated", func(t *testing.T) {
ctx := context.Background()
createObjectIfNotExists(t, "test-targetallocator", &expectedTADeploy)
orgUID := expectedTADeploy.OwnerReferences[0].UID

updatedParam, err := newParams("test/test-img", "")
assert.NoError(t, err)
updatedDeploy := targetallocator.Deployment(updatedParam.Config, logger, param.Instance)
*updatedDeploy.Spec.Replicas = int32(3)
jaronoff97 marked this conversation as resolved.
Show resolved Hide resolved
updatedDeploy := targetallocator.Deployment(updatedParam.Config, logger, updatedParam.Instance)

err = expectedDeployments(ctx, param, []v1.Deployment{updatedDeploy})
assert.NoError(t, err)
Expand All @@ -187,17 +186,18 @@ func TestExpectedDeployments(t *testing.T) {
assert.NoError(t, err)
assert.True(t, exists)
assert.Equal(t, orgUID, actual.OwnerReferences[0].UID)
assert.Equal(t, expectedTADeploy.Spec.Template.Spec.Containers[0].Image, actual.Spec.Template.Spec.Containers[0].Image)
assert.NotEqual(t, expectedTADeploy.Spec.Template.Spec.Containers[0].Image, actual.Spec.Template.Spec.Containers[0].Image)
assert.Equal(t, int32(1), *actual.Spec.Replicas)
})

t.Run("should update target allocator deployment when the container image is updated", func(t *testing.T) {
t.Run("should update target allocator deployment when the prometheusCR is updated", func(t *testing.T) {
ctx := context.Background()
createObjectIfNotExists(t, "test-targetallocator", &expectedTADeploy)
orgUID := expectedTADeploy.OwnerReferences[0].UID

updatedParam, err := newParams("test/test-img", "")
updatedParam, err := newParams(expectedTADeploy.Spec.Template.Spec.Containers[0].Image, "")
assert.NoError(t, err)
updatedParam.Instance.Spec.TargetAllocator.PrometheusCR.Enabled = true
updatedDeploy := targetallocator.Deployment(updatedParam.Config, logger, updatedParam.Instance)

err = expectedDeployments(ctx, param, []v1.Deployment{updatedDeploy})
Expand All @@ -209,7 +209,8 @@ func TestExpectedDeployments(t *testing.T) {
assert.NoError(t, err)
assert.True(t, exists)
assert.Equal(t, orgUID, actual.OwnerReferences[0].UID)
assert.NotEqual(t, expectedTADeploy.Spec.Template.Spec.Containers[0].Image, actual.Spec.Template.Spec.Containers[0].Image)
assert.True(t, len(actual.Spec.Template.Spec.Containers[0].Args) == 1)
assert.True(t, actual.Spec.Template.Spec.Containers[0].Args[0] == "--enable-prometheus-cr-watcher")
jaronoff97 marked this conversation as resolved.
Show resolved Hide resolved
assert.Equal(t, int32(1), *actual.Spec.Replicas)
})

Expand Down