Skip to content

Commit d051f30

Browse files
author
Supreeth Basabattini
committed
fix: Update RBAC & add int test
1 parent 46fc06f commit d051f30

4 files changed

Lines changed: 81 additions & 0 deletions

File tree

config/deploy/rbac.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ rules:
101101
- operatorgroups
102102
- catalogsources
103103
- subscriptions
104+
- installplans
104105
verbs:
105106
- create
106107
- delete

config/olm/addon-operator.csv.tpl.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ spec:
101101
- operatorgroups
102102
- catalogsources
103103
- subscriptions
104+
- installplans
104105
verbs:
105106
- create
106107
- delete

config/openshift/manifests/addon-operator.csv.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ spec:
101101
- operatorgroups
102102
- catalogsources
103103
- subscriptions
104+
- installplans
104105
verbs:
105106
- create
106107
- delete

integration/addon_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,84 @@ func (s *integrationTestSuite) TestAddonConditions() {
492492
s.T().Cleanup(func() {
493493
s.addonCleanup(addon, ctx)
494494
})
495+
496+
s.Run("test_installplan_pending_condition", func() {
497+
// remove addon before starting the test.
498+
s.addonCleanup(addon, ctx)
499+
500+
addon := addonWithVersion("v0.1.0", referenceAddonCatalogSourceImageWorkingLatest)
501+
502+
err := integration.Client.Create(ctx, addon)
503+
s.Require().NoError(err)
504+
505+
// wait until the addon has installed.
506+
err = integration.WaitForObject(
507+
ctx,
508+
s.T(), defaultAddonAvailabilityTimeout, addon, "to be installed",
509+
func(obj client.Object) (done bool, err error) {
510+
a := obj.(*addonsv1alpha1.Addon)
511+
return meta.IsStatusConditionTrue(
512+
a.Status.Conditions, addonsv1alpha1.Installed), nil
513+
})
514+
s.Require().NoError(err)
515+
516+
err = integration.Client.Get(ctx, client.ObjectKeyFromObject(addon), addon)
517+
s.Require().NoError(err)
518+
519+
// Fetch addon subscription
520+
subscription := &operatorsv1alpha1.Subscription{}
521+
err = integration.Client.Get(ctx, client.ObjectKey{
522+
Namespace: addon.Spec.Install.OLMOwnNamespace.Namespace,
523+
Name: addonUtil.SubscriptionName(addon),
524+
}, subscription)
525+
s.Require().NoError(err)
526+
527+
// Impersonate addon maintainer and patch install plan approval to manual.
528+
subscription.Spec.InstallPlanApproval = operatorsv1alpha1.ApprovalManual
529+
subscription.Status.State = operatorsv1alpha1.SubscriptionStateUpgradePending
530+
err = integration.Client.Update(ctx, subscription)
531+
s.Require().NoError(err)
532+
533+
// Fetch addon installplan
534+
installPlan := &operatorsv1alpha1.InstallPlan{}
535+
err = integration.Client.Get(ctx, client.ObjectKey{
536+
Namespace: addon.Spec.Install.OLMOwnNamespace.Namespace,
537+
Name: subscription.Status.InstallPlanRef.Name,
538+
}, installPlan)
539+
s.Require().NoError(err)
540+
541+
installPlan.Spec.Approval = operatorsv1alpha1.ApprovalManual
542+
installPlan.Spec.Approved = false
543+
err = integration.Client.Update(ctx, installPlan)
544+
s.Require().NoError(err)
545+
546+
err = integration.Client.Get(ctx, client.ObjectKeyFromObject(installPlan), installPlan)
547+
s.Require().NoError(err)
548+
549+
installPlan.Status.Phase = operatorsv1alpha1.InstallPlanPhaseRequiresApproval
550+
err = integration.Client.Status().Update(ctx, installPlan)
551+
s.Require().NoError(err)
552+
553+
// wait until the addon reports as unavailable.
554+
err = integration.WaitForObject(
555+
ctx,
556+
s.T(), defaultAddonAvailabilityTimeout, addon, "to be unavailable",
557+
func(obj client.Object) (done bool, err error) {
558+
a := obj.(*addonsv1alpha1.Addon)
559+
return meta.IsStatusConditionFalse(
560+
a.Status.Conditions, addonsv1alpha1.Available), nil
561+
})
562+
s.Require().NoError(err)
563+
564+
err = integration.Client.Get(ctx, client.ObjectKeyFromObject(addon), addon)
565+
s.Require().NoError(err)
566+
567+
// Assert pending installplan approval reason is reported.
568+
availableCond := meta.FindStatusCondition(addon.Status.Conditions, addonsv1alpha1.Available)
569+
s.Require().NotNil(availableCond)
570+
s.Require().Equal(metav1.ConditionFalse, availableCond.Status)
571+
s.Require().Equal(addonsv1alpha1.AddonReasonInstallPlanPending, availableCond.Reason)
572+
})
495573
}
496574

497575
func (s *integrationTestSuite) TestAddonWithAdditionalCatalogSrc() {

0 commit comments

Comments
 (0)