Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add api_version to codersdk.ProvisionerDaemon
  • Loading branch information
johnstcn committed Jan 2, 2024
commit 2b272118c5ccbe57e15d1ef3a6aded2a27745399
3 changes: 3 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ func (api *API) CreateInMemoryProvisionerDaemon(ctx context.Context, name string
Tags: provisionersdk.MutateTags(uuid.Nil, nil),
LastSeenAt: sql.NullTime{Time: dbtime.Now(), Valid: true},
Version: buildinfo.Version(),
APIVersion: "1.0",
APIVersion: provisionersdk.APIVersionCurrent,
})
if err != nil {
return nil, xerrors.Errorf("failed to create in-memory provisioner daemon: %w", err)
Expand Down
1 change: 1 addition & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -7279,6 +7279,7 @@ func (q *FakeQuerier) UpsertProvisionerDaemon(_ context.Context, arg database.Up
ReplicaID: uuid.NullUUID{},
LastSeenAt: arg.LastSeenAt,
Version: arg.Version,
APIVersion: arg.APIVersion,
}
q.provisionerDaemons = append(q.provisionerDaemons, d)
return d, nil
Expand Down
8 changes: 4 additions & 4 deletions coderd/database/dbpurge/dbpurge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func TestDeleteOldProvisionerDaemons(t *testing.T) {
CreatedAt: now.Add(-14 * 24 * time.Hour),
LastSeenAt: sql.NullTime{Valid: true, Time: now.Add(-7 * 24 * time.Hour).Add(time.Minute)},
Version: "1.0.0",
APIVersion: "1.0",
APIVersion: provisionersdk.APIVersionCurrent,
})
require.NoError(t, err)
_, err = db.UpsertProvisionerDaemon(ctx, database.UpsertProvisionerDaemonParams{
Expand All @@ -229,7 +229,7 @@ func TestDeleteOldProvisionerDaemons(t *testing.T) {
CreatedAt: now.Add(-8 * 24 * time.Hour),
LastSeenAt: sql.NullTime{Valid: true, Time: now.Add(-8 * 24 * time.Hour).Add(time.Hour)},
Version: "1.0.0",
APIVersion: "1.0",
APIVersion: provisionersdk.APIVersionCurrent,
})
require.NoError(t, err)
_, err = db.UpsertProvisionerDaemon(ctx, database.UpsertProvisionerDaemonParams{
Expand All @@ -242,7 +242,7 @@ func TestDeleteOldProvisionerDaemons(t *testing.T) {
},
CreatedAt: now.Add(-9 * 24 * time.Hour),
Version: "1.0.0",
APIVersion: "1.0",
APIVersion: provisionersdk.APIVersionCurrent,
})
require.NoError(t, err)
_, err = db.UpsertProvisionerDaemon(ctx, database.UpsertProvisionerDaemonParams{
Expand All @@ -256,7 +256,7 @@ func TestDeleteOldProvisionerDaemons(t *testing.T) {
CreatedAt: now.Add(-6 * 24 * time.Hour),
LastSeenAt: sql.NullTime{Valid: true, Time: now.Add(-6 * 24 * time.Hour)},
Version: "1.0.0",
APIVersion: "1.0",
APIVersion: provisionersdk.APIVersionCurrent,
})
require.NoError(t, err)

Expand Down
5 changes: 3 additions & 2 deletions coderd/provisionerdserver/provisionerdserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"golang.org/x/oauth2"

"cdr.dev/slog/sloggers/slogtest"
"github.com/coder/coder/v2/buildinfo"
"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/coderd/audit"
"github.com/coder/coder/v2/coderd/database"
Expand Down Expand Up @@ -1784,8 +1785,8 @@ func setup(t *testing.T, ignoreLogErrors bool, ov *overrides) (proto.DRPCProvisi
Provisioners: []database.ProvisionerType{database.ProvisionerTypeEcho},
Tags: database.StringMap{},
LastSeenAt: sql.NullTime{},
Version: "",
APIVersion: "1.0",
Version: buildinfo.Version(),
APIVersion: provisionersdk.APIVersionCurrent,
})
require.NoError(t, err)

Expand Down
1 change: 1 addition & 0 deletions codersdk/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ProvisionerDaemon struct {
LastSeenAt NullTime `json:"last_seen_at,omitempty" format:"date-time"`
Name string `json:"name"`
Version string `json:"version"`
APIVersion string `json:"api_version"`
Provisioners []ProvisionerType `json:"provisioners"`
Tags map[string]string `json:"tags"`
}
Expand Down
2 changes: 2 additions & 0 deletions docs/api/enterprise.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/api/schemas.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions enterprise/cli/provisionerdaemons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestProvisionerDaemon_PSK(t *testing.T) {
require.Equal(t, "matt-daemon", daemons[0].Name)
require.Equal(t, provisionersdk.ScopeOrganization, daemons[0].Tags[provisionersdk.TagScope])
require.Equal(t, buildinfo.Version(), daemons[0].Version)
require.Equal(t, "1.0", daemons[0].APIVersion)
require.Equal(t, provisionersdk.APIVersionCurrent, daemons[0].APIVersion)
}

func TestProvisionerDaemon_SessionToken(t *testing.T) {
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) {
assert.Equal(t, provisionersdk.ScopeUser, daemons[0].Tags[provisionersdk.TagScope])
assert.Equal(t, anotherUser.ID.String(), daemons[0].Tags[provisionersdk.TagOwner])
assert.Equal(t, buildinfo.Version(), daemons[0].Version)
assert.Equal(t, "1.0", daemons[0].APIVersion)
assert.Equal(t, provisionersdk.APIVersionCurrent, daemons[0].APIVersion)
})

t.Run("ScopeAnotherUser", func(t *testing.T) {
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) {
// This should get clobbered to the user who started the daemon.
assert.Equal(t, anotherUser.ID.String(), daemons[0].Tags[provisionersdk.TagOwner])
assert.Equal(t, buildinfo.Version(), daemons[0].Version)
assert.Equal(t, "1.0", daemons[0].APIVersion)
assert.Equal(t, provisionersdk.APIVersionCurrent, daemons[0].APIVersion)
})

t.Run("ScopeOrg", func(t *testing.T) {
Expand Down Expand Up @@ -158,6 +158,6 @@ func TestProvisionerDaemon_SessionToken(t *testing.T) {
assert.Equal(t, "org-daemon", daemons[0].Name)
assert.Equal(t, provisionersdk.ScopeOrganization, daemons[0].Tags[provisionersdk.TagScope])
assert.Equal(t, buildinfo.Version(), daemons[0].Version)
assert.Equal(t, "1.0", daemons[0].APIVersion)
assert.Equal(t, provisionersdk.APIVersionCurrent, daemons[0].APIVersion)
})
}
3 changes: 2 additions & 1 deletion enterprise/coderd/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (api *API) provisionerDaemonServe(rw http.ResponseWriter, r *http.Request)
CreatedAt: now,
LastSeenAt: sql.NullTime{Time: now, Valid: true},
Version: versionHdrVal,
APIVersion: "1.0",
APIVersion: provisionersdk.APIVersionCurrent,
})
if err != nil {
if !xerrors.Is(err, context.Canceled) {
Expand Down Expand Up @@ -363,6 +363,7 @@ func convertProvisionerDaemon(daemon database.ProvisionerDaemon) codersdk.Provis
Name: daemon.Name,
Tags: daemon.Tags,
Version: daemon.Version,
APIVersion: daemon.APIVersion,
}
for _, provisionerType := range daemon.Provisioners {
result.Provisioners = append(result.Provisioners, codersdk.ProvisionerType(provisionerType))
Expand Down
6 changes: 3 additions & 3 deletions enterprise/coderd/provisionerdaemons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func TestProvisionerDaemonServe(t *testing.T) {
daemons, err := client.ProvisionerDaemons(ctx) //nolint:gocritic // Test assertion.
require.NoError(t, err)
if assert.Len(t, daemons, 1) {
assert.Equal(t, daemons[0].Name, daemonName)
assert.Equal(t, daemons[0].Version, buildinfo.Version())
assert.Equal(t, daemons[0].APIVersion, "1.0")
assert.Equal(t, daemonName, daemons[0].Name)
assert.Equal(t, buildinfo.Version(), daemons[0].Version)
assert.Equal(t, provisionersdk.APIVersionCurrent, daemons[0].APIVersion)
}
})

Expand Down
7 changes: 7 additions & 0 deletions provisionersdk/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import (
"github.com/coder/coder/v2/provisionersdk/proto"
)

const (
// APIVersionCurrent is the current provisionerd API version.
// Breaking changes to the provisionerd API **MUST** increment
// the major version below.
APIVersionCurrent = "1.0"
)

// ServeOptions are configurations to serve a provisioner.
type ServeOptions struct {
// Listener serves multiple connections. Cannot be combined with Conn.
Expand Down
2 changes: 2 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const provisioners: TypesGen.ProvisionerDaemon[] = [
provisioners: [],
tags: {},
version: "v2.34.5",
api_version: "1.0",
},
{
id: "cdr-basic",
Expand All @@ -87,6 +88,7 @@ export const provisioners: TypesGen.ProvisionerDaemon[] = [
provisioners: [],
tags: {},
version: "v2.34.5",
api_version: "1.0",
},
];

Expand Down
1 change: 1 addition & 0 deletions site/src/api/typesGenerated.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export const MockProvisioner: TypesGen.ProvisionerDaemon = {
provisioners: ["echo"],
tags: { scope: "organization" },
version: "v2.34.5",
api_version: "1.0",
};

export const MockUserProvisioner: TypesGen.ProvisionerDaemon = {
Expand All @@ -345,6 +346,7 @@ export const MockUserProvisioner: TypesGen.ProvisionerDaemon = {
provisioners: ["echo"],
tags: { scope: "user", owner: "12345678-abcd-1234-abcd-1234567890abcd" },
version: "v2.34.5",
api_version: "1.0",
};

export const MockProvisionerJob: TypesGen.ProvisionerJob = {
Expand Down