Skip to content

Commit

Permalink
Prepare 1.32.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rfrancom committed Apr 10, 2024
1 parent f741c1e commit f4740b1
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# GoKube Release Notes

## Version 1.32.0 - 04/05/2024
* Bump to minikube v1.32.0, K8S v1.28.3, helm v3.14.3
* Added swap memory option MINIKUBE_SWAP. Disabled by default (0).

## Version 1.31.0 - 10/07/2023
* Bump to minikube v1.31.2, K8S v1.27.4, helm v3.12.3

Expand Down
50 changes: 50 additions & 0 deletions cmd/gokube/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ import (
"github.com/gemalto/gokube/pkg/kubectl"
"github.com/gemalto/gokube/pkg/minikube"
"github.com/spf13/cobra"
"os/exec"
)

var memory int16
var cpus int16
var swap int16
var enableSwap bool
var disk string
var checkIP string
var ipCheckNeeded bool
Expand All @@ -64,6 +67,11 @@ var initCmd = &cobra.Command{
func init() {
defaultVMMemory, _ := strconv.Atoi(utils.GetValueFromEnv("MINIKUBE_MEMORY", strconv.Itoa(DEFAULT_MINIKUBE_MEMORY)))
defaultVMCPUs, _ := strconv.Atoi(utils.GetValueFromEnv("MINIKUBE_CPUS", strconv.Itoa(DEFAULT_MINIKUBE_CPUS)))
defaultVMSwap, _ := strconv.Atoi(utils.GetValueFromEnv("MINIKUBE_SWAP", strconv.Itoa(DEFAULT_MINIKUBE_SWAP)))
enableSwap = false
if defaultVMSwap != 0 {
enableSwap = true
}
defaultGokubeQuiet := false
if len(utils.GetValueFromEnv("GOKUBE_QUIET", "")) > 0 {
defaultGokubeQuiet = true
Expand All @@ -75,6 +83,7 @@ func init() {
initCmd.Flags().BoolVarP(&askForClean, "clean", "c", false, "Clean gokube (remove docker, minikube, kubectl and helm working directories)")
initCmd.Flags().Int16VarP(&memory, "memory", "", int16(defaultVMMemory), "Amount of RAM allocated to the minikube VM in MB")
initCmd.Flags().Int16VarP(&cpus, "cpus", "", int16(defaultVMCPUs), "Number of CPUs allocated to the minikube VM")
initCmd.Flags().Int16VarP(&swap, "swap", "", int16(defaultVMSwap), "Amount of SWAP allocated to the minikube VM in MB")
initCmd.Flags().StringVarP(&disk, "disk", "", utils.GetValueFromEnv("MINIKUBE_DISK", DEFAULT_MINIKUBE_DISK), "Disk size allocated to the minikube VM. Format: <number>[<unit>], where unit = b, k, m or g")
initCmd.Flags().StringVarP(&checkIP, "check-ip", "", utils.GetValueFromEnv("GOKUBE_CHECK_IP", DEFAULT_GOKUBE_CHECK_IP), "Checks if minikube VM allocated IP matches the provided one (0.0.0.0 means no check)")
initCmd.Flags().StringVarP(&insecureRegistry, "insecure-registry", "", os.Getenv("INSECURE_REGISTRY"), "Insecure Docker registries to pass to the Docker daemon. The default service CIDR range will automatically be added.")
Expand Down Expand Up @@ -289,6 +298,16 @@ func initRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("cannot start minikube VM: %w", err)
}

// Create & attach swap drive to minikube
if enableSwap {
fmt.Println("Creating & attaching swap drive to minikube VM...")
vboxManager := virtualbox.NewVBoxManager()
err = vboxManager.AddSwapDisk(swap)
if err != nil {
fmt.Printf("Warning: cannot create & attach swap drive to minikube VM: %s\n", err)
}
}

// Enable dashboard
err = minikube.AddonsEnable("dashboard")
if err != nil {
Expand Down Expand Up @@ -331,6 +350,7 @@ func initRun(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}

}

if askForUpgrade {
Expand All @@ -347,6 +367,36 @@ func initRun(cmd *cobra.Command, args []string) error {
return fmt.Errorf("cannot write gokube configuration: %w", err)
}

// Format & enable swap drive in minikube VM
if enableSwap {
fmt.Println("Formatting & enabling swap drive in minikube VM...")
err = addSwapToMinikube()
if err != nil {
fmt.Printf("Warning: cannot format/enable swap drive in minikube VM: %s\n", err)
}
}

fmt.Printf("\ngokube init completed in %s\n", util.Duration(time.Since(startTime)))
return nil
}

func addSwapToMinikube() error {

// Add swap file commands
swapCmds := []string{
"sudo mkswap /dev/sdb",
"sudo swapon /dev/sdb",
"echo '/dev/sdb none swap defaults 0 0' | sudo tee -a /etc/fstab",
}

// Execute each command
for _, cmd := range swapCmds {
sshCmd := exec.Command("minikube", "ssh", cmd)
err := sshCmd.Run()
if err != nil {
return fmt.Errorf("error running command '%s': %w", cmd, err)
}
}

return nil
}
13 changes: 7 additions & 6 deletions cmd/gokube/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ import (
)

const (
DEFAULT_KUBERNETES_VERSION = "v1.27.4"
DEFAULT_KUBECTL_VERSION = "v1.27.4"
DEFAULT_MINIKUBE_VERSION = "v1.31.2"
DEFAULT_KUBERNETES_VERSION = "v1.28.3"
DEFAULT_KUBECTL_VERSION = "v1.28.3"
DEFAULT_MINIKUBE_VERSION = "v1.32.0"
DEFAULT_MINIKUBE_MEMORY = 12288
DEFAULT_MINIKUBE_CPUS = 6
DEFAULT_MINIKUBE_SWAP = 0
DEFAULT_MINIKUBE_DISK = "20g"
DEFAULT_MINIKUBE_DNS_DOMAIN = "cluster.local"
DEFAULT_MINIKUBE_CONTAINER_RUNTIME = "docker"
DEFAULT_DOCKER_VERSION = "20.10.14"
DEFAULT_HELM_VERSION = "v3.12.3"
DEFAULT_HELM_VERSION = "v3.14.3"
DEFAULT_HELM_SPRAY_VERSION = "v4.0.10"
DEFAULT_HELM_IMAGE_VERSION = "v1.0.7"
DEFAULT_HELM_PUSH_VERSION = "0.10.3"
DEFAULT_STERN_VERSION = "1.23.0"
DEFAULT_HELM_PUSH_VERSION = "0.10.4"
DEFAULT_STERN_VERSION = "1.28.0"
DEFAULT_MINIAPPS_REPO = "https://thalesgroup.github.io/miniapps"
DEFAULT_GOKUBE_CHECK_IP = "192.168.99.100"
DEFAULT_GOKUBE_CIDR = "192.168.99.1/24"
Expand Down
48 changes: 47 additions & 1 deletion cmd/gokube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/gemalto/gokube/pkg/virtualbox"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os/exec"
)

// startCmd represents the start command
Expand Down Expand Up @@ -62,6 +63,16 @@ func start() error {
if err != nil {
return fmt.Errorf("cannot restart minikube VM: %w", err)
}

// Add swap to Minikube VM
if enableSwap {
fmt.Println("Enabling swap drive in minikube VM...")
err = addSwapToMinikubeDuringStart()
if err != nil {
fmt.Printf("Warning: cannot enable swap drive in minikube VM - start: %s\n", err)
}
}

return nil
}

Expand All @@ -84,5 +95,40 @@ func startRun(cmd *cobra.Command, args []string) error {
return err
}
}
return start()
// Start minikube
err := start()
if err != nil {
return err
}

// Add swap to Minikube VM
if enableSwap {
fmt.Println("Enabling swap drive in minikube VM...")
err = addSwapToMinikubeDuringStart()
if err != nil {
fmt.Printf("Warning: cannot enable swap drive in minikube VM - start: %s\n", err)
}
}

return nil
}

func addSwapToMinikubeDuringStart() error {

// Add swap file commands
swapCmds := []string{
"sudo swapon /dev/sdb",
"echo '/dev/sdb none swap defaults 0 0' | sudo tee -a /etc/fstab",
}

// Execute each command
for _, cmd := range swapCmds {
sshCmd := exec.Command("minikube", "ssh", cmd)
err := sshCmd.Run()
if err != nil {
return fmt.Errorf("error running command '%s': %w", cmd, err)
}
}

return nil
}
2 changes: 1 addition & 1 deletion cmd/gokube/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

const (
GOKUBE_VERSION = "1.31.0"
GOKUBE_VERSION = "1.32.0"
)

var gokubeVersion string
Expand Down
41 changes: 41 additions & 0 deletions pkg/virtualbox/vbm.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strconv"

"time"
"os"
"github.com/gemalto/gokube/pkg/utils"
)

const (
Expand Down Expand Up @@ -56,6 +58,26 @@ func NewVBoxManager() *VBoxCmdManager {
}
}

// CreateDisk create a disk in VBox to be used as swap
func (v *VBoxCmdManager) CreateDisk(sizeInMB int16, filePath string) error {
size := fmt.Sprintf("--size=%d", sizeInMB)
command := []string{"createmedium", "disk", "--filename", filePath, size, "--format", "VDI"}
return v.vbm(command...)
}

// AttachDisk attach the disk created for swap to the minikube VM
func (v *VBoxCmdManager) AttachDisk(vmName string, port int, device int, filePath string) error {
command := []string{
"storageattach", vmName,
"--storagectl", "SATA",
"--port", fmt.Sprintf("%d", port),
"--device", fmt.Sprintf("%d", device),
"--type", "hdd",
"--medium", filePath,
}
return v.vbm(command...)
}

func (v *VBoxCmdManager) vbm(args ...string) error {
_, _, err := v.vbmOutErr(args...)
return err
Expand Down Expand Up @@ -155,3 +177,22 @@ func parseKeyValues(stdOut string, regexp *regexp.Regexp, callback func(key, val

return s.Err()
}

// AddSwapDisk prepare, create, and attach swap disk to minikube VM
func (v *VBoxCmdManager) AddSwapDisk(swapsize int16) error {

// Create the disk
swapDiskPath := utils.GetUserHome() + string(os.PathSeparator) + ".minikube/machines/minikube/swapdisk.vdi"
err := v.CreateDisk(swapsize, swapDiskPath)
if err != nil {
return fmt.Errorf("cannot create swap disk: %w", err)
}

// Attach the disk to the VM
err = v.AttachDisk("minikube", 2, 0, swapDiskPath)
if err != nil {
return fmt.Errorf("cannot attach swap disk to VM: %w", err)
}

return nil
}

0 comments on commit f4740b1

Please sign in to comment.