Skip to content
Open
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
51 changes: 51 additions & 0 deletions automation/Clean.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

param(
[string]$SwitchName = "Default Switch",

[Parameter(Mandatory=$true)]
[string]$VMName,

[Parameter()]
[string]$Platform = "Hyper-V"
)

if ($VMName) {
try{
if ($Platform -eq "Hyper-V") {
$dirPath = "C:\Users\$env:USERNAME\.minikube\machines\$VMName"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split HyperV and Virtual box to seperate functions to make it easier to mange each of them

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, eventually will do, this is in draft state, not finished

Stop-VM -Name $VMName -Force
Remove-Vm -Name $VMName -Force
}
elseif ($Platform -eq "VirtualBox") {
$dirPath = "C:\Users\$env:USERNAME\VirtualBox VMs\$VMName"
& VBoxManage controlvm $VMName poweroff --type headless
& VBoxManage unregistervm $VMName --delete
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log message for success and if the plaform is not supported

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a validated set to this file too

Start-Sleep -Seconds 10
}
catch {
Write-Warning "Couldn't stop the $VMName Virtual Machine. It doesn't exist. $_"
}
try{
if (Test-Path $dirPath) {
Remove-Item -Path $dirPath -Recurse -Force
"{0} - * The $dirPath directory has been removed." -f (Get-Date) >> logs
$VHDPath = "${env:homepath}\VirtualBox VMs\$VMName\VHD.vhdx"
# Unregister and delete the existing hard disk if it exists
if (Test-Path $VHDPath) {
& VBoxManage closemedium disk $VHDPath --delete
}
}
else {
Write-Warning "The $dirPath directory doesn't exist."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya good point

}

"{0} - * The $VMName Virtual Machine has been removed." -f (Get-Date) > logs
}
catch {
Write-Warning "Couldn't remove the $VMName directory. It doesn't exist. $_"
}
}
else {
Write-Warning "VMName is required"
}
12 changes: 6 additions & 6 deletions automation/ContainerdTools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Install-Containerd {

$Version = $Version.TrimStart('v')
Write-Output "* Downloading and installing Containerd v$version at $InstallPath"
"Downloading and installing Containerd v$version at $InstallPath" >> logs
"{0} - Downloading and installing Containerd v$version at $InstallPath" -f (Get-Date) >> logs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timestamp is a good addition. However, we do not need to redirect each message to a logger, since we can do this: Install-Containerd >> logs.txt. This way, the code will be much cleaner and we'll not need to remember to add >> logs to every log.



# Download file from repo
Expand All @@ -50,10 +50,10 @@ function Install-Containerd {
Install-RequiredFeature @params | Out-Null

Write-Output "* Containerd v$version successfully installed at $InstallPath"
"Containerd v$version successfully installed at $InstallPath" >> logs
"{0} Containerd v$version successfully installed at $InstallPath" -f (Get-Date) >> logs
containerd.exe -v >> logs

"For containerd usage: run 'containerd -h'" >> logs
"{0} - For containerd usage: run 'containerd -h'" -f (Get-Date) >> logs
}

function Start-ContainerdService {
Expand All @@ -69,15 +69,15 @@ function Start-ContainerdService {
}

Write-Output "* Containerd is installed and the service is started ..."
"Containerd is installed and the service is started" >> logs
"{0} - Containerd is installed and the service is started" -f (Get-Date) >> logs

}

function Stop-ContainerdService {
$containerdStatus = Get-Service containerd -ErrorAction SilentlyContinue
if (!$containerdStatus) {
Write-Warning "Containerd service does not exist as an installed service."
"Containerd service does not exist as an installed service." >> logs
"{0} - Containerd service does not exist as an installed service." -f (Get-Date) >> logs
return
}

Expand All @@ -99,7 +99,7 @@ function Initialize-ContainerdService {
$ContainerdPath = "$Env:ProgramFiles\containerd"
)

"Configuring the containerd service" >> logs
"{0} - Configuring the containerd service" -f (Get-Date) >> logs

#Configure containerd service
$containerdConfigFile = "$ContainerdPath\config.toml"
Expand Down
57 changes: 39 additions & 18 deletions automation/Remote.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,49 @@ function Start-VirtualMachine {

[String]
[ValidateNotNullOrEmpty()]
$ISOFile
$ISOFile,

[String]
[ValidateNotNullOrEmpty()]
$Platform = "Hyper-V"
)

# set the vm switch first
$Switch = Set-VmSwitch -SwitchName $SwitchName
if($Platform -eq "Hyper-V"){
# set the vm switch first
$Switch = Set-VmSwitch -SwitchName $SwitchName
$VM = @{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split HyperV and Virtual box to seperate functions to make it easier to mange each of them

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya will do eventually, wanted to push code a bit earlier, will clean up eventually when finished with everything else on this PR

Name = $VMName
MemoryStartupBytes = 1GB
NewVHDPath = "${env:homepath}\.minikube\machines\$VMName\VHD.vhdx"
NewVHDSizeBytes = 10GB
BootDevice = "VHD"
Path = "${env:homepath}\.minikube\machines\"
SwitchName = $Switch.Name
}

$VM = @{
Name = $VMName
MemoryStartupBytes = 1GB
NewVHDPath = "${env:homepath}\.minikube\machines\$VMName\VHD.vhdx"
NewVHDSizeBytes = 10GB
BootDevice = "VHD"
Path = "${env:homepath}\.minikube\machines\"
SwitchName = $Switch.Name
New-VM @VM

Set-VM -Name $VMName -ProcessorCount 2 -AutomaticCheckpointsEnabled $false
Set-VMProcessor -VMName $VMName -ExposeVirtualizationExtensions $true
Set-VMDvdDrive -VMName $VMName -Path $ISOFile
Start-VM -Name $VMName
}
elseif ($Platform -eq "VirtualBox") {
$VM = @{
Name = $VMName;
OSType = "Windows10_64";
Register = $true;
BaseFolder = "${env:homepath}\VirtualBox VMs";
}
& VBoxManage createvm --name $VM.Name --ostype $VM.OSType --register --basefolder $VM.BaseFolder
& VBoxManage modifyvm $VMName --cpus 2 --memory 1024 | Out-Null
& VBoxManage createmedium disk --filename "${env:homepath}\VirtualBox VMs\$VMName\VHD.vhdx" --size 15000 | Out-Null
& VBoxManage storagectl $VMName --name "IDE Controller" --add ide
& VBoxManage storageattach $VMName --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium "${env:homepath}\VirtualBox VMs\$VMName\VHD.vhdx" | Out-Null
& VBoxManage storageattach $VMName --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium $ISOFilePath | Out-Null
& VBoxManage startvm $VMName --type headless | Out-Null
& VBoxManage modifyvm $VMName --nic1 bridged --bridgeadapter1 $Switch.Name --cableconnected1 on
}

New-VM @VM

Set-VM -Name $VMName -ProcessorCount 2 -AutomaticCheckpointsEnabled $false
Set-VMProcessor -VMName $VMName -ExposeVirtualizationExtensions $true
Set-VMDvdDrive -VMName $VMName -Path $ISOFile
Start-VM -Name $VMName
}

function Set-NodeForMinikube {
Expand Down
18 changes: 14 additions & 4 deletions automation/Run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ function Run {
[string]$UserName,
[string]$Pass,
[System.Management.Automation.PSCredential]$Credential,
[string]$KubernetesVersion
[string]$KubernetesVersion,
[ValidateSet("Hyper-V", "VirtualBox")]
[string]$Platform = "Hyper-V"
)

# create and configure a new minikube cluster
Write-Output "* Creating and configuring a new minikube cluster ..."
& minikube start --driver=hyperv --hyperv-virtual-switch=$SwitchName --nodes=2 --cni=flannel --container-runtime=containerd --kubernetes-version=$KubernetesVersion
# & minikube start --driver=hyperv --hyperv-virtual-switch=$SwitchName --memory=4096 --cpus=2 --kubernetes-version=v1.20.2 --network-plugin=cni --cni=flannel --container-runtime=containerd --disk-size=15GB --wait=false >> logs
Write-Output "* Minikube cluster is created and configured ..."
if ($Platform -eq "Hyper-V") {
& minikube start --driver=hyperv --hyperv-virtual-switch=$SwitchName --nodes=2 --cni=flannel --container-runtime=containerd --kubernetes-version=$KubernetesVersion
# & minikube start --driver=hyperv --hyperv-virtual-switch=$SwitchName --memory=4096 --cpus=2 --kubernetes-version=v1.20.2 --network-plugin=cni --cni=flannel --container-runtime=containerd --disk-size=15GB --wait=false >> logs
}
elseif ($Platform -eq "Virtualbox") {
& minikube start --driver=virtualbox --nodes=2 --cni=flannel --container-runtime=containerd --kubernetes-version=$KubernetesVersion
} else {
Write-Output "Unsupported platform: $Platform"
return
}
Write-Output "* Minikube cluster is created and configured ..."
# Prepare the Linux nodes for Windows-specific Flannel CNI configuration
# at the moment we are assuming that you only have two linux nodes named minikube and minikube-m02
& minikube ssh "sudo sysctl net.bridge.bridge-nf-call-iptables=1 && exit" >> logs
Expand Down
Loading