Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add integration tests for install ack #447

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GOLANGCI_LINT_VERSION:=v1.43.0
OPM_VERSION:=v1.24.0

# Build Flags
export CGO_ENABLED:=1
export CGO_ENABLED:=0
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
SHORT_SHA=$(shell git rev-parse --short HEAD)
VERSION?=${SHORT_SHA}
Expand Down
5 changes: 4 additions & 1 deletion apis/addons/v1alpha1/addons_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,11 @@ const (
// Addon has timed out waiting for acknowledgement from the underlying addon.
AddonReasonDeletionTimedOut = "AddonReasonDeletionTimedOut"

// Addon Instance is not yet installed.
// Addon instance is not yet installed.
AddonReasonInstanceNotInstalled = "AddonInstanceNotInstalled"

// Addon instance has been successfully installed.
AddonReasonInstanceInstalled = "AddonInstanceInstalled"
)

type AddonNamespace struct {
Expand Down
82 changes: 82 additions & 0 deletions integration/addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,88 @@ func (s *integrationTestSuite) TestAddonConditions() {
s.Require().Equal(addonsv1alpha1.AddonReasonMissingCSV, availableCond.Reason)
})

s.Run("sets_installed=true_with_install_ack_required", func() {
// Remove addon before starting the test.
s.addonCleanup(addon, ctx)

addon := addonWithInstallAck()

err := integration.Client.Create(ctx, addon)
s.Require().NoError(err)

addonCSV := &operatorsv1alpha1.ClusterServiceVersion{
ObjectMeta: metav1.ObjectMeta{
Namespace: "namespace-onbgdions",
Name: "reference-addon.v0.1.0",
},
}

// Assert that the csv phase has succeeded while the
// addon is being installed.
err = integration.WaitForObject(
supreeth7 marked this conversation as resolved.
Show resolved Hide resolved
ctx,
s.T(), defaultAddonAvailabilityTimeout, addonCSV, "to have succeeded phase",
func(obj client.Object) (done bool, err error) {
csv := obj.(*operatorsv1alpha1.ClusterServiceVersion)
return csv.Status.Phase == operatorsv1alpha1.CSVPhaseSucceeded, nil
})
s.Require().NoError(err)

err = integration.Client.Get(ctx, client.ObjectKeyFromObject(addon), addon)
s.Require().NoError(err)

// Assert that the addon's installed condition is false.
// i.e. even though the csv phase has succeeded, addon doesn't report as installed.
s.Require().True(meta.IsStatusConditionFalse(addon.Status.Conditions, addonsv1alpha1.Installed))

instance := &addonsv1alpha1.AddonInstance{}
err = integration.Client.Get(ctx, types.NamespacedName{
Name: addonsv1alpha1.DefaultAddonInstanceName,
Namespace: addon.Spec.Install.OLMOwnNamespace.Namespace,
}, instance)
s.Require().NoError(err)

// Assert 'Installed' condition is not present in addon instance.
s.Require().Nil(meta.FindStatusCondition(instance.Status.Conditions, addonsv1alpha1.AddonInstanceConditionInstalled.String()))

// We impersonate the addon's operator and report its addon instance as installed.
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
Type: addonsv1alpha1.AddonInstanceConditionInstalled.String(),
Reason: addonsv1alpha1.AddonReasonInstanceInstalled,
Message: "Addon instance is installed",
Status: metav1.ConditionTrue,
})

err = integration.Client.Status().Update(ctx, instance)
s.Require().NoError(err)

// Wait until addon has installed=true.
// i.e. Addon Instance has been installed & CSV phase has succeeded.
err = integration.WaitForObject(
ctx,
s.T(), defaultAddonAvailabilityTimeout, addon, "to be installed",
func(obj client.Object) (done bool, err error) {
a := obj.(*addonsv1alpha1.Addon)
return meta.IsStatusConditionTrue(
a.Status.Conditions, addonsv1alpha1.Installed), nil
})
s.Require().NoError(err)

err = integration.Client.Get(ctx, client.ObjectKeyFromObject(addon), addon)
s.Require().NoError(err)

// Assert that the required conditions are met.
instanceInstalledCond := meta.FindStatusCondition(instance.Status.Conditions, addonsv1alpha1.AddonInstanceConditionInstalled.String())
s.Require().NotNil(instanceInstalledCond)
s.Require().Equal(metav1.ConditionTrue, instanceInstalledCond.Status)
availableCond := meta.FindStatusCondition(addon.Status.Conditions, addonsv1alpha1.Available)
s.Require().NotNil(availableCond)
s.Require().Equal(metav1.ConditionTrue, availableCond.Status)
addonInstalledCond := meta.FindStatusCondition(addon.Status.Conditions, addonsv1alpha1.Installed)
s.Require().NotNil(addonInstalledCond)
s.Require().Equal(metav1.ConditionTrue, addonInstalledCond.Status)
})

s.T().Cleanup(func() {
s.addonCleanup(addon, ctx)
})
Expand Down
38 changes: 34 additions & 4 deletions integration/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ func addonWithVersion(version string, catalogSrc string) *addonsv1alpha1.Addon {
},
Spec: addonsv1alpha1.AddonSpec{
DeleteAckRequired: true,
// TODO: Modify reference-addon to report addon instance as installed without depending on the addon's availability
// InstallAckRequired: true,
Version: version,
DisplayName: "addon-oisafbo12",
Version: version,
DisplayName: "addon-oisafbo12",
Namespaces: []addonsv1alpha1.AddonNamespace{
{Name: "namespace-onbgdions"},
{Name: "namespace-pioghfndb"},
Expand All @@ -140,6 +138,38 @@ func addonWithVersion(version string, catalogSrc string) *addonsv1alpha1.Addon {
}
}

func addonWithInstallAck() *addonsv1alpha1.Addon {
return &addonsv1alpha1.Addon{
ObjectMeta: metav1.ObjectMeta{
Name: "addon-oisafbo12",
},
Spec: addonsv1alpha1.AddonSpec{
DeleteAckRequired: true,
InstallAckRequired: true,
Version: "v0.1.0",
DisplayName: "addon-oisafbo12",
Namespaces: []addonsv1alpha1.AddonNamespace{
{Name: "namespace-onbgdions"},
{Name: "namespace-pioghfndb"},
},
Install: addonsv1alpha1.AddonInstallSpec{
Type: addonsv1alpha1.OLMOwnNamespace,
OLMOwnNamespace: &addonsv1alpha1.AddonInstallOLMOwnNamespace{
AddonInstallOLMCommon: addonsv1alpha1.AddonInstallOLMCommon{
Namespace: "namespace-onbgdions",
CatalogSourceImage: referenceAddonCatalogSourceImageWorking,
Channel: "alpha",
PackageName: "reference-addon",
Config: &addonsv1alpha1.SubscriptionConfig{
EnvironmentVariables: referenceAddonConfigEnvObjects,
},
},
},
},
},
}
}

func addonWithAdditionalCatalogSource() *addonsv1alpha1.Addon {
return &addonsv1alpha1.Addon{
ObjectMeta: metav1.ObjectMeta{
Expand Down