Skip to content

Commit

Permalink
feat(pkger): add env default vaules for template references
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteenb2 committed Jun 22, 2020
1 parent 2d4a12f commit cd04731
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
1. [18600](https://github.com/influxdata/influxdb/pull/18600): Extend influx apply with resource filter capabilities
1. [18601](https://github.com/influxdata/influxdb/pull/18601): Provide active config running influx config without args
1. [18606](https://github.com/influxdata/influxdb/pull/18606): Enable influxd binary to look for a config file on startup
1. [18647](https://github.com/influxdata/influxdb/pull/18647): Add support for env ref default values to the template parser

### Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions pkger/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,7 @@ func (r Resource) references(key string) *references {
switch f {
case fieldReferencesEnv:
ref.EnvRef = keyRes.stringShort(fieldKey)
ref.defaultVal = keyRes.stringShort(fieldDefault)
case fieldReferencesSecret:
ref.Secret = keyRes.stringShort(fieldKey)
}
Expand Down
11 changes: 8 additions & 3 deletions pkger/parser_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func summarizeCommonReferences(ident identity, labels sortedLabels) []SummaryRef
const (
fieldAPIVersion = "apiVersion"
fieldAssociations = "associations"
fieldDefault = "default"
fieldDescription = "description"
fieldEvery = "every"
fieldKey = "key"
Expand Down Expand Up @@ -1992,9 +1993,10 @@ const (
)

type references struct {
val interface{}
EnvRef string
Secret string
val interface{}
defaultVal string
EnvRef string
Secret string
}

func (r *references) hasValue() bool {
Expand All @@ -2019,6 +2021,9 @@ func (r *references) String() string {
}

func (r *references) defaultEnvValue() string {
if r.defaultVal != "" {
return r.defaultVal
}
return "env-" + r.EnvRef
}

Expand Down
32 changes: 16 additions & 16 deletions pkger/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func TestParse(t *testing.T) {
{
Field: "metadata.name",
EnvRefKey: "meta-name",
DefaultValue: "env-meta-name",
DefaultValue: "meta",
},
{
Field: "spec.name",
EnvRefKey: "spec-name",
DefaultValue: "env-spec-name",
DefaultValue: "spectacles",
},
{
Field: "spec.associations[0].name",
Expand Down Expand Up @@ -582,12 +582,12 @@ spec:
{
Field: "metadata.name",
EnvRefKey: "meta-name",
DefaultValue: "env-meta-name",
DefaultValue: "meta",
},
{
Field: "spec.name",
EnvRefKey: "spec-name",
DefaultValue: "env-spec-name",
DefaultValue: "spectacles",
},
{
Field: "spec.associations[0].name",
Expand Down Expand Up @@ -2281,12 +2281,12 @@ spec:
{
Field: "metadata.name",
EnvRefKey: "meta-name",
DefaultValue: "env-meta-name",
DefaultValue: "meta",
},
{
Field: "spec.name",
EnvRefKey: "spec-name",
DefaultValue: "env-spec-name",
DefaultValue: "spectacles",
},
{
Field: "spec.associations[0].name",
Expand Down Expand Up @@ -2528,12 +2528,12 @@ spec:
{
Field: "metadata.name",
EnvRefKey: "meta-name",
DefaultValue: "env-meta-name",
DefaultValue: "meta",
},
{
Field: "spec.name",
EnvRefKey: "spec-name",
DefaultValue: "env-spec-name",
DefaultValue: "spectacles",
},
{
Field: "spec.associations[0].name",
Expand Down Expand Up @@ -2852,12 +2852,12 @@ spec:
{
Field: "metadata.name",
EnvRefKey: "meta-name",
DefaultValue: "env-meta-name",
DefaultValue: "meta",
},
{
Field: "spec.name",
EnvRefKey: "spec-name",
DefaultValue: "env-spec-name",
DefaultValue: "spectacles",
},
{
Field: "spec.associations[0].name",
Expand Down Expand Up @@ -3189,12 +3189,12 @@ spec:
{
Field: "metadata.name",
EnvRefKey: "meta-name",
DefaultValue: "env-meta-name",
DefaultValue: "meta",
},
{
Field: "spec.name",
EnvRefKey: "spec-name",
DefaultValue: "env-spec-name",
DefaultValue: "spectacles",
},
{
Field: "spec.associations[0].name",
Expand Down Expand Up @@ -3407,12 +3407,12 @@ spec:
{
Field: "metadata.name",
EnvRefKey: "meta-name",
DefaultValue: "env-meta-name",
DefaultValue: "meta",
},
{
Field: "spec.name",
EnvRefKey: "spec-name",
DefaultValue: "env-spec-name",
DefaultValue: "spectacles",
},
{
Field: "spec.associations[0].name",
Expand Down Expand Up @@ -3527,12 +3527,12 @@ spec:
{
Field: "metadata.name",
EnvRefKey: "meta-name",
DefaultValue: "env-meta-name",
DefaultValue: "meta",
},
{
Field: "spec.name",
EnvRefKey: "spec-name",
DefaultValue: "env-spec-name",
DefaultValue: "spectacles",
},
{
Field: "spec.associations[0].name",
Expand Down
2 changes: 2 additions & 0 deletions pkger/testdata/bucket_ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ metadata:
name:
envRef:
key: meta-name
default: meta
spec:
name:
envRef:
key: spec-name
default: spectacles
associations:
- kind: Label
name:
Expand Down
2 changes: 2 additions & 0 deletions pkger/testdata/checks_ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ metadata:
name:
envRef:
key: meta-name
default: meta
spec:
name:
envRef:
key: spec-name
default: spectacles
every: 1m
offset: 15s
query: |
Expand Down
2 changes: 2 additions & 0 deletions pkger/testdata/dashboard_ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ metadata:
name:
envRef:
key: meta-name
default: meta
spec:
name:
envRef:
key: spec-name
default: spectacles
associations:
- kind: Label
name:
Expand Down
2 changes: 2 additions & 0 deletions pkger/testdata/notification_endpoint_ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ metadata:
name:
envRef:
key: meta-name
default: meta
spec:
name:
envRef:
key: spec-name
default: spectacles
url: https://hooks.slack.com/services/bip/piddy/boppidy
token: tokenval
associations:
Expand Down
2 changes: 2 additions & 0 deletions pkger/testdata/notification_rule_ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ metadata:
name:
envRef:
key: meta-name
default: meta
spec:
name:
envRef:
key: spec-name
default: spectacles
endpointName:
envRef:
key: endpoint-meta-name
Expand Down
2 changes: 2 additions & 0 deletions pkger/testdata/task_ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ metadata:
name:
envRef:
key: meta-name
default: meta
spec:
name:
envRef:
key: spec-name
default: spectacles
every: 10m
offset: 15s
query: >
Expand Down
2 changes: 2 additions & 0 deletions pkger/testdata/telegraf_ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ metadata:
name:
envRef:
key: meta-name
default: meta
spec:
name:
envRef:
key: spec-name
default: spectacles
config: |
# Configuration for telegraf agent
[agent]
Expand Down
2 changes: 2 additions & 0 deletions pkger/testdata/variable_ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ metadata:
name:
envRef:
key: meta-name
default: meta
spec:
name:
envRef:
key: spec-name
default: spectacles
type: constant
values:
- first val
Expand Down

0 comments on commit cd04731

Please sign in to comment.