Skip to content

Commit 53d386a

Browse files
authored
feat: support inspect the config (#224)
Signed-off-by: chlins <[email protected]>
1 parent 9db6cee commit 53d386a

File tree

6 files changed

+66
-10
lines changed

6 files changed

+66
-10
lines changed

cmd/inspect.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func init() {
4949
flags.BoolVar(&inspectConfig.Remote, "remote", false, "inspect model artifact from remote registry")
5050
flags.BoolVar(&inspectConfig.PlainHTTP, "plain-http", false, "use plain HTTP instead of HTTPS")
5151
flags.BoolVar(&inspectConfig.Insecure, "insecure", false, "allow insecure connections")
52+
flags.BoolVar(&inspectConfig.Config, "config", false, "inspect the config of the model artifact")
5253

5354
if err := viper.BindPFlags(flags); err != nil {
5455
panic(fmt.Errorf("bind cache inspect flags to viper: %w", err))

pkg/backend/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type Backend interface {
5959
Prune(ctx context.Context, dryRun, removeUntagged bool) error
6060

6161
// Inspect inspects the model artifact.
62-
Inspect(ctx context.Context, target string, cfg *config.Inspect) (*InspectedModelArtifact, error)
62+
Inspect(ctx context.Context, target string, cfg *config.Inspect) (any, error)
6363

6464
// Extract extracts the model artifact.
6565
Extract(ctx context.Context, target string, cfg *config.Extract) error

pkg/backend/inspect.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type InspectedModelArtifactLayer struct {
6666
}
6767

6868
// Inspect inspects the target from the storage.
69-
func (b *backend) Inspect(ctx context.Context, target string, cfg *config.Inspect) (*InspectedModelArtifact, error) {
69+
func (b *backend) Inspect(ctx context.Context, target string, cfg *config.Inspect) (any, error) {
7070
logrus.Infof("inspect: starting inspect operation for target %s [config: %+v]", target, cfg)
7171
_, err := ParseReference(target)
7272
if err != nil {
@@ -92,6 +92,10 @@ func (b *backend) Inspect(ctx context.Context, target string, cfg *config.Inspec
9292

9393
logrus.Debugf("inspect: loaded model config for target %s [family: %s, name: %s]", target, config.Descriptor.Family, config.Descriptor.Name)
9494

95+
if cfg.Config {
96+
return config, nil
97+
}
98+
9599
inspectedModelArtifact := &InspectedModelArtifact{
96100
ID: manifest.Config.Digest.String(),
97101
Digest: godigest.FromBytes(manifestRaw).String(),

pkg/backend/inspect_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ func TestInspect(t *testing.T) {
131131
mockStore.On("PullManifest", ctx, "example.com/repo", "tag").Return([]byte(manifest), "sha256:9ca701e8784e5656e2c36f10f82410a0af4c44f859590a28a3d1519ee1eea89d", nil)
132132
mockStore.On("PullBlob", ctx, "example.com/repo", "sha256:e31b55920173ba79526491fbd01efe609c1d0d72c3a83df85b2c4fe74df2eea2").Return(io.NopCloser(bytes.NewReader([]byte(config))), nil)
133133

134-
inspected, err := b.Inspect(ctx, target, &pkgconfig.Inspect{})
134+
inspectedAny, err := b.Inspect(ctx, target, &pkgconfig.Inspect{})
135+
inspected := inspectedAny.(*InspectedModelArtifact)
135136
assert.NoError(t, err)
136137
assert.Equal(t, "sha256:e31b55920173ba79526491fbd01efe609c1d0d72c3a83df85b2c4fe74df2eea2", inspected.ID)
137138
assert.Equal(t, "sha256:9ca701e8784e5656e2c36f10f82410a0af4c44f859590a28a3d1519ee1eea89d", inspected.Digest)

pkg/config/inspect.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ type Inspect struct {
2020
Remote bool
2121
PlainHTTP bool
2222
Insecure bool
23+
Config bool
2324
}
2425

2526
func NewInspect() *Inspect {
2627
return &Inspect{
2728
Remote: false,
2829
PlainHTTP: false,
2930
Insecure: false,
31+
Config: false,
3032
}
3133
}

test/mocks/backend/backend.go

Lines changed: 55 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)