Skip to content

Commit 25abfc7

Browse files
committed
Modify the manual instalplan test case to verify the recreation
Signed-off-by: Vu Dinh <[email protected]>
1 parent 554d40b commit 25abfc7

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

Diff for: pkg/controller/operators/catalog/operator.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
2222
"k8s.io/apiextensions-apiserver/pkg/apiserver/validation"
2323
extinf "k8s.io/apiextensions-apiserver/pkg/client/informers/externalversions"
24+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2627
"k8s.io/apimachinery/pkg/labels"
@@ -959,7 +960,7 @@ func (o *Operator) nothingToUpdate(logger *logrus.Entry, sub *v1alpha1.Subscript
959960
// isInstallPlanMissing checks if the installplan is missing or not
960961
func (o *Operator) isInstallPlanMissing(sub *v1alpha1.Subscription) bool {
961962
_, err := o.client.OperatorsV1alpha1().InstallPlans(sub.GetNamespace()).Get(context.TODO(), sub.Status.Install.Name, metav1.GetOptions{})
962-
if err != nil {
963+
if k8serrors.IsNotFound(err) {
963964
return true
964965
}
965966
return false

Diff for: pkg/controller/registry/resolver/step_resolver.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (r *OperatorStepResolver) ResolveSteps(namespace string, _ SourceQuerier) (
205205
func (r *OperatorStepResolver) requireInstallPlanRecreate(sub *v1alpha1.Subscription) bool {
206206
if sub.Status.InstallPlanRef != nil && sub.Status.State == v1alpha1.SubscriptionStateUpgradePending {
207207
_, err := r.client.OperatorsV1alpha1().InstallPlans(sub.GetNamespace()).Get(context.TODO(), sub.Status.Install.Name, metav1.GetOptions{})
208-
if err != nil {
208+
if errors.IsNotFound(err) {
209209
return true
210210
}
211211
}

Diff for: test/e2e/csv_e2e_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -3439,6 +3439,29 @@ func awaitCSV(t GinkgoTInterface, c versioned.Interface, namespace, name string,
34393439
return fetched, err
34403440
}
34413441

3442+
func awaitInstallPlanChanged(t GinkgoTInterface, c versioned.Interface, namespace, subName, ipName string) (string, error) {
3443+
var name string
3444+
var err error
3445+
3446+
err = wait.Poll(pollInterval, pollDuration, func() (bool, error) {
3447+
fetched, err := c.OperatorsV1alpha1().Subscriptions(namespace).Get(context.TODO(), subName, metav1.GetOptions{})
3448+
if err != nil {
3449+
if k8serrors.IsNotFound(err) {
3450+
return false, nil
3451+
}
3452+
return false, err
3453+
}
3454+
3455+
if fetched.Status.Install.Name == ipName {
3456+
return false, nil
3457+
}
3458+
name = fetched.Status.Install.Name
3459+
return true, nil
3460+
})
3461+
3462+
return name, err
3463+
}
3464+
34423465
func waitForDeployment(c operatorclient.ClientInterface, name string) error {
34433466
return wait.Poll(pollInterval, pollDuration, func() (bool, error) {
34443467
_, err := c.GetDeployment(testNamespace, name)

Diff for: test/e2e/subscription_e2e_test.go

+18-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,24 @@ var _ = Describe("Subscription", func() {
217217
require.Equal(GinkgoT(), v1alpha1.ApprovalManual, installPlan.Spec.Approval)
218218
require.Equal(GinkgoT(), v1alpha1.InstallPlanPhaseRequiresApproval, installPlan.Status.Phase)
219219

220-
installPlan.Spec.Approved = true
221-
_, err = crc.OperatorsV1alpha1().InstallPlans(testNamespace).Update(context.Background(), installPlan, metav1.UpdateOptions{})
220+
// Delete the current installplan
221+
err = crc.OperatorsV1alpha1().InstallPlans(testNamespace).Delete(context.Background(), installPlan.Name, metav1.DeleteOptions{})
222+
require.NoError(GinkgoT(), err)
223+
224+
ipName, err := awaitInstallPlanChanged(GinkgoT(), crc, testNamespace, "manual-subscription", installPlan.Name)
225+
require.NoError(GinkgoT(), err)
226+
227+
// Fetch new installplan
228+
newInstallPlan, err := fetchInstallPlan(GinkgoT(), crc, ipName, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseRequiresApproval))
229+
require.NoError(GinkgoT(), err)
230+
require.NotNil(GinkgoT(), newInstallPlan)
231+
232+
require.NotEqual(GinkgoT(), installPlan.Name, newInstallPlan.Name, "expected new installplan recreated")
233+
require.Equal(GinkgoT(), v1alpha1.ApprovalManual, newInstallPlan.Spec.Approval)
234+
require.Equal(GinkgoT(), v1alpha1.InstallPlanPhaseRequiresApproval, newInstallPlan.Status.Phase)
235+
236+
newInstallPlan.Spec.Approved = true
237+
_, err = crc.OperatorsV1alpha1().InstallPlans(testNamespace).Update(context.Background(), newInstallPlan, metav1.UpdateOptions{})
222238
require.NoError(GinkgoT(), err)
223239

224240
subscription, err = fetchSubscription(crc, testNamespace, "manual-subscription", subscriptionStateAtLatestChecker)

0 commit comments

Comments
 (0)