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

Add better test coverage, debug log #2599

Merged
merged 1 commit into from
Feb 2, 2024
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
18 changes: 18 additions & 0 deletions controllers/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
}
deploymentExtraPorts := paramsWithModeAndReplicas(v1alpha1.ModeDeployment, 3)
deploymentExtraPorts.OtelCol.Spec.Ports = append(deploymentExtraPorts.OtelCol.Spec.Ports, extraPorts)
deploymentExtraPorts.OtelCol.Spec.DeploymentUpdateStrategy = appsv1.DeploymentStrategy{
RollingUpdate: &appsv1.RollingUpdateDeployment{
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
MaxSurge: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
},
},
}
ingressParams := newParamsAssertNoErr(t, "", testFileIngress)
ingressParams.OtelCol.Spec.Ingress.Type = "ingress"
updatedIngressParams := newParamsAssertNoErr(t, "", testFileIngress)
Expand Down Expand Up @@ -143,6 +155,9 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
assert.Equal(t, int32(2), *d.Spec.Replicas)
assert.Contains(t, d.Annotations, annotationName)
assert.Contains(t, d.Labels, labelName)
// confirm the initial strategy is unset
assert.Equal(t, d.Spec.Strategy.RollingUpdate.MaxUnavailable.IntVal, int32(0))
assert.Equal(t, d.Spec.Strategy.RollingUpdate.MaxSurge.IntVal, int32(0))
exists, err = populateObjectIfExists(t, &v1.Service{}, namespacedObjectName(naming.Service(params.OtelCol.Name), params.OtelCol.Namespace))
assert.NoError(t, err)
assert.True(t, exists)
Expand All @@ -163,6 +178,9 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
assert.NoError(t, err)
assert.True(t, exists)
assert.Equal(t, int32(3), *d.Spec.Replicas)
// confirm the strategy has been changed
assert.Equal(t, d.Spec.Strategy.RollingUpdate.MaxUnavailable.IntVal, int32(1))
assert.Equal(t, d.Spec.Strategy.RollingUpdate.MaxSurge.IntVal, int32(1))
// confirm that we don't remove annotations and labels even if we don't set them
assert.Contains(t, d.Annotations, annotationName)
assert.Contains(t, d.Labels, labelName)
Expand Down
4 changes: 2 additions & 2 deletions pkg/collector/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (u VersionUpgrade) ManagedInstance(ctx context.Context, otelcol v1alpha1.Op

if instanceV.GreaterThan(&Latest.Version) {
// Update with the latest known version, which is what we have from versions.txt
u.Log.Info("no upgrade routines are needed for the OpenTelemetry instance", "name", otelcol.Name, "namespace", otelcol.Namespace, "version", otelcol.Status.Version, "latest", Latest.Version.String())
u.Log.V(4).Info("no upgrade routines are needed for the OpenTelemetry instance", "name", otelcol.Name, "namespace", otelcol.Namespace, "version", otelcol.Status.Version, "latest", Latest.Version.String())

otelColV, err := semver.NewVersion(u.Version.OpenTelemetryCollector)
if err != nil {
Expand All @@ -125,7 +125,7 @@ func (u VersionUpgrade) ManagedInstance(ctx context.Context, otelcol v1alpha1.Op
u.Log.Info("upgraded OpenTelemetry Collector version", "name", otelcol.Name, "namespace", otelcol.Namespace, "version", otelcol.Status.Version)
otelcol.Status.Version = u.Version.OpenTelemetryCollector
} else {
u.Log.Info("skipping upgrade for OpenTelemetry Collector instance", "name", otelcol.Name, "namespace", otelcol.Namespace)
u.Log.V(4).Info("skipping upgrade for OpenTelemetry Collector instance", "name", otelcol.Name, "namespace", otelcol.Namespace)
}

return otelcol, nil
Expand Down
Loading