Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
k8s.io/api v0.34.1
k8s.io/apimachinery v0.34.1
k8s.io/client-go v0.34.1
sigs.k8s.io/controller-runtime v0.21.0
sigs.k8s.io/yaml v1.6.0
)

Expand Down Expand Up @@ -99,6 +100,7 @@ require (
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
github.com/extism/go-sdk v1.7.1 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand Down Expand Up @@ -215,7 +217,6 @@ require (
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect
sigs.k8s.io/controller-runtime v0.21.0 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ github.com/envoyproxy/go-control-plane/ratelimit v0.1.0 h1:/G9QYbddjL25KvtKTv3an
github.com/envoyproxy/go-control-plane/ratelimit v0.1.0/go.mod h1:Wk+tMFAFbCXaJPzVVHnPgRKdUdwW/KdbRt94AzgRee4=
github.com/envoyproxy/protoc-gen-validate v1.2.1 h1:DEo3O99U8j4hBFwbJfrz9VtgcDfUKS7KJ7spH3d86P8=
github.com/envoyproxy/protoc-gen-validate v1.2.1/go.mod h1:d/C80l/jxXLdfEIhX1W2TmLfsJ31lvEjwamM4DxlWXU=
github.com/evanphx/json-patch/v5 v5.9.11 h1:/8HVnzMq13/3x9TPvjG08wUGqBTmZBsCWzjTM0wiaDU=
github.com/evanphx/json-patch/v5 v5.9.11/go.mod h1:3j+LviiESTElxA4p3EMKAB9HXj3/XEtnUf6OZxqIQTM=
github.com/extism/go-sdk v1.7.1 h1:lWJos6uY+tRFdlIHR+SJjwFDApY7OypS/2nMhiVQ9Sw=
github.com/extism/go-sdk v1.7.1/go.mod h1:IT+Xdg5AZM9hVtpFUA+uZCJMge/hbvshl8bwzLtFyKA=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
Expand Down Expand Up @@ -220,6 +222,8 @@ github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
Expand Down
16 changes: 10 additions & 6 deletions pkg/artifact/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (a *ArtifactBuilder) GetTemplateData(ociRef string) (map[string][]byte, err
var metadataName string
jsonnetFiles := make(map[string][]byte)
var hasMetadata, hasBlueprintJsonnet bool
var valuesContent []byte
var schemaContent []byte

for {
header, err := tarReader.Next()
Expand All @@ -399,10 +399,10 @@ func (a *ArtifactBuilder) GetTemplateData(ociRef string) (map[string][]byte, err
return nil, fmt.Errorf("failed to parse metadata.yaml: %w", err)
}
metadataName = metadata.Name
case name == "_template/values.yaml":
valuesContent, err = io.ReadAll(tarReader)
case name == "_template/schema.yaml":
schemaContent, err = io.ReadAll(tarReader)
if err != nil {
return nil, fmt.Errorf("failed to read _template/values.yaml: %w", err)
return nil, fmt.Errorf("failed to read _template/schema.yaml: %w", err)
}
case strings.HasSuffix(name, ".jsonnet"):
normalized := strings.TrimPrefix(name, "_template/")
Expand All @@ -425,9 +425,13 @@ func (a *ArtifactBuilder) GetTemplateData(ociRef string) (map[string][]byte, err
}

templateData["name"] = []byte(metadataName)
if valuesContent != nil {
templateData["values"] = valuesContent

if schemaContent != nil {
templateData["schema"] = schemaContent
} else {
return nil, fmt.Errorf("OCI artifact missing required _template/schema.yaml file")
}

maps.Copy(templateData, jsonnetFiles)

return templateData, nil
Expand Down
14 changes: 10 additions & 4 deletions pkg/artifact/artifact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3047,6 +3047,7 @@ func TestArtifactBuilder_GetTemplateData(t *testing.T) {
testData := createTestTarGz(t, map[string][]byte{
"metadata.yaml": []byte("name: test\nversion: v1.0.0\n"),
"_template/blueprint.jsonnet": []byte("{ blueprint: 'content' }"),
"_template/schema.yaml": []byte("$schema: https://json-schema.org/draft/2020-12/schema\ntype: object\nproperties: {}\nrequired: []\nadditionalProperties: false"),
"template.jsonnet": []byte("{ template: 'content' }"),
"ignored.yaml": []byte("ignored: content"),
})
Expand Down Expand Up @@ -3085,8 +3086,8 @@ func TestArtifactBuilder_GetTemplateData(t *testing.T) {
if templateData == nil {
t.Fatal("Expected template data, got nil")
}
if len(templateData) != 4 {
t.Errorf("Expected 4 files (2 .jsonnet + 2 metadata), got %d", len(templateData))
if len(templateData) != 5 {
t.Errorf("Expected 5 files (2 .jsonnet + name + ociUrl + schema), got %d", len(templateData))
}
if string(templateData["template.jsonnet"]) != "{ template: 'content' }" {
t.Errorf("Expected template.jsonnet content to be '{ template: 'content' }', got %s", string(templateData["template.jsonnet"]))
Expand All @@ -3110,6 +3111,7 @@ func TestArtifactBuilder_GetTemplateData(t *testing.T) {
testData := createTestTarGz(t, map[string][]byte{
"metadata.yaml": []byte("name: test\nversion: v1.0.0\n"),
"_template/blueprint.jsonnet": []byte("{ blueprint: 'content' }"),
"_template/schema.yaml": []byte("$schema: https://json-schema.org/draft/2020-12/schema\ntype: object\nproperties: {}\nrequired: []\nadditionalProperties: false"),
"template.jsonnet": []byte("{ template: 'content' }"),
"config.yaml": []byte("config: value"),
"script.sh": []byte("#!/bin/bash"),
Expand Down Expand Up @@ -3145,8 +3147,8 @@ func TestArtifactBuilder_GetTemplateData(t *testing.T) {
if templateData == nil {
t.Fatal("Expected template data, got nil")
}
if len(templateData) != 6 {
t.Errorf("Expected 6 files (4 .jsonnet + 2 metadata), got %d", len(templateData))
if len(templateData) != 7 {
t.Errorf("Expected 7 files (4 .jsonnet + name + ociUrl + schema), got %d", len(templateData))
}

// And should contain OCI metadata
Expand Down Expand Up @@ -3258,6 +3260,7 @@ func TestArtifactBuilder_GetTemplateData(t *testing.T) {
testData := createTestTarGz(t, map[string][]byte{
"metadata.yaml": []byte("name: test\nversion: v1.0.0\n"),
"_template/blueprint.jsonnet": []byte("{ blueprint: 'content' }"),
"_template/schema.yaml": []byte("$schema: https://json-schema.org/draft/2020-12/schema\ntype: object\nproperties: {}\nrequired: []\nadditionalProperties: false"),
"_template/other.jsonnet": []byte("{ other: 'content' }"),
"config.yaml": []byte("config: value"),
})
Expand Down Expand Up @@ -3302,6 +3305,9 @@ func TestArtifactBuilder_GetTemplateData(t *testing.T) {
if string(templateData["ociUrl"]) != "oci://registry.example.com/test:v1.0.0" {
t.Errorf("Expected ociUrl to be 'oci://registry.example.com/test:v1.0.0', got %s", string(templateData["ociUrl"]))
}
if _, exists := templateData["schema"]; !exists {
t.Error("Expected schema key to be included")
}
})
}

Expand Down
Loading
Loading