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

Commit

Permalink
Fix raw values missing json parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
adracus committed Sep 10, 2021
1 parent 90b033c commit df18e7e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/template_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type TemplateSource struct {
Object *LocalObjectReference `json:"object,omitempty"`
// Value is a literal yaml value to use as source.
// +optional
Value apiextensionsv1.JSON `json:"value,omitempty"`
Value *apiextensionsv1.JSON `json:"value,omitempty"`
}

// LocalObjectReference references an object in a specific api version.
Expand Down
7 changes: 6 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion charts/template-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: template-operator
description: A Helm chart for the template operator
type: application
version: 0.1.5
version: 0.1.6
appVersion: 0.1.0
engine: gotpl
home: https://github.com/onmetal/template-operator
Expand Down
15 changes: 8 additions & 7 deletions config/samples/template_v1alpha1_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ spec:
managed-by: template-sample
prune: true
sources:
# - name: token
# object:
# apiVersion: v1
# kind: Secret
# namespace: default
# name: default-token-rtxld
- name: secretName
value: my-secret
# - name: token
# object:
# apiVersion: v1
# kind: Secret
# name: default-token-rtxld
data:
inline: |-
apiVersion: v1
kind: Secret
metadata:
namespace: {{ .Template.metadata.namespace }}
name: my-secret
name: {{ .Values.secretName }}
type: Opaque
data:
kubeconfig: {{ .Template.metadata.name | b64enc }}
9 changes: 8 additions & 1 deletion pkg/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -179,7 +180,13 @@ func (e *Engine) resolveSources(ctx context.Context, logger logr.Logger, templat

values[src.Name] = u.Object
default:
values[src.Name] = src.Value
var v interface{}
if src.Value != nil {
if err := json.Unmarshal(src.Value.Raw, &v); err != nil {
return nil, fmt.Errorf("error unmarshaling raw value %s: %w", src.Name, err)
}
}
values[src.Name] = v
}
}

Expand Down

0 comments on commit df18e7e

Please sign in to comment.