-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding preflight command to check deps
- Loading branch information
1 parent
3443dd2
commit 10bbfe1
Showing
3 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package nexnode | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"os" | ||
"os/exec" | ||
|
||
"github.com/fatih/color" | ||
|
||
_ "embed" | ||
) | ||
|
||
var ( | ||
requiredPlugins = [...]fileSpec{ | ||
{name: "/opt/cni/bin/host-local", description: "host-local CNI plugin"}, | ||
{name: "/opt/cni/bin/ptp", description: "ptp CNI plugin"}, | ||
{name: "/opt/cni/bin/tc-redirect-tap", description: "tc-redirect-tap CNI plugin"}, | ||
} | ||
) | ||
|
||
type fileSpec struct { | ||
name string | ||
description string | ||
} | ||
|
||
func CheckPreRequisites(config *NodeConfiguration) { | ||
cyan := color.New(color.FgCyan).SprintFunc() | ||
red := color.New(color.FgRed).SprintFunc() | ||
|
||
fmt.Printf("\nChecking for required files and dependencies...\n\n") | ||
for _, p := range requiredPlugins { | ||
if _, err := os.Stat(p.name); errors.Is(err, os.ErrNotExist) { | ||
fmt.Printf("⛔ %s was not found (%s)\n", p.description, red(p.name)) | ||
} else { | ||
fmt.Printf("✅ %s found (%s)\n", p.description, cyan(p.name)) | ||
} | ||
} | ||
|
||
cniConfig := fmt.Sprintf("/etc/cni/conf.d/%s.conflist", config.CNI.NetworkName) | ||
if _, err := os.Stat(cniConfig); errors.Is(err, os.ErrNotExist) { | ||
err = writeCniConf(cniConfig, config.CNI.NetworkName) | ||
if err != nil { | ||
fmt.Printf("⛔ CNI network configuration file not found (%s), Unable to write a default\n", red(cniConfig)) | ||
} else { | ||
fmt.Printf("✅ Created a default CNI configuration for %s (%s)\n", cyan(config.CNI.NetworkName), cyan(cniConfig)) | ||
} | ||
|
||
} else { | ||
fmt.Printf("✅ CNI network configuration file found (%s)\n", cyan(cniConfig)) | ||
} | ||
|
||
firecrackerBinary, err := exec.LookPath("firecracker") | ||
if err != nil { | ||
fmt.Println("⛔ Could not locate the 'firecracker' binary in path") | ||
} else { | ||
fmt.Printf("✅ Located the firecracker executable in path (%s)\n", cyan(firecrackerBinary)) | ||
} | ||
} | ||
|
||
func writeCniConf(fileName string, networkName string) error { | ||
f, err := os.Create(fileName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var fcConfig map[string]interface{} | ||
err = json.Unmarshal(defaultFcNetConf, &fcConfig) | ||
if err != nil { | ||
return err | ||
} | ||
fcConfig["name"] = networkName | ||
raw, _ := json.Marshal(fcConfig) | ||
|
||
_, err = f.Write(raw) | ||
if err != nil { | ||
return nil | ||
} | ||
f.Close() | ||
return nil | ||
} | ||
|
||
//go:embed templates/fcnet.conflist | ||
var defaultFcNetConf []byte |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "fcnet", | ||
"cniVersion": "0.4.0", | ||
"plugins": [ | ||
{ | ||
"type": "ptp", | ||
"ipMasq": true, | ||
"ipam": { | ||
"type": "host-local", | ||
"subnet": "192.168.127.0/24", | ||
"resolvConf": "/etc/resolv.conf" | ||
} | ||
}, | ||
{ | ||
"type": "tc-redirect-tap" | ||
} | ||
] | ||
} |