Skip to content

Commit

Permalink
Add better test coverage, debug log (#2599)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaronoff97 authored Feb 2, 2024
1 parent 16c712c commit d9a0715
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
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

0 comments on commit d9a0715

Please sign in to comment.