Skip to content

Commit 8cb0757

Browse files
committed
don't copy bundle contents to ip status
1 parent a90b83a commit 8cb0757

File tree

4 files changed

+119
-28
lines changed

4 files changed

+119
-28
lines changed

pkg/controller/bundle/bundle_unpacker.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"crypto/sha256"
66
"fmt"
7-
87
"github.com/operator-framework/operator-registry/pkg/api"
98
"github.com/operator-framework/operator-registry/pkg/configmap"
109
batchv1 "k8s.io/api/batch/v1"
@@ -34,6 +33,10 @@ func (b *BundleUnpackResult) Bundle() *api.Bundle {
3433
return b.bundle
3534
}
3635

36+
func (b *BundleUnpackResult) Name() string {
37+
return b.name
38+
}
39+
3740
var catalogSourceGVK = operatorsv1alpha1.SchemeGroupVersion.WithKind(operatorsv1alpha1.CatalogSourceKind)
3841

3942
func newBundleUnpackResult(lookup *operatorsv1alpha1.BundleLookup) *BundleUnpackResult {

pkg/controller/operators/catalog/operator.go

Lines changed: 104 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import (
5353
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/scoped"
5454
sharedtime "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/time"
5555
"github.com/operator-framework/operator-lifecycle-manager/pkg/metrics"
56+
"github.com/operator-framework/operator-registry/pkg/configmap"
5657
)
5758

5859
const (
@@ -1105,6 +1106,16 @@ func (o *Operator) createInstallPlan(namespace string, gen int, subs []*v1alpha1
11051106
return reference.GetReference(res)
11061107
}
11071108

1109+
type UnpackedBundleReference struct {
1110+
kind string
1111+
name string
1112+
namespace string
1113+
catalogSourceName string
1114+
catalogSourceNamespace string
1115+
replaces string
1116+
}
1117+
1118+
// unpackBundles makes one walk through the bundlelookups and attempts to progress them
11081119
func (o *Operator) unpackBundles(plan *v1alpha1.InstallPlan) (bool, *v1alpha1.InstallPlan, error) {
11091120
out := plan.DeepCopy()
11101121
unpacked := true
@@ -1129,17 +1140,33 @@ func (o *Operator) unpackBundles(plan *v1alpha1.InstallPlan) (bool, *v1alpha1.In
11291140
continue
11301141
}
11311142

1143+
// Ensure that bundle can be applied by the current version of OLM
11321144
steps, err := resolver.NewStepsFromBundle(res.Bundle(), out.GetNamespace(), res.Replaces, res.CatalogSourceRef.Name, res.CatalogSourceRef.Namespace)
11331145
if err != nil {
1134-
errs = append(errs, fmt.Errorf("failed to turn bundle into steps: %s", err.Error()))
1146+
errs = append(errs, fmt.Errorf("failed to turn bundle into steps: %v", err))
11351147
unpacked = false
11361148
continue
11371149
}
11381150

1139-
// Add steps and remove resolved bundle lookup
1151+
// step manifests are replaced with references to the configmap containing them
1152+
for _, s := range steps {
1153+
ref := UnpackedBundleReference{
1154+
kind: "ConfigMap",
1155+
namespace: res.CatalogSourceRef.Namespace,
1156+
name: res.Name(),
1157+
catalogSourceName: res.CatalogSourceRef.Name,
1158+
catalogSourceNamespace: res.CatalogSourceRef.Namespace,
1159+
replaces: res.Replaces,
1160+
}
1161+
r, err := json.Marshal(ref)
1162+
if err != nil {
1163+
errs = append(errs, fmt.Errorf("failed to generate reference for configmap: %v", err))
1164+
unpacked = false
1165+
continue
1166+
}
1167+
s.Resource.Manifest = string(r)
1168+
}
11401169
out.Status.Plan = append(out.Status.Plan, steps...)
1141-
out.Status.BundleLookups = append(out.Status.BundleLookups[:i], out.Status.BundleLookups[i+1:]...)
1142-
i--
11431170
}
11441171

11451172
if err := utilerrors.NewAggregate(errs); err != nil {
@@ -1418,9 +1445,70 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
14181445
ensurer := newStepEnsurer(kubeclient, crclient, dynamicClient)
14191446
b := newBuilder(kubeclient, dynamicClient, o.csvProvidedAPIsIndexer, o.logger)
14201447

1448+
refForStep := func(step *v1alpha1.Step) (ref *UnpackedBundleReference) {
1449+
if err := json.Unmarshal([]byte(step.Resource.Manifest), &ref); err != nil {
1450+
return nil
1451+
}
1452+
if ref.kind != "ConfigMap" || ref.name == "" || ref.namespace == "" || ref.catalogSourceName == "" || ref.catalogSourceNamespace == "" {
1453+
return nil
1454+
}
1455+
return ref
1456+
}
1457+
1458+
// for each step that points to a configmap instead of holding the full step manifest, find the steps and cache them
1459+
unpackedSteps := map[string][]v1alpha1.StepResource{}
1460+
loader := configmap.NewBundleLoader()
1461+
for _, step := range plan.Status.Plan {
1462+
ref := refForStep(step)
1463+
if ref == nil {
1464+
continue
1465+
}
1466+
cm, err := o.lister.CoreV1().ConfigMapLister().ConfigMaps(ref.namespace).Get(ref.name)
1467+
if err != nil {
1468+
return errorwrap.Wrapf(err, "error finding unpacked bundle configmap for ref %s", step.Resource.Manifest)
1469+
}
1470+
b, err := loader.Load(cm)
1471+
if err != nil {
1472+
return errorwrap.Wrapf(err, "error loading unpacked bundle configmap for ref %s", step.Resource.Manifest)
1473+
}
1474+
steps, err := resolver.NewStepResourceFromBundle(b, plan.GetNamespace(), ref.replaces, ref.catalogSourceName, ref.catalogSourceNamespace)
1475+
if err != nil {
1476+
return errorwrap.Wrapf(err, "error calculating steps for ref %s", step.Resource.Manifest)
1477+
}
1478+
unpackedSteps[step.Resolving] = steps
1479+
}
1480+
1481+
manifestForStep := func(step *v1alpha1.Step) (string, error) {
1482+
manifest := step.Resource.Manifest
1483+
ref := refForStep(step)
1484+
if ref != nil {
1485+
if usteps, ok := unpackedSteps[step.Resolving]; ok {
1486+
// need to find the real manifest from the unpacked steps
1487+
for _, u := range usteps {
1488+
if u.Name == step.Resource.Name &&
1489+
u.Kind == step.Resource.Kind &&
1490+
u.Version == step.Resource.Version &&
1491+
u.Group == step.Resource.Group {
1492+
manifest = u.Manifest
1493+
}
1494+
}
1495+
}
1496+
if manifest == step.Resource.Manifest {
1497+
return "", errorwrap.Wrapf(err, "couldn't find unpacked step for %v", step)
1498+
}
1499+
}
1500+
return manifest, nil
1501+
}
1502+
14211503
for i, step := range plan.Status.Plan {
1504+
// TODO: should lazy load only when the manifest is actually needed
1505+
manifest, err := manifestForStep(step)
1506+
if err != nil {
1507+
return err
1508+
}
1509+
14221510
doStep := true
1423-
s, err := b.create(step)
1511+
s, err := b.create(step, manifest)
14241512
if err != nil {
14251513
if _, ok := err.(notSupportedStepperErr); ok {
14261514
// stepper not implemented for this type yet
@@ -1448,7 +1536,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
14481536
case v1alpha1.ClusterServiceVersionKind:
14491537
// Marshal the manifest into a CSV instance.
14501538
var csv v1alpha1.ClusterServiceVersion
1451-
err := json.Unmarshal([]byte(step.Resource.Manifest), &csv)
1539+
err := json.Unmarshal([]byte(manifest), &csv)
14521540
if err != nil {
14531541
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
14541542
}
@@ -1481,7 +1569,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
14811569
case v1alpha1.SubscriptionKind:
14821570
// Marshal the manifest into a subscription instance.
14831571
var sub v1alpha1.Subscription
1484-
err := json.Unmarshal([]byte(step.Resource.Manifest), &sub)
1572+
err := json.Unmarshal([]byte(manifest), &sub)
14851573
if err != nil {
14861574
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
14871575
}
@@ -1505,7 +1593,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
15051593

15061594
case resolver.BundleSecretKind:
15071595
var s corev1.Secret
1508-
err := json.Unmarshal([]byte(step.Resource.Manifest), &s)
1596+
err := json.Unmarshal([]byte(manifest), &s)
15091597
if err != nil {
15101598
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
15111599
}
@@ -1544,7 +1632,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
15441632
case clusterRoleKind:
15451633
// Marshal the manifest into a ClusterRole instance.
15461634
var cr rbacv1.ClusterRole
1547-
err := json.Unmarshal([]byte(step.Resource.Manifest), &cr)
1635+
err := json.Unmarshal([]byte(manifest), &cr)
15481636
if err != nil {
15491637
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
15501638
}
@@ -1559,7 +1647,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
15591647
case clusterRoleBindingKind:
15601648
// Marshal the manifest into a RoleBinding instance.
15611649
var rb rbacv1.ClusterRoleBinding
1562-
err := json.Unmarshal([]byte(step.Resource.Manifest), &rb)
1650+
err := json.Unmarshal([]byte(manifest), &rb)
15631651
if err != nil {
15641652
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
15651653
}
@@ -1574,7 +1662,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
15741662
case roleKind:
15751663
// Marshal the manifest into a Role instance.
15761664
var r rbacv1.Role
1577-
err := json.Unmarshal([]byte(step.Resource.Manifest), &r)
1665+
err := json.Unmarshal([]byte(manifest), &r)
15781666
if err != nil {
15791667
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
15801668
}
@@ -1597,7 +1685,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
15971685
case roleBindingKind:
15981686
// Marshal the manifest into a RoleBinding instance.
15991687
var rb rbacv1.RoleBinding
1600-
err := json.Unmarshal([]byte(step.Resource.Manifest), &rb)
1688+
err := json.Unmarshal([]byte(manifest), &rb)
16011689
if err != nil {
16021690
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
16031691
}
@@ -1620,7 +1708,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
16201708
case serviceAccountKind:
16211709
// Marshal the manifest into a ServiceAccount instance.
16221710
var sa corev1.ServiceAccount
1623-
err := json.Unmarshal([]byte(step.Resource.Manifest), &sa)
1711+
err := json.Unmarshal([]byte(manifest), &sa)
16241712
if err != nil {
16251713
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
16261714
}
@@ -1643,7 +1731,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
16431731
case serviceKind:
16441732
// Marshal the manifest into a Service instance
16451733
var s corev1.Service
1646-
err := json.Unmarshal([]byte(step.Resource.Manifest), &s)
1734+
err := json.Unmarshal([]byte(manifest), &s)
16471735
if err != nil {
16481736
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
16491737
}
@@ -1673,7 +1761,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
16731761

16741762
case configMapKind:
16751763
var cfg corev1.ConfigMap
1676-
err := json.Unmarshal([]byte(step.Resource.Manifest), &cfg)
1764+
err := json.Unmarshal([]byte(manifest), &cfg)
16771765
if err != nil {
16781766
return errorwrap.Wrapf(err, "error parsing step manifest: %s", step.Resource.Name)
16791767
}
@@ -1709,7 +1797,7 @@ func (o *Operator) ExecutePlan(plan *v1alpha1.InstallPlan) error {
17091797
}
17101798

17111799
// Marshal the manifest into an unstructured object
1712-
dec := yaml.NewYAMLOrJSONDecoder(strings.NewReader(step.Resource.Manifest), 10)
1800+
dec := yaml.NewYAMLOrJSONDecoder(strings.NewReader(manifest), 10)
17131801
unstructuredObject := &unstructured.Unstructured{}
17141802
if err := dec.Decode(unstructuredObject); err != nil {
17151803
return errorwrap.Wrapf(err, "error decoding %s object to an unstructured object", step.Resource.Name)

pkg/controller/operators/catalog/operator_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@ func TestExecutePlan(t *testing.T) {
269269
Version: "v1",
270270
Kind: "ConfigMap",
271271
Name: "cfg",
272-
Manifest: toManifest(t, configmap("cfg", namespace)),
272+
Manifest: toManifest(t, configMap("cfg", namespace)),
273273
},
274274
Status: v1alpha1.StepStatusUnknown,
275275
},
276276
},
277277
),
278-
want: []runtime.Object{configmap("cfg", namespace)},
278+
want: []runtime.Object{configMap("cfg", namespace)},
279279
err: nil,
280280
},
281281
{
@@ -1307,7 +1307,7 @@ func serviceAccount(name, namespace, generateName string, secretRef *corev1.Obje
13071307
}
13081308
}
13091309

1310-
func configmap(name, namespace string) *corev1.ConfigMap {
1310+
func configMap(name, namespace string) *corev1.ConfigMap {
13111311
return &corev1.ConfigMap{
13121312
TypeMeta: metav1.TypeMeta{Kind: configMapKind},
13131313
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace},

pkg/controller/operators/catalog/step.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,24 @@ func (n notSupportedStepperErr) Error() string {
6161
}
6262

6363
// step is a factory that creates StepperFuncs based on the install plan step Kind.
64-
func (b *builder) create(step *v1alpha1.Step) (Stepper, error) {
64+
func (b *builder) create(step *v1alpha1.Step, manifest string) (Stepper, error) {
6565
switch step.Resource.Kind {
6666
case crdKind:
67-
version, err := crdlib.Version(&step.Resource.Manifest)
67+
version, err := crdlib.Version(&manifest)
6868
if err != nil {
6969
return nil, err
7070
}
7171
switch version {
7272
case crdlib.V1Version:
73-
return b.NewCRDV1Step(b.opclient.ApiextensionsInterface().ApiextensionsV1(), step), nil
73+
return b.NewCRDV1Step(b.opclient.ApiextensionsInterface().ApiextensionsV1(), step, manifest), nil
7474
case crdlib.V1Beta1Version:
75-
return b.NewCRDV1Beta1Step(b.opclient.ApiextensionsInterface().ApiextensionsV1beta1(), step), nil
75+
return b.NewCRDV1Beta1Step(b.opclient.ApiextensionsInterface().ApiextensionsV1beta1(), step, manifest), nil
7676
}
7777
}
7878
return nil, notSupportedStepperErr{fmt.Sprintf("stepper interface does not support %s", step.Resource.Kind)}
7979
}
8080

81-
func (b *builder) NewCRDV1Step(client apiextensionsv1client.ApiextensionsV1Interface, step *v1alpha1.Step) StepperFunc {
81+
func (b *builder) NewCRDV1Step(client apiextensionsv1client.ApiextensionsV1Interface, step *v1alpha1.Step, manifest string) StepperFunc {
8282
return func() (v1alpha1.StepStatus, error) {
8383
switch step.Status {
8484
case v1alpha1.StepStatusPresent:
@@ -111,7 +111,7 @@ func (b *builder) NewCRDV1Step(client apiextensionsv1client.ApiextensionsV1Inter
111111
return v1alpha1.StepStatusCreated, nil
112112
}
113113
case v1alpha1.StepStatusUnknown, v1alpha1.StepStatusNotPresent:
114-
crd, err := crdlib.UnmarshalV1(step.Resource.Manifest)
114+
crd, err := crdlib.UnmarshalV1(manifest)
115115
if err != nil {
116116
return v1alpha1.StepStatusUnknown, err
117117
}
@@ -168,7 +168,7 @@ func (b *builder) NewCRDV1Step(client apiextensionsv1client.ApiextensionsV1Inter
168168
}
169169
}
170170

171-
func (b *builder) NewCRDV1Beta1Step(client apiextensionsv1beta1client.ApiextensionsV1beta1Interface, step *v1alpha1.Step) StepperFunc {
171+
func (b *builder) NewCRDV1Beta1Step(client apiextensionsv1beta1client.ApiextensionsV1beta1Interface, step *v1alpha1.Step, manifest string) StepperFunc {
172172
return func() (v1alpha1.StepStatus, error) {
173173
switch step.Status {
174174
case v1alpha1.StepStatusPresent:
@@ -201,7 +201,7 @@ func (b *builder) NewCRDV1Beta1Step(client apiextensionsv1beta1client.Apiextensi
201201
return v1alpha1.StepStatusCreated, nil
202202
}
203203
case v1alpha1.StepStatusUnknown, v1alpha1.StepStatusNotPresent:
204-
crd, err := crdlib.UnmarshalV1Beta1(step.Resource.Manifest)
204+
crd, err := crdlib.UnmarshalV1Beta1(manifest)
205205
if err != nil {
206206
return v1alpha1.StepStatusUnknown, err
207207
}

0 commit comments

Comments
 (0)