-
Notifications
You must be signed in to change notification settings - Fork 562
Bug 1849164: don't store full manifests in installplan status (for bundle images) #1589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 1 commit into
operator-framework:master
from
ecordell:ip-status-is-status
Jun 24, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package catalog | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/operator-framework/api/pkg/operators/v1alpha1" | ||
"github.com/operator-framework/operator-registry/pkg/configmap" | ||
errorwrap "github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
v1 "k8s.io/client-go/listers/core/v1" | ||
|
||
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver" | ||
) | ||
|
||
// ManifestResolver can dereference a manifest for a step. Steps may embed manifests directly or reference content | ||
// in configmaps | ||
type ManifestResolver interface { | ||
ManifestForStep(step *v1alpha1.Step) (string, error) | ||
} | ||
|
||
// manifestResolver caches manifest from unpacked bundles (via configmaps) | ||
type manifestResolver struct { | ||
configMapLister v1.ConfigMapLister | ||
unpackedSteps map[string][]v1alpha1.StepResource | ||
namespace string | ||
logger logrus.FieldLogger | ||
} | ||
|
||
func newManifestResolver(namespace string, configMapLister v1.ConfigMapLister, logger logrus.FieldLogger) *manifestResolver { | ||
return &manifestResolver{ | ||
namespace: namespace, | ||
configMapLister: configMapLister, | ||
unpackedSteps: map[string][]v1alpha1.StepResource{}, | ||
logger: logger, | ||
} | ||
} | ||
|
||
// ManifestForStep always returns the manifest that should be applied to the cluster for a given step | ||
// the manifest field in the installplan status can contain a reference to a configmap instead | ||
func (r *manifestResolver) ManifestForStep(step *v1alpha1.Step) (string, error) { | ||
manifest := step.Resource.Manifest | ||
ref := refForStep(step, r.logger) | ||
if ref == nil { | ||
return manifest, nil | ||
} | ||
|
||
log := r.logger.WithFields(logrus.Fields{"resolving": step.Resolving, "step": step.Resource.Name}) | ||
log.WithField("ref", ref).Debug("step is a reference to configmap") | ||
|
||
usteps, err := r.unpackedStepsForBundle(step.Resolving, ref) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
log.Debugf("checking cache for unpacked step") | ||
// need to find the real manifest from the unpacked steps | ||
for _, u := range usteps { | ||
if u.Name == step.Resource.Name && | ||
u.Kind == step.Resource.Kind && | ||
u.Version == step.Resource.Version && | ||
u.Group == step.Resource.Group { | ||
manifest = u.Manifest | ||
log.WithField("manifest", manifest).Debug("step replaced with unpacked value") | ||
break | ||
} | ||
} | ||
if manifest == step.Resource.Manifest { | ||
return "", fmt.Errorf("couldn't find unpacked step for %v", step) | ||
} | ||
return manifest, nil | ||
} | ||
|
||
func (r *manifestResolver) unpackedStepsForBundle(bundleName string, ref *UnpackedBundleReference) ([]v1alpha1.StepResource, error) { | ||
usteps, ok := r.unpackedSteps[bundleName] | ||
if ok { | ||
return usteps, nil | ||
} | ||
cm, err := r.configMapLister.ConfigMaps(ref.Namespace).Get(ref.Name) | ||
if err != nil { | ||
return nil, errorwrap.Wrapf(err, "error finding unpacked bundle configmap for ref %v", *ref) | ||
} | ||
loader := configmap.NewBundleLoader() | ||
bundle, err := loader.Load(cm) | ||
if err != nil { | ||
return nil, errorwrap.Wrapf(err, "error loading unpacked bundle configmap for ref %v", *ref) | ||
} | ||
steps, err := resolver.NewStepResourceFromBundle(bundle, r.namespace, ref.Replaces, ref.CatalogSourceName, ref.CatalogSourceNamespace) | ||
if err != nil { | ||
return nil, errorwrap.Wrapf(err, "error calculating steps for ref %v", *ref) | ||
} | ||
r.unpackedSteps[bundleName] = steps | ||
return steps, nil | ||
} | ||
|
||
func refForStep(step *v1alpha1.Step, log logrus.FieldLogger) *UnpackedBundleReference { | ||
log = log.WithFields(logrus.Fields{"resolving": step.Resolving, "step": step.Resource.Name}) | ||
var ref UnpackedBundleReference | ||
if err := json.Unmarshal([]byte(step.Resource.Manifest), &ref); err != nil { | ||
log.Debug("step is not a reference to an unpacked bundle (this is not an error if the step is a manifest)") | ||
return nil | ||
} | ||
log = log.WithField("ref", ref) | ||
if ref.Kind != "ConfigMap" || ref.Name == "" || ref.Namespace == "" || ref.CatalogSourceName == "" || ref.CatalogSourceNamespace == "" { | ||
log.Debug("step is not a reference to an unpacked bundle (this is not an error if the step is a manifest)") | ||
return nil | ||
} | ||
return &ref | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I've been asking myself whether we treat in-org dependencies as "external" for the purposes of import grouping. Thoughts?