Skip to content

Commit

Permalink
fix(cdsctl): worker model list - image field (#5267)
Browse files Browse the repository at this point in the history
  • Loading branch information
yesnault authored Jun 19, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 4b5bbf6 commit 11d37a6
Showing 5 changed files with 81 additions and 30 deletions.
55 changes: 54 additions & 1 deletion cli/cdsctl/worker_model.go
Original file line number Diff line number Diff line change
@@ -44,6 +44,53 @@ var workerModelListCmd = cli.Command{
},
}

type workerModelDisplay struct {
Name string `json:"name" cli:"name,key"`
Type string `json:"type" cli:"type"`
Disabled bool `json:"disabled" cli:"disabled"`
Restricted bool `json:"restricted" cli:"restricted"`
NeedRegistration bool `json:"need_registration" cli:"need_registration"`
NbSpawnErr int64 `json:"nb_spawn_err" cli:"nb_spawn_err"`
IsDeprecated bool `json:"is_deprecated" cli:"deprecated"`
IsOfficial bool `json:"is_official" cli:"official"`
Image string `json:"image" cli:"image"`
Flavor string `json:"flavor" cli:"flavor"`
}

func newWorkerModelDisplay(wm sdk.Model) workerModelDisplay {
name := wm.Name
if wm.Group != nil {
name = fmt.Sprintf("%s/%s", wm.Group.Name, wm.Name)
} else {
name = wm.Name
}

var image, flavor string

switch wm.Type {
case sdk.Docker:
image = wm.ModelDocker.Image
case sdk.Openstack, sdk.VSphere:
image = wm.ModelVirtualMachine.Image
flavor = wm.ModelVirtualMachine.Flavor
}

w := workerModelDisplay{
Name: name,
Type: wm.Type,
Disabled: wm.Disabled,
Restricted: wm.Restricted,
NeedRegistration: wm.NeedRegistration,
NbSpawnErr: wm.NbSpawnErr,
IsDeprecated: wm.IsDeprecated,
Image: image,
Flavor: flavor,
IsOfficial: wm.IsOfficial,
}

return w
}

func workerModelListRun(v cli.Values) (cli.ListResult, error) {
var err error
var workerModels []sdk.Model
@@ -63,7 +110,13 @@ func workerModelListRun(v cli.Values) (cli.ListResult, error) {
if err != nil {
return nil, err
}
return cli.AsListResult(workerModels), nil

wms := make([]workerModelDisplay, len(workerModels))
for i := range workerModels {
wms[i] = newWorkerModelDisplay(workerModels[i])
}

return cli.AsListResult(wms), nil
}

var workerModelImportCmd = cli.Command{
12 changes: 3 additions & 9 deletions engine/hatchery/swarm/swarm_util_create_test.go
Original file line number Diff line number Diff line change
@@ -149,9 +149,7 @@ func TestHatcherySwarm_createAndStartContainer(t *testing.T) {
// RegisterOnly = true, this will pull image if image is not found
spawnArgs := hatchery.SpawnArguments{
RegisterOnly: true,
Model: &sdk.Model{
Image: args.image,
},
Model: &sdk.Model{},
}
err := h.createAndStartContainer(context.TODO(), h.dockerClients["default"], args, spawnArgs)
require.NoError(t, err)
@@ -195,9 +193,7 @@ func TestHatcherySwarm_createAndStartContainerWithMount(t *testing.T) {

spawnArgs := hatchery.SpawnArguments{
RegisterOnly: false,
Model: &sdk.Model{
Image: args.image,
},
Model: &sdk.Model{},
}
err = h.createAndStartContainer(context.TODO(), h.dockerClients["default"], args, spawnArgs)
require.NoError(t, err)
@@ -230,9 +226,7 @@ func TestHatcherySwarm_createAndStartContainerWithNetwork(t *testing.T) {

spawnArgs := hatchery.SpawnArguments{
RegisterOnly: false,
Model: &sdk.Model{
Image: args.image,
},
Model: &sdk.Model{},
}
err = h.createAndStartContainer(context.TODO(), h.dockerClients["default"], args, spawnArgs)
require.NoError(t, err)
7 changes: 7 additions & 0 deletions engine/sql/208_worker_model.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- +migrate Up

ALTER TABLE "worker_model" DROP COLUMN IF EXISTS image;

-- +migrate Down

ALTER TABLE "worker_model" ADD COLUMN IF NOT EXISTS image TEXT;
36 changes: 17 additions & 19 deletions sdk/exportentities/worker_model.go
Original file line number Diff line number Diff line change
@@ -6,24 +6,23 @@ import (

// WorkerModel is the as code format of a worker model
type WorkerModel struct {
Name string `json:"name" yaml:"name"`
Group string `json:"group" yaml:"group"`
Communication string `json:"communication,omitempty" yaml:"communication,omitempty"`
Image string `json:"image" yaml:"image"`
Registry string `json:"registry,omitempty" yaml:"registry,omitempty"`
Username string `json:"username,omitempty" yaml:"username,omitempty"`
Password string `json:"password,omitempty" yaml:"password,omitempty"`
Description string `json:"description" yaml:"description"`
Type string `json:"type" yaml:"type"`
Flavor string `json:"flavor,omitempty" yaml:"flavor,omitempty"`
Envs map[string]string `json:"envs,omitempty" yaml:"envs,omitempty"`
PatternName string `json:"pattern_name,omitempty" yaml:"pattern_name,omitempty"`
Shell string `json:"shell,omitempty" yaml:"shell,omitempty"`
PreCmd string `json:"pre_cmd,omitempty" yaml:"pre_cmd,omitempty"`
Cmd string `json:"cmd,omitempty" yaml:"cmd,omitempty"`
PostCmd string `json:"post_cmd,omitempty" yaml:"post_cmd,omitempty"`
Restricted bool `json:"restricted,omitempty" yaml:"restricted,omitempty"`
IsDeprecated bool `json:"is_deprecated,omitempty" yaml:"is_deprecated,omitempty"`
Name string `json:"name" yaml:"name"`
Group string `json:"group" yaml:"group"`
Image string `json:"image" yaml:"image"`
Registry string `json:"registry,omitempty" yaml:"registry,omitempty"`
Username string `json:"username,omitempty" yaml:"username,omitempty"`
Password string `json:"password,omitempty" yaml:"password,omitempty"`
Description string `json:"description" yaml:"description"`
Type string `json:"type" yaml:"type"`
Flavor string `json:"flavor,omitempty" yaml:"flavor,omitempty"`
Envs map[string]string `json:"envs,omitempty" yaml:"envs,omitempty"`
PatternName string `json:"pattern_name,omitempty" yaml:"pattern_name,omitempty"`
Shell string `json:"shell,omitempty" yaml:"shell,omitempty"`
PreCmd string `json:"pre_cmd,omitempty" yaml:"pre_cmd,omitempty"`
Cmd string `json:"cmd,omitempty" yaml:"cmd,omitempty"`
PostCmd string `json:"post_cmd,omitempty" yaml:"post_cmd,omitempty"`
Restricted bool `json:"restricted,omitempty" yaml:"restricted,omitempty"`
IsDeprecated bool `json:"is_deprecated,omitempty" yaml:"is_deprecated,omitempty"`
}

type WorkerModelOption func(sdk.Model, *WorkerModel) error
@@ -53,7 +52,6 @@ func NewWorkerModel(wm sdk.Model, opts ...WorkerModelOption) WorkerModel {
IsDeprecated: wm.IsDeprecated,
Description: wm.Description,
Restricted: wm.Restricted,
Image: wm.Image,
}

switch wm.Type {
1 change: 0 additions & 1 deletion sdk/worker_model.go
Original file line number Diff line number Diff line change
@@ -42,7 +42,6 @@ type Model struct {
Name string `json:"name" db:"name" cli:"name,key"`
Description string `json:"description" db:"description" cli:"description"`
Type string `json:"type" db:"type" cli:"type"`
Image string `json:"image" db:"image" cli:"image"` // TODO: DELETE after migration done
Disabled bool `json:"disabled" db:"disabled" cli:"disabled"`
Restricted bool `json:"restricted" db:"restricted" cli:"restricted"`
RegisteredOS *string `json:"registered_os" db:"registered_os" cli:"-"`

0 comments on commit 11d37a6

Please sign in to comment.