Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(demo): Add destroy command #276

Merged
merged 1 commit into from
Apr 30, 2024
Merged
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
18 changes: 17 additions & 1 deletion cmd/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,23 @@ var demoCmd = &cobra.Command{
}

if args[0] == "destroy" {
panic("Destroy is not yet implemented")
err := os.WriteFile("destroy_demo_cluster.sh", demoScriptsDestroy, 0700)
if err != nil {
log.Errorf("Cannot write file to disk: %s", err)
os.Exit(1)
}

cmd := exec.Command("/bin/sh", "destroy_demo_cluster.sh", demoClusterName, organizationId, string(token))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Errorf("Error executing the command %s", err)
}
os.Exit(0)
}

log.Errorf("Unknown command %s. Only `up` and `destroy` are supported", args[0])
os.Exit(1)
},
}
var (
Expand All @@ -73,6 +86,9 @@ var (
//go:embed demo_scripts/create_qovery_demo.sh
var demoScriptsCreate []byte

//go:embed demo_scripts/destroy_qovery_demo.sh
var demoScriptsDestroy []byte

func init() {
var userName string
currentUser, err := user.Current()
Expand Down
4 changes: 2 additions & 2 deletions cmd/demo_scripts/create_qovery_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ setup_network() {
if [ "$(uname -s)" = 'Darwin' ]; then
# MacOs
set -x
sudo ifconfig lo0 alias 172.42.0.3/32 up || exit 1
sudo ifconfig lo0 alias 172.42.0.3/32 up || true
elif grep -qi microsoft /proc/version; then
# Wsl
echo '******** PLEASE READ ********'
echo 'For Qovery url to work outside WSL (from your windows host). You need to run this command within an administrator terminal'
echo 'netsh interface ipv4 add address name="Loopback Pseudo-Interface 1" address=172.42.0.3 mask=255.255.255.255 skipassource=true'
echo '******** PLEASE READ ********'
set -x
sudo ip addr add 172.42.0.3/32 dev lo || exit 1
sudo ip addr add 172.42.0.3/32 dev lo || true
fi
set +x
}
Expand Down
69 changes: 69 additions & 0 deletions cmd/demo_scripts/destroy_qovery_demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh

set -eu

CLUSTER_NAME=$1
ORGANIZATION_ID=$2
#case $2 in
# qov_*)
# AUTHORIZATION_HEADER="Authorization: Token $3"
# ;;
#
# *)
# AUTHORIZATION_HEADER="Authorization: Bearer $3"
# ;;
#esac

delete_cluster() {
clusterName=$1
clusterExist=$(k3d cluster list -o json | jq '.[] | select(.name=="'"$clusterName"'") | .name')
if [ -n "$clusterExist" ]
then
k3d cluster delete "$clusterName" || true
fi
docker network rm "k3d-${clusterName}" || true
}

teardown_network() {
if [ "$(uname -s)" = 'Darwin' ]; then
# MacOs
set -x
sudo ifconfig lo0 -alias 172.42.0.3/32 up || true
elif grep -qi microsoft /proc/version; then
# Wsl
echo '******** PLEASE READ ********'
echo 'You must run this command from an administrator terminal to finish the cleanup'
echo 'netsh interface ipv4 delete address name="Loopback Pseudo-Interface 1" address=172.42.0.3'
echo '******** PLEASE READ ********'
set -x
sudo ip addr del 172.42.0.3/32 dev lo || true
fi
set +x
}


echo ''
echo '""""""""""""""""""""""""""""""""""""""""""""'
echo 'Removing Qovery helm repositories'
echo '""""""""""""""""""""""""""""""""""""""""""""'
helm repo remove qovery || true

echo ''
echo '""""""""""""""""""""""""""""""""""""""""""""'
echo "Removing $CLUSTER_NAME kube cluster"
echo '""""""""""""""""""""""""""""""""""""""""""""'
delete_cluster "$CLUSTER_NAME"

echo ''
echo '""""""""""""""""""""""""""""""""""""""""""""'
echo 'Removing network config'
echo '""""""""""""""""""""""""""""""""""""""""""""'
teardown_network


echo ''
echo '""""""""""""""""""""""""""""""""""""""""""""'
echo "Qovery local demo cluster is now deleted"
echo "Your created environments still exits !"
echo "Go to https://console.qovery.com/organization/${ORGANIZATION_ID}/clusters/general to delete Qovery cluster config"
echo '""""""""""""""""""""""""""""""""""""""""""""'
2 changes: 1 addition & 1 deletion pkg/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func GetCurrentVersion() string {
return "0.90.4" // ci-version-check
return "0.90.5" // ci-version-check
}

func GetLatestOnlineVersionUrl() (string, error) {
Expand Down
Loading