Skip to content

🌱 Proposed way to unskip some tests #874

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

Merged
merged 10 commits into from
May 29, 2024
12 changes: 9 additions & 3 deletions api/v1alpha1/clusterextension_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const (
TypePackageDeprecated = "PackageDeprecated"
TypeChannelDeprecated = "ChannelDeprecated"
TypeBundleDeprecated = "BundleDeprecated"
TypeUnpacked = "Unpacked"

ReasonErrorGettingClient = "ErrorGettingClient"
ReasonBundleLoadFailed = "BundleLoadFailed"
Expand All @@ -101,9 +102,11 @@ const (
ReasonInstallationSucceeded = "InstallationSucceeded"
ReasonResolutionFailed = "ResolutionFailed"

ReasonSuccess = "Success"
ReasonDeprecated = "Deprecated"
ReasonUpgradeFailed = "UpgradeFailed"
ReasonSuccess = "Success"
ReasonDeprecated = "Deprecated"
ReasonUpgradeFailed = "UpgradeFailed"
ReasonHasValidBundleUnknown = "HasValidBundleUnknown"
ReasonUnpackPending = "UnpackPending"
)

func init() {
Expand All @@ -116,6 +119,7 @@ func init() {
TypePackageDeprecated,
TypeChannelDeprecated,
TypeBundleDeprecated,
TypeUnpacked,
)
// TODO(user): add Reasons from above
conditionsets.ConditionReasons = append(conditionsets.ConditionReasons,
Expand All @@ -128,6 +132,8 @@ func init() {
ReasonBundleLoadFailed,
ReasonErrorGettingClient,
ReasonInstallationStatusUnknown,
ReasonHasValidBundleUnknown,
ReasonUnpackPending,
)
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ require (
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/vbatts/tar-split v0.11.5 // indirect
Expand Down
81 changes: 44 additions & 37 deletions internal/controllers/clusterextension_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
setDeprecationStatusesUnknown(&ext.Status.Conditions, "deprecation checks have not been attempted as installation has failed", ext.GetGeneration())
return ctrl.Result{}, err
}
// set deprecation status after _successful_ resolution
SetDeprecationStatus(ext, bundle)

bundleVersion, err := bundle.Version()
if err != nil {
Expand All @@ -259,12 +261,17 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp

switch unpackResult.State {
case rukpaksource.StatePending:
updateStatusUnpackPending(&ext.Status, unpackResult)
updateStatusUnpackPending(&ext.Status, unpackResult, ext.GetGeneration())
// There must be a limit to number of entries if status is stuck at
// unpack pending.
setHasValidBundleUnknown(&ext.Status.Conditions, "unpack pending", ext.GetGeneration())
setInstalledStatusConditionUnknown(&ext.Status.Conditions, "installation has not been attempted as unpack is pending", ext.GetGeneration())

return ctrl.Result{}, nil
case rukpaksource.StateUnpacking:
updateStatusUnpacking(&ext.Status, unpackResult)
setHasValidBundleUnknown(&ext.Status.Conditions, "unpack pending", ext.GetGeneration())
setInstalledStatusConditionUnknown(&ext.Status.Conditions, "installation has not been attempted as unpack is pending", ext.GetGeneration())
return ctrl.Result{}, nil
case rukpaksource.StateUnpacked:
// TODO: Add finalizer to clean the stored bundles, after https://github.com/operator-framework/rukpak/pull/897
Expand Down Expand Up @@ -409,7 +416,7 @@ func (r *ClusterExtensionReconciler) resolve(ctx context.Context, ext ocv1alpha1
channelName := ext.Spec.Channel
versionRange := ext.Spec.Version

installedBundle, err := r.installedBundle(ctx, allBundles, &ext)
installedBundle, err := GetInstalledbundle(ctx, r.ActionClientGetter, allBundles, &ext)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -669,8 +676,41 @@ func clusterExtensionRequestsForCatalog(c client.Reader, logger logr.Logger) crh
}
}

func (r *ClusterExtensionReconciler) installedBundle(ctx context.Context, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
cl, err := r.ActionClientGetter.ActionClientFor(ctx, ext)
type releaseState string

const (
stateNeedsInstall releaseState = "NeedsInstall"
stateNeedsUpgrade releaseState = "NeedsUpgrade"
stateUnchanged releaseState = "Unchanged"
stateError releaseState = "Error"
)

func (r *ClusterExtensionReconciler) getReleaseState(cl helmclient.ActionInterface, obj metav1.Object, chrt *chart.Chart, values chartutil.Values, post *postrenderer) (*release.Release, releaseState, error) {
currentRelease, err := cl.Get(obj.GetName())
if err != nil && !errors.Is(err, driver.ErrReleaseNotFound) {
return nil, stateError, err
}
if errors.Is(err, driver.ErrReleaseNotFound) {
return nil, stateNeedsInstall, nil
}

desiredRelease, err := cl.Upgrade(obj.GetName(), r.ReleaseNamespace, chrt, values, func(upgrade *action.Upgrade) error {
upgrade.DryRun = true
return nil
}, helmclient.AppendUpgradePostRenderer(post))
if err != nil {
return currentRelease, stateError, err
}
if desiredRelease.Manifest != currentRelease.Manifest ||
currentRelease.Info.Status == release.StatusFailed ||
currentRelease.Info.Status == release.StatusSuperseded {
return currentRelease, stateNeedsUpgrade, nil
}
return currentRelease, stateUnchanged, nil
}

var GetInstalledbundle = func(ctx context.Context, acg helmclient.ActionClientGetter, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
cl, err := acg.ActionClientFor(ctx, ext)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -706,39 +746,6 @@ func (r *ClusterExtensionReconciler) installedBundle(ctx context.Context, allBun
return resultSet[0], nil
}

type releaseState string

const (
stateNeedsInstall releaseState = "NeedsInstall"
stateNeedsUpgrade releaseState = "NeedsUpgrade"
stateUnchanged releaseState = "Unchanged"
stateError releaseState = "Error"
)

func (r *ClusterExtensionReconciler) getReleaseState(cl helmclient.ActionInterface, obj metav1.Object, chrt *chart.Chart, values chartutil.Values, post *postrenderer) (*release.Release, releaseState, error) {
currentRelease, err := cl.Get(obj.GetName())
if err != nil && !errors.Is(err, driver.ErrReleaseNotFound) {
return nil, stateError, err
}
if errors.Is(err, driver.ErrReleaseNotFound) {
return nil, stateNeedsInstall, nil
}

desiredRelease, err := cl.Upgrade(obj.GetName(), r.ReleaseNamespace, chrt, values, func(upgrade *action.Upgrade) error {
upgrade.DryRun = true
return nil
}, helmclient.AppendUpgradePostRenderer(post))
if err != nil {
return currentRelease, stateError, err
}
if desiredRelease.Manifest != currentRelease.Manifest ||
currentRelease.Info.Status == release.StatusFailed ||
currentRelease.Info.Status == release.StatusSuperseded {
return currentRelease, stateNeedsUpgrade, nil
}
return currentRelease, stateUnchanged, nil
}

type errRequiredResourceNotFound struct {
error
}
Expand Down
Loading
Loading