-
Notifications
You must be signed in to change notification settings - Fork 417
NO-JIRA: Isolate manifest handling in release-extraction #2048
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
"hash" | ||
"io" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
"regexp" | ||
"runtime" | ||
|
@@ -21,25 +22,25 @@ import ( | |
"sync" | ||
"syscall" | ||
|
||
"k8s.io/utils/ptr" | ||
|
||
"github.com/MakeNowJust/heredoc" | ||
"github.com/pkg/errors" | ||
"golang.org/x/crypto/openpgp" | ||
terminal "golang.org/x/term" | ||
|
||
"k8s.io/klog/v2" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
"k8s.io/cli-runtime/pkg/genericiooptions" | ||
appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/klog/v2" | ||
"k8s.io/utils/ptr" | ||
"sigs.k8s.io/yaml" | ||
|
||
"github.com/MakeNowJust/heredoc" | ||
configv1 "github.com/openshift/api/config/v1" | ||
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1" | ||
imagereference "github.com/openshift/library-go/pkg/image/reference" | ||
"github.com/openshift/library-go/pkg/manifest" | ||
|
||
"github.com/openshift/oc/pkg/cli/admin/internal/codesign" | ||
"github.com/openshift/oc/pkg/cli/image/extract" | ||
"github.com/openshift/oc/pkg/cli/image/imagesource" | ||
|
@@ -1286,3 +1287,32 @@ func newIncluder(config manifestInclusionConfiguration) includer { | |
return m.Include(config.ExcludeIdentifier, config.RequiredFeatureSet, config.Profile, config.Capabilities, config.Overrides) | ||
} | ||
} | ||
|
||
// ManifestReceiver has a TarEntryCallback function which can be used to as a callback to ExtractOptions.TarEntryCallback. | ||
// It feeds the downstream manifestsCallback | ||
// * with the manifests from every file whose name is not in skipNames, OR | ||
// * with the reader that contains the content of each file whose name is in skipNames. | ||
// All the errors encountered when parsing the manifests are collected in ManifestErrs. | ||
type ManifestReceiver struct { | ||
manifestsCallback func(filename string, manifests []manifest.Manifest, reader io.Reader) (cont bool, err error) | ||
skipNames sets.Set[string] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
ManifestErrs []error | ||
} | ||
|
||
func (mr *ManifestReceiver) TarEntryCallback(h *tar.Header, _ extract.LayerInfo, r io.Reader) (cont bool, err error) { | ||
if mr.skipNames.Has(h.Name) { | ||
return mr.manifestsCallback(h.Name, nil, r) | ||
} | ||
|
||
if ext := path.Ext(h.Name); len(ext) == 0 || !(ext == ".yaml" || ext == ".yml" || ext == ".json") { | ||
return true, nil | ||
} | ||
klog.V(4).Infof("Found manifest %s", h.Name) | ||
ms, err := manifest.ParseManifests(r) | ||
if err != nil { | ||
mr.ManifestErrs = append(mr.ManifestErrs, errors.Wrapf(err, "error parsing %s", h.Name)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the callback concurrent-unsafe; that's fine (IIRC you already checked once that it is never called in parallel - but maybe it should?) but the GoDoc should mention it. |
||
return true, nil | ||
} | ||
return mr.manifestsCallback(h.Name, ms, nil) | ||
} |
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.
Maybe just call it
downstreamCallback
? Even your Godoc talks about it that way. Calling itmanifestCallback
is a bit confusing to me because it kinda hints that it would be called with just manifests (esp. together with the other field called 'skipNames`)