Skip to content

Commit 04df6fb

Browse files
bentitovarshaprasad96dtfranz
authored
🌱 Proposed way to unskip some tests (#874)
* Proposed way to unskip some tests TestClusterExtensionChannelVersionExists mostly restored here Signed-off-by: Brett Tofel <[email protected]> * Refactors global variable names Signed-off-by: Brett Tofel <[email protected]> * Removes BundleDeployment related checking In just one test, for now. Signed-off-by: Brett Tofel <[email protected]> * fix unit test - TestClusterExtensionChannelVersionExists * Unskip all - failing tests (up|down)grade should err Unskips all in clusterextension_controller_test.go Signed-off-by: Brett Tofel <[email protected]> * Unskip all clusterextension_registryv1_validation_test.go Still failing tests (up|down)grade should err b/c we don't have an installedBundle to check against Signed-off-by: Brett Tofel <[email protected]> * debugging Signed-off-by: Varsha Prasad Narsing <[email protected]> * Fixes and additions pending & unpack path Signed-off-by: Brett Tofel <[email protected]> * Fix linter, remove debug logs and extraneous file Signed-off-by: dtfranz <[email protected]> * Fix e2e failure due to race condition Signed-off-by: dtfranz <[email protected]> --------- Signed-off-by: Brett Tofel <[email protected]> Signed-off-by: Varsha Prasad Narsing <[email protected]> Signed-off-by: dtfranz <[email protected]> Co-authored-by: Varsha Prasad Narsing <[email protected]> Co-authored-by: dtfranz <[email protected]>
1 parent b993945 commit 04df6fb

9 files changed

+343
-249
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const (
9292
TypePackageDeprecated = "PackageDeprecated"
9393
TypeChannelDeprecated = "ChannelDeprecated"
9494
TypeBundleDeprecated = "BundleDeprecated"
95+
TypeUnpacked = "Unpacked"
9596

9697
ReasonErrorGettingClient = "ErrorGettingClient"
9798
ReasonBundleLoadFailed = "BundleLoadFailed"
@@ -101,9 +102,11 @@ const (
101102
ReasonInstallationSucceeded = "InstallationSucceeded"
102103
ReasonResolutionFailed = "ResolutionFailed"
103104

104-
ReasonSuccess = "Success"
105-
ReasonDeprecated = "Deprecated"
106-
ReasonUpgradeFailed = "UpgradeFailed"
105+
ReasonSuccess = "Success"
106+
ReasonDeprecated = "Deprecated"
107+
ReasonUpgradeFailed = "UpgradeFailed"
108+
ReasonHasValidBundleUnknown = "HasValidBundleUnknown"
109+
ReasonUnpackPending = "UnpackPending"
107110
)
108111

109112
func init() {
@@ -116,6 +119,7 @@ func init() {
116119
TypePackageDeprecated,
117120
TypeChannelDeprecated,
118121
TypeBundleDeprecated,
122+
TypeUnpacked,
119123
)
120124
// TODO(user): add Reasons from above
121125
conditionsets.ConditionReasons = append(conditionsets.ConditionReasons,
@@ -128,6 +132,8 @@ func init() {
128132
ReasonBundleLoadFailed,
129133
ReasonErrorGettingClient,
130134
ReasonInstallationStatusUnknown,
135+
ReasonHasValidBundleUnknown,
136+
ReasonUnpackPending,
131137
)
132138
}
133139

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ require (
165165
github.com/skeema/knownhosts v1.2.2 // indirect
166166
github.com/spf13/cast v1.5.0 // indirect
167167
github.com/stoewer/go-strcase v1.3.0 // indirect
168+
github.com/stretchr/objx v0.5.2 // indirect
168169
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
169170
github.com/ulikunitz/xz v0.5.11 // indirect
170171
github.com/vbatts/tar-split v0.11.5 // indirect

internal/controllers/clusterextension_controller.go

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
235235
setDeprecationStatusesUnknown(&ext.Status.Conditions, "deprecation checks have not been attempted as installation has failed", ext.GetGeneration())
236236
return ctrl.Result{}, err
237237
}
238+
// set deprecation status after _successful_ resolution
239+
SetDeprecationStatus(ext, bundle)
238240

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

260262
switch unpackResult.State {
261263
case rukpaksource.StatePending:
262-
updateStatusUnpackPending(&ext.Status, unpackResult)
264+
updateStatusUnpackPending(&ext.Status, unpackResult, ext.GetGeneration())
263265
// There must be a limit to number of entries if status is stuck at
264266
// unpack pending.
267+
setHasValidBundleUnknown(&ext.Status.Conditions, "unpack pending", ext.GetGeneration())
268+
setInstalledStatusConditionUnknown(&ext.Status.Conditions, "installation has not been attempted as unpack is pending", ext.GetGeneration())
269+
265270
return ctrl.Result{}, nil
266271
case rukpaksource.StateUnpacking:
267272
updateStatusUnpacking(&ext.Status, unpackResult)
273+
setHasValidBundleUnknown(&ext.Status.Conditions, "unpack pending", ext.GetGeneration())
274+
setInstalledStatusConditionUnknown(&ext.Status.Conditions, "installation has not been attempted as unpack is pending", ext.GetGeneration())
268275
return ctrl.Result{}, nil
269276
case rukpaksource.StateUnpacked:
270277
// TODO: Add finalizer to clean the stored bundles, after https://github.com/operator-framework/rukpak/pull/897
@@ -409,7 +416,7 @@ func (r *ClusterExtensionReconciler) resolve(ctx context.Context, ext ocv1alpha1
409416
channelName := ext.Spec.Channel
410417
versionRange := ext.Spec.Version
411418

412-
installedBundle, err := r.installedBundle(ctx, allBundles, &ext)
419+
installedBundle, err := GetInstalledbundle(ctx, r.ActionClientGetter, allBundles, &ext)
413420
if err != nil {
414421
return nil, err
415422
}
@@ -669,8 +676,41 @@ func clusterExtensionRequestsForCatalog(c client.Reader, logger logr.Logger) crh
669676
}
670677
}
671678

672-
func (r *ClusterExtensionReconciler) installedBundle(ctx context.Context, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
673-
cl, err := r.ActionClientGetter.ActionClientFor(ctx, ext)
679+
type releaseState string
680+
681+
const (
682+
stateNeedsInstall releaseState = "NeedsInstall"
683+
stateNeedsUpgrade releaseState = "NeedsUpgrade"
684+
stateUnchanged releaseState = "Unchanged"
685+
stateError releaseState = "Error"
686+
)
687+
688+
func (r *ClusterExtensionReconciler) getReleaseState(cl helmclient.ActionInterface, obj metav1.Object, chrt *chart.Chart, values chartutil.Values, post *postrenderer) (*release.Release, releaseState, error) {
689+
currentRelease, err := cl.Get(obj.GetName())
690+
if err != nil && !errors.Is(err, driver.ErrReleaseNotFound) {
691+
return nil, stateError, err
692+
}
693+
if errors.Is(err, driver.ErrReleaseNotFound) {
694+
return nil, stateNeedsInstall, nil
695+
}
696+
697+
desiredRelease, err := cl.Upgrade(obj.GetName(), r.ReleaseNamespace, chrt, values, func(upgrade *action.Upgrade) error {
698+
upgrade.DryRun = true
699+
return nil
700+
}, helmclient.AppendUpgradePostRenderer(post))
701+
if err != nil {
702+
return currentRelease, stateError, err
703+
}
704+
if desiredRelease.Manifest != currentRelease.Manifest ||
705+
currentRelease.Info.Status == release.StatusFailed ||
706+
currentRelease.Info.Status == release.StatusSuperseded {
707+
return currentRelease, stateNeedsUpgrade, nil
708+
}
709+
return currentRelease, stateUnchanged, nil
710+
}
711+
712+
var GetInstalledbundle = func(ctx context.Context, acg helmclient.ActionClientGetter, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
713+
cl, err := acg.ActionClientFor(ctx, ext)
674714
if err != nil {
675715
return nil, err
676716
}
@@ -706,39 +746,6 @@ func (r *ClusterExtensionReconciler) installedBundle(ctx context.Context, allBun
706746
return resultSet[0], nil
707747
}
708748

709-
type releaseState string
710-
711-
const (
712-
stateNeedsInstall releaseState = "NeedsInstall"
713-
stateNeedsUpgrade releaseState = "NeedsUpgrade"
714-
stateUnchanged releaseState = "Unchanged"
715-
stateError releaseState = "Error"
716-
)
717-
718-
func (r *ClusterExtensionReconciler) getReleaseState(cl helmclient.ActionInterface, obj metav1.Object, chrt *chart.Chart, values chartutil.Values, post *postrenderer) (*release.Release, releaseState, error) {
719-
currentRelease, err := cl.Get(obj.GetName())
720-
if err != nil && !errors.Is(err, driver.ErrReleaseNotFound) {
721-
return nil, stateError, err
722-
}
723-
if errors.Is(err, driver.ErrReleaseNotFound) {
724-
return nil, stateNeedsInstall, nil
725-
}
726-
727-
desiredRelease, err := cl.Upgrade(obj.GetName(), r.ReleaseNamespace, chrt, values, func(upgrade *action.Upgrade) error {
728-
upgrade.DryRun = true
729-
return nil
730-
}, helmclient.AppendUpgradePostRenderer(post))
731-
if err != nil {
732-
return currentRelease, stateError, err
733-
}
734-
if desiredRelease.Manifest != currentRelease.Manifest ||
735-
currentRelease.Info.Status == release.StatusFailed ||
736-
currentRelease.Info.Status == release.StatusSuperseded {
737-
return currentRelease, stateNeedsUpgrade, nil
738-
}
739-
return currentRelease, stateUnchanged, nil
740-
}
741-
742749
type errRequiredResourceNotFound struct {
743750
error
744751
}

0 commit comments

Comments
 (0)