Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1cb254c
Use Helm List operator to determine Deployed status (#1379)
tmshort Oct 23, 2024
14d7349
Merge branch 'main' into synchronize
Oct 24, 2024
bf84b22
UPSTREAM: <carry>: Add OpenShift specific files
dtfranz Oct 26, 2023
fb079d5
UPSTREAM: <carry>: Drop commitchecker
awgreene Nov 3, 2023
faef13a
UPSTREAM: <carry>: Updating ose-olm-operator-controller-container ima…
Dec 16, 2023
5519b99
UPSTREAM: <carry>: update owners
Mar 27, 2024
ad4542b
UPSTREAM: <carry>: Add pointer to tooling README
bentito Apr 1, 2024
f4b51c3
UPSTREAM: <carry>: Disable Validating Admission Policy APIs downstream
Apr 26, 2024
e3d2603
UPSTREAM: <carry>: Updating ose-olm-operator-controller-container ima…
Mar 27, 2024
b1f25dd
UPSTREAM: <carry>: Enable Validating Admission Policy APIs downstream
Apr 30, 2024
951d924
UPSTREAM: <carry>: manifests: set required-scc for openshift workloads
liouk May 2, 2024
ba64a89
UPSTREAM: <carry>: Updating ose-olm-operator-controller-container ima…
May 25, 2024
7e7ad10
UPSTREAM: <carry>: add everettraven to approvers+reviewers
everettraven Jun 24, 2024
87c3686
UPSTREAM: <carry>: add openshift kustomize overlay
everettraven Jul 9, 2024
9043db2
UPSTREAM: <carry>: Add tmshort to approvers
tmshort Sep 11, 2024
1150825
UPSTREAM: <carry>: Updating ose-olm-operator-controller-container ima…
Sep 18, 2024
94d50e0
UPSTREAM: <carry>: Properly copy and call kustomize
tmshort Sep 23, 2024
980a9c6
UPSTREAM: <carry>: manifests: add hostPath mount for /etc/containers
joelanford Sep 20, 2024
669c6ce
UPSTREAM: <carry>: Add test-e2e target for downstream Makefile to be …
dtfranz Sep 26, 2024
ebd4890
UPSTREAM: <carry>: Add downstream verify makefile target
dtfranz Sep 27, 2024
c7df747
UPSTREAM: <carry>: openshift: template log verbosity to be managed by…
joelanford Sep 28, 2024
ba9aa3e
UPSTREAM: <carry>: Add global-pull-secret flag
Oct 8, 2024
606fcb6
UPSTREAM: <drop>: go mod vendor
Oct 24, 2024
bea7385
UPSTREAM: <drop>: remove upstream GitHub configuration
Oct 24, 2024
0db55ab
UPSTREAM: <drop>: configure the commit-checker
Oct 24, 2024
dc9afa8
UPSTREAM: <drop>: rewrite go mod
Oct 24, 2024
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 commitchecker.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
expectedMergeBase: 6f422740ceb64853e72450a5f5a0d4a136444b85
expectedMergeBase: 1cb254ce62b3d621d2d1dbf45b7be1611c32e455
upstreamBranch: main
upstreamOrg: operator-framework
upstreamRepo: operator-controller
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/opencontainers/go-digest v1.0.0
github.com/operator-framework/api v0.27.0
github.com/operator-framework/catalogd v0.35.0
github.com/operator-framework/helm-operator-plugins v0.5.0
github.com/operator-framework/helm-operator-plugins v0.7.0
github.com/operator-framework/operator-registry v1.47.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ github.com/openshift/operator-framework-catalogd v0.0.0-20241019022544-13b7c1b5f
github.com/openshift/operator-framework-catalogd v0.0.0-20241019022544-13b7c1b5f077/go.mod h1:anZurjcFMBvbkuyqlJ98v9z+yjniPKqmhlyitk9DuBQ=
github.com/operator-framework/api v0.27.0 h1:OrVaGKZJvbZo58HTv2guz7aURkhVKYhFqZ/6VpifiXI=
github.com/operator-framework/api v0.27.0/go.mod h1:lg2Xx+S8NQWGYlEOvFwQvH46E5EK5IrAIL7HWfAhciM=
github.com/operator-framework/helm-operator-plugins v0.5.0 h1:qph2OoECcI9mpuUBtOsWOMgvpx52mPTTSvzVxICsT04=
github.com/operator-framework/helm-operator-plugins v0.5.0/go.mod h1:yVncrZ/FJNqedMil+055fk6sw8aMKRrget/AqGM0ig0=
github.com/operator-framework/helm-operator-plugins v0.7.0 h1:YmtIWFc9BaNaDc5mk/dkG0P2BqPZOqpDvjWih5Fczuk=
github.com/operator-framework/helm-operator-plugins v0.7.0/go.mod h1:fUUCJR3bWtMBZ1qdDhbwjacsBHi9uT576tF4u/DwOgQ=
github.com/operator-framework/operator-lib v0.15.0 h1:0QeRM4PMtThqINpcFGCEBnIV3Z8u7/8fYLEx6mUtdcM=
github.com/operator-framework/operator-lib v0.15.0/go.mod h1:ZxLvFuQ7bRWiTNBOqodbuNvcsy/Iq0kOygdxhlbNdI0=
github.com/operator-framework/operator-registry v1.47.0 h1:Imr7X/W6FmXczwpIOXfnX8d6Snr1dzwWxkMG+lLAfhg=
Expand Down
6 changes: 6 additions & 0 deletions internal/action/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func (a ActionClient) Get(name string, opts ...actionclient.GetOption) (*release
return resp, err
}

func (a ActionClient) History(name string, opts ...actionclient.HistoryOption) ([]*release.Release, error) {
resp, err := a.ActionInterface.History(name, opts...)
err = a.actionClientErrorTranslator(err)
return resp, err
}

func (a ActionClient) Reconcile(rel *release.Release) error {
return a.actionClientErrorTranslator(a.ActionInterface.Reconcile(rel))
}
16 changes: 16 additions & 0 deletions internal/action/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ func (m *mockActionClient) Get(name string, opts ...actionclient.GetOption) (*re
return args.Get(0).(*release.Release), args.Error(1)
}

func (m *mockActionClient) History(name string, opts ...actionclient.HistoryOption) ([]*release.Release, error) {
args := m.Called(name, opts)
if args.Get(0) == nil {
return nil, args.Error(1)
}
rel := []*release.Release{
args.Get(0).(*release.Release),
}
return rel, args.Error(1)
}

func (m *mockActionClient) Install(name, namespace string, chrt *chart.Chart, vals map[string]interface{}, opts ...actionclient.InstallOption) (*release.Release, error) {
args := m.Called(name, namespace, chrt, vals, opts)
if args.Get(0) == nil {
Expand Down Expand Up @@ -82,6 +93,7 @@ func TestActionClientErrorTranslation(t *testing.T) {

ac := new(mockActionClient)
ac.On("Get", mock.Anything, mock.Anything).Return(nil, originalError)
ac.On("History", mock.Anything, mock.Anything).Return(nil, originalError)
ac.On("Install", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, originalError)
ac.On("Uninstall", mock.Anything, mock.Anything).Return(nil, originalError)
ac.On("Upgrade", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, originalError)
Expand All @@ -93,6 +105,10 @@ func TestActionClientErrorTranslation(t *testing.T) {
_, err := wrappedAc.Get("something")
assert.Equal(t, expectedErr, err, "expected Get() to return translated error")

// History
_, err = wrappedAc.History("something")
assert.Equal(t, expectedErr, err, "expected History() to return translated error")

// Install
_, err = wrappedAc.Install("something", "somethingelse", nil, nil)
assert.Equal(t, expectedErr, err, "expected Install() to return translated error")
Expand Down
83 changes: 50 additions & 33 deletions internal/controllers/clusterextension_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type Applier interface {
}

type InstalledBundleGetter interface {
GetInstalledBundle(ctx context.Context, ext *ocv1alpha1.ClusterExtension) (*ocv1alpha1.BundleMetadata, error)
GetInstalledBundle(ctx context.Context, ext *ocv1alpha1.ClusterExtension) (*InstalledBundle, error)
}

//+kubebuilder:rbac:groups=olm.operatorframework.io,resources=clusterextensions,verbs=get;list;watch;update;patch
Expand Down Expand Up @@ -206,19 +206,22 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
installedBundle, err := r.InstalledBundleGetter.GetInstalledBundle(ctx, ext)
if err != nil {
setInstallStatus(ext, nil)
// TODO: use Installed=Unknown
setInstalledStatusConditionFailed(ext, err.Error())
setStatusProgressing(ext, err)
setInstalledStatusConditionUnknown(ext, err.Error())
setStatusProgressing(ext, errors.New("retrying to get installed bundle"))
return ctrl.Result{}, err
}

// run resolution
l.Info("resolving bundle")
resolvedBundle, resolvedBundleVersion, resolvedDeprecation, err := r.Resolver.Resolve(ctx, ext, installedBundle)
var bm *ocv1alpha1.BundleMetadata
if installedBundle != nil {
bm = &installedBundle.BundleMetadata
}
resolvedBundle, resolvedBundleVersion, resolvedDeprecation, err := r.Resolver.Resolve(ctx, ext, bm)
if err != nil {
// Note: We don't distinguish between resolution-specific errors and generic errors
setInstallStatus(ext, nil)
setStatusProgressing(ext, err)
setInstalledStatusFromBundle(ext, installedBundle)
ensureAllConditionsWithReason(ext, ocv1alpha1.ReasonFailed, err.Error())
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -255,6 +258,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
// installed since we intend for the progressing condition to replace the resolved condition
// and will be removing the .status.resolution field from the ClusterExtension status API
setStatusProgressing(ext, wrapErrorWithResolutionInfo(resolvedBundleMetadata, err))
setInstalledStatusFromBundle(ext, installedBundle)
return ctrl.Result{}, err
}

Expand All @@ -268,9 +272,10 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
}

storeLbls := map[string]string{
labels.BundleNameKey: resolvedBundle.Name,
labels.PackageNameKey: resolvedBundle.Package,
labels.BundleVersionKey: resolvedBundleVersion.String(),
labels.BundleNameKey: resolvedBundle.Name,
labels.PackageNameKey: resolvedBundle.Package,
labels.BundleVersionKey: resolvedBundleVersion.String(),
labels.BundleReferenceKey: resolvedBundle.Image,
}

l.Info("applying bundle contents")
Expand All @@ -286,18 +291,17 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
managedObjs, _, err := r.Applier.Apply(ctx, unpackResult.Bundle, ext, objLbls, storeLbls)
if err != nil {
setStatusProgressing(ext, wrapErrorWithResolutionInfo(resolvedBundleMetadata, err))
// If bundle is not already installed, set Installed status condition to False
if installedBundle == nil {
setInstalledStatusConditionFailed(ext, err.Error())
}
// Now that we're actually trying to install, use the error
setInstalledStatusFromBundle(ext, installedBundle)
return ctrl.Result{}, err
}

installStatus := &ocv1alpha1.ClusterExtensionInstallStatus{
Bundle: resolvedBundleMetadata,
newInstalledBundle := &InstalledBundle{
BundleMetadata: resolvedBundleMetadata,
Image: resolvedBundle.Image,
}
setInstallStatus(ext, installStatus)
setInstalledStatusConditionSuccess(ext, fmt.Sprintf("Installed bundle %s successfully", resolvedBundle.Image))
// Successful install
setInstalledStatusFromBundle(ext, newInstalledBundle)

l.Info("watching managed objects")
cache, err := r.Manager.Get(ctx, ext)
Expand Down Expand Up @@ -466,32 +470,45 @@ type DefaultInstalledBundleGetter struct {
helmclient.ActionClientGetter
}

func (d *DefaultInstalledBundleGetter) GetInstalledBundle(ctx context.Context, ext *ocv1alpha1.ClusterExtension) (*ocv1alpha1.BundleMetadata, error) {
type InstalledBundle struct {
ocv1alpha1.BundleMetadata
Image string
}

func (d *DefaultInstalledBundleGetter) GetInstalledBundle(ctx context.Context, ext *ocv1alpha1.ClusterExtension) (*InstalledBundle, error) {
cl, err := d.ActionClientFor(ctx, ext)
if err != nil {
return nil, err
}

rel, err := cl.Get(ext.GetName())
relhis, err := cl.History(ext.GetName())
if err != nil && !errors.Is(err, driver.ErrReleaseNotFound) {
return nil, err
}
if rel == nil {
if len(relhis) == 0 {
return nil, nil
}

switch rel.Info.Status {
case release.StatusUnknown:
return nil, fmt.Errorf("installation status is unknown")
case release.StatusDeployed, release.StatusUninstalled, release.StatusSuperseded, release.StatusFailed:
case release.StatusUninstalling, release.StatusPendingInstall, release.StatusPendingRollback, release.StatusPendingUpgrade:
return nil, fmt.Errorf("installation is still pending: %s", rel.Info.Status)
default:
return nil, fmt.Errorf("unknown installation status: %s", rel.Info.Status)
// relhis[0].Info.Status is the status of the most recent install attempt.
// But we need to look for the most-recent _Deployed_ release
for _, rel := range relhis {
if rel.Info != nil && rel.Info.Status == release.StatusDeployed {
// If there are blank values, we should consider this as not installed
if n, ok := rel.Labels[labels.BundleNameKey]; !ok || n == "" {
return nil, nil
}
if v, ok := rel.Labels[labels.BundleVersionKey]; !ok || v == "" {
return nil, nil
}
// Not checking BundleReferenceKey, as it's new; upgrade test would fail
return &InstalledBundle{
BundleMetadata: ocv1alpha1.BundleMetadata{
Name: rel.Labels[labels.BundleNameKey],
Version: rel.Labels[labels.BundleVersionKey],
},
Image: rel.Labels[labels.BundleReferenceKey],
}, nil
}
}

return &ocv1alpha1.BundleMetadata{
Name: rel.Labels[labels.BundleNameKey],
Version: rel.Labels[labels.BundleVersionKey],
}, nil
return nil, nil
}
Loading