Skip to content

Commit

Permalink
Merge branch 'master' into upgrade/jsonpb-to-protojson
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav Gahlot authored Jul 9, 2021
2 parents 455d4a6 + 8ea8a0e commit e1de0c7
Show file tree
Hide file tree
Showing 29 changed files with 309 additions and 590 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ all: cli server worker ## Build all binaries for host OS and CPU

crosscompile: $(crossbinaries) ## Build all binaries for Linux and all supported CPU arches
images: tink-cli-image tink-server-image tink-worker-image ## Build all docker images
run: crosscompile run-stack ## Builds and runs the Tink stack (tink, db, cli) via docker-compose

test: ## Run tests
go clean -testcache
Expand Down
3 changes: 2 additions & 1 deletion cmd/tink-cli/cmd/hardware/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -84,7 +85,7 @@ func readDataFromStdin() string {
}

func readDataFromFile() string {
f, err := os.Open(file)
f, err := os.Open(filepath.Clean(file))
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/tink-cli/cmd/template/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/spf13/cobra"
"github.com/tinkerbell/tink/client"
Expand Down Expand Up @@ -39,7 +40,7 @@ $ tink template create --file /tmp/example.tmpl
if isInputFromPipe() {
reader = os.Stdin
} else {
f, err := os.Open(filePath)
f, err := os.Open(filepath.Clean(filePath))
if err != nil {
log.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/tink-worker/internal/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -261,7 +262,7 @@ func (w *Worker) ProcessWorkflowActions(ctx context.Context, workerID string, ca
os.Exit(1)
}

f.Close()
err = f.Close()
if err != nil {
l.Error(err)
os.Exit(1)
Expand Down Expand Up @@ -473,7 +474,7 @@ func sendUpdate(ctx context.Context, logger log.Logger, client pb.WorkflowServic
}

func openDataFile(wfDir string, l log.Logger) *os.File {
f, err := os.OpenFile(wfDir+string(os.PathSeparator)+dataFile, os.O_RDWR|os.O_CREATE, 0644)
f, err := os.OpenFile(filepath.Clean(wfDir+string(os.PathSeparator)+dataFile), os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
l.Error(err)
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions db/mock/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Template struct {
}

// CreateTemplate creates a new workflow template
func (d DB) CreateTemplate(ctx context.Context, name string, data string, id uuid.UUID) error {
func (d *DB) CreateTemplate(ctx context.Context, name string, data string, id uuid.UUID) error {
if d.TemplateDB == nil {
d.TemplateDB = make(map[string]interface{})
}
Expand Down Expand Up @@ -66,6 +66,6 @@ func (d DB) UpdateTemplate(ctx context.Context, name string, data string, id uui
}

// ClearTemplateDB clear all the templates
func (d DB) ClearTemplateDB() {
func (d *DB) ClearTemplateDB() {
d.TemplateDB = make(map[string]interface{})
}
69 changes: 69 additions & 0 deletions db/testdata/hardware_2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"metadata": {
"state": "provisioning",
"manufacturer": {},
"instance": {
"operating_system_version": {
"distro": "ubuntu",
"version": "18.04",
"os_slug": "ubuntu_18_04"
},
"crypted_root_password": "$6$xyz$/pdZy4hazXmqu1t0TACitLlKZPD4bFyRUw6ycXiOTdf4kcnkmpgmtg9zUpEE8rG9KtOWwX7kp1Gl96NCGbDk60",
"storage": {
"disks": [
{
"device": "/dev/sda",
"wipe_table": true,
"partitions": [
{ "label": "BIOS", "number": 1, "size": 4096 },
{ "label": "SWAP", "number": 2, "size": 3993600 },
{ "label": "ROOT", "number": 3, "size": 15993600 }
]
}
],
"filesystems": [
{
"mount": {
"device": "/dev/sda3",
"format": "ext4",
"create": { "options": ["-L", "ROOT"] },
"point": "/"
}
},
{
"mount": {
"device": "/dev/sda2",
"format": "swap",
"create": { "options": ["-L", "SWAP"] },
"point": "none"
}
}
]
}
},
"facility": { "plan_slug": "c2.medium.x86", "facility_code": "onprem" }
},
"network": {
"interfaces": [
{
"dhcp": {
"mac": "ae:fb:27:a1:c4:02",
"hostname": "server002",
"lease_time": 86400,
"arch": "x86_64",
"ip": {
"address": "192.168.1.6",
"netmask": "255.255.255.248",
"gateway": "192.168.1.1"
}
},
"netboot": {
"allow_pxe": true,
"allow_workflow": true,
"osie": { "kernel": "vmlinuz-x86_64" }
}
}
]
},
"id": "0eba0bf8-3772-4b4a-ab9f-6ebe93b90a96"
}
4 changes: 2 additions & 2 deletions db/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ func getWorkerIDbyIP(ctx context.Context, db *sql.DB, ip string) (string, error)
}

func getWorkerID(ctx context.Context, db *sql.DB, addr string) (string, error) {
_, err := net.ParseMAC(addr)
parsedMAC, err := net.ParseMAC(addr)
if err != nil {
ip := net.ParseIP(addr)
if ip == nil || ip.To4() == nil {
Expand All @@ -772,7 +772,7 @@ func getWorkerID(ctx context.Context, db *sql.DB, addr string) (string, error) {
return id, errors.WithMessage(err, "no worker found")

}
id, err := getWorkerIDbyMac(ctx, db, addr)
id, err := getWorkerIDbyMac(ctx, db, parsedMAC.String())
return id, errors.WithMessage(err, "no worker found")
}

Expand Down
27 changes: 27 additions & 0 deletions db/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ func TestCreateWorkflow(t *testing.T) {
}
},
},
{
Name: "create-single-workflow-with-upper-case-worker-address",
Input: &input{
workflowCount: 1,
devices: "{\"device_1\":\"AE:FB:27:a1:C4:02\"}",
hardware: readHardwareData("./testdata/hardware_2.json"),
template: func() *workflow.Workflow {
tmp := workflow.MustParseFromFile("./testdata/template_happy_path_1.yaml")
tmp.ID = uuid.New().String()
tmp.Name = fmt.Sprintf("id_%d", rand.Int())
return tmp
}(),
},
Expectation: func(t *testing.T, in *input, tinkDB *db.TinkDB) {
count := 0
err := tinkDB.ListWorkflows(func(wf db.Workflow) error {
count = count + 1
return nil
})
if err != nil {
t.Error(err)
}
if count != in.workflowCount {
t.Errorf("expected %d workflows stored in the database but we got %d", in.workflowCount, count)
}
},
},
{
Name: "create-fails-invalid-worker-address",
Input: &input{
Expand Down
78 changes: 0 additions & 78 deletions deploy/db/tinkerbell-init.sql

This file was deleted.

Loading

0 comments on commit e1de0c7

Please sign in to comment.