Skip to content

Commit 4d047c2

Browse files
Merge pull request #447 from supreeth7/add-int-tests
feat: add integration tests for install ack
2 parents 9381448 + 6d97f1d commit 4d047c2

4 files changed

Lines changed: 121 additions & 6 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ GOLANGCI_LINT_VERSION:=v1.43.0
1111
OPM_VERSION:=v1.24.0
1212

1313
# Build Flags
14-
export CGO_ENABLED:=1
14+
export CGO_ENABLED:=0
1515
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
1616
SHORT_SHA=$(shell git rev-parse --short HEAD)
1717
VERSION?=${SHORT_SHA}

apis/addons/v1alpha1/addons_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,11 @@ const (
319319
// Addon has timed out waiting for acknowledgement from the underlying addon.
320320
AddonReasonDeletionTimedOut = "AddonReasonDeletionTimedOut"
321321

322-
// Addon Instance is not yet installed.
322+
// Addon instance is not yet installed.
323323
AddonReasonInstanceNotInstalled = "AddonInstanceNotInstalled"
324+
325+
// Addon instance has been successfully installed.
326+
AddonReasonInstanceInstalled = "AddonInstanceInstalled"
324327
)
325328

326329
type AddonNamespace struct {

integration/addon_test.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,88 @@ func (s *integrationTestSuite) TestAddonConditions() {
407407
s.Require().Equal(addonsv1alpha1.AddonReasonMissingCSV, availableCond.Reason)
408408
})
409409

410+
s.Run("sets_installed=true_with_install_ack_required", func() {
411+
// Remove addon before starting the test.
412+
s.addonCleanup(addon, ctx)
413+
414+
addon := addonWithInstallAck()
415+
416+
err := integration.Client.Create(ctx, addon)
417+
s.Require().NoError(err)
418+
419+
addonCSV := &operatorsv1alpha1.ClusterServiceVersion{
420+
ObjectMeta: metav1.ObjectMeta{
421+
Namespace: "namespace-onbgdions",
422+
Name: "reference-addon.v0.1.0",
423+
},
424+
}
425+
426+
// Assert that the csv phase has succeeded while the
427+
// addon is being installed.
428+
err = integration.WaitForObject(
429+
ctx,
430+
s.T(), defaultAddonAvailabilityTimeout, addonCSV, "to have succeeded phase",
431+
func(obj client.Object) (done bool, err error) {
432+
csv := obj.(*operatorsv1alpha1.ClusterServiceVersion)
433+
return csv.Status.Phase == operatorsv1alpha1.CSVPhaseSucceeded, nil
434+
})
435+
s.Require().NoError(err)
436+
437+
err = integration.Client.Get(ctx, client.ObjectKeyFromObject(addon), addon)
438+
s.Require().NoError(err)
439+
440+
// Assert that the addon's installed condition is false.
441+
// i.e. even though the csv phase has succeeded, addon doesn't report as installed.
442+
s.Require().True(meta.IsStatusConditionFalse(addon.Status.Conditions, addonsv1alpha1.Installed))
443+
444+
instance := &addonsv1alpha1.AddonInstance{}
445+
err = integration.Client.Get(ctx, types.NamespacedName{
446+
Name: addonsv1alpha1.DefaultAddonInstanceName,
447+
Namespace: addon.Spec.Install.OLMOwnNamespace.Namespace,
448+
}, instance)
449+
s.Require().NoError(err)
450+
451+
// Assert 'Installed' condition is not present in addon instance.
452+
s.Require().Nil(meta.FindStatusCondition(instance.Status.Conditions, addonsv1alpha1.AddonInstanceConditionInstalled.String()))
453+
454+
// We impersonate the addon's operator and report its addon instance as installed.
455+
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
456+
Type: addonsv1alpha1.AddonInstanceConditionInstalled.String(),
457+
Reason: addonsv1alpha1.AddonReasonInstanceInstalled,
458+
Message: "Addon instance is installed",
459+
Status: metav1.ConditionTrue,
460+
})
461+
462+
err = integration.Client.Status().Update(ctx, instance)
463+
s.Require().NoError(err)
464+
465+
// Wait until addon has installed=true.
466+
// i.e. Addon Instance has been installed & CSV phase has succeeded.
467+
err = integration.WaitForObject(
468+
ctx,
469+
s.T(), defaultAddonAvailabilityTimeout, addon, "to be installed",
470+
func(obj client.Object) (done bool, err error) {
471+
a := obj.(*addonsv1alpha1.Addon)
472+
return meta.IsStatusConditionTrue(
473+
a.Status.Conditions, addonsv1alpha1.Installed), nil
474+
})
475+
s.Require().NoError(err)
476+
477+
err = integration.Client.Get(ctx, client.ObjectKeyFromObject(addon), addon)
478+
s.Require().NoError(err)
479+
480+
// Assert that the required conditions are met.
481+
instanceInstalledCond := meta.FindStatusCondition(instance.Status.Conditions, addonsv1alpha1.AddonInstanceConditionInstalled.String())
482+
s.Require().NotNil(instanceInstalledCond)
483+
s.Require().Equal(metav1.ConditionTrue, instanceInstalledCond.Status)
484+
availableCond := meta.FindStatusCondition(addon.Status.Conditions, addonsv1alpha1.Available)
485+
s.Require().NotNil(availableCond)
486+
s.Require().Equal(metav1.ConditionTrue, availableCond.Status)
487+
addonInstalledCond := meta.FindStatusCondition(addon.Status.Conditions, addonsv1alpha1.Installed)
488+
s.Require().NotNil(addonInstalledCond)
489+
s.Require().Equal(metav1.ConditionTrue, addonInstalledCond.Status)
490+
})
491+
410492
s.T().Cleanup(func() {
411493
s.addonCleanup(addon, ctx)
412494
})

integration/fixtures_test.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@ func addonWithVersion(version string, catalogSrc string) *addonsv1alpha1.Addon {
114114
},
115115
Spec: addonsv1alpha1.AddonSpec{
116116
DeleteAckRequired: true,
117-
// TODO: Modify reference-addon to report addon instance as installed without depending on the addon's availability
118-
// InstallAckRequired: true,
119-
Version: version,
120-
DisplayName: "addon-oisafbo12",
117+
Version: version,
118+
DisplayName: "addon-oisafbo12",
121119
Namespaces: []addonsv1alpha1.AddonNamespace{
122120
{Name: "namespace-onbgdions"},
123121
{Name: "namespace-pioghfndb"},
@@ -140,6 +138,38 @@ func addonWithVersion(version string, catalogSrc string) *addonsv1alpha1.Addon {
140138
}
141139
}
142140

141+
func addonWithInstallAck() *addonsv1alpha1.Addon {
142+
return &addonsv1alpha1.Addon{
143+
ObjectMeta: metav1.ObjectMeta{
144+
Name: "addon-oisafbo12",
145+
},
146+
Spec: addonsv1alpha1.AddonSpec{
147+
DeleteAckRequired: true,
148+
InstallAckRequired: true,
149+
Version: "v0.1.0",
150+
DisplayName: "addon-oisafbo12",
151+
Namespaces: []addonsv1alpha1.AddonNamespace{
152+
{Name: "namespace-onbgdions"},
153+
{Name: "namespace-pioghfndb"},
154+
},
155+
Install: addonsv1alpha1.AddonInstallSpec{
156+
Type: addonsv1alpha1.OLMOwnNamespace,
157+
OLMOwnNamespace: &addonsv1alpha1.AddonInstallOLMOwnNamespace{
158+
AddonInstallOLMCommon: addonsv1alpha1.AddonInstallOLMCommon{
159+
Namespace: "namespace-onbgdions",
160+
CatalogSourceImage: referenceAddonCatalogSourceImageWorking,
161+
Channel: "alpha",
162+
PackageName: "reference-addon",
163+
Config: &addonsv1alpha1.SubscriptionConfig{
164+
EnvironmentVariables: referenceAddonConfigEnvObjects,
165+
},
166+
},
167+
},
168+
},
169+
},
170+
}
171+
}
172+
143173
func addonWithAdditionalCatalogSource() *addonsv1alpha1.Addon {
144174
return &addonsv1alpha1.Addon{
145175
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)