Skip to content

Commit

Permalink
feat(pkger): extend public apply API with new action to skip resource…
Browse files Browse the repository at this point in the history
…s by kind

closes: #18490
  • Loading branch information
jsteenb2 committed Jun 18, 2020
1 parent d1f9807 commit db8c4fd
Show file tree
Hide file tree
Showing 4 changed files with 195 additions and 99 deletions.
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

0 comments on commit db8c4fd

Please sign in to comment.