Skip to content

Commit

Permalink
updated the new mock testing
Browse files Browse the repository at this point in the history
Signed-off-by: Dipankar Das <[email protected]>
  • Loading branch information
dipankardas011 committed Jun 21, 2024
1 parent a9bee9e commit b228a41
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 5 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/test-mock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ jobs:
run: |
Set-PSDebug -Trace 2
cd .\scripts
.\builder.ps1
.\builder-mock.ps1
echo "KSCTL_BIN=$env:LOCALAPPDATA\ksctl\ksctl.exe" >> $env:GITHUB_ENV
- name: build ksctl linux
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
set -x
make install_linux
make install_linux_mock
echo "KSCTL_BIN=ksctl" >> "${GITHUB_ENV}"
- name: build ksctl macos
if: ${{ matrix.os == 'macos-latest' }}
run: |
set -x
make install_macos_intel
make install_macos_intel_mock
echo "KSCTL_BIN=ksctl" >> "${GITHUB_ENV}"
- name: version
Expand All @@ -76,29 +76,48 @@ jobs:
run: |
${{ env.KSCTL_BIN }} create civo -n demo -r LON1 --nodeSizeMP "g4s.kube.small" --version 1.27.1 --verbose -1 -s store-local --yes
${{ env.KSCTL_BIN }} info -p civo -n demo -r LON1 --verbose -1 -s store-local
${{env.KSCTL_BIN}} create ha-civo -n ha-demo-k3s --nodeSizeDS "fake.small" --version 1.27.1 --nodeSizeLB "fake.small" --nodeSizeCP "fake.small" --nodeSizeWP "fake.small" -s store-local -r LON1 --verbose -1 --yes --bootstrap k3s
${{env.KSCTL_BIN}} info -p ha-civo -n ha-demo-k3s -s store-local -r LON1 --verbose -1
${{env.KSCTL_BIN}} create ha-civo -n ha-demo-kubeadm --nodeSizeDS "fake.small" --version 1.28 --nodeSizeLB "fake.small" --nodeSizeCP "fake.small" --nodeSizeWP "fake.small" -s store-local -r LON1 --verbose -1 --yes --bootstrap kubeadm
${{env.KSCTL_BIN}} info ha-civo -n ha-demo-kubeadm -s store-local -r LON1 --verbose -1
- name: azure create
run: |
${{env.KSCTL_BIN}} create azure -n demo -r fake --nodeSizeMP "fake" -s store-local --version 1.27.1 --verbose -1 --yes
${{env.KSCTL_BIN}} info -p azure -n demo -r fake -s store-local --verbose -1
${{env.KSCTL_BIN}} create ha-azure -n ha-demo-k3s --nodeSizeDS "fake" --version 1.27.1 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s store-local --yes --bootstrap k3s
${{env.KSCTL_BIN}} info -p ha-azure -n ha-demo-k3s -r fake -s store-local --verbose -1
${{env.KSCTL_BIN}} create ha-azure -n ha-demo-kubeadm --nodeSizeDS "fake" --version 1.28 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s store-local --yes --bootstrap kubeadm
${{env.KSCTL_BIN}} info -p ha-azure -n ha-demo-kubeadm -r fake -s store-local --verbose -1
- name: aws create
run: |
# ${{env.KSCTL_BIN}} create aws -n demo -r fake --nodeSizeMP "fake" --version 1.27.1 -s store-local --verbose -1 --yes
#${{env.KSCTL_BIN}} info -p aws -n demo -r fake -s store-local --verbose -1
${{env.KSCTL_BIN}} create ha-aws -n ha-demo-k3s --nodeSizeDS "fake" --version 1.27.1 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s store-local --yes --bootstrap k3s
${{env.KSCTL_BIN}} info -p ha-aws -n ha-demo-k3s -r fake -s store-local --verbose -1
${{env.KSCTL_BIN}} create ha-aws -n ha-demo-kubeadm --nodeSizeDS "fake" --version 1.28 --nodeSizeLB "fake" --nodeSizeCP "fake" --nodeSizeWP "fake" -r fake --verbose -1 -s store-local --yes --bootstrap kubeadm
${{env.KSCTL_BIN}} info -p ha-aws -n ha-demo-kubeadm -r fake -s store-local --verbose -1
- name: local create
run: |
${{env.KSCTL_BIN}} create local -n demolocal --version 1.27.1 --verbose -1 -s store-local --yes
${{env.KSCTL_BIN}} info -p local -n demolocal -s store-local --verbose -1
- name: local create mongodb
Expand All @@ -113,6 +132,7 @@ jobs:
mongo
export MONGODB_URI="mongodb://root:[email protected]:27017"
${{env.KSCTL_BIN}} create local -n demolocal-extmongo -s external-store-mongodb --verbose -1 --yes
${{env.KSCTL_BIN}} info -p local -n demolocal-extmongo -s external-store-mongodb --verbose -1
- name: civo get
run: |
Expand Down
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ gen-docs: ## Generates docs

##@ Install (Dev)


.PHONY: install_linux_mock
install_linux_mock: ## Install ksctl
@echo "Started to Install ksctl"
cd scripts && \
env GOOS=${GOOS_LINUX} GOARCH=${GOARCH_LINUX} ./builder-mock.sh

.PHONY: install_macos_mock
install_macos_mock: ## Install ksctl on macos m1,m2,..
@echo "Started to Install ksctl"
cd scripts && \
env GOOS=${GOOS_MACOS} GOARCH=${GOARCH_MACOS} ./builder-mock.sh

.PHONY: install_macos_intel_mock
install_macos_intel_mock: ## Install ksctl on macos intel
@echo "Started to Install ksctl"
cd scripts && \
env GOOS=${GOOS_MACOS} GOARCH=${GOARCH_MACOS_INTEL} ./builder-mock.sh

.PHONY: install_linux
install_linux: ## Install ksctl
@echo "Started to Install ksctl"
Expand Down Expand Up @@ -85,4 +104,4 @@ echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
endef
endef
28 changes: 27 additions & 1 deletion cli/cmd/infoCluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var infoClusterCmd = &cobra.Command{
Aliases: []string{"info"},
Example: `
ksctl info --provider azure --name demo --region eastus --storage store-local
ksctl info -p ha-azure -n ha-demo-kubeadm -r eastus -s store-local --verbose -1
`,
Short: "Use to info cluster",
Long: `It is used to detailed data for a given cluster`,
Expand All @@ -31,9 +32,34 @@ ksctl info --provider azure --name demo --region eastus --storage store-local
SetRequiredFeatureFlags(ctx, log, cmd)
cli.Client.Metadata.ClusterName = clusterName
cli.Client.Metadata.Region = region
cli.Client.Metadata.Provider = consts.KsctlCloud(provider)
cli.Client.Metadata.StateLocation = consts.KsctlStore(storage)

switch provider {
case string(consts.CloudLocal):
cli.Client.Metadata.Provider = consts.CloudLocal

case string(consts.ClusterTypeHa) + "-" + string(consts.CloudCivo):
cli.Client.Metadata.Provider = consts.CloudCivo
cli.Client.Metadata.IsHA = true

case string(consts.CloudCivo):
cli.Client.Metadata.Provider = consts.CloudCivo

case string(consts.ClusterTypeHa) + "-" + string(consts.CloudAzure):
cli.Client.Metadata.Provider = consts.CloudAzure
cli.Client.Metadata.IsHA = true

case string(consts.ClusterTypeHa) + "-" + string(consts.CloudAws):
cli.Client.Metadata.Provider = consts.CloudAws
cli.Client.Metadata.IsHA = true

case string(consts.CloudAzure):
cli.Client.Metadata.Provider = consts.CloudAzure
default:
log.Error("invalid provider specified", "provider", provider)
os.Exit(1)
}

m, err := controllers.NewManagerClusterKsctl(
ctx,
log,
Expand Down
40 changes: 40 additions & 0 deletions scripts/builder-mock.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#Requires -Version 5

$erroractionpreference = 'stop' # quit if anything goes wrong

if (($PSVersionTable.PSVersion.Major) -lt 5) {
Write-Output "PowerShell 5 or later is required to run Ksctl."
Write-Output "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell"
break
}

Write-Host "Welcome to Installation" -ForegroundColor DarkGreen

$env:GOOS = 'windows'
$env:GOARCH = 'amd64'
Set-Location .\..

Set-Location .\cli\

go build -tags testing-civo,testing-azure,testing-aws,testing-local -v -o ksctl.exe .

#Move-Item ksctl.exe $env:USERPROFILE\.ksctl\

$localAppDataPath = $env:LOCALAPPDATA
$ksctl = Join-Path "$localAppDataPath" 'ksctl'

Write-Information "Path of AppDataPath $ksctl"

New-Item -ItemType Directory -Force -Path $ksctl | Out-Null

Copy-Item ksctl.exe -Destination "$ksctl/" -Force | Out-Null

Remove-Item ksctl.exe

Set-Location ..\.. | Out-Null

Write-Host "[V] Finished Installation" -ForegroundColor DarkGreen
Write-Host ""
Write-Host "To run ksctl globally, please follow these steps:" -ForegroundColor Cyan
Write-Host ""
Write-Host " 1. Run the following command as administrator: ``setx PATH `"`$env:path;$ksctl`" -m``"
16 changes: 16 additions & 0 deletions scripts/builder-mock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

cd .. || echo -e "\033[1;31mUnable to cd into ksctl root\033[0m\n"

# Get the binary from the source code
cd cli || echo -e "\033[1;31mPath couldn't be found\033[0m\n"
# Check if sudo access
go get -d
go build -tags testing-civo,testing-azure,testing-aws,testing-local -v -o ksctl .
chmod +x ksctl

sudo mv -v ksctl /usr/local/bin/ksctl

echo -e "\033[1;32mINSTALL COMPLETE\033[0m\n"

cd - || echo -e "\033[1;31mFailed to move to previous directory\033[0m\n"

0 comments on commit b228a41

Please sign in to comment.