Skip to content

Commit 96b7457

Browse files
feat: add / get local blob transformers (open-component-model#1654)
<!-- markdownlint-disable MD041 --> #### What this PR does / why we need it creates AddLocalBlob / GetLocalBlob transformation variants for OCI / CTF #### Which issue(s) this PR fixes <!-- Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`. --> creates the transformers in OCI required for local blob transformations. add / get for now based on file buffers. copy op coming up separately ~NOTE: blocked until blob module is released~ 0.0.11 released part of open-component-model/ocm-project#795 --------- Signed-off-by: Jakob Möller <contact@jakob-moeller.com> Signed-off-by: Jakob Möller <jakob.moeller@sap.com> Co-authored-by: Fabian Burth <fabian.burth@sap.com>
1 parent 7e5db44 commit 96b7457

27 files changed

+5613
-6
lines changed

Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ tasks:
160160

161161
generate:
162162
desc: "Run all Code Generators in the project"
163-
deps:
163+
cmds:
164164
- task: 'bindings/go/generator:ocmtypegen/generate'
165165
- task: 'bindings/go/generator:jsonschemagen/generate'
166166
- task: 'tools:deepcopy-gen/generate-deepcopy'

bindings/go/oci/internal/pack/pack.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@ type Options struct {
4949
}
5050

5151
// ArtifactBlob packs a [ociblob.ArtifactBlob] into an OCI Storage
52-
func ArtifactBlob(ctx context.Context, storage content.Storage, b *ociblob.ArtifactBlob, opts Options) (desc ociImageSpecV1.Descriptor, err error) {
53-
localBlob, ok := b.GetAccess().(*v2.LocalBlob)
54-
if !ok {
55-
return ociImageSpecV1.Descriptor{}, fmt.Errorf("artifact access is not a local blob access: %T", b.GetAccess())
52+
func ArtifactBlob(ctx context.Context, storage content.Storage, b *ociblob.ArtifactBlob, opts Options) (ociImageSpecV1.Descriptor, error) {
53+
// Convert access to LocalBlob - this is a no-op if already the correct type
54+
localBlob := &v2.LocalBlob{}
55+
if err := opts.AccessScheme.Convert(b.GetAccess(), localBlob); err != nil {
56+
return ociImageSpecV1.Descriptor{}, fmt.Errorf(
57+
"failed to convert artifact access to local blob "+
58+
"(make sure this is a local blob access to prepare it for packing): %w", err)
5659
}
5760
return ResourceLocalBlob(ctx, storage, b, localBlob, opts)
5861
}

bindings/go/oci/internal/pack/pack_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func TestResourceBlob(t *testing.T) {
375375
opts: Options{
376376
AccessScheme: runtime.NewScheme(),
377377
},
378-
expectedError: "artifact access is not a local blob access",
378+
expectedError: "failed to convert artifact access to local blob",
379379
},
380380
}
381381

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package v1alpha1
2+
3+
import (
4+
"ocm.software/open-component-model/bindings/go/blob/filesystem/spec/access/v1alpha1"
5+
v2 "ocm.software/open-component-model/bindings/go/descriptor/v2"
6+
"ocm.software/open-component-model/bindings/go/oci/spec/repository/v1/ctf"
7+
"ocm.software/open-component-model/bindings/go/runtime"
8+
)
9+
10+
const CTFAddLocalResourceType = "CTFAddLocalResource"
11+
12+
// CTFAddLocalResource is a transformer specification to add a local resource
13+
// blob to a component version in a CTF repository.
14+
// +k8s:deepcopy-gen:interfaces=ocm.software/open-component-model/bindings/go/runtime.Typed
15+
// +k8s:deepcopy-gen=true
16+
// +ocm:typegen=true
17+
// +ocm:jsonschema-gen=true
18+
type CTFAddLocalResource struct {
19+
// +ocm:jsonschema-gen:enum=CTFAddLocalResource/v1alpha1
20+
Type runtime.Type `json:"type"`
21+
ID string `json:"id"`
22+
Spec *CTFAddLocalResourceSpec `json:"spec"`
23+
Output *CTFAddLocalResourceOutput `json:"output,omitempty"`
24+
}
25+
26+
// CTFAddLocalResourceOutput is the output specification of the
27+
// CTFAddLocalResource transformation.
28+
// +k8s:deepcopy-gen=true
29+
// +ocm:jsonschema-gen=true
30+
type CTFAddLocalResourceOutput struct {
31+
// Resource is the updated resource descriptor with populated LocalReference
32+
Resource *v2.Resource `json:"resource"`
33+
}
34+
35+
// CTFAddLocalResourceSpec is the input specification for the
36+
// CTFAddLocalResource transformation.
37+
// +k8s:deepcopy-gen=true
38+
// +ocm:jsonschema-gen=true
39+
type CTFAddLocalResourceSpec struct {
40+
// Repository is the CTF repository specification
41+
Repository ctf.Repository `json:"repository"`
42+
// Component is the component name to add the resource to.
43+
Component string `json:"component"`
44+
// Version is the component version to add the resource to.
45+
Version string `json:"version"`
46+
// Resource is the resource descriptor to add.
47+
// If the Resource contains an access specification, it may be used
48+
// by the underlying implementation to derive metadata to avoid additional compute
49+
// (such as digest information) or to steer implementation (such as a reference name)
50+
Resource *v2.Resource `json:"resource"`
51+
// File is the access specification to the data that should be added
52+
File v1alpha1.File `json:"file"`
53+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package v1alpha1
2+
3+
import (
4+
"ocm.software/open-component-model/bindings/go/blob/filesystem/spec/access/v1alpha1"
5+
v2 "ocm.software/open-component-model/bindings/go/descriptor/v2"
6+
"ocm.software/open-component-model/bindings/go/oci/spec/repository/v1/ctf"
7+
"ocm.software/open-component-model/bindings/go/runtime"
8+
)
9+
10+
const CTFGetLocalResourceType = "CTFGetLocalResource"
11+
12+
// CTFGetLocalResource is a transformer specification to get a local resource
13+
// blob from a component version in a CTF repository and buffer it to a file.
14+
// +k8s:deepcopy-gen:interfaces=ocm.software/open-component-model/bindings/go/runtime.Typed
15+
// +k8s:deepcopy-gen=true
16+
// +ocm:typegen=true
17+
// +ocm:jsonschema-gen=true
18+
type CTFGetLocalResource struct {
19+
// +ocm:jsonschema-gen:enum=CTFGetLocalResource/v1alpha1
20+
Type runtime.Type `json:"type"`
21+
ID string `json:"id"`
22+
Spec *CTFGetLocalResourceSpec `json:"spec"`
23+
Output *CTFGetLocalResourceOutput `json:"output,omitempty"`
24+
}
25+
26+
// CTFGetLocalResourceOutput is the output specification of the
27+
// CTFGetLocalResource transformation.
28+
// +k8s:deepcopy-gen=true
29+
// +ocm:jsonschema-gen=true
30+
type CTFGetLocalResourceOutput struct {
31+
// File is the file access specification for the downloaded resource
32+
File v1alpha1.File `json:"file"`
33+
// Resource is the resource descriptor from the repository
34+
Resource *v2.Resource `json:"resource"`
35+
}
36+
37+
// CTFGetLocalResourceSpec is the input specification for the
38+
// CTFGetLocalResource transformation.
39+
// +k8s:deepcopy-gen=true
40+
// +ocm:jsonschema-gen=true
41+
type CTFGetLocalResourceSpec struct {
42+
// Repository is the CTF repository specification
43+
Repository ctf.Repository `json:"repository"`
44+
// Component is the component name
45+
Component string `json:"component"`
46+
// Version is the component version
47+
Version string `json:"version"`
48+
// ResourceIdentity identifies the resource to retrieve.
49+
// Must match a resource in the component descriptor.
50+
ResourceIdentity runtime.Identity `json:"resourceIdentity"`
51+
// OutputPath is the path where the blob should be buffered.
52+
// If empty, a temporary file will be created.
53+
OutputPath string `json:"outputPath,omitempty"`
54+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package v1alpha1
2+
3+
import (
4+
"ocm.software/open-component-model/bindings/go/blob/filesystem/spec/access/v1alpha1"
5+
v2 "ocm.software/open-component-model/bindings/go/descriptor/v2"
6+
"ocm.software/open-component-model/bindings/go/oci/spec/repository/v1/oci"
7+
"ocm.software/open-component-model/bindings/go/runtime"
8+
)
9+
10+
const OCIAddLocalResourceType = "OCIAddLocalResource"
11+
12+
// OCIAddLocalResource is a transformer specification to add a local resource
13+
// blob to a component version in an OCI repository.
14+
// +k8s:deepcopy-gen:interfaces=ocm.software/open-component-model/bindings/go/runtime.Typed
15+
// +k8s:deepcopy-gen=true
16+
// +ocm:typegen=true
17+
// +ocm:jsonschema-gen=true
18+
type OCIAddLocalResource struct {
19+
// +ocm:jsonschema-gen:enum=OCIAddLocalResource/v1alpha1
20+
Type runtime.Type `json:"type"`
21+
ID string `json:"id"`
22+
Spec *OCIAddLocalResourceSpec `json:"spec"`
23+
Output *OCIAddLocalResourceOutput `json:"output,omitempty"`
24+
}
25+
26+
// OCIAddLocalResourceOutput is the output specification of the
27+
// OCIAddLocalResource transformation.
28+
// +k8s:deepcopy-gen=true
29+
// +ocm:jsonschema-gen=true
30+
type OCIAddLocalResourceOutput struct {
31+
// Resource is the updated resource descriptor with populated LocalReference
32+
Resource *v2.Resource `json:"resource"`
33+
}
34+
35+
// OCIAddLocalResourceSpec is the input specification for the
36+
// OCIAddLocalResource transformation.
37+
// +k8s:deepcopy-gen=true
38+
// +ocm:jsonschema-gen=true
39+
type OCIAddLocalResourceSpec struct {
40+
// Repository is the OCI repository specification
41+
Repository oci.Repository `json:"repository"`
42+
// Component is the component name to add the resource to.
43+
Component string `json:"component"`
44+
// Version is the component version to add the resource to.
45+
Version string `json:"version"`
46+
// Resource is the resource descriptor to add.
47+
// If the Resource contains an access specification, it may be used
48+
// by the underlying implementation to derive metadata to avoid additional compute
49+
// (such as digest information) or to steer implementation (such as a reference name)
50+
Resource *v2.Resource `json:"resource"`
51+
// File is the access specification to the file that should be added
52+
File v1alpha1.File `json:"file"`
53+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package v1alpha1
2+
3+
import (
4+
"ocm.software/open-component-model/bindings/go/blob/filesystem/spec/access/v1alpha1"
5+
v2 "ocm.software/open-component-model/bindings/go/descriptor/v2"
6+
"ocm.software/open-component-model/bindings/go/oci/spec/repository/v1/oci"
7+
"ocm.software/open-component-model/bindings/go/runtime"
8+
)
9+
10+
const OCIGetLocalResourceType = "OCIGetLocalResource"
11+
12+
// OCIGetLocalResource is a transformer specification to get a local resource
13+
// blob from a component version in an OCI repository and buffer it to a file.
14+
// +k8s:deepcopy-gen:interfaces=ocm.software/open-component-model/bindings/go/runtime.Typed
15+
// +k8s:deepcopy-gen=true
16+
// +ocm:typegen=true
17+
// +ocm:jsonschema-gen=true
18+
type OCIGetLocalResource struct {
19+
// +ocm:jsonschema-gen:enum=OCIGetLocalResource/v1alpha1
20+
Type runtime.Type `json:"type"`
21+
ID string `json:"id"`
22+
Spec *OCIGetLocalResourceSpec `json:"spec"`
23+
Output *OCIGetLocalResourceOutput `json:"output,omitempty"`
24+
}
25+
26+
// OCIGetLocalResourceOutput is the output specification of the
27+
// OCIGetLocalResource transformation.
28+
// +k8s:deepcopy-gen=true
29+
// +ocm:jsonschema-gen=true
30+
type OCIGetLocalResourceOutput struct {
31+
// File is the file access specification for the downloaded resource
32+
File v1alpha1.File `json:"file"`
33+
// Resource is the resource descriptor from the repository
34+
Resource *v2.Resource `json:"resource"`
35+
}
36+
37+
// OCIGetLocalResourceSpec is the input specification for the
38+
// OCIGetLocalResource transformation.
39+
// +k8s:deepcopy-gen=true
40+
// +ocm:jsonschema-gen=true
41+
type OCIGetLocalResourceSpec struct {
42+
// Repository is the OCI repository specification
43+
Repository oci.Repository `json:"repository"`
44+
// Component is the component name
45+
Component string `json:"component"`
46+
// Version is the component version
47+
Version string `json:"version"`
48+
// ResourceIdentity identifies the resource to retrieve.
49+
// Must match a resource in the component descriptor.
50+
ResourceIdentity runtime.Identity `json:"resourceIdentity"`
51+
// OutputPath is the path where the blob should be buffered.
52+
// If empty, a temporary file will be created.
53+
OutputPath string `json:"outputPath,omitempty"`
54+
}

0 commit comments

Comments
 (0)