mirror of https://github.com/dapr/cli.git
Installs,uninstalls,upgrade dapr-dashboard separately when applicable. (#1272)
Signed-off-by: Artur Souza <asouza.pro@gmail.com> Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
This commit is contained in:
parent
9f67738e24
commit
81fd09b7d1
|
@ -124,6 +124,7 @@ dapr init --runtime-path <path-to-install-directory>
|
||||||
config := kubernetes.InitConfiguration{
|
config := kubernetes.InitConfiguration{
|
||||||
Namespace: initNamespace,
|
Namespace: initNamespace,
|
||||||
Version: runtimeVersion,
|
Version: runtimeVersion,
|
||||||
|
DashboardVersion: dashboardVersion,
|
||||||
EnableMTLS: enableMTLS,
|
EnableMTLS: enableMTLS,
|
||||||
EnableHA: enableHA,
|
EnableHA: enableHA,
|
||||||
Args: values,
|
Args: values,
|
||||||
|
@ -205,7 +206,7 @@ func init() {
|
||||||
InitCmd.Flags().UintVarP(&timeout, "timeout", "", 300, "The wait timeout for the Kubernetes installation")
|
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().BoolVarP(&slimMode, "slim", "s", false, "Exclude placement service, Redis and Zipkin containers from self-hosted installation")
|
||||||
InitCmd.Flags().StringVarP(&runtimeVersion, "runtime-version", "", defaultRuntimeVersion, "The version of the Dapr runtime to install, for example: 1.0.0")
|
InitCmd.Flags().StringVarP(&runtimeVersion, "runtime-version", "", defaultRuntimeVersion, "The version of the Dapr runtime to install, for example: 1.0.0")
|
||||||
InitCmd.Flags().StringVarP(&dashboardVersion, "dashboard-version", "", defaultDashboardVersion, "The version of the Dapr dashboard to install, for example: 1.0.0")
|
InitCmd.Flags().StringVarP(&dashboardVersion, "dashboard-version", "", defaultDashboardVersion, "The version of the Dapr dashboard to install, for example: 0.13.0")
|
||||||
InitCmd.Flags().StringVarP(&initNamespace, "namespace", "n", "dapr-system", "The Kubernetes namespace to install Dapr in")
|
InitCmd.Flags().StringVarP(&initNamespace, "namespace", "n", "dapr-system", "The Kubernetes namespace to install Dapr in")
|
||||||
InitCmd.Flags().BoolVarP(&enableMTLS, "enable-mtls", "", true, "Enable mTLS in your cluster")
|
InitCmd.Flags().BoolVarP(&enableMTLS, "enable-mtls", "", true, "Enable mTLS in your cluster")
|
||||||
InitCmd.Flags().BoolVarP(&enableHA, "enable-ha", "", false, "Enable high availability (HA) mode")
|
InitCmd.Flags().BoolVarP(&enableHA, "enable-ha", "", false, "Enable high availability (HA) mode")
|
||||||
|
|
|
@ -27,6 +27,7 @@ import (
|
||||||
var (
|
var (
|
||||||
upgradeRuntimeVersion string
|
upgradeRuntimeVersion string
|
||||||
upgradeImageVariant string
|
upgradeImageVariant string
|
||||||
|
upgradeDashboardVersion string
|
||||||
)
|
)
|
||||||
|
|
||||||
var UpgradeCmd = &cobra.Command{
|
var UpgradeCmd = &cobra.Command{
|
||||||
|
@ -58,6 +59,7 @@ dapr upgrade -k
|
||||||
}
|
}
|
||||||
err = kubernetes.Upgrade(kubernetes.UpgradeConfig{
|
err = kubernetes.Upgrade(kubernetes.UpgradeConfig{
|
||||||
RuntimeVersion: upgradeRuntimeVersion,
|
RuntimeVersion: upgradeRuntimeVersion,
|
||||||
|
DashboardVersion: upgradeDashboardVersion,
|
||||||
Args: values,
|
Args: values,
|
||||||
Timeout: timeout,
|
Timeout: timeout,
|
||||||
ImageRegistryURI: imageRegistryURI,
|
ImageRegistryURI: imageRegistryURI,
|
||||||
|
@ -78,6 +80,7 @@ func init() {
|
||||||
UpgradeCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "Upgrade or downgrade Dapr in a Kubernetes cluster")
|
UpgradeCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "Upgrade or downgrade Dapr in a Kubernetes cluster")
|
||||||
UpgradeCmd.Flags().UintVarP(&timeout, "timeout", "", 300, "The timeout for the Kubernetes upgrade")
|
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 or downgrade to, for example: 1.0.0")
|
UpgradeCmd.Flags().StringVarP(&upgradeRuntimeVersion, "runtime-version", "", "", "The version of the Dapr runtime to upgrade or downgrade to, for example: 1.0.0")
|
||||||
|
UpgradeCmd.Flags().StringVarP(&upgradeDashboardVersion, "dashboard-version", "", "", "The version of the Dapr dashboard to upgrade or downgrade to, for example: 0.13.0")
|
||||||
UpgradeCmd.Flags().BoolP("help", "h", false, "Print this help message")
|
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)")
|
UpgradeCmd.Flags().StringArrayVar(&values, "set", []string{}, "set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
|
||||||
UpgradeCmd.Flags().String("image-registry", "", "Custom/Private docker image repository URL")
|
UpgradeCmd.Flags().String("image-registry", "", "Custom/Private docker image repository URL")
|
||||||
|
|
|
@ -37,12 +37,14 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
daprReleaseName = "dapr"
|
daprReleaseName = "dapr"
|
||||||
|
dashboardReleaseName = "dapr-dashboard"
|
||||||
daprHelmRepo = "https://dapr.github.io/helm-charts"
|
daprHelmRepo = "https://dapr.github.io/helm-charts"
|
||||||
latestVersion = "latest"
|
latestVersion = "latest"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InitConfiguration struct {
|
type InitConfiguration struct {
|
||||||
Version string
|
Version string
|
||||||
|
DashboardVersion string
|
||||||
Namespace string
|
Namespace string
|
||||||
EnableMTLS bool
|
EnableMTLS bool
|
||||||
EnableHA bool
|
EnableHA bool
|
||||||
|
@ -58,15 +60,38 @@ type InitConfiguration struct {
|
||||||
|
|
||||||
// Init deploys the Dapr operator using the supplied runtime version.
|
// Init deploys the Dapr operator using the supplied runtime version.
|
||||||
func Init(config InitConfiguration) error {
|
func Init(config InitConfiguration) error {
|
||||||
msg := "Deploying the Dapr control plane to your cluster..."
|
err := installWithConsole(daprReleaseName, config.Version, "Dapr control plane", config)
|
||||||
|
if err != nil {
|
||||||
stopSpinning := print.Spinner(os.Stdout, msg)
|
|
||||||
defer stopSpinning(print.Failure)
|
|
||||||
if err := install(config); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
stopSpinning(print.Success)
|
for _, dashboardClusterRole := range []string{"dashboard-reader", "dapr-dashboard"} {
|
||||||
|
// Detect Dapr Dashboard using a cluster-level resource (not dependent on namespace).
|
||||||
|
_, err = utils.RunCmdAndWait("kubectl", "describe", "clusterrole", dashboardClusterRole)
|
||||||
|
if err == nil {
|
||||||
|
// No need to install Dashboard since it is already present.
|
||||||
|
// Charts for versions < 1.11 contain Dashboard already.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = installWithConsole(dashboardReleaseName, config.DashboardVersion, "Dapr dashboard", config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func installWithConsole(releaseName string, releaseVersion string, prettyName string, config InitConfiguration) error {
|
||||||
|
installSpinning := print.Spinner(os.Stdout, "Deploying the "+prettyName+" with "+releaseVersion+" version to your cluster...")
|
||||||
|
defer installSpinning(print.Failure)
|
||||||
|
|
||||||
|
err := install(releaseName, releaseVersion, config)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
installSpinning(print.Success)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -96,16 +121,23 @@ func helmConfig(namespace string) (*helm.Configuration, error) {
|
||||||
return &ac, err
|
return &ac, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func getVersion(version string) (string, error) {
|
func getVersion(releaseName string, version string) (string, error) {
|
||||||
|
actualVersion := version
|
||||||
if version == latestVersion {
|
if version == latestVersion {
|
||||||
var err error
|
var err error
|
||||||
version, err = cli_ver.GetDaprVersion()
|
if releaseName == daprReleaseName {
|
||||||
|
actualVersion, err = cli_ver.GetDaprVersion()
|
||||||
|
} else if releaseName == dashboardReleaseName {
|
||||||
|
actualVersion, err = cli_ver.GetDashboardVersion()
|
||||||
|
} else {
|
||||||
|
return "", fmt.Errorf("cannot get latest version for unknown chart: %s", releaseName)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("cannot get the latest release version: %w", err)
|
return "", fmt.Errorf("cannot get the latest release version: %w", err)
|
||||||
}
|
}
|
||||||
version = strings.TrimPrefix(version, "v")
|
actualVersion = strings.TrimPrefix(actualVersion, "v")
|
||||||
}
|
}
|
||||||
return version, nil
|
return actualVersion, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTempDir() (string, error) {
|
func createTempDir() (string, error) {
|
||||||
|
@ -124,7 +156,7 @@ func locateChartFile(dirPath string) (string, error) {
|
||||||
return filepath.Join(dirPath, files[0].Name()), nil
|
return filepath.Join(dirPath, files[0].Name()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func daprChart(version string, config *helm.Configuration) (*chart.Chart, error) {
|
func daprChart(version string, releaseName string, config *helm.Configuration) (*chart.Chart, error) {
|
||||||
pull := helm.NewPullWithOpts(helm.WithConfig(config))
|
pull := helm.NewPullWithOpts(helm.WithConfig(config))
|
||||||
pull.RepoURL = utils.GetEnv("DAPR_HELM_REPO_URL", daprHelmRepo)
|
pull.RepoURL = utils.GetEnv("DAPR_HELM_REPO_URL", daprHelmRepo)
|
||||||
pull.Username = utils.GetEnv("DAPR_HELM_REPO_USERNAME", "")
|
pull.Username = utils.GetEnv("DAPR_HELM_REPO_USERNAME", "")
|
||||||
|
@ -132,7 +164,7 @@ func daprChart(version string, config *helm.Configuration) (*chart.Chart, error)
|
||||||
|
|
||||||
pull.Settings = &cli.EnvSettings{}
|
pull.Settings = &cli.EnvSettings{}
|
||||||
|
|
||||||
if version != latestVersion {
|
if version != latestVersion && releaseName == daprReleaseName {
|
||||||
pull.Version = chartVersion(version)
|
pull.Version = chartVersion(version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +176,7 @@ func daprChart(version string, config *helm.Configuration) (*chart.Chart, error)
|
||||||
|
|
||||||
pull.DestDir = dir
|
pull.DestDir = dir
|
||||||
|
|
||||||
_, err = pull.Run(daprReleaseName)
|
_, err = pull.Run(releaseName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -195,7 +227,7 @@ func chartValues(config InitConfiguration, version string) (map[string]interface
|
||||||
return chartVals, nil
|
return chartVals, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func install(config InitConfiguration) error {
|
func install(releaseName string, releaseVersion string, config InitConfiguration) error {
|
||||||
err := createNamespace(config.Namespace)
|
err := createNamespace(config.Namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -206,23 +238,25 @@ func install(config InitConfiguration) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
daprChart, err := daprChart(config.Version, helmConf)
|
daprChart, err := daprChart(releaseVersion, releaseName, helmConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
version, err := getVersion(config.Version)
|
version, err := getVersion(releaseName, releaseVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if releaseName == daprReleaseName {
|
||||||
err = applyCRDs(fmt.Sprintf("v%s", version))
|
err = applyCRDs(fmt.Sprintf("v%s", version))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
installClient := helm.NewInstall(helmConf)
|
installClient := helm.NewInstall(helmConf)
|
||||||
installClient.ReleaseName = daprReleaseName
|
installClient.ReleaseName = releaseName
|
||||||
installClient.Namespace = config.Namespace
|
installClient.Namespace = config.Namespace
|
||||||
installClient.Wait = config.Wait
|
installClient.Wait = config.Wait
|
||||||
installClient.Timeout = time.Duration(config.Timeout) * time.Second
|
installClient.Timeout = time.Duration(config.Timeout) * time.Second
|
||||||
|
@ -235,6 +269,7 @@ func install(config InitConfiguration) error {
|
||||||
if _, err = installClient.Run(daprChart, values); err != nil {
|
if _, err = installClient.Run(daprChart, values); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ func renewCertificate(rootCert, issuerCert, issuerKey []byte, timeout uint, imag
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
daprChart, err := daprChart(daprVersion, helmConf)
|
daprChart, err := daprChart(daprVersion, "dapr", helmConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,12 @@ func Uninstall(namespace string, uninstallAll bool, timeout uint) error {
|
||||||
|
|
||||||
uninstallClient := helm.NewUninstall(config)
|
uninstallClient := helm.NewUninstall(config)
|
||||||
uninstallClient.Timeout = time.Duration(timeout) * time.Second
|
uninstallClient.Timeout = time.Duration(timeout) * time.Second
|
||||||
|
|
||||||
|
// Uninstall Dashboard as a best effort.
|
||||||
|
// Chart versions < 1.11 for Dapr will delete dashboard as part of the main chart.
|
||||||
|
// Deleting Dashboard here is for versions >= 1.11.
|
||||||
|
uninstallClient.Run(dashboardReleaseName)
|
||||||
|
|
||||||
_, err = uninstallClient.Run(daprReleaseName)
|
_, err = uninstallClient.Run(daprReleaseName)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
helm "helm.sh/helm/v3/pkg/action"
|
helm "helm.sh/helm/v3/pkg/action"
|
||||||
|
"helm.sh/helm/v3/pkg/chart"
|
||||||
"k8s.io/helm/pkg/strvals"
|
"k8s.io/helm/pkg/strvals"
|
||||||
|
|
||||||
"github.com/hashicorp/go-version"
|
"github.com/hashicorp/go-version"
|
||||||
|
@ -46,6 +47,7 @@ var crdsFullResources = []string{
|
||||||
|
|
||||||
type UpgradeConfig struct {
|
type UpgradeConfig struct {
|
||||||
RuntimeVersion string
|
RuntimeVersion string
|
||||||
|
DashboardVersion string
|
||||||
Args []string
|
Args []string
|
||||||
Timeout uint
|
Timeout uint
|
||||||
ImageRegistryURI string
|
ImageRegistryURI string
|
||||||
|
@ -66,11 +68,19 @@ func Upgrade(conf UpgradeConfig) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
daprChart, err := daprChart(conf.RuntimeVersion, helmConf)
|
controlPlaneChart, err := daprChart(conf.RuntimeVersion, "dapr", helmConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dashboardChart *chart.Chart
|
||||||
|
if conf.DashboardVersion != "" {
|
||||||
|
dashboardChart, err = daprChart(conf.DashboardVersion, "dapr-dashboard", helmConf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
upgradeClient := helm.NewUpgrade(helmConf)
|
upgradeClient := helm.NewUpgrade(helmConf)
|
||||||
upgradeClient.ResetValues = true
|
upgradeClient.ResetValues = true
|
||||||
upgradeClient.Namespace = status[0].Namespace
|
upgradeClient.Namespace = status[0].Namespace
|
||||||
|
@ -121,9 +131,16 @@ func Upgrade(conf UpgradeConfig) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = upgradeClient.Run(chart, daprChart, vals); err != nil {
|
if _, err = upgradeClient.Run(chart, controlPlaneChart, vals); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dashboardChart != nil {
|
||||||
|
if _, err = upgradeClient.Run(chart, dashboardChart, vals); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,12 @@ func GetLatestReleaseHelmChart(helmChartURL string) (string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Did not find a non-rc version, so we fallback to an RC.
|
||||||
|
// This is helpful to allow us to validate installation of new charts (Dashboard).
|
||||||
|
for _, release := range helmChartReleases.Entries.Dapr {
|
||||||
|
return release.Version, nil
|
||||||
|
}
|
||||||
|
|
||||||
return "", fmt.Errorf("no releases")
|
return "", fmt.Errorf("no releases")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,8 +213,8 @@ func TestGetVersionsHelm(t *testing.T) {
|
||||||
ExpectedVer string
|
ExpectedVer string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"RC releases are skipped",
|
"Use RC releases if there isn't a full release yet",
|
||||||
"/rcs_are_skipped",
|
"/fallback_to_rc",
|
||||||
`apiVersion: v1
|
`apiVersion: v1
|
||||||
entries:
|
entries:
|
||||||
dapr:
|
dapr:
|
||||||
|
@ -268,8 +268,8 @@ entries:
|
||||||
urls:
|
urls:
|
||||||
- https://dapr.github.io/helm-charts/dapr-1.2.3-rc.1.tgz
|
- https://dapr.github.io/helm-charts/dapr-1.2.3-rc.1.tgz
|
||||||
version: 1.2.3-rc.1 `,
|
version: 1.2.3-rc.1 `,
|
||||||
"no releases",
|
|
||||||
"",
|
"",
|
||||||
|
"1.2.3-rc.1",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
m := http.NewServeMux()
|
m := http.NewServeMux()
|
||||||
|
|
Loading…
Reference in New Issue