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 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
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
46 changes: 23 additions & 23 deletions pkg/collector/reconcile/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,29 @@ func TestExpectedDeployments(t *testing.T) {
assert.Len(t, expected, 0)
})

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(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})
assert.NoError(t, err)

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

assert.NoError(t, err)
assert.True(t, exists)
assert.Equal(t, orgUID, actual.OwnerReferences[0].UID)
assert.ElementsMatch(t, actual.Spec.Template.Spec.Containers[0].Args, []string{"--enable-prometheus-cr-watcher"})
assert.Equal(t, int32(1), *actual.Spec.Replicas)
})

t.Run("should not update target allocator deployment replicas when collector max replicas is set", func(t *testing.T) {
replicas, maxReplicas := int32(2), int32(10)
param := Params{
Expand Down Expand Up @@ -168,29 +191,6 @@ 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) {
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

err = expectedDeployments(ctx, param, []v1.Deployment{updatedDeploy})
assert.NoError(t, err)

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

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.Equal(t, int32(1), *actual.Spec.Replicas)
})

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)
Expand Down