Skip to content

Commit c6a7cea

Browse files
everettravenbentito
authored andcommitted
updates to test so far
Signed-off-by: everettraven <[email protected]>
1 parent fdc4e8c commit c6a7cea

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

.github/workflows/e2e-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- name: Build controller image
2626
run: make e2e-build
2727
- name: Save image
28-
run: docker save quay.io/operator-framework/olm:local -o olm-image.tar
28+
run: docker save quay.io/operator-framework/olm:dev -o olm-image.tar
2929
- name: Upload Docker image as artifact
3030
uses: actions/upload-artifact@v4
3131
with:

pkg/controller/operators/olm/operatorgroup.go

+5
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ func (a *Operator) copyToNamespace(prototype *v1alpha1.ClusterServiceVersion, ns
808808

809809
existing, err := a.copiedCSVLister.Namespace(nsTo).Get(prototype.GetName())
810810
if apierrors.IsNotFound(err) {
811+
prototype.Annotations[nonStatusCopyHashAnnotation] = nonstatus
811812
created, err := a.client.OperatorsV1alpha1().ClusterServiceVersions(nsTo).Create(context.TODO(), prototype, metav1.CreateOptions{})
812813
if err != nil {
813814
return nil, fmt.Errorf("failed to create new CSV: %w", err)
@@ -816,6 +817,10 @@ func (a *Operator) copyToNamespace(prototype *v1alpha1.ClusterServiceVersion, ns
816817
if _, err := a.client.OperatorsV1alpha1().ClusterServiceVersions(nsTo).UpdateStatus(context.TODO(), created, metav1.UpdateOptions{}); err != nil {
817818
return nil, fmt.Errorf("failed to update status on new CSV: %w", err)
818819
}
820+
prototype.Annotations[statusCopyHashAnnotation] = status
821+
if _, err = a.client.OperatorsV1alpha1().ClusterServiceVersions(nsTo).Update(context.TODO(), prototype, metav1.UpdateOptions{}); err != nil {
822+
return nil, fmt.Errorf("failed to update annotations after updating status: %w", err)
823+
}
819824
return &v1alpha1.ClusterServiceVersion{
820825
ObjectMeta: metav1.ObjectMeta{
821826
Name: created.Name,

pkg/controller/operators/olm/operatorgroup_test.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ func TestCopyToNamespace(t *testing.T) {
4444
Name: "copy created if does not exist",
4545
FromNamespace: "from",
4646
ToNamespace: "to",
47+
Hash: "hn-1",
48+
StatusHash: "hs",
4749
Prototype: v1alpha1.ClusterServiceVersion{
4850
ObjectMeta: metav1.ObjectMeta{
4951
Name: "name",
52+
Annotations: map[string]string{},
5053
},
5154
Spec: v1alpha1.ClusterServiceVersionSpec{
5255
Replaces: "replacee",
@@ -60,6 +63,9 @@ func TestCopyToNamespace(t *testing.T) {
6063
ObjectMeta: metav1.ObjectMeta{
6164
Name: "name",
6265
Namespace: "to",
66+
Annotations: map[string]string{
67+
nonStatusCopyHashAnnotation: "hn-1",
68+
},
6369
},
6470
Spec: v1alpha1.ClusterServiceVersionSpec{
6571
Replaces: "replacee",
@@ -80,6 +86,13 @@ func TestCopyToNamespace(t *testing.T) {
8086
Phase: "waxing gibbous",
8187
},
8288
}),
89+
ktesting.NewUpdateAction(gvr, "to", &v1alpha1.ClusterServiceVersion{
90+
ObjectMeta: metav1.ObjectMeta{
91+
Annotations: map[string]string{
92+
statusCopyHashAnnotation: "hs",
93+
},
94+
},
95+
})
8396
},
8497
ExpectedResult: &v1alpha1.ClusterServiceVersion{
8598
ObjectMeta: metav1.ObjectMeta{
@@ -97,6 +110,7 @@ func TestCopyToNamespace(t *testing.T) {
97110
Prototype: v1alpha1.ClusterServiceVersion{
98111
ObjectMeta: metav1.ObjectMeta{
99112
Name: "name",
113+
Annotations: map[string]string{},
100114
},
101115
Spec: v1alpha1.ClusterServiceVersionSpec{
102116
Replaces: "replacee",
@@ -150,6 +164,7 @@ func TestCopyToNamespace(t *testing.T) {
150164
Prototype: v1alpha1.ClusterServiceVersion{
151165
ObjectMeta: metav1.ObjectMeta{
152166
Name: "name",
167+
Annotations: map[string]string{},
153168
},
154169
Spec: v1alpha1.ClusterServiceVersionSpec{
155170
Replaces: "replacee",
@@ -203,6 +218,7 @@ func TestCopyToNamespace(t *testing.T) {
203218
Prototype: v1alpha1.ClusterServiceVersion{
204219
ObjectMeta: metav1.ObjectMeta{
205220
Name: "name",
221+
Annotations: map[string]string{},
206222
},
207223
Spec: v1alpha1.ClusterServiceVersionSpec{
208224
Replaces: "replacee",
@@ -270,6 +286,7 @@ func TestCopyToNamespace(t *testing.T) {
270286
Prototype: v1alpha1.ClusterServiceVersion{
271287
ObjectMeta: metav1.ObjectMeta{
272288
Name: "name",
289+
Annotations: map[string]string{},
273290
},
274291
},
275292
ExistingCopy: &metav1.PartialObjectMetadata{
@@ -311,10 +328,15 @@ func TestCopyToNamespace(t *testing.T) {
311328
logger: logger,
312329
}
313330

314-
result, err := o.copyToNamespace(tc.Prototype.DeepCopy(), tc.FromNamespace, tc.ToNamespace, tc.Hash, tc.StatusHash)
331+
proto := tc.Prototype.DeepCopy()
332+
result, err := o.copyToNamespace(proto, tc.FromNamespace, tc.ToNamespace, tc.Hash, tc.StatusHash)
315333

316334
if tc.ExpectedError == nil {
317335
require.NoError(t, err)
336+
// if there is no error expected, ensure that the hash annotations are always present on the resulting CSV
337+
annotations := proto.GetObjectMeta().GetAnnotations()
338+
require.Equal(t, tc.Hash, annotations[nonStatusCopyHashAnnotation])
339+
require.Equal(t, tc.StatusHash, annotations[statusCopyHashAnnotation])
318340
} else {
319341
require.EqualError(t, err, tc.ExpectedError.Error())
320342
}

0 commit comments

Comments
 (0)