Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pkger): extend tasks with ability to define and rename it #17353

Merged
merged 2 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

1. [17232](https://github.com/influxdata/influxdb/pull/17232): Allow dashboards to optionally be displayed in light mode
1. [17273](https://github.com/influxdata/influxdb/pull/17273): Add shell completions command for the influx cli
1. [17353](https://github.com/influxdata/influxdb/pull/17353): Make all pkg resources unique by metadata.name field

### Bug Fixes

Expand Down
5 changes: 3 additions & 2 deletions cmd/influxd/launcher/pkger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ spec:
pkg, err := pkger.Parse(pkger.EncodingYAML, pkger.FromString(pkgStr))
require.NoError(t, err)

sum, _, err := svc.DryRun(context.Background(), l.Org.ID, l.User.ID, pkg, pkger.ApplyWithEnvRefs(map[string]string{
sum, _, err := svc.DryRun(timedCtx(2*time.Second), l.Org.ID, l.User.ID, pkg, pkger.ApplyWithEnvRefs(map[string]string{
"bkt-1-name-ref": "new-bkt-name",
"label-1-name-ref": "new-label-name",
}))
Expand Down Expand Up @@ -1167,8 +1167,9 @@ spec:
apiVersion: %[1]s
kind: Task
metadata:
name: task_1
name: task_UUID
spec:
name: task_1
description: desc_1
cron: 15 * * * *
query: >
Expand Down
20 changes: 4 additions & 16 deletions pkger/clone_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,21 +886,15 @@ func taskToObject(t influxdb.Task, name string) Object {

query := strings.TrimSpace(taskFluxRegex.ReplaceAllString(t.Flux, ""))

k := Object{
APIVersion: APIVersion,
Kind: KindTask,
Metadata: convertToMetadataResource(name),
Spec: Resource{
fieldQuery: strings.TrimSpace(query),
},
}
assignNonZeroStrings(k.Spec, map[string]string{
o := newObject(KindTask, name)
assignNonZeroStrings(o.Spec, map[string]string{
fieldTaskCron: t.Cron,
fieldDescription: t.Description,
fieldEvery: t.Every,
fieldOffset: durToStr(t.Offset),
fieldQuery: strings.TrimSpace(query),
})
return k
return o
}

func telegrafToObject(t influxdb.TelegrafConfig, name string) Object {
Expand Down Expand Up @@ -954,12 +948,6 @@ func VariableToObject(v influxdb.Variable, name string) Object {
return o
}

func convertToMetadataResource(name string) Resource {
return Resource{
fieldName: name,
}
}

func newObject(kind Kind, name string) Object {
return Object{
APIVersion: APIVersion,
Expand Down
160 changes: 46 additions & 114 deletions pkger/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,22 @@ type SummaryVariable struct {
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}

type identity struct {
name *references
displayName *references
}

func (i *identity) Name() string {
if displayName := i.displayName.String(); displayName != "" {
return displayName
}
return i.name.String()
}

func (i *identity) PkgName() string {
return i.name.String()
}

const (
fieldAPIVersion = "apiVersion"
fieldAssociations = "associations"
Expand Down Expand Up @@ -781,11 +797,11 @@ const (
const bucketNameMinLength = 2

type bucket struct {
identity

id influxdb.ID
OrgID influxdb.ID
Description string
name *references
displayName *references
RetentionRules retentionRules
labels sortedLabels

Expand All @@ -806,17 +822,6 @@ func (b *bucket) Labels() []*label {
return b.labels
}

func (b *bucket) Name() string {
if displayName := b.displayName.String(); displayName != "" {
return displayName
}
return b.name.String()
}

func (b *bucket) PkgName() string {
return b.name.String()
}

func (b *bucket) ResourceType() influxdb.ResourceType {
return KindBucket.ResourceType()
}
Expand Down Expand Up @@ -950,11 +955,11 @@ const (
const checkNameMinLength = 1

type check struct {
identity

id influxdb.ID
orgID influxdb.ID
kind checkKind
name *references
displayName *references
description string
every time.Duration
level string
Expand Down Expand Up @@ -988,17 +993,6 @@ func (c *check) Labels() []*label {
return c.labels
}

func (c *check) Name() string {
if displayName := c.displayName.String(); displayName != "" {
return displayName
}
return c.name.String()
}

func (c *check) PkgName() string {
return c.name.String()
}

func (c *check) ResourceType() influxdb.ResourceType {
return KindCheck.ResourceType()
}
Expand Down Expand Up @@ -1251,10 +1245,10 @@ const (
const labelNameMinLength = 2

type label struct {
identity

id influxdb.ID
OrgID influxdb.ID
name *references
displayName *references
Color string
Description string
associationMapping
Expand All @@ -1265,17 +1259,6 @@ type label struct {
existing *influxdb.Label
}

func (l *label) Name() string {
if displayName := l.displayName.String(); displayName != "" {
return displayName
}
return l.name.String()
}

func (l *label) PkgName() string {
return l.name.String()
}

func (l *label) ID() influxdb.ID {
if l.existing != nil {
return l.existing.ID
Expand Down Expand Up @@ -1398,11 +1381,11 @@ const (
)

type notificationEndpoint struct {
identity

kind notificationKind
id influxdb.ID
OrgID influxdb.ID
name *references
displayName *references
description string
method string
password *references
Expand Down Expand Up @@ -1433,17 +1416,6 @@ func (n *notificationEndpoint) Labels() []*label {
return n.labels
}

func (n *notificationEndpoint) Name() string {
if displayName := n.displayName.String(); displayName != "" {
return displayName
}
return n.name.String()
}

func (n *notificationEndpoint) PkgName() string {
return n.name.String()
}

func (n *notificationEndpoint) ResourceType() influxdb.ResourceType {
return KindNotificationEndpointSlack.ResourceType()
}
Expand Down Expand Up @@ -1616,10 +1588,10 @@ const (
)

type notificationRule struct {
id influxdb.ID
orgID influxdb.ID
name *references
displayName *references
identity

id influxdb.ID
orgID influxdb.ID

channel string
description string
Expand Down Expand Up @@ -1649,17 +1621,6 @@ func (r *notificationRule) Labels() []*label {
return r.labels
}

func (r *notificationRule) Name() string {
if displayName := r.displayName.String(); displayName != "" {
return displayName
}
return r.name.String()
}

func (r *notificationRule) PkgName() string {
return r.name.String()
}

func (r *notificationRule) ResourceType() influxdb.ResourceType {
return KindNotificationRule.ResourceType()
}
Expand Down Expand Up @@ -1871,9 +1832,10 @@ const (
)

type task struct {
identity

id influxdb.ID
orgID influxdb.ID
name *references
cron string
description string
every time.Duration
Expand All @@ -1896,10 +1858,6 @@ func (t *task) Labels() []*label {
return t.labels
}

func (t *task) Name() string {
return t.name.String()
}

func (t *task) ResourceType() influxdb.ResourceType {
return KindTask.ResourceType()
}
Expand All @@ -1914,7 +1872,7 @@ func (t *task) Status() influxdb.Status {
var fluxRegex = regexp.MustCompile(`import\s+\".*\"`)

func (t *task) flux() string {
taskOpts := []string{fmt.Sprintf("name: %q", t.name)}
taskOpts := []string{fmt.Sprintf("name: %q", t.Name())}
if t.cron != "" {
taskOpts = append(taskOpts, fmt.Sprintf("cron: %q", t.cron))
}
Expand Down Expand Up @@ -1987,7 +1945,14 @@ func (t *task) valid() []validationErr {
Msg: "must be 1 of [active, inactive]",
})
}
return vErrs

if len(vErrs) > 0 {
return []validationErr{
objectValidationErr(fieldSpec, vErrs...),
}
}

return nil
}

type mapperTasks []*task
Expand All @@ -2005,9 +1970,9 @@ const (
)

type telegraf struct {
name *references
displayName *references
config influxdb.TelegrafConfig
identity

config influxdb.TelegrafConfig

labels sortedLabels
}
Expand All @@ -2020,17 +1985,6 @@ func (t *telegraf) Labels() []*label {
return t.labels
}

func (t *telegraf) Name() string {
if displayName := t.displayName.String(); displayName != "" {
return displayName
}
return t.name.String()
}

func (t *telegraf) PkgName() string {
return t.name.String()
}

func (t *telegraf) ResourceType() influxdb.ResourceType {
return KindTelegraf.ResourceType()
}
Expand Down Expand Up @@ -2083,10 +2037,10 @@ const (
)

type variable struct {
identity

id influxdb.ID
OrgID influxdb.ID
name *references
displayName *references
Description string
Type string
Query string
Expand Down Expand Up @@ -2114,17 +2068,6 @@ func (v *variable) Labels() []*label {
return v.labels
}

func (v *variable) Name() string {
if displayName := v.displayName.String(); displayName != "" {
return displayName
}
return v.name.String()
}

func (v *variable) PkgName() string {
return v.name.String()
}

func (v *variable) ResourceType() influxdb.ResourceType {
return KindVariable.ResourceType()
}
Expand Down Expand Up @@ -2222,10 +2165,10 @@ const (
const dashboardNameMinLength = 2

type dashboard struct {
identity

id influxdb.ID
OrgID influxdb.ID
name *references
displayName *references
Description string
Charts []chart

Expand All @@ -2240,17 +2183,6 @@ func (d *dashboard) Labels() []*label {
return d.labels
}

func (d *dashboard) Name() string {
if displayName := d.displayName.String(); displayName != "" {
return displayName
}
return d.name.String()
}

func (d *dashboard) PkgName() string {
return d.name.String()
}

func (d *dashboard) ResourceType() influxdb.ResourceType {
return KindDashboard.ResourceType()
}
Expand Down
Loading