Skip to content

Commit

Permalink
Refactor openevec to base actions on top of type and fix multiple con…
Browse files Browse the repository at this point in the history
…figs (#906)

To use the same semantic in openevec we should use the same base type.
Also we use novel changers to load config directly to be able to load config directly from openevec.

Signed-off-by: Petr Fedchenkov <giggsoff@gmail.com>
  • Loading branch information
giggsoff authored Oct 19, 2023
1 parent 2b66eae commit 44f8608
Show file tree
Hide file tree
Showing 48 changed files with 464 additions and 362 deletions.
30 changes: 26 additions & 4 deletions .github/workflows/eden_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: # yamllint disable-line rule:truthy
branches: [master]

jobs:
setup:
build:
runs-on: ubuntu-22.04
steps:
- name: setup
Expand All @@ -29,19 +29,41 @@ jobs:
run: |
make LINUXKIT_TARGET=build DOCKER_PLATFORM=linux/arm64 build-docker
make LINUXKIT_TARGET=build DOCKER_PLATFORM=linux/amd64 build-docker
- name: cleanup
setup:
runs-on: ubuntu-22.04
steps:
- name: setup
run: |
rm -fr ~/.linuxkit
docker system prune --all --force --volumes
sudo apt update
sudo apt install -y qemu-utils qemu-user-static qemu-system-x86 jq swtpm
- name: host info
run: |
ip a
- name: get eden
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: setup go
uses: actions/setup-go@v3
with:
go-version: '1.18'
- name: build eden
run: |
make clean
make build-tests
- name: run
run: |
# check separate (non-default) config
./eden config add setup
./eden config set setup --key=eve.accel --value=false
./eden --config setup setup
./eden --config setup start
./eden --config setup eve onboard
./eden --config setup info
./eden --config setup clean
./eden config add setup --arch=arm64
./eden --config setup setup
./eden --config setup clean
Expand Down
2 changes: 1 addition & 1 deletion cmd/adam.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func newStartAdamCmd(cfg *openevec.EdenSetupArgs) *cobra.Command {
Short: "start adam",
Long: `Start adam.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.AdamStart(cfg); err != nil {
if err := openEVEC.AdamStart(); err != nil {
log.Fatalf("Adam start failed: %s", err)
}
},
Expand Down
12 changes: 6 additions & 6 deletions cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func newDebugStartEveCmd(cfg *openevec.EdenSetupArgs) *cobra.Command {
if _, err := os.Stat(cfg.Eden.SSHKey); !os.IsNotExist(err) {
commandToRun := fmt.Sprintf("perf record %s -o %s", perfOptions, perfLocation)
commandToRun = fmt.Sprintf("sh -c 'nohup %s > /dev/null 2>&1 &'", commandToRun)
if err = openevec.SdnForwardSSHToEve(commandToRun, cfg); err != nil {
if err = openEVEC.SdnForwardSSHToEve(commandToRun); err != nil {
log.Fatal(err)
}
} else {
Expand Down Expand Up @@ -94,7 +94,7 @@ func newDebugStopEveCmd(cfg *openevec.EdenSetupArgs) *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
if _, err := os.Stat(eveSSHKey); !os.IsNotExist(err) {
commandToRun := "killall -SIGINT perf"
if err = openevec.SdnForwardSSHToEve(commandToRun, cfg); err != nil {
if err = openEVEC.SdnForwardSSHToEve(commandToRun); err != nil {
log.Fatal(err)
}
} else {
Expand Down Expand Up @@ -132,10 +132,10 @@ func newDebugSaveEveCmd(cfg *openevec.EdenSetupArgs) *cobra.Command {
tmpFile := fmt.Sprintf("%s.tmp", absPath)
if _, err := os.Stat(eveSSHKey); !os.IsNotExist(err) {
commandToRun := fmt.Sprintf("perf script -i %s > %s", perfLocation, defaults.DefaultPerfScriptEVELocation)
if err = openevec.SdnForwardSSHToEve(commandToRun, cfg); err != nil {
if err = openEVEC.SdnForwardSSHToEve(commandToRun); err != nil {
log.Fatal(err)
}
err = openevec.SdnForwardSCPFromEve(defaults.DefaultPerfScriptEVELocation, tmpFile, cfg)
err = openEVEC.SdnForwardSCPFromEve(defaults.DefaultPerfScriptEVELocation, tmpFile)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -189,10 +189,10 @@ func newDebugHardwareEveCmd(cfg *openevec.EdenSetupArgs) *cobra.Command {
commandToRun = "lshw -short"
}
commandToRun += ">" + hwLocation
if err = openevec.SdnForwardSSHToEve(commandToRun, cfg); err != nil {
if err = openEVEC.SdnForwardSSHToEve(commandToRun); err != nil {
log.Fatal(err)
}
if err = openevec.SdnForwardSCPFromEve(hwLocation, absPath, cfg); err != nil {
if err = openEVEC.SdnForwardSCPFromEve(hwLocation, absPath); err != nil {
log.Fatal(err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/disks.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func newDisksLayoutCmd() *cobra.Command {
Short: "Get disks layout",
Long: `Get disks layout`,
Run: func(cmd *cobra.Command, args []string) {
if layout, err := openevec.GetDisksLayout(); err != nil {
if layout, err := openEVEC.GetDisksLayout(); err != nil {
log.Fatal(err)
} else {
fmt.Println(layout)
Expand All @@ -54,7 +54,7 @@ func newSetDisksLayoutCmd() *cobra.Command {
Short: "Set disks layout",
Long: `Set disks layout`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.SetDiskLayout(dc); err != nil {
if err := openEVEC.SetDiskLayout(dc); err != nil {
log.Fatal(err)
}
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func newDownloadEVECmd(cfg *openevec.EdenSetupArgs) *cobra.Command {
Short: "download eve live image from docker",
Long: `Download eve live image from docker.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.DownloadEve(cfg); err != nil {
if err := openEVEC.DownloadEve(); err != nil {
log.Fatal(err)
}
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/edenClean.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func newCleanCmd(configName, verbosity *string) *cobra.Command {
Long: `Clean harness.`,
PersistentPreRunE: preRunViperLoadFunction(cfg, configName, verbosity),
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.EdenClean(*cfg, *configName, configDist, vmName, currentContext); err != nil {
if err := openEVEC.EdenClean(*configName, configDist, vmName, currentContext); err != nil {
log.Fatalf("Setup eden failed: %s", err)
}
},
Expand Down
24 changes: 12 additions & 12 deletions cmd/edenController.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newEdgeNodeReboot(controllerMode string) *cobra.Command {
Short: "reboot EVE instance",
Long: `reboot EVE instance.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.EdgeNodeReboot(controllerMode); err != nil {
if err := openEVEC.EdgeNodeReboot(controllerMode); err != nil {
log.Fatal(err)
}
},
Expand All @@ -73,7 +73,7 @@ func newEdgeNodeEVEImageUpdateRetry(controllerMode string) *cobra.Command {
Short: "retry update of EVE image",
Long: `Update EVE image retry.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.EdgeNodeEVEImageUpdateRetry(controllerMode); err != nil {
if err := openEVEC.EdgeNodeEVEImageUpdateRetry(controllerMode); err != nil {
log.Fatal(err)
}
},
Expand All @@ -87,7 +87,7 @@ func newEdgeNodeShutdown(controllerMode string) *cobra.Command {
Short: "shutdown EVE app instances",
Long: `shutdown EVE app instances.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.EdgeNodeShutdown(controllerMode); err != nil {
if err := openEVEC.EdgeNodeShutdown(controllerMode); err != nil {
log.Fatal(err)
}
},
Expand All @@ -107,7 +107,7 @@ func newEdgeNodeEVEImageUpdate(controllerMode string, cfg *openevec.EdenSetupArg
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
baseOSImage := args[0]
if err := openevec.EdgeNodeEVEImageUpdate(baseOSImage, baseOSVersion, registry, controllerMode, baseOSImageActivate, baseOSVDrive); err != nil {
if err := openEVEC.EdgeNodeEVEImageUpdate(baseOSImage, baseOSVersion, registry, controllerMode, baseOSImageActivate, baseOSVDrive); err != nil {
log.Fatal(err)
}
},
Expand All @@ -131,7 +131,7 @@ func newEdgeNodeEVEImageRemove(controllerMode string, cfg *openevec.EdenSetupArg
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
baseOSImage := args[0]
if err := openevec.EdgeNodeEVEImageRemove(controllerMode, baseOSVersion, baseOSImage, cfg.Eden.Dist); err != nil {
if err := openEVEC.EdgeNodeEVEImageRemove(controllerMode, baseOSVersion, baseOSImage, cfg.Eden.Dist); err != nil {
log.Fatal(err)
}
},
Expand All @@ -150,7 +150,7 @@ func newEdgeNodeUpdate(controllerMode string) *cobra.Command {
Short: "update EVE config",
Long: `Update EVE config.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.EdgeNodeUpdate(controllerMode, deviceItems, configItems); err != nil {
if err := openEVEC.EdgeNodeUpdate(controllerMode, deviceItems, configItems); err != nil {
log.Fatal(err)
}
},
Expand All @@ -174,7 +174,7 @@ func newEdgeNodeGetOptions(controllerMode string) *cobra.Command {
Short: "fetch EVE options",
Long: `Fetch EVE options.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.EdgeNodeGetOptions(controllerMode, fileWithConfig); err != nil {
if err := openEVEC.EdgeNodeGetOptions(controllerMode, fileWithConfig); err != nil {
log.Fatal(err)
}
},
Expand All @@ -193,7 +193,7 @@ func newEdgeNodeSetOptions(controllerMode string) *cobra.Command {
Short: "set EVE options",
Long: `Set EVE options.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.EdgeNodeSetOptions(controllerMode, fileWithConfig); err != nil {
if err := openEVEC.EdgeNodeSetOptions(controllerMode, fileWithConfig); err != nil {
log.Fatal(err)
}
},
Expand All @@ -212,7 +212,7 @@ func newControllerGetOptions() *cobra.Command {
Short: "fetch controller options",
Long: `Fetch controller options.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.ControllerGetOptions(fileWithConfig); err != nil {
if err := openEVEC.ControllerGetOptions(fileWithConfig); err != nil {
log.Fatal(err)
}
},
Expand All @@ -231,7 +231,7 @@ func newControllerSetOptions() *cobra.Command {
Short: "set controller options",
Long: `Set controller options.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.ControllerSetOptions(fileWithConfig); err != nil {
if err := openEVEC.ControllerSetOptions(fileWithConfig); err != nil {
log.Fatal(err)
}
},
Expand All @@ -250,7 +250,7 @@ func newEdgeNodeGetConfig(controllerMode string) *cobra.Command {
Short: "fetch EVE config",
Long: `Fetch EVE config.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.EdgeNodeGetConfig(controllerMode, fileWithConfig); err != nil {
if err := openEVEC.EdgeNodeGetConfig(controllerMode, fileWithConfig); err != nil {
log.Fatal(err)
}
},
Expand All @@ -269,7 +269,7 @@ func newEdgeNodeSetConfig() *cobra.Command {
Short: "set EVE config",
Long: `Set EVE config.`,
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.EdgeNodeSetConfig(fileWithConfig); err != nil {
if err := openEVEC.EdgeNodeSetConfig(fileWithConfig); err != nil {
log.Fatal(err)
}
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/edenGcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func newGcpImageDelete(gcpKey, gcpProjectName *string) *cobra.Command {
Use: "delete",
Short: "delete image from gcp",
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.GcpImageDelete(*gcpKey, *gcpProjectName, gcpImageName, gcpBucketName); err != nil {
if err := openEVEC.GcpImageDelete(*gcpKey, *gcpProjectName, gcpImageName, gcpBucketName); err != nil {
log.Fatal(err)
}
},
Expand Down Expand Up @@ -81,7 +81,7 @@ func newGcpImageUploadCmd(cfg *openevec.EdenSetupArgs, gcpKey, gcpProjectName *s
Use: "upload",
Short: "upload image to gcp",
Run: func(cmd *cobra.Command, args []string) {
err := openevec.GcpImageUpload(*gcpKey, *gcpProjectName, gcpImageName, gcpBucketName, cfg.Eve.ImageFile, cfg.Eve.TPM)
err := openEVEC.GcpImageUpload(*gcpKey, *gcpProjectName, gcpImageName, gcpBucketName, cfg.Eve.ImageFile, cfg.Eve.TPM)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func newGcpRunCmd(cfg *openevec.EdenSetupArgs, gcpKey, gcpProjectName *string) *
Use: "run",
Short: "run vm in gcp",
Run: func(cmd *cobra.Command, args []string) {
err := openevec.GcpRun(*gcpKey, *gcpProjectName, gcpImageName, gcpVMName, gcpZone, gcpMachineType, cfg.Eve.TPM, cfg.Eve.Disks, cfg.Eve.ImageSizeMB)
err := openEVEC.GcpRun(*gcpKey, *gcpProjectName, gcpImageName, gcpVMName, gcpZone, gcpMachineType, cfg.Eve.TPM, cfg.Eve.Disks, cfg.Eve.ImageSizeMB)
if err != nil {
log.Fatal(err)
}
Expand All @@ -150,7 +150,7 @@ func newGcpDeleteCmd(gcpKey, gcpProjectName *string) *cobra.Command {
Use: "delete",
Short: "delete vm from gcp",
Run: func(cmd *cobra.Command, args []string) {
err := openevec.GcpDelete(*gcpKey, *gcpProjectName, gcpVMName, gcpZone)
err := openEVEC.GcpDelete(*gcpKey, *gcpProjectName, gcpVMName, gcpZone)
if err != nil {
log.Fatal(err)
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/edenNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/lf-edge/eden/pkg/controller/types"
"github.com/lf-edge/eden/pkg/openevec"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/thediveo/enumflag"
Expand Down Expand Up @@ -37,7 +36,7 @@ func newNetworkLsCmd() *cobra.Command {
Use: "ls",
Short: "List networks",
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.NetworkLs(outputFormat); err != nil {
if err := openEVEC.NetworkLs(outputFormat); err != nil {
log.Fatal(err)
}
},
Expand All @@ -57,7 +56,7 @@ func newNetworkDeleteCmd() *cobra.Command {
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
niName := args[0]
if err := openevec.NetworkDelete(niName); err != nil {
if err := openEVEC.NetworkDelete(niName); err != nil {
log.Fatal(err)
}
},
Expand All @@ -76,7 +75,7 @@ func newNetworkNetstatCmd() *cobra.Command {
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
niName := args[0]
if err := openevec.NetworkNetstat(niName, outputFormat, outputTail); err != nil {
if err := openEVEC.NetworkNetstat(niName, outputFormat, outputTail); err != nil {
log.Fatal(err)
}
},
Expand Down Expand Up @@ -105,7 +104,7 @@ func newNetworkCreateCmd() *cobra.Command {
if len(args) == 1 {
subnet = args[0]
}
if err := openevec.NetworkCreate(subnet, networkType, networkName, uplinkAdapter, staticDNSEntries); err != nil {
if err := openEVEC.NetworkCreate(subnet, networkType, networkName, uplinkAdapter, staticDNSEntries); err != nil {
log.Fatal(err)
}
},
Expand Down
6 changes: 3 additions & 3 deletions cmd/edenPacket.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func newPacketRunCmd(cfg *openevec.EdenSetupArgs, packetKey, packetProjectName *
Use: "run",
Short: "run vm in packet",
Run: func(cmd *cobra.Command, args []string) {
err := openevec.PacketRun(*packetKey, *packetProjectName, packetVMName, packetZone, packetMachineType, packetIPXEUrl, cfg)
err := openEVEC.PacketRun(*packetKey, *packetProjectName, packetVMName, packetZone, packetMachineType, packetIPXEUrl)
if err != nil {
log.Fatal(err)
}
Expand All @@ -75,7 +75,7 @@ func newPacketDeleteCmd(packetKey, packetProjectName *string) *cobra.Command {
Use: "delete",
Short: "delete vm from packet",
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.PacketDelete(*packetKey, *packetProjectName, packetVMName); err != nil {
if err := openEVEC.PacketDelete(*packetKey, *packetProjectName, packetVMName); err != nil {
log.Fatal(err)
}
},
Expand All @@ -93,7 +93,7 @@ func newPacketGetIPCmd(packetKey, packetProjectName *string) *cobra.Command {
Use: "get-ip",
Short: "print IP of VM in packet",
Run: func(cmd *cobra.Command, args []string) {
if err := openevec.PacketGetIP(*packetKey, *packetProjectName, packetVMName); err != nil {
if err := openEVEC.PacketGetIP(*packetKey, *packetProjectName, packetVMName); err != nil {
log.Fatal(err)
}
},
Expand Down
Loading

0 comments on commit 44f8608

Please sign in to comment.