Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
micahhausler committed Dec 3, 2021
1 parent 56d3436 commit 463d8ab
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 181 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ run: crosscompile run-stack ## Builds and runs the Tink stack (tink, db, cli) vi

test: ## Run tests
go clean -testcache
go test ./... -v
go test -coverprofile=coverage.txt ./... -v

verify: lint check-generated # Verify code style, is lint free, freshness ...
gofumpt -s -d .
Expand Down
33 changes: 33 additions & 0 deletions pkg/conversion/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,41 @@ import (

"github.com/tinkerbell/tink/pkg/apis/core/v1alpha1"
protoworkflow "github.com/tinkerbell/tink/protos/workflow"
"github.com/tinkerbell/tink/workflow"
)

func WorkflowYamlToCRD(wf *workflow.Workflow, crd *v1alpha1.Workflow) {
if wf == nil || crd == nil {
return
}

tasks := []v1alpha1.Task{}
for _, task := range wf.Tasks {
actions := []v1alpha1.Action{}
for _, action := range task.Actions {
actions = append(actions, v1alpha1.Action{
Name: action.Name,
Image: action.Image,
Timeout: action.Timeout,
Command: action.Command,
Volumes: action.Volumes,
Status: protoworkflow.State_name[int32(protoworkflow.State_STATE_PENDING)],
Environment: action.Environment,
Pid: action.Pid,
})
}
tasks = append(tasks, v1alpha1.Task{
Name: task.Name,
WorkerAddr: task.WorkerAddr,
Volumes: task.Volumes,
Environment: task.Environment,
Actions: actions,
})
}
crd.Status.GlobalTimeout = int64(wf.GlobalTimeout)
crd.Status.Tasks = tasks
}

func WorkflowCRDToProto(w *v1alpha1.Workflow) *protoworkflow.Workflow {
if w == nil {
return nil
Expand Down
39 changes: 0 additions & 39 deletions pkg/conversion/workflow_pkg.go

This file was deleted.

141 changes: 0 additions & 141 deletions pkg/conversion/workflow_pkg_test.go

This file was deleted.

130 changes: 130 additions & 0 deletions pkg/conversion/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/tinkerbell/tink/pkg/apis/core/v1alpha1"
protoworkflow "github.com/tinkerbell/tink/protos/workflow"
"github.com/tinkerbell/tink/workflow"
)

func TestWorkflowCRDToProto(t *testing.T) {
Expand Down Expand Up @@ -303,3 +304,132 @@ func TestWorkflowProtoToCRD(t *testing.T) {
})
}
}

func TestWorkflowYamlToCRD(t *testing.T) {
cases := []struct {
name string
inputWf *workflow.Workflow
inputCrd *v1alpha1.Workflow
want *v1alpha1.Workflow
}{
{
"Nil workflow",
nil,
nil,
nil,
},
{
"Nil crd",
&workflow.Workflow{
Version: "1",
Name: "debian-provision",
ID: "0a90fac9-b509-4aa5-b294-5944128ece81",
GlobalTimeout: 600,
Tasks: []workflow.Task{
{
Name: "do-or-do-not-there-is-no-try",
WorkerAddr: "00:00:53:00:53:F4",
Actions: []workflow.Action{
{
Name: "stream-image-to-disk",
Image: "quay.io/tinkerbell-actions/image2disk:v1.0.0",
Timeout: 300,
Volumes: []string{
"/dev:/dev",
"/dev/console:/dev/console",
"/lib/firmware:/lib/firmware:ro",
"/tmp/debug:/tmp/debug",
},
Environment: map[string]string{
"COMPRESSED": "true",
"DEST_DISK": "/dev/nvme0n1",
"IMG_URL": "http://10.1.1.11:8080/debian-10-openstack-amd64.raw.gz",
},
Pid: "host",
},
},
},
},
},
nil,
nil,
},
{
"Full crd",
&workflow.Workflow{
Version: "1",
Name: "debian-provision",
ID: "0a90fac9-b509-4aa5-b294-5944128ece81",
GlobalTimeout: 600,
Tasks: []workflow.Task{
{
Name: "do-or-do-not-there-is-no-try",
WorkerAddr: "00:00:53:00:53:F4",
Actions: []workflow.Action{
{
Name: "stream-image-to-disk",
Image: "quay.io/tinkerbell-actions/image2disk:v1.0.0",
Timeout: 300,
Volumes: []string{
"/dev:/dev",
"/dev/console:/dev/console",
"/lib/firmware:/lib/firmware:ro",
"/tmp/debug:/tmp/debug",
},
Environment: map[string]string{
"COMPRESSED": "true",
"DEST_DISK": "/dev/nvme0n1",
"IMG_URL": "http://10.1.1.11:8080/debian-10-openstack-amd64.raw.gz",
},
Pid: "host",
},
},
},
},
},
&v1alpha1.Workflow{
Status: v1alpha1.WorkflowStatus{},
},
&v1alpha1.Workflow{
Status: v1alpha1.WorkflowStatus{
GlobalTimeout: 600,
Tasks: []v1alpha1.Task{
{
Name: "do-or-do-not-there-is-no-try",
WorkerAddr: "00:00:53:00:53:F4",
Actions: []v1alpha1.Action{
{
Name: "stream-image-to-disk",
Image: "quay.io/tinkerbell-actions/image2disk:v1.0.0",
Timeout: 300,
Volumes: []string{
"/dev:/dev",
"/dev/console:/dev/console",
"/lib/firmware:/lib/firmware:ro",
"/tmp/debug:/tmp/debug",
},
Pid: "host",
Environment: map[string]string{
"COMPRESSED": "true",
"DEST_DISK": "/dev/nvme0n1",
"IMG_URL": "http://10.1.1.11:8080/debian-10-openstack-amd64.raw.gz",
},
Status: "STATE_PENDING",
},
},
},
},
},
},
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
WorkflowYamlToCRD(tc.inputWf, tc.inputCrd)
if diff := cmp.Diff(tc.inputCrd, tc.want, protocmp.Transform()); diff != "" {
t.Errorf("unexpected difference:\n%v", diff)
}
})
}
}

0 comments on commit 463d8ab

Please sign in to comment.