Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused metadata network call #149

Merged
merged 4 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
54 changes: 1 addition & 53 deletions hook-bootkit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path"
"strings"
Expand Down Expand Up @@ -37,9 +35,6 @@ type tinkConfig struct {
workerID string
ID string

// Metadata ID ... plus the other IDs :shrug:
MetadataID string `json:"id"`

// tinkWorkerImage is the Tink worker image location.
tinkWorkerImage string

Expand All @@ -55,20 +50,14 @@ func main() {
// // Read entire file content, giving us little control but
// // making it very simple. No need to close the file.

content, err := ioutil.ReadFile("/proc/cmdline")
content, err := os.ReadFile("/proc/cmdline")
if err != nil {
panic(err)
}

cmdLines := strings.Split(string(content), " ")
cfg := parseCmdLine(cmdLines)

// Get the ID from the metadata service
err = cfg.metaDataQuery()
if err != nil {
panic(err)
}

// Generate the path to the tink-worker
var imageName string
if cfg.registry != "" {
Expand All @@ -94,7 +83,6 @@ func main() {
fmt.Sprintf("TINKERBELL_TLS=%s", cfg.tinkServerTLS),
fmt.Sprintf("WORKER_ID=%s", cfg.workerID),
fmt.Sprintf("ID=%s", cfg.workerID),
fmt.Sprintf("container_uuid=%s", cfg.MetadataID),
},
AttachStdout: true,
AttachStderr: true,
Expand Down Expand Up @@ -220,43 +208,3 @@ func parseCmdLine(cmdLines []string) (cfg tinkConfig) {
}
return cfg
}

// metaDataQuery will query the metadata.
func (cfg *tinkConfig) metaDataQuery() error {
spaceClient := http.Client{
Timeout: time.Second * 60, // Timeout after 60 seconds (seems massively long is this dial-up?)
}

req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s:50061/metadata", cfg.tinkerbell), nil)
if err != nil {
return err
}

req.Header.Set("User-Agent", "bootkit")

res, getErr := spaceClient.Do(req)
if getErr != nil {
return err
}

if res.Body != nil {
defer res.Body.Close()
}

body, readErr := ioutil.ReadAll(res.Body)
if readErr != nil {
return err
}

var metadata struct {
ID string `json:"id"`
}

jsonErr := json.Unmarshal(body, &metadata)
if jsonErr != nil {
return err
}

cfg.MetadataID = metadata.ID
return err
}
5 changes: 2 additions & 3 deletions hook-docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
Expand Down Expand Up @@ -32,7 +31,7 @@ func main() {
go rebootWatch()

// Parse the cmdline in order to find the urls for the repository and path to the cert
content, err := ioutil.ReadFile("/proc/cmdline")
content, err := os.ReadFile("/proc/cmdline")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -80,7 +79,7 @@ func (d dockerConfig) writeToDisk(loc string) error {
if err != nil {
return fmt.Errorf("unable to marshal docker config: %w", err)
}
if err := ioutil.WriteFile(loc, b, 0o600); err != nil {
if err := os.WriteFile(loc, b, 0o600); err != nil {
return fmt.Errorf("error writing daemon.json: %w", err)
}

Expand Down
5 changes: 2 additions & 3 deletions hook-docker/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bytes"
"errors"
"io/ioutil"
"os"
"testing"
)
Expand All @@ -20,7 +19,7 @@ func TestWriteToDisk(t *testing.T) {
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
// Create a temporary directory
dir, err := ioutil.TempDir("", "hook-docker")
dir, err := os.MkdirTemp("", "hook-docker")
if err != nil {
t.Fatal(err)
}
Expand All @@ -33,7 +32,7 @@ func TestWriteToDisk(t *testing.T) {
}

if tt.wantErr == nil {
got, err := ioutil.ReadFile(loc)
got, err := os.ReadFile(loc)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion lint.mk
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ hadolint-lint: $(HADOLINT_BIN)
$(HADOLINT_BIN) --no-fail $(shell find . -name "*Dockerfile")

GOLANGCI_LINT_CONFIG := $(LINT_ROOT)/.golangci.yml
GOLANGCI_LINT_VERSION ?= v1.43.0
GOLANGCI_LINT_VERSION ?= v1.50.0
GOLANGCI_LINT_BIN := $(LINT_ROOT)/out/linters/golangci-lint-$(GOLANGCI_LINT_VERSION)-$(LINT_ARCH)
$(GOLANGCI_LINT_BIN):
mkdir -p $(LINT_ROOT)/out/linters
Expand Down
1 change: 0 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ in mkShell {
python3Packages.pip
python3Packages.setuptools
python3Packages.wheel
s3cmd
shfmt
util-linux
];
Expand Down