Skip to content

Commit 647fe25

Browse files
committed
Do not derive installplan.spec.clusterServiceNames from bundle IDs
Problem: Historically, when creating an installPlan it's spec.ClusterServiceVersionNames was derived from two sources: 1. The names of CSVs found in "steps" of the installPlan's status.plan 2. The metadata associated with the bundle image These sources couldn't result in duplicate entries as the unpacking job would finish after the installPlan was created and the steps weren't populated until the unpacking job finished. OLM was recently updated to complete the unpacking jobs prior to creating the installPlan, which means that the two sources can cause duplicate entries to appear in the array. Solution: Now that OLM creates the installPlan after successfully unpacking the bundles, we no longer need to derive the names of the CSV from the bundle metadata. Signed-off-by: Alexander Greene <[email protected]>
1 parent 060ce07 commit 647fe25

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

pkg/controller/operators/catalog/operator.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -1593,9 +1593,7 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
15931593
}
15941594
catalogSourceMap[s.Resource.CatalogSource] = struct{}{}
15951595
}
1596-
for _, b := range bundleLookups {
1597-
csvNames = append(csvNames, b.Identifier)
1598-
}
1596+
15991597
catalogSources := []string{}
16001598
for s := range catalogSourceMap {
16011599
catalogSources = append(catalogSources, s)

pkg/controller/operators/catalog/operator_test.go

+64
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,70 @@ func (m *mockTransitioner) ExecutePlan(plan *v1alpha1.InstallPlan) error {
7777
return m.err
7878
}
7979

80+
func TestCreateInstallPlanHasExpectedClusterServiceVersionNames(t *testing.T) {
81+
namespace := "foo"
82+
tests := []struct {
83+
testName string
84+
steps []*v1alpha1.Step
85+
bundleLookups []v1alpha1.BundleLookup
86+
expectedClusterServiceVersionNames []string
87+
}{
88+
/******************************************************************************
89+
Historically, when creating an installPlan it's spec.ClusterServiceVersionNames
90+
was derived from two sources:
91+
1. The names of CSVs found in "steps" of the installPlan's status.plan
92+
2. The metadata associated with the bundle image
93+
94+
These sources couldn't result in duplicate entries as the unpacking job would
95+
finish after the installPlan was created and the steps weren't populated until
96+
the unpacking job finished.
97+
98+
OLM was later updated to complete the unpacking jobs prior to creating
99+
the installPlan, which caused CSVs to be listed twice as the createInstallPlan
100+
function was called with steps and a bundle.
101+
*****************************************************************************/
102+
{
103+
testName: "Check that CSVs are not listed twice if steps and bundles are provided",
104+
steps: []*v1alpha1.Step{{
105+
Resolving: "csv",
106+
Resource: v1alpha1.StepResource{
107+
CatalogSource: "catalog",
108+
CatalogSourceNamespace: namespace,
109+
Group: "operators.coreos.com",
110+
Version: "v1alpha1",
111+
Kind: "ClusterServiceVersion",
112+
Name: "csvA",
113+
Manifest: toManifest(t, csv("csvA", namespace, nil, nil)),
114+
},
115+
Status: v1alpha1.StepStatusUnknown,
116+
}},
117+
bundleLookups: []v1alpha1.BundleLookup{
118+
{
119+
Identifier: "csvA",
120+
},
121+
},
122+
expectedClusterServiceVersionNames: []string{"csvA"},
123+
},
124+
}
125+
for _, tt := range tests {
126+
t.Run(tt.testName, func(t *testing.T) {
127+
ctx, cancel := context.WithCancel(context.TODO())
128+
defer cancel()
129+
130+
op, err := NewFakeOperator(ctx, namespace, []string{namespace})
131+
require.NoError(t, err)
132+
133+
_, err = op.createInstallPlan(namespace, 0, nil, v1alpha1.ApprovalAutomatic, tt.steps, tt.bundleLookups)
134+
require.NoError(t, err)
135+
136+
ipList, err := op.client.OperatorsV1alpha1().InstallPlans(namespace).List(ctx, metav1.ListOptions{})
137+
require.NoError(t, err)
138+
require.Len(t, ipList.Items, 1)
139+
require.Equal(t, tt.expectedClusterServiceVersionNames, ipList.Items[0].Spec.ClusterServiceVersionNames)
140+
})
141+
}
142+
}
143+
80144
func TestTransitionInstallPlan(t *testing.T) {
81145
errMsg := "transition test error"
82146
err := errors.New(errMsg)

0 commit comments

Comments
 (0)