Skip to content

Commit d6b4599

Browse files
Address Reviews
1 parent ff0c3aa commit d6b4599

File tree

6 files changed

+72
-25
lines changed

6 files changed

+72
-25
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,9 @@ const (
101101
ReasonInstallationSucceeded = "InstallationSucceeded"
102102
ReasonResolutionFailed = "ResolutionFailed"
103103

104-
ReasonSuccess = "Success"
105-
ReasonDeprecated = "Deprecated"
106-
ReasonErrorGettingReleaseState = "ErrorGettingReleaseState"
107-
ReasonUpgradeFailed = "UpgradeFailed"
108-
ReasonCreateDynamicWatchFailed = "CreateDynamicWatchFailed"
104+
ReasonSuccess = "Success"
105+
ReasonDeprecated = "Deprecated"
106+
ReasonUpgradeFailed = "UpgradeFailed"
109107
)
110108

111109
func init() {
@@ -124,14 +122,14 @@ func init() {
124122
ReasonInstallationSucceeded,
125123
ReasonResolutionFailed,
126124
ReasonInstallationFailed,
127-
ReasonInstallationStatusUnknown,
128125
ReasonSuccess,
129126
ReasonDeprecated,
130-
ReasonErrorGettingReleaseState,
131127
ReasonUpgradeFailed,
132-
ReasonCreateDynamicWatchFailed,
133128
ReasonBundleLoadFailed,
134129
ReasonErrorGettingClient,
130+
// TODO: this reason is not being used in the reconciler, it will be removed
131+
// when we fix the tests. Avoiding removal here, to reduce diffs.
132+
ReasonInstallationStatusUnknown,
135133
)
136134
}
137135

cmd/manager/main.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,12 @@ func main() {
7777
probeAddr string
7878
cachePath string
7979
operatorControllerVersion bool
80-
httpExternalAddr string
8180
systemNamespace string
8281
unpackImage string
8382
provisionerStorageDirectory string
8483
)
8584
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
8685
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
87-
flag.StringVar(&httpExternalAddr, "http-external-address", "http://localhost:8080", "The external address at which the http server is reachable.")
8886
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
8987
"Enable leader election for controller manager. "+
9088
"Enabling this will ensure there is only one active controller manager.")
@@ -177,15 +175,9 @@ func main() {
177175
os.Exit(1)
178176
}
179177

180-
storageURL, err := url.Parse(fmt.Sprintf("%s/bundles/", httpExternalAddr))
181-
if err != nil {
182-
setupLog.Error(err, "unable to parse bundle content server URL")
183-
os.Exit(1)
184-
}
185-
186178
localStorage := &storage.LocalDirectory{
187179
RootDirectory: provisionerStorageDirectory,
188-
URL: *storageURL,
180+
URL: url.URL{},
189181
}
190182

191183
if err = (&controllers.ClusterExtensionReconciler{

internal/catalogmetadata/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (b *Bundle) loadPackage() error {
7373
if b.semVersion == nil {
7474
semVer, err := bsemver.Parse(b.bundlePackage.Version)
7575
if err != nil {
76-
return fmt.Errorf("could not parse semver %q for bundle '%s': %s", b.bundlePackage.Version, b.Bundle.Name, err)
76+
return fmt.Errorf("could not parse semver %q for bundle '%s': %s", b.bundlePackage.Version, b.Name, err)
7777
}
7878
b.semVersion = &semVer
7979
}

internal/controllers/clusterextension_controller.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import (
4646
"k8s.io/apimachinery/pkg/runtime/schema"
4747
"k8s.io/apimachinery/pkg/types"
4848
utilerrors "k8s.io/apimachinery/pkg/util/errors"
49+
"k8s.io/apimachinery/pkg/util/sets"
4950
apimachyaml "k8s.io/apimachinery/pkg/util/yaml"
5051
ctrl "sigs.k8s.io/controller-runtime"
5152
"sigs.k8s.io/controller-runtime/pkg/cache"
@@ -63,6 +64,7 @@ import (
6364
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
6465
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
6566
"github.com/operator-framework/operator-registry/alpha/declcfg"
67+
"github.com/operator-framework/operator-registry/alpha/property"
6668
rukpakv1alpha2 "github.com/operator-framework/rukpak/api/v1alpha2"
6769
helmpredicate "github.com/operator-framework/rukpak/pkg/helm-operator-plugins/predicate"
6870
rukpaksource "github.com/operator-framework/rukpak/pkg/source"
@@ -106,6 +108,8 @@ type ClusterExtensionReconciler struct {
106108
//+kubebuilder:rbac:groups=catalogd.operatorframework.io,resources=catalogs,verbs=list;watch
107109
//+kubebuilder:rbac:groups=catalogd.operatorframework.io,resources=catalogmetadata,verbs=list;watch
108110

111+
// The operator controller needs to watch all the bundle objects and reconcile accordingly. Though not ideal, but these permissions are required.
112+
// This has been taken from rukpak, and an issue was created before to discuss it: https://github.com/operator-framework/rukpak/issues/800.
109113
func (r *ClusterExtensionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
110114
l := log.FromContext(ctx).WithName("operator-controller")
111115
l.V(1).Info("starting")
@@ -220,6 +224,12 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
220224
return r.handleResolutionErrors(ext, err)
221225
}
222226

227+
if err := r.validateBundle(bundle); err != nil {
228+
setInstalledStatusConditionFailed(&ext.Status.Conditions, err.Error(), ext.GetGeneration())
229+
setDeprecationStatusesUnknown(&ext.Status.Conditions, "deprecation checks have not been attempted as installation has failed", ext.GetGeneration())
230+
return ctrl.Result{}, err
231+
}
232+
223233
bundleVersion, err := bundle.Version()
224234
if err != nil {
225235
ext.Status.ResolvedBundle = nil
@@ -302,7 +312,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
302312

303313
rel, state, err := r.getReleaseState(ac, ext, chrt, values, post)
304314
if err != nil {
305-
setInstalledStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("%s:%v", ocv1alpha1.ReasonErrorGettingReleaseState, err), ext.Generation)
315+
setInstalledStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("%s:%v", rukpakv1alpha2.ReasonErrorGettingReleaseState, err), ext.Generation)
306316
return ctrl.Result{}, err
307317
}
308318

@@ -343,14 +353,14 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
343353

344354
relObjects, err := util.ManifestObjects(strings.NewReader(rel.Manifest), fmt.Sprintf("%s-release-manifest", rel.Name))
345355
if err != nil {
346-
setInstalledStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("%s:%v", ocv1alpha1.ReasonCreateDynamicWatchFailed, err), ext.Generation)
356+
setInstalledStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("%s:%v", rukpakv1alpha2.ReasonCreateDynamicWatchFailed, err), ext.Generation)
347357
return ctrl.Result{}, err
348358
}
349359

350360
for _, obj := range relObjects {
351361
uMap, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
352362
if err != nil {
353-
setInstalledStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("%s:%v", ocv1alpha1.ReasonCreateDynamicWatchFailed, err), ext.Generation)
363+
setInstalledStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("%s:%v", rukpakv1alpha2.ReasonCreateDynamicWatchFailed, err), ext.Generation)
354364
return ctrl.Result{}, err
355365
}
356366

@@ -372,7 +382,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
372382
return nil
373383
}(); err != nil {
374384
ext.Status.InstalledBundle = nil
375-
setInstalledStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("%s:%v", ocv1alpha1.ReasonCreateDynamicWatchFailed, err), ext.Generation)
385+
setInstalledStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("%s:%v", rukpakv1alpha2.ReasonCreateDynamicWatchFailed, err), ext.Generation)
376386
return ctrl.Result{}, err
377387
}
378388
}
@@ -804,3 +814,22 @@ func bundleMetadataFor(bundle *catalogmetadata.Bundle) *ocv1alpha1.BundleMetadat
804814
Version: ver.String(),
805815
}
806816
}
817+
818+
func (r *ClusterExtensionReconciler) validateBundle(bundle *catalogmetadata.Bundle) error {
819+
unsupportedProps := sets.New(
820+
property.TypePackageRequired,
821+
property.TypeGVKRequired,
822+
property.TypeConstraint,
823+
)
824+
for i := range bundle.Properties {
825+
if unsupportedProps.Has(bundle.Properties[i].Type) {
826+
return fmt.Errorf(
827+
"bundle %q has a dependency declared via property %q which is currently not supported",
828+
bundle.Name,
829+
bundle.Properties[i].Type,
830+
)
831+
}
832+
}
833+
834+
return nil
835+
}

internal/controllers/clusterextension_registryv1_validation_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestClusterExtensionRegistryV1DisallowDependencies(t *testing.T) {
3131
name string
3232
bundle *catalogmetadata.Bundle
3333
wantErr string
34+
skip bool
3435
}{
3536
{
3637
name: "package with no dependencies",
@@ -45,6 +46,9 @@ func TestClusterExtensionRegistryV1DisallowDependencies(t *testing.T) {
4546
},
4647
CatalogName: "fake-catalog",
4748
},
49+
// Skipping the happy path, since it requires us to mock unpacker, store and the
50+
// entire installation. This should be handled in an e2e instead.
51+
skip: true,
4852
},
4953
{
5054
name: "package with olm.package.required property",
@@ -96,15 +100,19 @@ func TestClusterExtensionRegistryV1DisallowDependencies(t *testing.T) {
96100
},
97101
} {
98102
t.Run(tt.name, func(t *testing.T) {
99-
t.Skip("Skip and replace with e2e for BundleDeployment")
100103
defer func() {
101104
require.NoError(t, cl.DeleteAllOf(ctx, &ocv1alpha1.ClusterExtension{}))
102105
}()
103106

107+
if tt.skip {
108+
return
109+
}
110+
104111
fakeCatalogClient := testutil.NewFakeCatalogClient([]*catalogmetadata.Bundle{tt.bundle})
105112
reconciler := &controllers.ClusterExtensionReconciler{
106-
Client: cl,
107-
BundleProvider: &fakeCatalogClient,
113+
Client: cl,
114+
BundleProvider: &fakeCatalogClient,
115+
ActionClientGetter: acg,
108116
}
109117

110118
installNamespace := fmt.Sprintf("test-ns-%s", rand.String(8))

internal/controllers/common_controller.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,23 @@ func setInstalledStatusConditionFailed(conditions *[]metav1.Condition, message s
7575
ObservedGeneration: generation,
7676
})
7777
}
78+
79+
// setDeprecationStatusesUnknown sets the deprecation status conditions to unknown.
80+
func setDeprecationStatusesUnknown(conditions *[]metav1.Condition, message string, generation int64) {
81+
conditionTypes := []string{
82+
ocv1alpha1.TypeDeprecated,
83+
ocv1alpha1.TypePackageDeprecated,
84+
ocv1alpha1.TypeChannelDeprecated,
85+
ocv1alpha1.TypeBundleDeprecated,
86+
}
87+
88+
for _, conditionType := range conditionTypes {
89+
apimeta.SetStatusCondition(conditions, metav1.Condition{
90+
Type: conditionType,
91+
Reason: ocv1alpha1.ReasonDeprecated,
92+
Status: metav1.ConditionUnknown,
93+
Message: message,
94+
ObservedGeneration: generation,
95+
})
96+
}
97+
}

0 commit comments

Comments
 (0)