Skip to content

Commit d97e721

Browse files
committed
Handle unpacking non kitops ModelPacks
If Kit generates a model-spec artifact, it will include the Kitfile with the manifest. However, if the artifact was generated by another tool, we can still try to unpack it based on model-spec metadata annotations (e.g. file names). This is more error-prone, so a warning is logged in this case. Signed-off-by: Angel Misevski <[email protected]>
1 parent ac59b15 commit d97e721

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

pkg/lib/filesystem/unpack/core.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,26 @@ func unpackRecursive(ctx context.Context, opts *UnpackOptions, visitedRefs []str
8080
if err != nil {
8181
return fmt.Errorf("failed to resolve reference: %w", err)
8282
}
83-
manifest, config, err := util.GetManifestAndConfig(ctx, store, manifestDesc)
83+
84+
manifest, err := util.GetManifest(ctx, store, manifestDesc)
8485
if err != nil {
85-
return fmt.Errorf("failed to read model: %s", err)
86+
return fmt.Errorf("failed to read manifest: %s", err)
8687
}
87-
if config.Model != nil && util.IsModelKitReference(config.Model.Path) {
88-
output.Infof("Unpacking referenced modelkit %s", config.Model.Path)
89-
if err := unpackParent(ctx, config.Model.Path, opts, visitedRefs); err != nil {
90-
return err
91-
}
88+
config, err := util.GetKitfileForManifest(ctx, store, manifest)
89+
if err != nil {
90+
output.Infof("Could not get Kitfile: %s", err)
9291
}
93-
94-
if shouldUnpackLayer(config, opts.FilterConfs) {
95-
if err := unpackConfig(config, opts.UnpackDir, opts.Overwrite); err != nil {
96-
return err
92+
if config != nil {
93+
if config.Model != nil && util.IsModelKitReference(config.Model.Path) {
94+
output.Infof("Unpacking referenced modelkit %s", config.Model.Path)
95+
if err := unpackParent(ctx, config.Model.Path, opts, visitedRefs); err != nil {
96+
return err
97+
}
98+
}
99+
if shouldUnpackLayer(config, opts.FilterConfs) {
100+
if err := unpackConfig(config, opts.UnpackDir, opts.Overwrite); err != nil {
101+
return err
102+
}
97103
}
98104
}
99105

pkg/lib/repo/util/reference.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,9 @@ func GetKitfileForManifest(ctx context.Context, store oras.ReadOnlyTarget, manif
227227
return nil, fmt.Errorf("failed to parse config: %w", err)
228228
}
229229
return kitfile, nil
230+
default:
231+
return nil, fmt.Errorf("Unknown artifact type")
230232
}
231-
return nil, fmt.Errorf("Could not find config for artifact")
232233
}
233234

234235
// GetConfig returns the config (Kitfile) described by a descriptor. Returns an error if the config blob cannot

0 commit comments

Comments
 (0)