Skip to content

Commit ac59b15

Browse files
committed
Handle retreiving Kitfiles from ModelPack artifact annotations
Since we can't trust tools will handle unknown layers in a ModelPack artifact (and also modctl stores its metadata in an annotation) we need to be able to read Kitfiles from an annotation if the artifact is a ModelPack Signed-off-by: Angel Misevski <[email protected]>
1 parent d163153 commit ac59b15

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

pkg/lib/repo/util/reference.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"strings"
2626

2727
"github.com/kitops-ml/kitops/pkg/artifact"
28+
"github.com/kitops-ml/kitops/pkg/lib/constants"
2829
"github.com/kitops-ml/kitops/pkg/lib/constants/mediatype"
2930

3031
"github.com/opencontainers/go-digest"
@@ -212,22 +213,22 @@ func GetKitfileForManifest(ctx context.Context, store oras.ReadOnlyTarget, manif
212213
if err != nil {
213214
return nil, ErrNotAModelKit
214215
}
215-
var configDesc ocispec.Descriptor
216-
if modelFormat == mediatype.KitFormat {
217-
configDesc = manifest.Config
218-
} else {
219-
for _, layer := range manifest.Layers {
220-
if layer.MediaType == mediatype.KitConfigMediaType.String() {
221-
configDesc = layer
222-
break
223-
}
216+
switch modelFormat {
217+
case mediatype.KitFormat:
218+
return GetConfig(ctx, store, manifest.Config)
219+
case mediatype.ModelPackFormat:
220+
// TODO: can we (try to) generate a Kitfile from a ModelPack manifest?
221+
if manifest.Annotations == nil || manifest.Annotations[constants.KitfileJsonAnnotation] == "" {
222+
return nil, fmt.Errorf("ModelPack artifact does not contain a Kitfile")
224223
}
224+
kfstring := manifest.Annotations[constants.KitfileJsonAnnotation]
225+
kitfile := &artifact.KitFile{}
226+
if err := json.Unmarshal([]byte(kfstring), kitfile); err != nil {
227+
return nil, fmt.Errorf("failed to parse config: %w", err)
228+
}
229+
return kitfile, nil
225230
}
226-
if configDesc.Digest == "" {
227-
// TODO: handle ModelPack cases where no Kitfile is available
228-
return nil, fmt.Errorf("could not find config for artifact")
229-
}
230-
return GetConfig(ctx, store, configDesc)
231+
return nil, fmt.Errorf("Could not find config for artifact")
231232
}
232233

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

0 commit comments

Comments
 (0)