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 public apply API with new action to skip resources by kind #18595

Merged
merged 1 commit into from
Jun 18, 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 @@ -10,6 +10,7 @@
1. [18560](https://github.com/influxdata/influxdb/pull/18560): Extend stacks API with update capability
1. [18568](https://github.com/influxdata/influxdb/pull/18568): Add support for config files to influxd and any cli.NewCommand use case
1. [18573](https://github.com/influxdata/influxdb/pull/18573): Extend influx stacks cmd with new influx stacks update cmd
1. [18595](https://github.com/influxdata/influxdb/pull/18595): Add ability to skip resources in a template by kind or by metadata.name

## v2.0.0-beta.12 [2020-06-12]

Expand Down
183 changes: 118 additions & 65 deletions cmd/influxd/launcher/pkger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1539,9 +1539,6 @@ func TestLauncher_Pkger(t *testing.T) {
})

t.Run("apply with actions", func(t *testing.T) {
stack, cleanup := newStackFn(t, pkger.Stack{})
defer cleanup()

var (
bucketPkgName = "rucketeer-1"
checkPkgName = "checkers"
Expand All @@ -1553,70 +1550,126 @@ func TestLauncher_Pkger(t *testing.T) {
telegrafPkgName = "teletype"
variablePkgName = "laces-out-dan"
)
pkg := newPkg(
newBucketObject(bucketPkgName, "", ""),
newCheckDeadmanObject(t, checkPkgName, "", time.Hour),
newDashObject(dashPkgName, "", ""),
newEndpointHTTP(endpointPkgName, "", ""),
newLabelObject(labelPkgName, "", "", ""),
newRuleObject(t, rulePkgName, "", endpointPkgName, ""),
newTaskObject(taskPkgName, "", ""),
newTelegrafObject(telegrafPkgName, "", ""),
newVariableObject(variablePkgName, "", ""),
)

impact, err := svc.Apply(ctx, l.Org.ID, l.User.ID,
pkger.ApplyWithPkg(pkg),
pkger.ApplyWithStackID(stack.ID),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindBucket,
MetaName: bucketPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindCheckDeadman,
MetaName: checkPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindDashboard,
MetaName: dashPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindNotificationEndpointHTTP,
MetaName: endpointPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindLabel,
MetaName: labelPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindNotificationRule,
MetaName: rulePkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindTask,
MetaName: taskPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindTelegraf,
MetaName: telegrafPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindVariable,
MetaName: variablePkgName,
}),
)
require.NoError(t, err)
tests := []struct {
name string
applyOpts []pkger.ApplyOptFn
}{
{
name: "skip resource",
applyOpts: []pkger.ApplyOptFn{
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindBucket,
MetaName: bucketPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindCheckDeadman,
MetaName: checkPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindDashboard,
MetaName: dashPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindNotificationEndpointHTTP,
MetaName: endpointPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindLabel,
MetaName: labelPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindNotificationRule,
MetaName: rulePkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindTask,
MetaName: taskPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindTelegraf,
MetaName: telegrafPkgName,
}),
pkger.ApplyWithResourceSkip(pkger.ActionSkipResource{
Kind: pkger.KindVariable,
MetaName: variablePkgName,
}),
},
},
{
name: "skip kind",
applyOpts: []pkger.ApplyOptFn{
pkger.ApplyWithKindSkip(pkger.ActionSkipKind{
Kind: pkger.KindBucket,
}),
pkger.ApplyWithKindSkip(pkger.ActionSkipKind{
Kind: pkger.KindCheckDeadman,
}),
pkger.ApplyWithKindSkip(pkger.ActionSkipKind{
Kind: pkger.KindDashboard,
}),
pkger.ApplyWithKindSkip(pkger.ActionSkipKind{
Kind: pkger.KindNotificationEndpointHTTP,
}),
pkger.ApplyWithKindSkip(pkger.ActionSkipKind{
Kind: pkger.KindLabel,
}),
pkger.ApplyWithKindSkip(pkger.ActionSkipKind{
Kind: pkger.KindNotificationRule,
}),
pkger.ApplyWithKindSkip(pkger.ActionSkipKind{
Kind: pkger.KindTask,
}),
pkger.ApplyWithKindSkip(pkger.ActionSkipKind{
Kind: pkger.KindTelegraf,
}),
pkger.ApplyWithKindSkip(pkger.ActionSkipKind{
Kind: pkger.KindVariable,
}),
},
},
}

for _, tt := range tests {
fn := func(t *testing.T) {
stack, cleanup := newStackFn(t, pkger.Stack{})
defer cleanup()

pkg := newPkg(
newBucketObject(bucketPkgName, "", ""),
newCheckDeadmanObject(t, checkPkgName, "", time.Hour),
newDashObject(dashPkgName, "", ""),
newEndpointHTTP(endpointPkgName, "", ""),
newLabelObject(labelPkgName, "", "", ""),
newRuleObject(t, rulePkgName, "", endpointPkgName, ""),
newTaskObject(taskPkgName, "", ""),
newTelegrafObject(telegrafPkgName, "", ""),
newVariableObject(variablePkgName, "", ""),
)

impact, err := svc.Apply(ctx, l.Org.ID, l.User.ID,
append(
tt.applyOpts,
pkger.ApplyWithPkg(pkg),
pkger.ApplyWithStackID(stack.ID),
)...,
)
require.NoError(t, err)

summary := impact.Summary
assert.Empty(t, summary.Buckets)
assert.Empty(t, summary.Checks)
assert.Empty(t, summary.Dashboards)
assert.Empty(t, summary.NotificationEndpoints)
assert.Empty(t, summary.Labels)
assert.Empty(t, summary.NotificationRules, 0)
assert.Empty(t, summary.Tasks)
assert.Empty(t, summary.TelegrafConfigs)
assert.Empty(t, summary.Variables)
summary := impact.Summary
assert.Empty(t, summary.Buckets)
assert.Empty(t, summary.Checks)
assert.Empty(t, summary.Dashboards)
assert.Empty(t, summary.NotificationEndpoints)
assert.Empty(t, summary.Labels)
assert.Empty(t, summary.NotificationRules, 0)
assert.Empty(t, summary.Tasks)
assert.Empty(t, summary.TelegrafConfigs)
assert.Empty(t, summary.Variables)
}

t.Run(tt.name, fn)
}
})

t.Run("exporting the existing state of stack resources to a pkg", func(t *testing.T) {
Expand Down
63 changes: 33 additions & 30 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7695,6 +7695,17 @@ components:
type: array
items:
oneOf:
- type: object
properties:
action:
type: string
enum: ["skipKind"]
properties:
type: object
properties:
kind:
$ref: "#/components/schemas/TemplateKind"
required: ["kind"]
- type: object
properties:
action:
Expand All @@ -7704,22 +7715,27 @@ components:
type: object
properties:
kind:
type: string
$ref: "#/components/schemas/TemplateKind"
resourceTemplateName:
type: string
required: ["kind", "resourceTemplateName"]
PkgCreateKind:
TemplateKind:
type: string
enum:
- bucket
- check
- dashboard
- label
- notification_endpoint
- notification_rule
- task
- telegraf
- variable
- Bucket
- Check
- CheckDeadman
- CheckThreshold
- Dashboard
- Label
- NotificationEndpoint
- NotificationEndpointHTTP
- NotificationEndpointPagerDuty
- NotificationEndpointSlack
- NotificationRule
- Task
- Telegraf
- Variable
PkgCreate:
type: object
properties:
Expand All @@ -7740,14 +7756,14 @@ components:
byResourceKind:
type: array
items:
$ref: "#/components/schemas/PkgCreateKind"
$ref: "#/components/schemas/TemplateKind"
resources:
type: object
properties:
id:
type: string
kind:
$ref: "#/components/schemas/PkgCreateKind"
$ref: "#/components/schemas/TemplateKind"
name:
type: string
required: [id, kind]
Expand All @@ -7759,20 +7775,7 @@ components:
apiVersion:
type: string
kind:
type: string
enum:
- Bucket
- CheckDeadman
- CheckThreshold
- Dashboard
- Label
- NotificationEndpointHTTP
- NotificationEndpointPagerDuty
- NotificationEndpointSlack
- NotificationRule
- Task
- Telegraf
- Variable
$ref: "#/components/schemas/TemplateKind"
meta:
type: object
properties:
Expand Down Expand Up @@ -8368,7 +8371,7 @@ components:
type: object
properties:
kind:
type: string
$ref: "#/components/schemas/TemplateKind"
reason:
type: string
fields:
Expand Down Expand Up @@ -8437,7 +8440,7 @@ components:
resourceID:
type: string
kind:
type: string
$ref: "#/components/schemas/TemplateKind"
pkgName:
type: string
associations:
Expand All @@ -8446,7 +8449,7 @@ components:
type: object
properties:
kind:
type: string
$ref: "#/components/schemas/TemplateKind"
pkgName:
type: string
urls:
Expand Down
10 changes: 10 additions & 0 deletions pkger/http_remote_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ func (s *HTTPRemoteService) apply(ctx context.Context, orgID influxdb.ID, dryRun
Properties: b,
})
}
for kind := range opt.KindsToSkip {
b, err := json.Marshal(ActionSkipKind{Kind: kind})
if err != nil {
return PkgImpactSummary{}, influxErr(influxdb.EInvalid, err)
}
reqBody.RawActions = append(reqBody.RawActions, ReqRawAction{
Action: string(ActionTypeSkipKind),
Properties: b,
})
}

var resp RespApplyPkg
err := s.Client.
Expand Down
Loading