Skip to content

Commit f04062f

Browse files
committed
test(install): expect revision history = 1
1 parent 81616cc commit f04062f

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

pkg/controller/install/deployment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,16 @@ func (i *StrategyDeploymentInstaller) deploymentForSpec(name string, spec appsv1
150150
return
151151
}
152152

153-
hash = HashDeploymentSpec(dep.Spec)
154-
dep.Labels[DeploymentSpecHashLabelKey] = hash
155-
156153
// OLM does not support Rollbacks.
157154
// By default, each deployment created by OLM could spawn up to 10 replicaSets.
158155
// By setting the deployments revisionHistoryLimit to 1, OLM will only create up
159156
// to 2 ReplicaSets per deployment it manages, saving memory.
160157
revisionHistoryLimit := int32(1)
161158
dep.Spec.RevisionHistoryLimit = &revisionHistoryLimit
162159

160+
hash = HashDeploymentSpec(dep.Spec)
161+
dep.Labels[DeploymentSpecHashLabelKey] = hash
162+
163163
deployment = dep
164164
return
165165
}

pkg/controller/install/deployment_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ func TestInstallStrategyDeploymentCheckInstallErrors(t *testing.T) {
309309
},
310310
}
311311

312+
revisionHistoryLimit := int32(1)
312313
for _, tt := range tests {
313314
t.Run(tt.description, func(t *testing.T) {
314315
fakeClient := new(clientfakes.FakeInstallStrategyDeploymentInterface)
@@ -317,6 +318,7 @@ func TestInstallStrategyDeploymentCheckInstallErrors(t *testing.T) {
317318

318319
dep := testDeployment("olm-dep-1", namespace, &mockOwner)
319320
dep.Spec.Template.SetAnnotations(map[string]string{"test": "annotation"})
321+
dep.Spec.RevisionHistoryLimit = &revisionHistoryLimit
320322
dep.SetLabels(labels.CloneAndAddLabel(dep.ObjectMeta.GetLabels(), DeploymentSpecHashLabelKey, HashDeploymentSpec(dep.Spec)))
321323
fakeClient.FindAnyDeploymentsMatchingLabelsReturns(
322324
[]*appsv1.Deployment{
@@ -333,6 +335,7 @@ func TestInstallStrategyDeploymentCheckInstallErrors(t *testing.T) {
333335

334336
deployment := testDeployment("olm-dep-1", namespace, &mockOwner)
335337
deployment.Spec.Template.SetAnnotations(map[string]string{"test": "annotation"})
338+
deployment.Spec.RevisionHistoryLimit = &revisionHistoryLimit
336339
deployment.SetLabels(labels.CloneAndAddLabel(dep.ObjectMeta.GetLabels(), DeploymentSpecHashLabelKey, HashDeploymentSpec(deployment.Spec)))
337340
fakeClient.CreateOrUpdateDeploymentReturns(&deployment, tt.createDeploymentErr)
338341
defer func() {
@@ -342,7 +345,6 @@ func TestInstallStrategyDeploymentCheckInstallErrors(t *testing.T) {
342345
if tt.createDeploymentErr != nil {
343346
err := installer.Install(strategy)
344347
require.Error(t, err)
345-
return
346348
}
347349
})
348350
}

pkg/controller/operators/olm/operator_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"crypto/x509"
99
"crypto/x509/pkix"
1010
"fmt"
11-
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
1211
"math"
1312
"math/big"
1413
"reflect"
@@ -62,6 +61,7 @@ import (
6261
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/ownerutil"
6362
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer"
6463
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/scoped"
64+
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
6565
)
6666

6767
type TestStrategy struct{}
@@ -326,7 +326,10 @@ func buildFakeAPIIntersectionReconcilerThatReturns(result resolver.APIReconcilia
326326
}
327327

328328
func deployment(deploymentName, namespace, serviceAccountName string, templateAnnotations map[string]string) *appsv1.Deployment {
329-
var singleInstance = int32(1)
329+
var (
330+
singleInstance = int32(1)
331+
revisionHistoryLimit = int32(1)
332+
)
330333
return &appsv1.Deployment{
331334
ObjectMeta: metav1.ObjectMeta{
332335
Name: deploymentName,
@@ -338,7 +341,8 @@ func deployment(deploymentName, namespace, serviceAccountName string, templateAn
338341
"app": deploymentName,
339342
},
340343
},
341-
Replicas: &singleInstance,
344+
RevisionHistoryLimit: &revisionHistoryLimit,
345+
Replicas: &singleInstance,
342346
Template: corev1.PodTemplateSpec{
343347
ObjectMeta: metav1.ObjectMeta{
344348
Labels: map[string]string{

0 commit comments

Comments
 (0)