Skip to content

Commit 49b7c51

Browse files
everettraventmshort
authored andcommitted
updates to test so far
Signed-off-by: everettraven <[email protected]>
1 parent 670d12b commit 49b7c51

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,7 @@ func (a *Operator) copyToNamespace(prototype *v1alpha1.ClusterServiceVersion, ns
809809

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

pkg/controller/operators/olm/operatorgroup_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ func TestCopyToNamespace(t *testing.T) {
4646
Name: "copy created if does not exist",
4747
FromNamespace: "from",
4848
ToNamespace: "to",
49+
Hash: "hn-1",
50+
StatusHash: "hs",
4951
Prototype: v1alpha1.ClusterServiceVersion{
5052
ObjectMeta: metav1.ObjectMeta{
5153
Name: "name",
54+
Annotations: map[string]string{},
5255
},
5356
Spec: v1alpha1.ClusterServiceVersionSpec{
5457
Replaces: "replacee",
@@ -62,6 +65,9 @@ func TestCopyToNamespace(t *testing.T) {
6265
ObjectMeta: metav1.ObjectMeta{
6366
Name: "name",
6467
Namespace: "to",
68+
Annotations: map[string]string{
69+
nonStatusCopyHashAnnotation: "hn-1",
70+
},
6571
},
6672
Spec: v1alpha1.ClusterServiceVersionSpec{
6773
Replaces: "replacee",
@@ -82,6 +88,13 @@ func TestCopyToNamespace(t *testing.T) {
8288
Phase: "waxing gibbous",
8389
},
8490
}),
91+
ktesting.NewUpdateAction(gvr, "to", &v1alpha1.ClusterServiceVersion{
92+
ObjectMeta: metav1.ObjectMeta{
93+
Annotations: map[string]string{
94+
statusCopyHashAnnotation: "hs",
95+
},
96+
},
97+
})
8598
},
8699
ExpectedResult: &v1alpha1.ClusterServiceVersion{
87100
ObjectMeta: metav1.ObjectMeta{
@@ -99,6 +112,7 @@ func TestCopyToNamespace(t *testing.T) {
99112
Prototype: v1alpha1.ClusterServiceVersion{
100113
ObjectMeta: metav1.ObjectMeta{
101114
Name: "name",
115+
Annotations: map[string]string{},
102116
},
103117
Spec: v1alpha1.ClusterServiceVersionSpec{
104118
Replaces: "replacee",
@@ -152,6 +166,7 @@ func TestCopyToNamespace(t *testing.T) {
152166
Prototype: v1alpha1.ClusterServiceVersion{
153167
ObjectMeta: metav1.ObjectMeta{
154168
Name: "name",
169+
Annotations: map[string]string{},
155170
},
156171
Spec: v1alpha1.ClusterServiceVersionSpec{
157172
Replaces: "replacee",
@@ -205,6 +220,7 @@ func TestCopyToNamespace(t *testing.T) {
205220
Prototype: v1alpha1.ClusterServiceVersion{
206221
ObjectMeta: metav1.ObjectMeta{
207222
Name: "name",
223+
Annotations: map[string]string{},
208224
},
209225
Spec: v1alpha1.ClusterServiceVersionSpec{
210226
Replaces: "replacee",
@@ -272,6 +288,7 @@ func TestCopyToNamespace(t *testing.T) {
272288
Prototype: v1alpha1.ClusterServiceVersion{
273289
ObjectMeta: metav1.ObjectMeta{
274290
Name: "name",
291+
Annotations: map[string]string{},
275292
},
276293
},
277294
ExistingCopy: &metav1.PartialObjectMetadata{
@@ -313,10 +330,15 @@ func TestCopyToNamespace(t *testing.T) {
313330
logger: logger,
314331
}
315332

316-
result, err := o.copyToNamespace(tc.Prototype.DeepCopy(), tc.FromNamespace, tc.ToNamespace, tc.Hash, tc.StatusHash)
333+
proto := tc.Prototype.DeepCopy()
334+
result, err := o.copyToNamespace(proto, tc.FromNamespace, tc.ToNamespace, tc.Hash, tc.StatusHash)
317335

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

0 commit comments

Comments
 (0)