Skip to content
This repository was archived by the owner on Mar 17, 2023. It is now read-only.

Commit df18e7e

Browse files
committed
Fix raw values missing json parsing
1 parent 90b033c commit df18e7e

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

api/v1alpha1/template_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type TemplateSource struct {
5050
Object *LocalObjectReference `json:"object,omitempty"`
5151
// Value is a literal yaml value to use as source.
5252
// +optional
53-
Value apiextensionsv1.JSON `json:"value,omitempty"`
53+
Value *apiextensionsv1.JSON `json:"value,omitempty"`
5454
}
5555

5656
// LocalObjectReference references an object in a specific api version.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/template-operator/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: template-operator
33
description: A Helm chart for the template operator
44
type: application
5-
version: 0.1.5
5+
version: 0.1.6
66
appVersion: 0.1.0
77
engine: gotpl
88
home: https://github.com/onmetal/template-operator

config/samples/template_v1alpha1_template.yaml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ spec:
1313
managed-by: template-sample
1414
prune: true
1515
sources:
16-
# - name: token
17-
# object:
18-
# apiVersion: v1
19-
# kind: Secret
20-
# namespace: default
21-
# name: default-token-rtxld
16+
- name: secretName
17+
value: my-secret
18+
# - name: token
19+
# object:
20+
# apiVersion: v1
21+
# kind: Secret
22+
# name: default-token-rtxld
2223
data:
2324
inline: |-
2425
apiVersion: v1
2526
kind: Secret
2627
metadata:
2728
namespace: {{ .Template.metadata.namespace }}
28-
name: my-secret
29+
name: {{ .Values.secretName }}
2930
type: Opaque
3031
data:
3132
kubeconfig: {{ .Template.metadata.name | b64enc }}

pkg/template/template.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3333
"k8s.io/apimachinery/pkg/labels"
3434
"k8s.io/apimachinery/pkg/runtime"
35+
"k8s.io/apimachinery/pkg/util/json"
3536
"k8s.io/apimachinery/pkg/util/yaml"
3637
"k8s.io/client-go/kubernetes/scheme"
3738
ctrl "sigs.k8s.io/controller-runtime"
@@ -179,7 +180,13 @@ func (e *Engine) resolveSources(ctx context.Context, logger logr.Logger, templat
179180

180181
values[src.Name] = u.Object
181182
default:
182-
values[src.Name] = src.Value
183+
var v interface{}
184+
if src.Value != nil {
185+
if err := json.Unmarshal(src.Value.Raw, &v); err != nil {
186+
return nil, fmt.Errorf("error unmarshaling raw value %s: %w", src.Name, err)
187+
}
188+
}
189+
values[src.Name] = v
183190
}
184191
}
185192

0 commit comments

Comments
 (0)