Skip to content

Commit 6caaf33

Browse files
varshaprasad96dtfranz
authored andcommitted
debugging
Signed-off-by: Varsha Prasad Narsing <[email protected]>
1 parent 39e42df commit 6caaf33

File tree

5 files changed

+179
-109
lines changed

5 files changed

+179
-109
lines changed

internal/.DS_Store

6 KB
Binary file not shown.

internal/controllers/clusterextension_controller.go

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func (r *ClusterExtensionReconciler) resolve(ctx context.Context, ext ocv1alpha1
409409
channelName := ext.Spec.Channel
410410
versionRange := ext.Spec.Version
411411

412-
installedBundle, err := r.installedBundle(ctx, allBundles, &ext)
412+
installedBundle, err := GetInstalledbundle(ctx, r.ActionClientGetter, allBundles, &ext)
413413
if err != nil {
414414
return nil, err
415415
}
@@ -447,11 +447,14 @@ func (r *ClusterExtensionReconciler) resolve(ctx context.Context, ext ocv1alpha1
447447
if err != nil {
448448
return nil, err
449449
}
450+
fmt.Println("upgrade error!!!!")
450451
upgradeErrorPrefix = fmt.Sprintf("error upgrading from currently installed version %q: ", installedBundleVersion.String())
451452
}
452453
if len(resultSet) == 0 {
454+
fmt.Println("empty resilt set!!")
453455
switch {
454456
case versionRange != "" && channelName != "":
457+
fmt.Println("here!!!")
455458
return nil, fmt.Errorf("%sno package %q matching version %q in channel %q found", upgradeErrorPrefix, packageName, versionRange, channelName)
456459
case versionRange != "":
457460
return nil, fmt.Errorf("%sno package %q matching version %q found", upgradeErrorPrefix, packageName, versionRange)
@@ -669,8 +672,41 @@ func clusterExtensionRequestsForCatalog(c client.Reader, logger logr.Logger) crh
669672
}
670673
}
671674

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

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-
742745
type errRequiredResourceNotFound struct {
743746
error
744747
}

internal/controllers/clusterextension_controller_test.go

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
ctrl "sigs.k8s.io/controller-runtime"
2020
"sigs.k8s.io/controller-runtime/pkg/client"
2121

22+
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
2223
"github.com/operator-framework/operator-registry/alpha/declcfg"
2324
"github.com/operator-framework/operator-registry/alpha/property"
2425
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
@@ -416,11 +417,16 @@ func verifyConditionsInvariants(t *testing.T, ext *ocv1alpha1.ClusterExtension)
416417
func TestClusterExtensionUpgrade(t *testing.T) {
417418
cl, reconciler := newClientAndReconciler(t)
418419
mockUnpacker := unpacker.(*MockUnpacker)
419-
// Set up the Unpack method to return a result with StateUnpacked
420+
// Set up the Unpack method to return a result with StateUnpackPending
420421
mockUnpacker.On("Unpack", mock.Anything, mock.AnythingOfType("*v1alpha2.BundleDeployment")).Return(&source.Result{
421422
State: source.StatePending,
422423
}, nil)
423424
ctx := context.Background()
425+
defer func() {
426+
controllers.GetInstalledbundle = func(ctx context.Context, acg helmclient.ActionClientGetter, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
427+
return nil, nil
428+
}
429+
}()
424430

425431
t.Run("semver upgrade constraints enforcement of upgrades within major version", func(t *testing.T) {
426432
defer featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.ForceSemverUpgradeConstraints, true)()
@@ -470,6 +476,22 @@ func TestClusterExtensionUpgrade(t *testing.T) {
470476
err = cl.Update(ctx, clusterExtension)
471477
require.NoError(t, err)
472478

479+
controllers.GetInstalledbundle = func(ctx context.Context, acg helmclient.ActionClientGetter, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
480+
return &catalogmetadata.Bundle{
481+
Bundle: declcfg.Bundle{
482+
Name: "operatorhub/prometheus/beta/1.0.0",
483+
Package: "prometheus",
484+
Image: "quay.io/operatorhubio/[email protected]",
485+
Properties: []property.Property{
486+
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName":"prometheus","version":"1.0.0"}`)},
487+
{Type: property.TypeGVK, Value: json.RawMessage(`[]`)},
488+
},
489+
},
490+
CatalogName: "fake-catalog",
491+
InChannels: []*catalogmetadata.Channel{&prometheusBetaChannel},
492+
}, nil
493+
}
494+
473495
// Run reconcile again
474496
res, err = reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: extKey})
475497
require.Error(t, err)
@@ -488,7 +510,7 @@ func TestClusterExtensionUpgrade(t *testing.T) {
488510
require.NotNil(t, cond)
489511
assert.Equal(t, metav1.ConditionFalse, cond.Status)
490512
assert.Equal(t, ocv1alpha1.ReasonResolutionFailed, cond.Reason)
491-
assert.Equal(t, "error upgrading from currently installed version \"1.0.0\": no package \"prometheus\" matching version \"2.0.0\" found in channel \"beta\"", cond.Message)
513+
assert.Equal(t, "error upgrading from currently installed version \"1.0.0\": no package \"prometheus\" matching version \"2.0.0\" in channel \"beta\" found", cond.Message)
492514

493515
// Valid update skipping one version
494516
clusterExtension.Spec.Version = "1.2.0"
@@ -563,6 +585,22 @@ func TestClusterExtensionUpgrade(t *testing.T) {
563585
err = cl.Update(ctx, clusterExtension)
564586
require.NoError(t, err)
565587

588+
controllers.GetInstalledbundle = func(ctx context.Context, acg helmclient.ActionClientGetter, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
589+
return &catalogmetadata.Bundle{
590+
Bundle: declcfg.Bundle{
591+
Name: "operatorhub/prometheus/beta/1.0.0",
592+
Package: "prometheus",
593+
Image: "quay.io/operatorhubio/[email protected]",
594+
Properties: []property.Property{
595+
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName":"prometheus","version":"1.0.0"}`)},
596+
{Type: property.TypeGVK, Value: json.RawMessage(`[]`)},
597+
},
598+
},
599+
CatalogName: "fake-catalog",
600+
InChannels: []*catalogmetadata.Channel{&prometheusBetaChannel},
601+
}, nil
602+
}
603+
566604
// Run reconcile again
567605
res, err = reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: extKey})
568606
require.Error(t, err)
@@ -581,7 +619,7 @@ func TestClusterExtensionUpgrade(t *testing.T) {
581619
require.NotNil(t, cond)
582620
assert.Equal(t, metav1.ConditionFalse, cond.Status)
583621
assert.Equal(t, ocv1alpha1.ReasonResolutionFailed, cond.Reason)
584-
assert.Equal(t, "error upgrading from currently installed version \"1.0.0\": no package \"prometheus\" matching version \"1.2.0\" found in channel \"beta\"", cond.Message)
622+
assert.Equal(t, "error upgrading from currently installed version \"1.0.0\": no package \"prometheus\" matching version \"1.2.0\" in channel \"beta\" found", cond.Message)
585623

586624
// Valid update skipping one version
587625
clusterExtension.Spec.Version = "1.0.1"
@@ -670,6 +708,22 @@ func TestClusterExtensionUpgrade(t *testing.T) {
670708
err = cl.Update(ctx, clusterExtension)
671709
require.NoError(t, err)
672710

711+
controllers.GetInstalledbundle = func(ctx context.Context, acg helmclient.ActionClientGetter, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
712+
return &catalogmetadata.Bundle{
713+
Bundle: declcfg.Bundle{
714+
Name: "operatorhub/prometheus/beta/1.0.0",
715+
Package: "prometheus",
716+
Image: "quay.io/operatorhubio/[email protected]",
717+
Properties: []property.Property{
718+
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName":"prometheus","version":"1.0.0"}`)},
719+
{Type: property.TypeGVK, Value: json.RawMessage(`[]`)},
720+
},
721+
},
722+
CatalogName: "fake-catalog",
723+
InChannels: []*catalogmetadata.Channel{&prometheusBetaChannel},
724+
}, nil
725+
}
726+
673727
// Run reconcile again
674728
res, err = reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: extKey})
675729
require.NoError(t, err)
@@ -701,6 +755,11 @@ func TestClusterExtensionDowngrade(t *testing.T) {
701755
State: source.StatePending,
702756
}, nil)
703757
ctx := context.Background()
758+
defer func() {
759+
controllers.GetInstalledbundle = func(ctx context.Context, acg helmclient.ActionClientGetter, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
760+
return nil, nil
761+
}
762+
}()
704763

705764
t.Run("enforce upgrade constraints", func(t *testing.T) {
706765
for _, tt := range []struct {
@@ -761,6 +820,22 @@ func TestClusterExtensionDowngrade(t *testing.T) {
761820
err = cl.Update(ctx, clusterExtension)
762821
require.NoError(t, err)
763822

823+
controllers.GetInstalledbundle = func(ctx context.Context, acg helmclient.ActionClientGetter, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
824+
return &catalogmetadata.Bundle{
825+
Bundle: declcfg.Bundle{
826+
Name: "operatorhub/prometheus/beta/1.0.1",
827+
Package: "prometheus",
828+
Image: "quay.io/operatorhubio/[email protected]",
829+
Properties: []property.Property{
830+
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName":"prometheus","version":"1.0.1"}`)},
831+
{Type: property.TypeGVK, Value: json.RawMessage(`[]`)},
832+
},
833+
},
834+
CatalogName: "fake-catalog",
835+
InChannels: []*catalogmetadata.Channel{&prometheusBetaChannel},
836+
}, nil
837+
}
838+
764839
// Run reconcile again
765840
res, err = reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: extKey})
766841
require.Error(t, err)
@@ -779,7 +854,7 @@ func TestClusterExtensionDowngrade(t *testing.T) {
779854
require.NotNil(t, cond)
780855
assert.Equal(t, metav1.ConditionFalse, cond.Status)
781856
assert.Equal(t, ocv1alpha1.ReasonResolutionFailed, cond.Reason)
782-
assert.Equal(t, "error upgrading from currently installed version \"1.0.1\": no package \"prometheus\" matching version \"1.0.0\" found in channel \"beta\"", cond.Message)
857+
assert.Equal(t, "error upgrading from currently installed version \"1.0.1\": no package \"prometheus\" matching version \"1.0.0\" in channel \"beta\" found", cond.Message)
783858
})
784859
}
785860
})
@@ -844,6 +919,22 @@ func TestClusterExtensionDowngrade(t *testing.T) {
844919
err = cl.Update(ctx, clusterExtension)
845920
require.NoError(t, err)
846921

922+
controllers.GetInstalledbundle = func(ctx context.Context, acg helmclient.ActionClientGetter, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
923+
return &catalogmetadata.Bundle{
924+
Bundle: declcfg.Bundle{
925+
Name: "operatorhub/prometheus/beta/2.0.0",
926+
Package: "prometheus",
927+
Image: "quay.io/operatorhubio/[email protected]",
928+
Properties: []property.Property{
929+
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName":"prometheus","version":"2.0.0"}`)},
930+
{Type: property.TypeGVK, Value: json.RawMessage(`[]`)},
931+
},
932+
},
933+
CatalogName: "fake-catalog",
934+
InChannels: []*catalogmetadata.Channel{&prometheusBetaChannel},
935+
}, nil
936+
}
937+
847938
// Run reconcile again
848939
res, err = reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: extKey})
849940
require.NoError(t, err)

internal/controllers/clusterextension_status.go

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)