Skip to content

Commit c2b0989

Browse files
parauliyagauravgahlot
andauthoredMay 9, 2020
Merge hardware and target. (tinkerbell#88)
* Merged hardware and target. Now while creating a workflow you can directly provide hardware/devices mac addr. And now there is no need of targets. * using hello-world as the first example Signed-off-by: Gaurav Gahlot <[email protected]> * fixes Signed-off-by: Gaurav Gahlot <[email protected]> * moved comments out of data JSON Signed-off-by: Gaurav Gahlot <[email protected]> * Changed the way of writing template and creating workflow * Updating the docs with current implementation * Incorporated some minor review comments Co-authored-by: Gaurav Gahlot <[email protected]>
1 parent 01f2e19 commit c2b0989

31 files changed

+123
-1446
lines changed
 

‎cli/tink/cmd/target.go

-26
This file was deleted.

‎cli/tink/cmd/target/commands.go

-59
This file was deleted.

‎cli/tink/cmd/target/create.go

-35
This file was deleted.

‎cli/tink/cmd/target/delete.go

-32
This file was deleted.

‎cli/tink/cmd/target/get.go

-34
This file was deleted.

‎cli/tink/cmd/target/list.go

-58
This file was deleted.

‎cli/tink/cmd/target/update.go

-59
This file was deleted.

‎cli/tink/cmd/workflow/create.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212

1313
var (
1414
fTemplate = "template"
15-
fTarget = "target"
15+
fHardware = "hardware"
1616
template string
17-
target string
17+
hardware string
1818
)
1919

2020
// createCmd represents the create subcommand for worflow command
@@ -25,11 +25,6 @@ var createCmd = &cobra.Command{
2525
PreRunE: func(c *cobra.Command, args []string) error {
2626
tmp, _ := c.Flags().GetString(fTemplate)
2727
err := validateID(tmp)
28-
if err != nil {
29-
return err
30-
}
31-
tar, _ := c.Flags().GetString(fTarget)
32-
err = validateID(tar)
3328
return err
3429
},
3530
Run: func(c *cobra.Command, args []string) {
@@ -40,14 +35,14 @@ var createCmd = &cobra.Command{
4035
func addFlags() {
4136
flags := createCmd.PersistentFlags()
4237
flags.StringVarP(&template, "template", "t", "", "workflow template")
43-
flags.StringVarP(&target, "target", "r", "", "workflow target")
38+
flags.StringVarP(&hardware, "hardware", "r", "", "workflow targeted hardwares")
4439

45-
createCmd.MarkPersistentFlagRequired(fTarget)
40+
createCmd.MarkPersistentFlagRequired(fHardware)
4641
createCmd.MarkPersistentFlagRequired(fTemplate)
4742
}
4843

4944
func createWorkflow(c *cobra.Command, args []string) {
50-
req := workflow.CreateRequest{Template: template, Target: target}
45+
req := workflow.CreateRequest{Template: template, Target: hardware}
5146
res, err := client.WorkflowClient.CreateWorkflow(context.Background(), &req)
5247
if err != nil {
5348
log.Fatal(err)

‎client/main.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ import (
77
"net/http"
88
"os"
99

10+
"github.com/pkg/errors"
1011
"github.com/tinkerbell/tink/protos/hardware"
11-
"github.com/tinkerbell/tink/protos/target"
1212
"github.com/tinkerbell/tink/protos/template"
1313
"github.com/tinkerbell/tink/protos/workflow"
14-
"github.com/pkg/errors"
1514
"google.golang.org/grpc"
1615
"google.golang.org/grpc/credentials"
1716
)
1817

1918
// gRPC clients
2019
var (
2120
TemplateClient template.TemplateClient
22-
TargetClient target.TargetClient
2321
WorkflowClient workflow.WorkflowSvcClient
2422
HardwareClient hardware.HardwareServiceClient
2523
)
@@ -66,15 +64,14 @@ func Setup() {
6664
log.Fatal(err)
6765
}
6866
TemplateClient = template.NewTemplateClient(conn)
69-
TargetClient = target.NewTargetClient(conn)
7067
WorkflowClient = workflow.NewWorkflowSvcClient(conn)
7168
HardwareClient = hardware.NewHardwareServiceClient(conn)
7269
}
7370

7471
func NewTinkerbellClient() (hardware.HardwareServiceClient, error) {
7572
conn, err := GetConnection()
76-
if err != nil {
77-
log.Fatal(err)
78-
}
73+
if err != nil {
74+
log.Fatal(err)
75+
}
7976
return hardware.NewHardwareServiceClient(conn), nil
8077
}

‎db/target.go

-117
This file was deleted.

‎db/workflow.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import (
1414
"github.com/docker/distribution/reference"
1515
"github.com/golang/protobuf/ptypes"
1616
"github.com/golang/protobuf/ptypes/timestamp"
17-
pb "github.com/tinkerbell/tink/protos/workflow"
1817
"github.com/pkg/errors"
1918
uuid "github.com/satori/go.uuid"
19+
pb "github.com/tinkerbell/tink/protos/workflow"
2020
"gopkg.in/yaml.v2"
2121
)
2222

@@ -91,13 +91,13 @@ func CreateWorkflow(ctx context.Context, db *sql.DB, wf Workflow, data string, i
9191
func insertInWorkflow(ctx context.Context, db *sql.DB, wf Workflow, tx *sql.Tx) error {
9292
_, err := tx.Exec(`
9393
INSERT INTO
94-
workflow (created_at, updated_at, template, target, id)
94+
workflow (created_at, updated_at, template, devices, id)
9595
VALUES
9696
($1, $1, $2, $3, $4)
9797
ON CONFLICT (id)
9898
DO
9999
UPDATE SET
100-
(updated_at, deleted_at, template, target) = ($1, NULL, $2, $3);
100+
(updated_at, deleted_at, template, devices) = ($1, NULL, $2, $3);
101101
`, time.Now(), wf.Template, wf.Target, wf.ID)
102102
if err != nil {
103103
return errors.Wrap(err, "INSERT in to workflow")
@@ -378,7 +378,7 @@ func GetfromWfWorkflowTable(ctx context.Context, db *sql.DB, id string) ([]strin
378378
// GetWorkflow returns a workflow
379379
func GetWorkflow(ctx context.Context, db *sql.DB, id string) (Workflow, error) {
380380
query := `
381-
SELECT template, target
381+
SELECT template, devices
382382
FROM workflow
383383
WHERE
384384
id = $1
@@ -448,7 +448,7 @@ func DeleteWorkflow(ctx context.Context, db *sql.DB, id string, state int32) err
448448
// ListWorkflows returns all workflows
449449
func ListWorkflows(db *sql.DB, fn func(wf Workflow) error) error {
450450
rows, err := db.Query(`
451-
SELECT id, template, target, created_at, updated_at
451+
SELECT id, template, devices, created_at, updated_at
452452
FROM workflow
453453
WHERE
454454
deleted_at IS NULL;
@@ -510,15 +510,15 @@ func UpdateWorkflow(ctx context.Context, db *sql.DB, wf Workflow, state int32) e
510510
_, err = tx.Exec(`
511511
UPDATE workflow
512512
SET
513-
updated_at = NOW(), target = $2
513+
updated_at = NOW(), devices = $2
514514
WHERE
515515
id = $1;
516516
`, wf.ID, wf.Target)
517517
} else {
518518
_, err = tx.Exec(`
519519
UPDATE workflow
520520
SET
521-
updated_at = NOW(), template = $2, target = $3
521+
updated_at = NOW(), template = $2, devices = $3
522522
WHERE
523523
id = $1;
524524
`, wf.ID, wf.Template, wf.Target)

‎deploy/db/docker-entrypoint-initdb.d/tinkerbell-init.sql

+2-13
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,10 @@ CREATE TABLE IF NOT EXISTS template (
2525
CREATE INDEX IF NOT EXISTS idx_tid ON template (id);
2626
CREATE INDEX IF NOT EXISTS idx_tdeleted_at ON template (deleted_at NULLS FIRST);
2727

28-
CREATE TABLE IF NOT EXISTS targets (
29-
id UUID UNIQUE
30-
, inserted_at TIMESTAMPTZ
31-
, deleted_at TIMESTAMPTZ
32-
, data JSONB
33-
);
34-
35-
CREATE INDEX IF NOT EXISTS idx_rid ON targets (id);
36-
CREATE INDEX IF NOT EXISTS idx_rdeleted_at ON targets (deleted_at NULLS FIRST);
37-
CREATE INDEX IF NOT EXISTS idxgin_rtype ON targets USING GIN (data JSONB_PATH_OPS);
38-
3928
CREATE TABLE IF NOT EXISTS workflow (
4029
id UUID UNIQUE NOT NULL
4130
, template UUID NOT NULL
42-
, target UUID NOT NULL
31+
, devices JSONB NOT NULL
4332
, created_at TIMESTAMPTZ
4433
, updated_at TIMESTAMPTZ
4534
, deleted_at TIMESTAMPTZ
@@ -84,4 +73,4 @@ CREATE TABLE IF NOT EXISTS workflow_data (
8473
, version INT
8574
, metadata JSONB
8675
, data JSONB
87-
);
76+
);

‎docs/cli/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ Command line interface for Packet Workflow.
66

77
### Synopsis
88

9-
Command line interface for Packet Workflow. The CLI allows you to update the hardware details with respect to a worker machine. It also enables you to create a template and a target which is eventually used to create a workflow.
9+
Command line interface for Packet Workflow. The CLI allows you to update the hardware details with respect to a worker machine. It also enables you to create a template which is eventually used to create a workflow.
1010

1111
### Operations
1212

1313
```shell
1414
hardware tink hardware client
1515
help Help about any command
16-
target tink target client
1716
template tink template client
1817
workflow tink workflow client
1918
```
@@ -27,7 +26,6 @@ Command line interface for Packet Workflow. The CLI allows you to update the har
2726
### See Also
2827

2928
- [tink hardware](hardware.md) - Hardware (worker) data operations
30-
- [tink target](target.md) - Target operations
3129
- [tink template](template.md) - Template operations
3230
- [tink workflow](workflow.md) - Workflow operations
3331

‎docs/cli/hardware.md

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Hardware operations:
2323

2424
### See Also
2525

26-
- [tink target](target.md) - Target operations
2726
- [tink template](template.md) - Template operations
2827
- [tink workflow](workflow.md) - Workflow operations
2928

‎docs/cli/target.md

-34
This file was deleted.

‎docs/cli/template.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Template operations:
1616
### Options
1717

1818
```
19-
-h, --help help for target
19+
-h, --help help for template
2020
```
2121

2222
### Examples
@@ -47,6 +47,5 @@ Template operations:
4747
### See Also
4848

4949
- [tink hardware](hardware.md) - Hardware (worker) data operations
50-
- [tink target](target.md) - Target operations
5150
- [tink workflow](workflow.md) - Workflow operations
5251

‎docs/cli/workflow.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,22 @@ Workflow operations:
1818
### Options
1919

2020
```
21-
-h, --help help for target
21+
-h, --help help for workflow
2222
```
2323

2424
### Examples
2525

26-
- Create a workflow using a template and a target
26+
- Create a workflow using a template and hardware devices
2727
```shell
28-
$ tink workflow create -t <template-uuid> -r <target-uuid>
29-
$ tink workflow create -t edb80a56-b1f2-4502-abf9-17326324192b -r 9356ae1d-6165-4890-908d-7860ed04b421
28+
$ tink workflow create -t <template-uuid> -r <hardware_input_in_json_format>
29+
$ tink workflow create -t edb80a56-b1f2-4502-abf9-17326324192b -r {"device_1": "mac/IP"}
3030
```
31+
#### Note:
32+
1. The key used in the above command which is "device_1" should be in sync with "worker" field in the template. Click [here](../concepts.md) to check the template structure.
33+
2. These keys can only contain letter, numbers and underscore.
3134

3235
### See Also
3336

34-
- [tink hardware](hardware.md) - Hardware (worker) data operations
35-
- [tink target](target.md) - Target operations
37+
- [tink hardware](hardware.md) - Hardware (worker) data operations
3638
- [tink template](template.md) - Template operations
3739

‎docs/components.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Installs operating systems and handles deprovisioning.
1010

1111
### Tinkerbell
1212

13-
Service responsible for processing workflows. It is comprised of a server and a CLI, which communicate over gRPC. The CLI is used to create a workflow along with its building blocks, i.e., a template and a target.
13+
Service responsible for processing workflows. It is comprised of a server and a CLI, which communicate over gRPC. The CLI is used to create a workflow along with its building blocks, i.e., a template hardware devices.
1414

1515
### Hegel
1616

‎docs/concepts.md

+5-25
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Concepts
22

3+
### Hardware
4+
A *hardware device* is defined separately and is substituted in a template at the time of creating a workflow.
5+
36
### Template
47

5-
A template is a Go template based definition that defines the overall flow of a workflow. A user must write a template based on a valid template format. Template can consist of custom variable which can be substituted before execution. For example, a target is defined separately and is substituted in a template at the time of creating a workflow.
8+
A template is a Go template based definition that defines the overall flow of a workflow. A user must write a template based on a valid template format. Template can consist of custom variable which can be substituted before execution. For example, a hardware device is defined separately and is substituted in a template at the time of creating a workflow.
69

710
A template is stored as a blob in the database and is parsed later during the creation of a worflow. A user can CRUD a template using the CLI (`tink template`). Here is a sample workflow template:
811

@@ -12,7 +15,7 @@ name: ubuntu_provisioning
1215
global_timeout: 6000
1316
tasks:
1417
- name: "os-installation"
15-
worker: "{{index .Targets "machine1" "mac_addr"}}"
18+
worker: "{{.device_1}}"
1619
volumes:
1720
- /dev:/dev
1821
- /dev/console:/dev/console
@@ -45,28 +48,6 @@ A template comprises Tasks, which are executed in a sequential manner. A task ca
4548
It is important to note that an action can also have its own volumes and environment variables. Therefore, any entry at an action will overwrite the value defined at the task level. For example, in the above template the `MIRROR_HOST` environment variable defined at action `disk-partition` will overwrite the value defined at task level. However, the other actions will receive the original value defined at the task level.
4649

4750

48-
### Targets
49-
50-
Targets are mapping between the virtual worker name and the actual host. Currently we are refer targets with MAC or IP address. Here is a sample target definition:
51-
52-
```json
53-
{
54-
"machine1": {
55-
"ip_addr": "192.168.1.2"
56-
},
57-
"machine2" : {
58-
"mac_addr": "ca:00:64:b8:2d:00"
59-
}
60-
}
61-
```
62-
63-
A target can be accessed in template like (refer above template):
64-
65-
```
66-
{{ index .Targets "machine1" "ip_addr"}}
67-
{{ index .Targets "machine2" "mac_addr"}}
68-
```
69-
7051
### Provisioner
7152

7253
The provisioner machine is the main driver for executing a workflow. A provisioner houses the following components:
@@ -104,4 +85,3 @@ The other worker may retrieve and use this data and eventually add some more:
10485
```
10586
![](img/ephemeral-data.png)
10687

107-

‎docs/examples/hello-world.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: hello_world_workflow
33
global_timeout: 600
44
tasks:
55
- name: "hello world"
6-
worker: "{{index .Targets "machine1" "mac_addr"}}"
6+
worker: "{{.device_1}}"
77
actions:
88
- name: "hello_world"
99
image: hello-world

‎docs/hello-world.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,14 @@ $ docker push <registry-host>/hello-world
6767
### Workflow
6868

6969
We can now define a workflow with the following steps:
70-
- Create a target:
71-
```shell
72-
$ tink target create '{"targets": {"machine1": {"mac_addr": "<worker-mac-address>"}}}'
73-
```
7470
- Create a template:
7571
```shell
7672
# get the template from examples/hello-world.tmpl and save it
7773
$ tink template create -n hello-world -p hello-world.tmpl
7874
```
7975
- Create a workflow:
8076
```shell
81-
$ tink workflow create -t <template-uuid> -r <target-uuid>
77+
$ tink workflow create -t <template-uuid> -r '{"device_1":"mac/IP"}'
8278
```
8379
- Reboot the worker machine
8480

‎docs/writing-workflow.md

+17-28
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
# Writing a [Workflow](concepts.md#workflow)
22

3-
Any workflow comprises two building blocks: target and template.
3+
Any workflow comprises two building blocks: worker (targeted hardware) and a template.
44

5-
### Creating a [target](concepts.md#target)
5+
### Creating a [worker](concepts.md#worker)
66

7-
A target is referred with MAC or IP address. Here is a sample target definition using the MAC address:
8-
9-
```json
10-
{
11-
"machine1" : {
12-
"mac_addr": "98:03:9b:4b:c5:34"
13-
}
14-
}
15-
```
16-
17-
The command below creates a workflow target and returns its UUID:
7+
A worker is targeted hardware on which workflow needs to run.
8+
User need to push the hardware details as per the below command:
189
```shell
19-
$ tink target create '{"targets": {"machine1": {"mac_addr": "98:03:9b:4b:c5:34"}}}'
10+
$ tink hardware push "<targeted hardware data in json format>"
2011
```
21-
22-
2312
### Creating a [template](concepts.md#template)
2413

2514
Consider a sample template like the following saved as `/tmp/sample.tmpl`.
@@ -30,18 +19,18 @@ name: ubuntu_provisioning
3019
global_timeout: 2500
3120
tasks:
3221
- name: "os-installation"
33-
worker: "{{index .Targets "machine1" "mac_addr"}}"
22+
worker: "{{.device_1}}"
3423
volumes:
3524
- /dev:/dev
3625
- /lib/firmware:/lib/firmware:ro
3726
environment:
38-
MIRROR_HOST: 192.168.1.2
27+
MIRROR_HOST: <MIRROR_HOST_IP>
3928
actions:
4029
- name: "disk-partition"
4130
image: disk-partition
4231
timeout: 600
4332
environment:
44-
MIRROR_HOST: 192.168.1.3
33+
MIRROR_HOST: <MIRROR_HOST_IP>
4534
volumes:
4635
- /statedir:/statedir
4736
- name: "install-root-fs"
@@ -61,11 +50,11 @@ Key points:
6150
- An action cannot have space (` `) in its name.
6251
- Environment variables and volumes at action level overwrites the values for duplicate keys defined at task level.
6352

64-
A target can be accessed in a template like:
53+
A worker can be accessed in a template like:
6554

6655
```
67-
{{ index .Targets "machine1" "ip_addr"}}
68-
{{ index .Targets "machine2" "mac_addr"}}
56+
{{.device_1}}
57+
{{.device_2}}
6958
```
7059

7160
The following command creates a workflow template and returns a UUID:
@@ -76,17 +65,17 @@ The following command creates a workflow template and returns a UUID:
7665

7766
### Creating a [workflow](concepts.md#workflow)
7867

79-
We can create a workflow using the above created (or existing) template and target.
68+
We can create a workflow using the above created (or existing) template and worker.
8069
```shell
81-
$ tink workflow create -t <template-uuid> -r <target-uuid>
82-
$ tink workflow create -t edb80a56-b1f2-4502-abf9-17326324192b -r 9356ae1d-6165-4890-908d-7860ed04b421
70+
$ tink workflow create -t <template-uuid> -r '{worker machines in json format}'
71+
$ tink workflow create -t edb80a56-b1f2-4502-abf9-17326324192b -r '{"device_1":"mac/IP"}'
8372
```
8473

8574
The above command returns a UUID for the workflow thus created. The workflow ID can be used for getting further details about a workflow. Please refer the [Tinkerbell CLI reference](cli/workflow.md) for the same.
8675

87-
It's a good practice to verify that the targets have been well substituted in the template. In order to do so, use the following command:
76+
It's a good practice to verify that the worker have been well substituted in the template. In order to do so, use the following command:
8877
```yaml
89-
$ tink workflow get edb80a56-b1f2-4502-abf9-17326324192b
78+
$ tink workflow get <workflow Id returned from the above command>
9079
9180
version: '0.1'
9281
name: ubuntu_provisioning
@@ -117,5 +106,5 @@ tasks:
117106
- /statedir:/statedir
118107
```
119108

120-
Notice how `worker` is set to the MAC address we had defined in the target.
109+
Notice how `worker` is set to the MAC address we had defined in the input while creating a workflow.
121110

‎go.mod

+1-34
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,23 @@ module github.com/tinkerbell/tink
33
go 1.13
44

55
require (
6-
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
7-
github.com/Microsoft/go-winio v0.4.14 // indirect
8-
github.com/containerd/containerd v1.3.2 // indirect
96
github.com/docker/distribution v2.7.1+incompatible
107
github.com/docker/docker v1.4.2-0.20191212201129-5f9f41018e9d
11-
github.com/docker/go-connections v0.4.0 // indirect
12-
github.com/docker/go-units v0.4.0 // indirect
13-
github.com/fsnotify/fsnotify v1.4.7 // indirect
14-
github.com/go-openapi/strfmt v0.19.3 // indirect
15-
github.com/gogo/protobuf v1.2.0 // indirect
168
github.com/golang/protobuf v1.3.5
17-
github.com/google/go-cmp v0.3.1 // indirect
18-
github.com/gorilla/context v1.1.1 // indirect
19-
github.com/gorilla/mux v1.6.2 // indirect
20-
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 // indirect
219
github.com/grpc-ecosystem/go-grpc-prometheus v0.0.0-20160910222444-6b7015e65d36
22-
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce // indirect
23-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
2410
github.com/jedib0t/go-pretty v4.3.0+incompatible
25-
github.com/kr/pretty v0.2.0 // indirect
2611
github.com/lib/pq v1.2.1-0.20191011153232-f91d3411e481
27-
github.com/magiconair/properties v1.8.0 // indirect
28-
github.com/mattn/go-runewidth v0.0.5 // indirect
29-
github.com/morikuni/aec v1.0.0 // indirect
30-
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
31-
github.com/opencontainers/image-spec v1.0.1 // indirect
3212
github.com/packethost/pkg v0.0.0-20190410153520-e8e15f4ce770
33-
github.com/pelletier/go-toml v1.2.0 // indirect
13+
github.com/packethost/tinkerbell v0.0.0-20200326045848-98d7d0594340
3414
github.com/pkg/errors v0.8.1
3515
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829
36-
github.com/rollbar/rollbar-go v1.0.2 // indirect
3716
github.com/satori/go.uuid v1.2.0
3817
github.com/sirupsen/logrus v1.4.1
39-
github.com/spf13/afero v1.1.1 // indirect
40-
github.com/spf13/cast v1.2.0 // indirect
4118
github.com/spf13/cobra v0.0.3
42-
github.com/spf13/jwalterweatherman v0.0.0-20180109140146-7c0cea34c8ec // indirect
43-
github.com/spf13/pflag v1.0.1 // indirect
4419
github.com/spf13/viper v1.0.2
45-
go.mongodb.org/mongo-driver v1.1.2 // indirect
46-
go.uber.org/atomic v1.2.0 // indirect
47-
go.uber.org/multierr v1.1.0 // indirect
48-
go.uber.org/zap v1.7.1 // indirect
4920
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
5021
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d // indirect
51-
golang.org/x/text v0.3.2 // indirect
52-
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
5322
google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940 // indirect
5423
google.golang.org/grpc v1.28.0
55-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
5624
gopkg.in/yaml.v2 v2.2.2
57-
gotest.tools v2.2.0+incompatible // indirect
5825
)

‎go.sum

+52
Large diffs are not rendered by default.

‎grpc-server/grpc-server.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ import (
1313

1414
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
1515
"github.com/packethost/pkg/log"
16+
"github.com/pkg/errors"
1617
"github.com/tinkerbell/tink/db"
1718
"github.com/tinkerbell/tink/metrics"
1819
"github.com/tinkerbell/tink/protos/hardware"
19-
"github.com/tinkerbell/tink/protos/target"
2020
"github.com/tinkerbell/tink/protos/template"
2121
"github.com/tinkerbell/tink/protos/workflow"
22-
"github.com/pkg/errors"
2322
"google.golang.org/grpc"
2423
"google.golang.org/grpc/credentials"
2524
)
@@ -70,7 +69,6 @@ func SetupGRPC(ctx context.Context, log log.Logger, facility string, errCh chan<
7069
// register servers
7170
s := grpc.NewServer(params...)
7271
template.RegisterTemplateServer(s, server)
73-
target.RegisterTargetServer(s, server)
7472
workflow.RegisterWorkflowSvcServer(s, server)
7573
hardware.RegisterHardwareServiceServer(s, server)
7674

‎grpc-server/target.go

-147
This file was deleted.

‎grpc-server/workflow.go

+15-20
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import (
55
"context"
66
"database/sql"
77
"encoding/json"
8+
"fmt"
89
"text/template"
910

11+
"github.com/pkg/errors"
12+
"github.com/prometheus/client_golang/prometheus"
13+
uuid "github.com/satori/go.uuid"
1014
"github.com/tinkerbell/tink/db"
1115
"github.com/tinkerbell/tink/metrics"
1216
"github.com/tinkerbell/tink/protos/workflow"
1317
workflowpb "github.com/tinkerbell/tink/protos/workflow"
14-
"github.com/pkg/errors"
15-
"github.com/prometheus/client_golang/prometheus"
16-
uuid "github.com/satori/go.uuid"
1718
)
1819

1920
var state = map[int32]workflow.State{
@@ -262,40 +263,34 @@ func (s *server) ShowWorkflowEvents(req *workflow.GetRequest, stream workflow.Wo
262263
return nil
263264
}
264265

265-
func createYaml(ctx context.Context, sqlDB *sql.DB, temp string, tar string) (string, error) {
266+
func createYaml(ctx context.Context, sqlDB *sql.DB, temp string, devices string) (string, error) {
266267
tempData, err := db.GetTemplate(ctx, sqlDB, temp)
267268
if err != nil {
268269
return "", err
269270
}
270-
tarData, err := db.TargetsByID(ctx, sqlDB, tar)
271-
if err != nil {
272-
return "", err
273-
}
274-
return renderTemplate(string(tempData), []byte(tarData))
271+
return renderTemplate(string(tempData), []byte(devices))
275272
}
276273

277-
func renderTemplate(tempData string, tarData []byte) (string, error) {
278-
type machine map[string]string
279-
type Environment struct {
280-
Targets map[string]machine `json:"targets"`
281-
}
282-
283-
var env Environment
284-
t := template.New("workflow-template")
285-
_, err := t.Parse(tempData)
274+
func renderTemplate(tempData string, devices []byte) (string, error) {
275+
var hardware map[string]interface{}
276+
err := json.Unmarshal(devices, &hardware)
286277
if err != nil {
287278
logger.Error(err)
288279
return "", nil
289280
}
290-
err = json.Unmarshal(tarData, &env)
281+
282+
t := template.New("workflow-template")
283+
_, err = t.Parse(string(tempData))
291284
if err != nil {
292285
logger.Error(err)
293286
return "", nil
294287
}
288+
295289
buf := new(bytes.Buffer)
296-
err = t.Execute(buf, env)
290+
err = t.Execute(buf, hardware)
297291
if err != nil {
298292
return "", nil
299293
}
294+
fmt.Println(buf.String())
300295
return buf.String(), nil
301296
}

‎protos/target/target.pb.go

-596
This file was deleted.

‎protos/target/target.proto

-42
This file was deleted.

‎test/framework/target.go

-35
This file was deleted.

‎test/framework/utils.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ var Log = logger
1212

1313
// SetupWorkflow ... Set up workflow
1414
func SetupWorkflow(tar string, tmpl string) (string, error) {
15-
//Add target machine mac/ip addr into targets table
16-
targetID, err := CreateTargets(tar)
17-
if err != nil {
18-
return "", err
19-
}
20-
logger.Infoln("Target Created : ", targetID)
15+
targetID := "c9d6faa4-08a2-4285-ae6c-f3401211bd56"
2116
//Add template in template table
2217
templateID, err := CreateTemplate(tmpl)
2318
if err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.