Add --wait amd --timeout flags for dapr init -k which are passed to Helm (#629)

* Added --wait flag for dapr init -k which is passed on to Helm

* Simplification

* Added --timeout flag to kubernetes init, upgrade, and uninstall

* Tweaks

* Tweak

* Fixing conflict after merge from master

Co-authored-by: Mukundan Sundararajan <musundar@microsoft.com>
This commit is contained in:
Phil Kedy 2021-03-17 14:15:18 -04:00 committed by GitHub
parent 3d511bde6b
commit e966e40694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 2 deletions

View File

@ -211,6 +211,12 @@ $ dapr init -k --enable-ha=true
$ dapr init -k --enable-mtls=false
```
#### Waiting for the Helm install to complete (default timeout is 300s/5m)
```
$ dapr init -k --wait --timeout 600
```
#### Uninstall Dapr on Kubernetes
To remove Dapr from your Kubernetes cluster, use the `uninstall` command with `--kubernetes` flag or the `-k` shorthand.
@ -219,6 +225,12 @@ To remove Dapr from your Kubernetes cluster, use the `uninstall` command with `-
$ dapr uninstall -k
```
The default timeout is 300s/5m and can be overridden using the `--timeout` flag.
```
$ dapr uninstall -k --timeout 600
```
### Upgrade Dapr on Kubernetes
To perform a zero downtime upgrade of the Dapr control plane:

View File

@ -18,6 +18,8 @@ import (
var (
kubernetesMode bool
wait bool
timeout uint
slimMode bool
runtimeVersion string
dashboardVersion string
@ -40,6 +42,9 @@ dapr init
# Initialize Dapr in Kubernetes
dapr init -k
# Initialize Dapr in Kubernetes and wait for the installation to complete (default timeout is 300s/5m)
dapr init -k --wait --timeout 600
# Initialize particular Dapr runtime in self-hosted mode
dapr init --runtime-version 0.10.0
@ -63,6 +68,8 @@ dapr init -s
EnableMTLS: enableMTLS,
EnableHA: enableHA,
Args: values,
Wait: wait,
Timeout: timeout,
}
err := kubernetes.Init(config)
if err != nil {
@ -87,6 +94,8 @@ dapr init -s
func init() {
InitCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "Deploy Dapr to a Kubernetes cluster")
InitCmd.Flags().BoolVarP(&wait, "wait", "", false, "Wait for Kubernetes initialization to complete")
InitCmd.Flags().UintVarP(&timeout, "timeout", "", 300, "The wait timeout for the Kubernetes installation")
InitCmd.Flags().BoolVarP(&slimMode, "slim", "s", false, "Exclude placement service, Redis and Zipkin containers from self-hosted installation")
InitCmd.Flags().StringVarP(&runtimeVersion, "runtime-version", "", "latest", "The version of the Dapr runtime to install, for example: 1.0.0")
InitCmd.Flags().StringVarP(&dashboardVersion, "dashboard-version", "", "latest", "The version of the Dapr dashboard to install, for example: 1.0.0")

View File

@ -45,7 +45,7 @@ dapr uninstall -k
if uninstallKubernetes {
print.InfoStatusEvent(os.Stdout, "Removing Dapr from your cluster...")
err = kubernetes.Uninstall(uninstallNamespace)
err = kubernetes.Uninstall(uninstallNamespace, timeout)
} else {
print.InfoStatusEvent(os.Stdout, "Removing Dapr from your machine...")
dockerNetwork := viper.GetString("network")
@ -62,6 +62,7 @@ dapr uninstall -k
func init() {
UninstallCmd.Flags().BoolVarP(&uninstallKubernetes, "kubernetes", "k", false, "Uninstall Dapr from a Kubernetes cluster")
UninstallCmd.Flags().UintVarP(&timeout, "timeout", "", 300, "The timeout for the Kubernetes uninstall")
UninstallCmd.Flags().BoolVar(&uninstallAll, "all", false, "Remove .dapr directory, Redis, Placement and Zipkin containers")
UninstallCmd.Flags().String("network", "", "The Docker network from which to remove the Dapr runtime")
UninstallCmd.Flags().StringVarP(&uninstallNamespace, "namespace", "n", "dapr-system", "The Kubernetes namespace to uninstall Dapr from")

View File

@ -28,6 +28,7 @@ dapr upgrade -k
err := kubernetes.Upgrade(kubernetes.UpgradeConfig{
RuntimeVersion: upgradeRuntimeVersion,
Args: values,
Timeout: timeout,
})
if err != nil {
print.FailureStatusEvent(os.Stdout, "Failed to upgrade Dapr: %s", err)
@ -39,6 +40,7 @@ dapr upgrade -k
func init() {
UpgradeCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "Upgrade Dapr in a Kubernetes cluster")
UpgradeCmd.Flags().UintVarP(&timeout, "timeout", "", 300, "The timeout for the Kubernetes upgrade")
UpgradeCmd.Flags().StringVarP(&upgradeRuntimeVersion, "runtime-version", "", "", "The version of the Dapr runtime to upgrade to, for example: 1.0.0")
UpgradeCmd.Flags().BoolP("help", "h", false, "Print this help message")
UpgradeCmd.Flags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")

View File

@ -11,6 +11,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"time"
"github.com/dapr/cli/pkg/print"
helm "helm.sh/helm/v3/pkg/action"
@ -35,6 +36,8 @@ type InitConfiguration struct {
EnableMTLS bool
EnableHA bool
Args []string
Wait bool
Timeout uint
}
// Init deploys the Dapr operator using the supplied runtime version.
@ -159,6 +162,8 @@ func install(config InitConfiguration) error {
installClient := helm.NewInstall(helmConf)
installClient.ReleaseName = daprReleaseName
installClient.Namespace = config.Namespace
installClient.Wait = config.Wait
installClient.Timeout = time.Duration(config.Timeout) * time.Second
values, err := chartValues(config)
if err != nil {

View File

@ -6,17 +6,20 @@
package kubernetes
import (
"time"
helm "helm.sh/helm/v3/pkg/action"
)
// Uninstall removes Dapr from a Kubernetes cluster.
func Uninstall(namespace string) error {
func Uninstall(namespace string, timeout uint) error {
config, err := helmConfig(namespace)
if err != nil {
return err
}
uninstallClient := helm.NewUninstall(config)
uninstallClient.Timeout = time.Duration(timeout) * time.Second
_, err = uninstallClient.Run(daprReleaseName)
return err
}

View File

@ -10,6 +10,7 @@ import (
"fmt"
"os"
"strings"
"time"
"github.com/dapr/cli/pkg/print"
"github.com/dapr/cli/utils"
@ -28,6 +29,7 @@ var crds = []string{
type UpgradeConfig struct {
RuntimeVersion string
Args []string
Timeout uint
}
func Upgrade(conf UpgradeConfig) error {
@ -68,6 +70,7 @@ func Upgrade(conf UpgradeConfig) error {
upgradeClient.Namespace = status[0].Namespace
upgradeClient.CleanupOnFail = true
upgradeClient.Wait = true
upgradeClient.Timeout = time.Duration(conf.Timeout) * time.Second
print.InfoStatusEvent(os.Stdout, "Starting upgrade...")