Skip to content

Commit

Permalink
feat(pkger): extend SummaryTasks with its env references
Browse files Browse the repository at this point in the history
references: #18407
  • Loading branch information
jsteenb2 committed Jun 11, 2020
1 parent 8ca8ce9 commit b4e1ea7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
2 changes: 2 additions & 0 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8105,6 +8105,8 @@ components:
type: string
status:
type: string
envReferences:
$ref: "#/components/schemas/PkgEnvReferences"
telegrafConfigs:
type: array
items:
Expand Down
3 changes: 2 additions & 1 deletion pkger/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ type SummaryTask struct {
Query string `json:"query"`
Status influxdb.Status `json:"status"`

LabelAssociations []SummaryLabel `json:"labelAssociations"`
EnvReferences []SummaryReference `json:"envReferences"`
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}

// SummaryTelegraf provides a summary of a pkg telegraf config.
Expand Down
11 changes: 8 additions & 3 deletions pkger/parser_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func (i *identity) PkgName() string {

func (i *identity) summarizeReferences() []SummaryReference {
refs := make([]SummaryReference, 0)
if i.name != nil && i.name.EnvRef != "" {
if i.name.hasEnvRef() {
refs = append(refs, convertRefToRefSummary("metadata.name", i.name))
}
if i.displayName != nil && i.displayName.EnvRef != "" {
if i.displayName.hasEnvRef() {
refs = append(refs, convertRefToRefSummary("spec.name", i.displayName))
}
return refs
Expand Down Expand Up @@ -1474,7 +1474,7 @@ func (r *notificationRule) summarize() SummaryNotificationRule {
}

envRefs := summarizeCommonReferences(r.identity, r.labels)
if r.endpointName != nil && r.endpointName.EnvRef != "" {
if r.endpointName.hasEnvRef() {
envRefs = append(envRefs, convertRefToRefSummary("spec.endpointName", r.endpointName))
}

Expand Down Expand Up @@ -1722,6 +1722,7 @@ func (t *task) summarize() SummaryTask {
Query: t.query,
Status: t.Status(),

EnvReferences: summarizeCommonReferences(t.identity, t.labels),
LabelAssociations: toSummaryLabels(t.labels...),
}
}
Expand Down Expand Up @@ -1995,6 +1996,10 @@ func (r *references) hasValue() bool {
return r.EnvRef != "" || r.Secret != "" || r.val != nil
}

func (r *references) hasEnvRef() bool {
return r != nil && r.EnvRef != ""
}

func (r *references) String() string {
if r == nil {
return ""
Expand Down
21 changes: 21 additions & 0 deletions pkger/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3163,6 +3163,27 @@ spec:
})
})

t.Run("with env refs should be valid", func(t *testing.T) {
testfileRunner(t, "testdata/task_ref.yml", func(t *testing.T, pkg *Pkg) {
actual := pkg.Summary().Tasks
require.Len(t, actual, 1)

expectedEnvRefs := []SummaryReference{
{
Field: "metadata.name",
EnvRefKey: "meta-name",
DefaultValue: "env-meta-name",
},
{
Field: "spec.name",
EnvRefKey: "spec-name",
DefaultValue: "env-spec-name",
},
}
assert.Equal(t, expectedEnvRefs, actual[0].EnvReferences)
})
})

t.Run("handles bad config", func(t *testing.T) {
tests := []struct {
kind Kind
Expand Down
14 changes: 14 additions & 0 deletions pkger/testdata/task_ref.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: influxdata.com/v2alpha1
kind: Task
metadata:
name:
envRef:
key: meta-name
spec:
name:
envRef:
key: spec-name
every: 10m
offset: 15s
query: >
from(bucket: "rucket_1")

0 comments on commit b4e1ea7

Please sign in to comment.