feat(pkger): add env default vaules for template references

pull/18650/head
Johnny Steenbergen 2020-06-22 14:49:14 -07:00 committed by Johnny Steenbergen
parent 2d4a12fdf6
commit 34c4e5a48b
12 changed files with 42 additions and 19 deletions

View File

@ -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

View File

@ -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)
}

View File

@ -50,6 +50,7 @@ func summarizeCommonReferences(ident identity, labels sortedLabels) []SummaryRef
const (
fieldAPIVersion = "apiVersion"
fieldAssociations = "associations"
fieldDefault = "default"
fieldDescription = "description"
fieldEvery = "every"
fieldKey = "key"
@ -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 {
@ -2019,6 +2021,9 @@ func (r *references) String() string {
}
func (r *references) defaultEnvValue() string {
if r.defaultVal != "" {
return r.defaultVal
}
return "env-" + r.EnvRef
}

View File

@ -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",
@ -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",
@ -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",
@ -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",
@ -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",
@ -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",
@ -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",
@ -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",

View File

@ -4,10 +4,12 @@ metadata:
name:
envRef:
key: meta-name
default: meta
spec:
name:
envRef:
key: spec-name
default: spectacles
associations:
- kind: Label
name:

View File

@ -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: |

View File

@ -4,10 +4,12 @@ metadata:
name:
envRef:
key: meta-name
default: meta
spec:
name:
envRef:
key: spec-name
default: spectacles
associations:
- kind: Label
name:

View File

@ -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:

View File

@ -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

View File

@ -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: >

View File

@ -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]

View File

@ -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