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 stacks with update functionality #18560

Merged
merged 1 commit into from
Jun 17, 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 @@ -7,6 +7,7 @@
1. [18539](https://github.com/influxdata/influxdb/pull/18539): Collect stats on installed influxdata community template usage.
1. [18541](https://github.com/influxdata/influxdb/pull/18541): Pkger allow raw github.com host URLs for yaml|json|jsonnet URLs
1. [18546](https://github.com/influxdata/influxdb/pull/18546): Influx allow for files to be remotes for all template commands
1. [18560](https://github.com/influxdata/influxdb/pull/18560): Extend stacks API with update capability

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

Expand Down
8 changes: 8 additions & 0 deletions cmd/influx/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ func (f *fakePkgSVC) ExportStack(ctx context.Context, orgID, stackID influxdb.ID
panic("not implemented")
}

func (f *fakePkgSVC) ReadStack(ctx context.Context, id influxdb.ID) (pkger.Stack, error) {
panic("not implemented")
}

func (f *fakePkgSVC) UpdateStack(ctx context.Context, upd pkger.StackUpdate) (pkger.Stack, error) {
panic("not implemented")
}

func (f *fakePkgSVC) CreatePkg(ctx context.Context, setters ...pkger.CreatePkgSetFn) (*pkger.Pkg, error) {
if f.createFn != nil {
return f.createFn(ctx, setters...)
Expand Down
73 changes: 70 additions & 3 deletions cmd/influxd/launcher/pkger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ func TestLauncher_Pkger(t *testing.T) {
newStack, err := svc.InitStack(ctx, l.User.ID, stack)
require.NoError(t, err)

assert.NotZero(t, newStack.OrgID)
assert.Equal(t, l.Org.ID, newStack.OrgID)
assert.Equal(t, stack.Name, newStack.Name)
assert.Equal(t, stack.Description, newStack.Description)
assert.Equal(t, stack.URLs, newStack.URLs)
assert.NotNil(t, newStack.Resources)
assert.NotNil(t, newStack.Resources, "failed to match stack resorces")
expectedURLs := stack.URLs
if expectedURLs == nil {
expectedURLs = []string{}
}
assert.Equal(t, expectedURLs, newStack.URLs, "failed to match stack URLs")
assert.NotZero(t, newStack.CRUDLog)

return newStack, func() {
Expand Down Expand Up @@ -371,6 +375,65 @@ func TestLauncher_Pkger(t *testing.T) {
})
})

t.Run("read a stack", func(t *testing.T) {
stacks, err := svc.ListStacks(ctx, l.Org.ID, pkger.ListFilter{})
require.NoError(t, err)
require.Empty(t, stacks)

newStack1, cleanup1 := newStackFn(t, pkger.Stack{
Name: "first stack",
})
defer cleanup1()

newStack2, cleanup2 := newStackFn(t, pkger.Stack{
Name: "second stack",
})
defer cleanup2()

actual, err := svc.ReadStack(ctx, newStack1.ID)
require.NoError(t, err)
assert.Equal(t, newStack1, actual)

actual, err = svc.ReadStack(ctx, newStack2.ID)
require.NoError(t, err)
assert.Equal(t, newStack2, actual)

_, err = svc.ReadStack(ctx, influxdb.ID(9000))
require.Equal(t, influxdb.ENotFound, influxdb.ErrorCode(err))
})

t.Run("updating a stack", func(t *testing.T) {
stack, cleanup := newStackFn(t, pkger.Stack{
OrgID: l.Org.ID,
Name: "first name",
Description: "first desc",
URLs: []string{},
})
defer cleanup()

assertStack := func(t *testing.T, st pkger.Stack) {
t.Helper()
assert.Equal(t, stack.ID, st.ID)
assert.Equal(t, "2nd name", st.Name)
assert.Equal(t, "2nd desc", st.Description)
assert.Equal(t, []string{"http://example.com"}, st.URLs)
assert.True(t, st.UpdatedAt.After(stack.UpdatedAt))
}

updStack, err := svc.UpdateStack(ctx, pkger.StackUpdate{
ID: stack.ID,
Name: strPtr("2nd name"),
Description: strPtr("2nd desc"),
URLs: []string{"http://example.com"},
})
require.NoError(t, err)
assertStack(t, updStack)

readStack, err := svc.ReadStack(ctx, stack.ID)
require.NoError(t, err)
assertStack(t, readStack)
})

t.Run("apply with only a stackID succeeds when stack has URLs", func(t *testing.T) {
svr := httptest.NewServer(nethttp.HandlerFunc(func(w nethttp.ResponseWriter, r *nethttp.Request) {
pkg := newPkg(newBucketObject("bucket-0", "", ""))
Expand Down Expand Up @@ -3664,3 +3727,7 @@ func sortLabels(labels []pkger.SummaryLabel) {
return labels[i].Name < labels[j].Name
})
}

func strPtr(s string) *string {
return &s
}
191 changes: 120 additions & 71 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4725,52 +4725,7 @@ paths:
stacks:
type: array
items:
type: object
properties:
id:
type: string
orgID:
type: string
name:
type: string
description:
type: string
sources:
type: array
items:
type: string
urls:
type: array
items:
type: string
createdAt:
type: string
format: date-time
readOnly: true
updatedAt:
type: string
format: date-time
readOnly: true
resources:
type: object
properties:
apiVersion:
type: string
resourceID:
type: string
kind:
type: string
pkgName:
type: string
associations:
type: array
items:
type: object
properties:
kind:
type: string
pkgName:
type: string
$ref: "#/components/schemas/Stack"
default:
description: Unexpected error
content:
Expand All @@ -4781,9 +4736,9 @@ paths:
operationId: CreateStack
tags:
- InfluxPackages
summary: Create a new Influx package
summary: Create a new stack
requestBody:
description: Influx package to create.
description: Influx stack to create.
required: true
content:
application/json:
Expand All @@ -4806,35 +4761,80 @@ paths:
content:
application/json:
schema:
type: object
properties:
id:
type: string
orgID:
type: string
name:
type: string
description:
type: string
urls:
type: array
items:
type: string
createdAt:
type: string
format: date-time
readOnly: true
updatedAt:
type: string
format: date-time
readOnly: true
$ref: "#/components/schemas/Stack"
default:
description: Unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/packages/stacks/{stack_id}:
get:
operationId: ReadStack
tags:
- InfluxPackages
summary: Grab a stack by its ID
parameters:
- in: path
name: stack_id
required: true
schema:
type: string
description: The stack id
responses:
"200":
description: Read an influx stack by ID
content:
application/json:
schema:
$ref: "#/components/schemas/Stack"
default:
description: Unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
patch:
operationId: UpdateStack
tags:
- InfluxPackages
summary: Update a an Influx Stack
parameters:
- in: path
name: stack_id
required: true
schema:
type: string
description: The stack id
requestBody:
description: Influx stack to update.
required: true
content:
application/json:
schema:
type: object
properties:
name:
type: string
description:
type: string
urls:
type: array
items:
type: string
responses:
"200":
description: Influx stack updated
content:
application/json:
schema:
$ref: "#/components/schemas/Stack"
default:
description: Unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
delete:
operationId: DeleteStack
tags:
Expand All @@ -4846,7 +4846,7 @@ paths:
required: true
schema:
type: string
description: The stack id to be removed
description: The stack id
- in: query
name: orgID
required: true
Expand Down Expand Up @@ -8395,6 +8395,55 @@ components:
type: integer
properties: # field name is properties
$ref: "#/components/schemas/ViewProperties"
Stack:
type: object
properties:
id:
type: string
orgID:
type: string
name:
type: string
description:
type: string
sources:
type: array
items:
type: string
resources:
type: array
items:
type: object
properties:
apiVersion:
type: string
resourceID:
type: string
kind:
type: string
pkgName:
type: string
associations:
type: array
items:
type: object
properties:
kind:
type: string
pkgName:
type: string
urls:
type: array
items:
type: string
createdAt:
type: string
format: date-time
readOnly: true
updatedAt:
type: string
format: date-time
readOnly: true
Runs:
type: object
properties:
Expand Down
Loading