Skip to content

Commit e120237

Browse files
catalog: don't treat permissions errors as terminal
Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent 5c5e862 commit e120237

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

pkg/controller/operators/catalog/operator.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -2036,13 +2036,15 @@ func transitionInstallPlanState(log logrus.FieldLogger, transitioner installPlan
20362036
}
20372037
log.Debug("attempting to install")
20382038
if err := transitioner.ExecutePlan(out); err != nil {
2039-
if now.Sub(out.Status.StartTime.Time) >= timeout {
2039+
if apierrors.IsForbidden(err) || now.Sub(out.Status.StartTime.Time) < timeout {
2040+
// forbidden problems are never terminal since we don't know when a user might provide
2041+
// the service account they specified with more permissions
2042+
out.Status.Message = fmt.Sprintf("retrying execution due to error: %s", err.Error())
2043+
} else {
20402044
out.Status.SetCondition(v1alpha1.ConditionFailed(v1alpha1.InstallPlanInstalled,
20412045
v1alpha1.InstallPlanReasonComponentFailed, err.Error(), &now))
20422046
out.Status.Phase = v1alpha1.InstallPlanPhaseFailed
20432047
out.Status.Message = err.Error()
2044-
} else {
2045-
out.Status.Message = fmt.Sprintf("retrying execution due to error: %s", err.Error())
20462048
}
20472049
return out, err
20482050
} else if !out.Status.NeedsRequeue() {

test/e2e/installplan_e2e_test.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -3638,11 +3638,9 @@ var _ = Describe("Install Plan", func() {
36383638
}
36393639
Expect(ctx.Ctx().Client().Status().Update(context.Background(), newPlan)).To(Succeed())
36403640

3641-
newKey := client.ObjectKeyFromObject(newPlan)
3642-
3643-
Eventually(func() (*operatorsv1alpha1.InstallPlan, error) {
3644-
return newPlan, ctx.Ctx().Client().Get(context.Background(), newKey, newPlan)
3645-
}).Should(HavePhase(operatorsv1alpha1.InstallPlanPhaseFailed))
3641+
ipPhaseCheckerFunc := buildInstallPlanMessageCheckFunc(`cannot create resource "services" in API group`)
3642+
_, err = fetchInstallPlanWithNamespace(GinkgoT(), crc, newPlan.Name, newPlan.Namespace, ipPhaseCheckerFunc)
3643+
require.NoError(GinkgoT(), err)
36463644

36473645
Expect(client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.Background(), &crd))).To(Succeed())
36483646
Eventually(func() error {
@@ -3928,6 +3926,19 @@ func validateCRDVersions(t GinkgoTInterface, c operatorclient.ClientInterface, n
39283926
require.Equal(t, 0, len(expectedVersions), "Actual CRD versions do not match expected")
39293927
}
39303928

3929+
func buildInstallPlanMessageCheckFunc(substring string) checkInstallPlanFunc {
3930+
var lastMessage string
3931+
lastTime := time.Now()
3932+
return func(fip *operatorsv1alpha1.InstallPlan) bool {
3933+
if fip.Status.Message != lastMessage {
3934+
ctx.Ctx().Logf("waiting %s for installplan %s/%s to have message substring %s, have message %s", time.Since(lastTime), fip.Namespace, fip.Name, substring, fip.Status.Phase)
3935+
lastMessage = fip.Status.Message
3936+
lastTime = time.Now()
3937+
}
3938+
return strings.Contains(fip.Status.Message, substring)
3939+
}
3940+
}
3941+
39313942
func buildInstallPlanPhaseCheckFunc(phases ...operatorsv1alpha1.InstallPlanPhase) checkInstallPlanFunc {
39323943
var lastPhase operatorsv1alpha1.InstallPlanPhase
39333944
lastTime := time.Now()

test/e2e/user_defined_sa_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ var _ = Describe("User defined service account", func() {
8383

8484
By("We expect the InstallPlan to be in status: Failed.")
8585
ipName := subscription.Status.Install.Name
86-
ipPhaseCheckerFunc := buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseFailed)
86+
ipPhaseCheckerFunc := buildInstallPlanMessageCheckFunc(`cannot create resource`)
8787
ipGot, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, ipName, generatedNamespace.GetName(), ipPhaseCheckerFunc)
8888
require.NoError(GinkgoT(), err)
8989

@@ -186,12 +186,11 @@ var _ = Describe("User defined service account", func() {
186186
require.NoError(GinkgoT(), err)
187187
require.NotNil(GinkgoT(), subscription)
188188

189-
By("We expect the InstallPlan to be in status: Failed.")
189+
By("We expect the InstallPlan to expose the permissions error.")
190190
ipNameOld := subscription.Status.InstallPlanRef.Name
191-
ipPhaseCheckerFunc := buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseFailed)
192-
ipGotOld, err := fetchInstallPlanWithNamespace(GinkgoT(), crc, ipNameOld, generatedNamespace.GetName(), ipPhaseCheckerFunc)
191+
ipPhaseCheckerFunc := buildInstallPlanMessageCheckFunc(`cannot create resource "clusterserviceversions" in API group "operators.coreos.com" in the namespace`)
192+
_, err = fetchInstallPlanWithNamespace(GinkgoT(), crc, ipNameOld, generatedNamespace.GetName(), ipPhaseCheckerFunc)
193193
require.NoError(GinkgoT(), err)
194-
require.Equal(GinkgoT(), v1alpha1.InstallPlanPhaseFailed, ipGotOld.Status.Phase)
195194

196195
By("Grant permission now and this should trigger an retry of InstallPlan.")
197196
cleanupPerm := grantPermission(GinkgoT(), c, generatedNamespace.GetName(), saName)

0 commit comments

Comments
 (0)