Skip to content

Commit 6536b4f

Browse files
committed
Downgrade invalid manifest versions to just a warning
In order to preserve compatibility with older ModelKits, treat any unrecognized manifestVersion as 1.0.0 and print a warning instead of refusing to process the Kitfile Signed-off-by: Angel Misevski <amisevsk@gmail.com>
1 parent 0ec8f95 commit 6536b4f

2 files changed

Lines changed: 13 additions & 13 deletions

File tree

pkg/artifact/kitfile.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"strings"
3030
"time"
3131

32+
"github.com/kitops-ml/kitops/pkg/output"
3233
modelspecv1 "github.com/modelpack/model-spec/specs-go/v1"
3334
"github.com/opencontainers/go-digest"
3435
"go.yaml.in/yaml/v3"
@@ -140,16 +141,17 @@ type (
140141
}
141142
)
142143

143-
func (kf *KitFile) LoadModel(kitfileContent io.ReadCloser) error {
144+
func (kf *KitFile) LoadModel(kitfileContent io.ReadCloser) (err error) {
144145
decoder := yaml.NewDecoder(kitfileContent)
145146
decoder.KnownFields(true)
146147
if err := decoder.Decode(kf); err != nil {
147148
return err
148149
}
149-
if err := kf.Validate(); err != nil {
150-
return err
150+
err, warnings := kf.Validate()
151+
for _, warning := range warnings {
152+
output.Logln(output.LogLevelWarn, warning)
151153
}
152-
return nil
154+
return err
153155
}
154156

155157
func (kf *KitFile) MarshalToJSON() ([]byte, error) {
@@ -171,15 +173,16 @@ func (kf *KitFile) MarshalToYAML() ([]byte, error) {
171173
return buf.Bytes(), nil
172174
}
173175

174-
func (kf *KitFile) Validate() error {
176+
func (kf *KitFile) Validate() (err error, warnings []string) {
177+
if kf.ManifestVersion != "1.0.0" {
178+
warnings = append(warnings, fmt.Sprintf("Unrecognized manifestVersion %s: treating Kitfile as 1.0.0", kf.ManifestVersion))
179+
}
180+
175181
var errs []string
176182
addErr := func(format string, a ...any) {
177183
s := fmt.Sprintf(format, a...)
178184
errs = append(errs, fmt.Sprintf(" * %s", s))
179185
}
180-
if kf.ManifestVersion != "1.0.0" {
181-
addErr("invalid manifestVersion: expect 1.0.0 but got %s", kf.ManifestVersion)
182-
}
183186

184187
// Map of paths to the component that uses them; used to detect duplicate paths
185188
paths := map[string][]string{}
@@ -287,10 +290,10 @@ func (kf *KitFile) Validate() error {
287290
if len(errs) > 0 {
288291
// Iterating through the paths map is random; sort to get a consistent message
289292
slices.Sort(errs)
290-
return fmt.Errorf("errors while validating Kitfile: \n%s", strings.Join(errs, "\n"))
293+
return fmt.Errorf("errors while validating Kitfile: \n%s", strings.Join(errs, "\n")), warnings
291294
}
292295

293-
return nil
296+
return nil, warnings
294297
}
295298

296299
func (kf *KitFile) ToModelPackConfig(diffIDs []digest.Digest) modelspecv1.Model {

pkg/artifact/testdata/validation/bad-manifest-version.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)