Skip to content

Commit 2a38b10

Browse files
committed
use bundle image prefix to chose source type
Signed-off-by: Joe Lanford <[email protected]>
1 parent dbf285f commit 2a38b10

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

internal/controllers/operator_controller.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"strings"
2223

2324
"github.com/go-logr/logr"
2425
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
@@ -152,6 +153,12 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
152153
return ctrl.Result{}, err
153154
}
154155

156+
sourceType := rukpakv1alpha1.SourceTypeImage
157+
if strings.HasPrefix(bundleImage, "oci://") {
158+
sourceType = rukpakv1alpha1.SourceTypeOCIArtifact
159+
bundleImage = strings.TrimPrefix(bundleImage, "oci://")
160+
}
161+
155162
// Now we can set the Resolved Condition, and the resolvedBundleSource field to the bundleImage value.
156163
op.Status.ResolvedBundleResource = bundleImage
157164
setResolvedStatusConditionSuccess(&op.Status.Conditions, fmt.Sprintf("resolved to %q", bundleImage), op.GetGeneration())
@@ -166,9 +173,10 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
166173
setInstalledStatusConditionFailed(&op.Status.Conditions, err.Error(), op.GetGeneration())
167174
return ctrl.Result{}, err
168175
}
176+
169177
// Ensure a BundleDeployment exists with its bundle source from the bundle
170178
// image we just looked up in the solution.
171-
dep := r.generateExpectedBundleDeployment(*op, bundleImage, bundleProvisioner)
179+
dep := r.generateExpectedBundleDeployment(*op, bundleImage, bundleProvisioner, sourceType)
172180
if err := r.ensureBundleDeployment(ctx, dep); err != nil {
173181
// originally Reason: operatorsv1alpha1.ReasonInstallationFailed
174182
op.Status.InstalledBundleResource = ""
@@ -261,7 +269,7 @@ func (r *OperatorReconciler) getBundleEntityFromSolution(solution *solver.Soluti
261269
return nil, fmt.Errorf("entity for package %q not found in solution", packageName)
262270
}
263271

264-
func (r *OperatorReconciler) generateExpectedBundleDeployment(o operatorsv1alpha1.Operator, bundlePath string, bundleProvisioner string) *unstructured.Unstructured {
272+
func (r *OperatorReconciler) generateExpectedBundleDeployment(o operatorsv1alpha1.Operator, bundlePath string, bundleProvisioner string, sourceType rukpakv1alpha1.SourceType) *unstructured.Unstructured {
265273
// We use unstructured here to avoid problems of serializing default values when sending patches to the apiserver.
266274
// If you use a typed object, any default values from that struct get serialized into the JSON patch, which could
267275
// cause unrelated fields to be patched back to the default value even though that isn't the intention. Using an
@@ -281,9 +289,8 @@ func (r *OperatorReconciler) generateExpectedBundleDeployment(o operatorsv1alpha
281289
"spec": map[string]interface{}{
282290
"provisionerClassName": bundleProvisioner,
283291
"source": map[string]interface{}{
284-
// TODO: Don't assume artifact type
285-
"type": rukpakv1alpha1.SourceTypeOCIArtifact,
286-
string(rukpakv1alpha1.SourceTypeOCIArtifact): map[string]interface{}{
292+
"type": sourceType,
293+
string(sourceType): map[string]interface{}{
287294
"ref": bundlePath,
288295
},
289296
},

0 commit comments

Comments
 (0)