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

Fix errors from lint-install run. #74

Merged
merged 1 commit into from
Aug 30, 2021
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ run:
sudo ~/go/bin/linuxkit run qemu --mem 2048 out/hook-${ARCH}

dev-bootkitBuild:
cd bootkit; docker buildx build -load -t $(ORG)/hook-bootkit:0.0 .
cd bootkit; docker buildx build --load -t $(ORG)/hook-bootkit:0.0 .

bootkitBuild:
cd bootkit; docker buildx build --platform linux/amd64,linux/arm64 --push -t $(ORG)/hook-bootkit:0.0 .

dev-tink-dockerBuild:
cd tink-docker; docker buildx build -load -t $(ORG)/hook-docker:0.0 .
cd tink-docker; docker buildx build --load -t $(ORG)/hook-docker:0.0 .

tink-dockerBuild:
cd tink-docker; docker buildx build --platform linux/amd64,linux/arm64 --push -t $(ORG)/hook-docker:0.0 .
Expand Down Expand Up @@ -145,4 +145,4 @@ out/linters/golangci-lint-$(GOLINT_VERSION):
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b out/linters $(GOLINT_VERSION)
mv out/linters/golangci-lint out/linters/golangci-lint-$(GOLINT_VERSION)

# END: lint-install ../hook
# END: lint-install ../hook
106 changes: 39 additions & 67 deletions bootkit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func main() {
panic(err)
}

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

// Get the ID from the metadata service
err = cfg.MetaDataQuery()
err = cfg.metaDataQuery()
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -131,7 +131,11 @@ func main() {
if err != nil {
panic(err)
}
io.Copy(os.Stdout, out)

_, err = io.Copy(os.Stdout, out)
if err != nil {
panic(err)
}

resp, err := cli.ContainerCreate(ctx, tinkContainer, tinkHostConfig, nil, nil, "")
if err != nil {
Expand All @@ -145,74 +149,42 @@ func main() {
fmt.Println(resp.ID)
}

func parsecmdline(cmdlines []string) (cfg tinkConfig, err error) {

for i := range cmdlines {
cmdline := strings.Split(cmdlines[i], "=")
if len(cmdline) != 0 {

// Find Registry configuration
if cmdline[0] == "docker_registry" {
cfg.registry = cmdline[1]
}
if cmdline[0] == "registry_username" {
cfg.username = cmdline[1]
}
if cmdline[0] == "registry_password" {
cfg.password = cmdline[1]
}

// Find Tinkerbell servers settings
if cmdline[0] == "packet_base_url" {
cfg.baseURL = cmdline[1]
}
if cmdline[0] == "tinkerbell" {
cfg.tinkerbell = cmdline[1]
}

// Find GRPC configuration
if cmdline[0] == "grpc_authority" {
cfg.grpcAuthority = cmdline[1]
}
if cmdline[0] == "grpc_cert_url" {
cfg.grpcCertURL = cmdline[1]
}

// Find the worker configuration
if cmdline[0] == "worker_id" {
cfg.workerID = cmdline[1]
}
// parseCmdLine will parse the command line.
func parseCmdLine(cmdLines []string) (cfg tinkConfig) {
for i := range cmdLines {
cmdLine := strings.Split(cmdLines[i], "=")
if len(cmdLine) == 0 {
continue
}
}
return
}

// DownloadFile will download a url to a local file. It's efficient because it will
// write as it downloads and not load the whole file into memory.
func DownloadFile(filepath string, url string) error {

// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

// Create the file
out, err := os.Create(filepath)
if err != nil {
return err
switch cmd := cmdLine[0]; cmd {
// Find Registry configuration
case "docker_registry":
cfg.registry = cmdLine[1]
case "registry_username":
cfg.username = cmdLine[1]
case "registry_password":
cfg.password = cmdLine[1]
// Find Tinkerbell servers settings
case "packet_base_url":
cfg.baseURL = cmdLine[1]
case "tinkerbell":
cfg.tinkerbell = cmdLine[1]
// Find GRPC configuration
case "grpc_authority":
cfg.grpcAuthority = cmdLine[1]
case "grpc_cert_url":
cfg.grpcCertURL = cmdLine[1]
// Find the worker configuration
case "worker_id":
cfg.workerID = cmdLine[1]
}
}
defer out.Close()

// Write the body to file
_, err = io.Copy(out, resp.Body)
return err
return cfg
}

// MetaDataQuery will query the metadata
func (cfg *tinkConfig) MetaDataQuery() error {

// 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?)
}
Expand Down
44 changes: 22 additions & 22 deletions tink-docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func main() {
fmt.Println("Starting Tink-Docker")
go rebootWatch()

// Parse the cmdline in order to find the urls for the repostiory and path to the cert
// Parse the cmdline in order to find the urls for the repository and path to the cert
content, err := ioutil.ReadFile("/proc/cmdline")
if err != nil {
panic(err)
}
cmdlines := strings.Split(string(content), " ")
cfg, _ := parsecmdline(cmdlines)
cmdLines := strings.Split(string(content), " ")
cfg := parseCmdLine(cmdLines)

path := fmt.Sprintf("/etc/docker/certs.d/%s/", cfg.registry)

Expand All @@ -39,7 +39,7 @@ func main() {
panic(err)
}
// Download the configuration
err = DownloadFile(path+"ca.crt", cfg.baseURL+"/ca.pem")
err = downloadFile(path+"ca.crt", cfg.baseURL+"/ca.pem")
if err != nil {
panic(err)
}
Expand All @@ -55,29 +55,30 @@ func main() {
}
}

func parsecmdline(cmdlines []string) (cfg tinkConfig, err error) {
// parseCmdLine will parse the command line.
func parseCmdLine(cmdLines []string) (cfg tinkConfig) {
for i := range cmdLines {
cmdLine := strings.Split(cmdLines[i], "=")
if len(cmdLine) == 0 {
continue
}

for i := range cmdlines {
cmdline := strings.Split(cmdlines[i], "=")
if len(cmdline) != 0 {
if cmdline[0] == "docker_registry" {
cfg.registry = cmdline[1]
}
if cmdline[0] == "packet_base_url" {
cfg.baseURL = cmdline[1]
}
if cmdline[0] == "tinkerbell" {
cfg.tinkerbell = cmdline[1]
}
switch cmd := cmdLine[0]; cmd {
// Find Registry configuration
case "docker_registry":
cfg.registry = cmdLine[1]
case "packet_base_url":
cfg.baseURL = cmdLine[1]
case "tinkerbell":
cfg.tinkerbell = cmdLine[1]
}
}
return
return cfg
}

// DownloadFile will download a url to a local file. It's efficient because it will
// downloadFile will download a url to a local file. It's efficient because it will
// write as it downloads and not load the whole file into memory.
func DownloadFile(filepath string, url string) error {

func downloadFile(filepath string, url string) error {
// Get the data
resp, err := http.Get(url)
if err != nil {
Expand All @@ -103,7 +104,6 @@ func rebootWatch() {
// Forever loop
for {
if fileExists("/worker/reboot") {
//Build the command, and execute
cmd := exec.Command("/sbin/reboot")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down