diff --git a/cmd/authelia-scripts/cmd_bootstrap.go b/cmd/authelia-scripts/cmd_bootstrap.go index b13b3fe3a..40e74f20b 100644 --- a/cmd/authelia-scripts/cmd_bootstrap.go +++ b/cmd/authelia-scripts/cmd_bootstrap.go @@ -39,6 +39,9 @@ var hostEntries = []HostEntry{ HostEntry{Domain: "proxy-client1.example.com", IP: "192.168.240.201"}, HostEntry{Domain: "proxy-client2.example.com", IP: "192.168.240.202"}, HostEntry{Domain: "proxy-client3.example.com", IP: "192.168.240.203"}, + + // Kubernetes dashboard + HostEntry{Domain: "kubernetes.example.com", IP: "192.168.240.110"}, } func runCommand(cmd string, args ...string) { diff --git a/example/compose/kind/entrypoint-dashboard.sh b/example/compose/kind/entrypoint-dashboard.sh index 8788e74db..eb27de4e4 100755 --- a/example/compose/kind/entrypoint-dashboard.sh +++ b/example/compose/kind/entrypoint-dashboard.sh @@ -1,4 +1,25 @@ #!/bin/bash +# Retries a command on failure. +# $1 - the max number of attempts +# $2... - the command to run + +retry() { + local -r -i max_attempts="$1"; shift + local -r cmd="$@" + local -i attempt_num=1 + until $cmd + do + if ((attempt_num==max_attempts)) + then + echo "Attempt $attempt_num failed and there are no more attempts left!" + return 1 + else + echo "Attempt $attempt_num failed! Trying again in 10 seconds..." + sleep 10 + fi + done +} + kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}') -kubectl port-forward --address 0.0.0.0 -n kubernetes-dashboard service/kubernetes-dashboard 443:443 \ No newline at end of file +retry 10 kubectl port-forward --address 0.0.0.0 -n kubernetes-dashboard service/kubernetes-dashboard 443:443 \ No newline at end of file diff --git a/example/kube/authelia/configs/config.yml b/example/kube/authelia/configs/config.yml index 357387111..c7ad71e8b 100644 --- a/example/kube/authelia/configs/config.yml +++ b/example/kube/authelia/configs/config.yml @@ -93,6 +93,8 @@ storage: host: mariadb-service port: 3306 database: authelia + username: admin + password: password notifier: smtp: diff --git a/example/kube/bootstrap-dashboard.sh b/example/kube/bootstrap-dashboard.sh new file mode 100755 index 000000000..5c3213fa8 --- /dev/null +++ b/example/kube/bootstrap-dashboard.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +start_dashboard() { + kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta4/aio/deploy/recommended.yaml + kubectl apply -f dashboard.yml + + echo "Bearer token for UI user." + kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}') +} + +start_dashboard diff --git a/example/kube/bootstrap.sh b/example/kube/bootstrap.sh index cb5f2f6f5..32a722869 100755 --- a/example/kube/bootstrap.sh +++ b/example/kube/bootstrap.sh @@ -12,14 +12,6 @@ start_ingress_controller() { kubectl apply -f ingress-controller } -start_dashboard() { - kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta4/aio/deploy/recommended.yaml - kubectl apply -f dashboard.yml - - echo "Bearer token for UI user." - kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}') -} - # Spawn Redis and storage backend # Please note they are not configured to be distributed on several machines start_storage() { @@ -42,7 +34,6 @@ create_namespace() { } create_namespace -start_dashboard start_storage start_ldap start_mail diff --git a/suites/kubernetes.go b/suites/kubernetes.go index a39e9db5e..2cfa346cf 100644 --- a/suites/kubernetes.go +++ b/suites/kubernetes.go @@ -83,6 +83,24 @@ func (k Kubectl) StopProxy() error { return cmd.Run() } +// StartDashboard start Kube dashboard +func (k Kubectl) StartDashboard() error { + if err := kindCommand("sh -c 'cd /authelia && ./bootstrap-dashboard.sh'").Run(); err != nil { + return err + } + + if err := utils.Shell("docker-compose -f docker-compose.yml -f example/compose/kind/docker-compose.yml up -d kube-dashboard").Run(); err != nil { + return err + } + return nil +} + +// StopDashboard stop kube dashboard +func (k Kubectl) StopDashboard() error { + cmd := utils.Shell("docker-compose -f docker-compose.yml -f example/compose/kind/docker-compose.yml rm -s -f kube-dashboard") + return cmd.Run() +} + // DeployThirdparties deploy thirdparty services (ldap, db, ingress controllers, etc...) func (k Kubectl) DeployThirdparties() error { cmd := kindCommand("sh -c 'cd /authelia && ./bootstrap.sh'") diff --git a/suites/suite_kubernetes.go b/suites/suite_kubernetes.go index 48f916c55..b0c97eb4e 100644 --- a/suites/suite_kubernetes.go +++ b/suites/suite_kubernetes.go @@ -41,6 +41,11 @@ func init() { return err } + log.Debug("Starting Kubernetes dashboard...") + if err := kubectl.StartDashboard(); err != nil { + return err + } + log.Debug("Deploying thirdparties...") if err = kubectl.DeployThirdparties(); err != nil { return err