Skip to content

Commit d9a0715

Browse files
authored
Add better test coverage, debug log (#2599)
1 parent 16c712c commit d9a0715

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

controllers/reconcile_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
8888
}
8989
deploymentExtraPorts := paramsWithModeAndReplicas(v1alpha1.ModeDeployment, 3)
9090
deploymentExtraPorts.OtelCol.Spec.Ports = append(deploymentExtraPorts.OtelCol.Spec.Ports, extraPorts)
91+
deploymentExtraPorts.OtelCol.Spec.DeploymentUpdateStrategy = appsv1.DeploymentStrategy{
92+
RollingUpdate: &appsv1.RollingUpdateDeployment{
93+
MaxUnavailable: &intstr.IntOrString{
94+
Type: intstr.Int,
95+
IntVal: 1,
96+
},
97+
MaxSurge: &intstr.IntOrString{
98+
Type: intstr.Int,
99+
IntVal: 1,
100+
},
101+
},
102+
}
91103
ingressParams := newParamsAssertNoErr(t, "", testFileIngress)
92104
ingressParams.OtelCol.Spec.Ingress.Type = "ingress"
93105
updatedIngressParams := newParamsAssertNoErr(t, "", testFileIngress)
@@ -143,6 +155,9 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
143155
assert.Equal(t, int32(2), *d.Spec.Replicas)
144156
assert.Contains(t, d.Annotations, annotationName)
145157
assert.Contains(t, d.Labels, labelName)
158+
// confirm the initial strategy is unset
159+
assert.Equal(t, d.Spec.Strategy.RollingUpdate.MaxUnavailable.IntVal, int32(0))
160+
assert.Equal(t, d.Spec.Strategy.RollingUpdate.MaxSurge.IntVal, int32(0))
146161
exists, err = populateObjectIfExists(t, &v1.Service{}, namespacedObjectName(naming.Service(params.OtelCol.Name), params.OtelCol.Namespace))
147162
assert.NoError(t, err)
148163
assert.True(t, exists)
@@ -163,6 +178,9 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
163178
assert.NoError(t, err)
164179
assert.True(t, exists)
165180
assert.Equal(t, int32(3), *d.Spec.Replicas)
181+
// confirm the strategy has been changed
182+
assert.Equal(t, d.Spec.Strategy.RollingUpdate.MaxUnavailable.IntVal, int32(1))
183+
assert.Equal(t, d.Spec.Strategy.RollingUpdate.MaxSurge.IntVal, int32(1))
166184
// confirm that we don't remove annotations and labels even if we don't set them
167185
assert.Contains(t, d.Annotations, annotationName)
168186
assert.Contains(t, d.Labels, labelName)

pkg/collector/upgrade/upgrade.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (u VersionUpgrade) ManagedInstance(ctx context.Context, otelcol v1alpha1.Op
115115

116116
if instanceV.GreaterThan(&Latest.Version) {
117117
// Update with the latest known version, which is what we have from versions.txt
118-
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())
118+
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())
119119

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

131131
return otelcol, nil

0 commit comments

Comments
 (0)