Skip to content

Commit

Permalink
support assign specified dashboard version for init (#535)
Browse files Browse the repository at this point in the history
Signed-off-by: luhualin <n.betula.lu@gmail.com>

Co-authored-by: root <root@nvm-ops-image-lnx-1>
  • Loading branch information
Betula-L and root authored Jan 25, 2021
1 parent 7cf8fad commit 49afc98
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
10 changes: 5 additions & 5 deletions cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const (
)

var (
dashboardNamespace string
dashboardLocalPort int
dashboardVersion bool
dashboardNamespace string
dashboardLocalPort int
dashboardVersionCmd bool
)

var DashboardCmd = &cobra.Command{
Expand All @@ -60,7 +60,7 @@ dapr dashboard -k
dapr dashboard -k -p 9999
`,
Run: func(cmd *cobra.Command, args []string) {
if dashboardVersion {
if dashboardVersionCmd {
fmt.Println(standalone.GetDashboardVersion())
os.Exit(0)
}
Expand Down Expand Up @@ -166,7 +166,7 @@ dapr dashboard -k -p 9999

func init() {
DashboardCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "Opens Dapr dashboard in local browser via local proxy to Kubernetes cluster")
DashboardCmd.Flags().BoolVarP(&dashboardVersion, "version", "v", false, "Print the version for Dapr dashboard")
DashboardCmd.Flags().BoolVarP(&dashboardVersionCmd, "version", "v", false, "Print the version for Dapr dashboard")
DashboardCmd.Flags().IntVarP(&dashboardLocalPort, "port", "p", defaultLocalPort, "The local port on which to serve Dapr dashboard")
DashboardCmd.Flags().StringVarP(&dashboardNamespace, "namespace", "n", daprSystemNamespace, "The namespace where Dapr dashboard is running")
DashboardCmd.Flags().BoolP("help", "h", false, "Print this help message")
Expand Down
18 changes: 10 additions & 8 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ import (
)

var (
kubernetesMode bool
slimMode bool
runtimeVersion string
initNamespace string
enableMTLS bool
enableHA bool
values []string
kubernetesMode bool
slimMode bool
runtimeVersion string
dashboardVersion string
initNamespace string
enableMTLS bool
enableHA bool
values []string
)

var InitCmd = &cobra.Command{
Expand Down Expand Up @@ -74,7 +75,7 @@ dapr init -s
if !slimMode {
dockerNetwork = viper.GetString("network")
}
err := standalone.Init(runtimeVersion, dockerNetwork, slimMode)
err := standalone.Init(runtimeVersion, dashboardVersion, dockerNetwork, slimMode)
if err != nil {
print.FailureStatusEvent(os.Stdout, err.Error())
return
Expand All @@ -88,6 +89,7 @@ func init() {
InitCmd.Flags().BoolVarP(&kubernetesMode, "kubernetes", "k", false, "Deploy Dapr to a Kubernetes cluster")
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")
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(&enableHA, "enable-ha", "", false, "Enable high availability (HA) mode")
Expand Down
8 changes: 4 additions & 4 deletions pkg/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import (
)

const (
daprReleaseName = "dapr"
daprHelmRepo = "https://dapr.github.io/helm-charts"
daprLatestVersion = "latest"
daprReleaseName = "dapr"
daprHelmRepo = "https://dapr.github.io/helm-charts"
latestVersion = "latest"
)

type InitConfiguration struct {
Expand Down Expand Up @@ -116,7 +116,7 @@ func daprChart(version string, config *helm.Configuration) (*chart.Chart, error)
pull.RepoURL = daprHelmRepo
pull.Settings = &cli.EnvSettings{}

if version != daprLatestVersion {
if version != latestVersion {
pull.Version = chartVersion(version)
}

Expand Down
35 changes: 21 additions & 14 deletions pkg/standalone/standalone.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ const (
dashboardFilePrefix = "dashboard"
placementServiceFilePrefix = "placement"
daprWindowsOS = "windows"
daprLatestVersion = "latest"
dashboardLatestVersion = "latest"
latestVersion = "latest"
daprDefaultHost = "localhost"
pubSubYamlFileName = "pubsub.yaml"
stateStoreYamlFileName = "statestore.yaml"
Expand Down Expand Up @@ -99,7 +98,7 @@ func isBinaryInstallationRequired(binaryFilePrefix, installDir string) (bool, er
}

// Init installs Dapr on a local machine using the supplied runtimeVersion.
func Init(runtimeVersion string, dockerNetwork string, slimMode bool) error {
func Init(runtimeVersion, dashboardVersion string, dockerNetwork string, slimMode bool) error {
if !slimMode {
dockerInstalled := utils.IsDockerInstalled()
if !dockerInstalled {
Expand Down Expand Up @@ -156,7 +155,7 @@ func Init(runtimeVersion string, dockerNetwork string, slimMode bool) error {
go installBinary(&wg, errorChan, daprBinDir, runtimeVersion, daprRuntimeFilePrefix, dockerNetwork, cli_ver.DaprGitHubRepo)

// Initialize dashboard binary
go installBinary(&wg, errorChan, daprBinDir, dashboardLatestVersion, dashboardFilePrefix, dockerNetwork, cli_ver.DashboardGitHubRepo)
go installBinary(&wg, errorChan, daprBinDir, dashboardVersion, dashboardFilePrefix, dockerNetwork, cli_ver.DashboardGitHubRepo)

if slimMode {
// Initialize placement binary only on slim install
Expand Down Expand Up @@ -380,7 +379,7 @@ func runPlacementService(wg *sync.WaitGroup, errorChan chan<- error, dir, versio
image := fmt.Sprintf("%s:%s", daprDockerImageName, version)

// Use only image for latest version
if version == daprLatestVersion {
if version == latestVersion {
image = daprDockerImageName
}

Expand Down Expand Up @@ -462,6 +461,18 @@ func moveDashboardFiles(extractedFilePath string, dir string) (string, error) {
return extractedFilePath, nil
}

func overrideLastestVersion(version, repo string) (string, error) {
if version == latestVersion {
var err error
version, err = cli_ver.GetLatestRelease(cli_ver.DaprGitHubOrg, repo)
if err != nil {
return "", fmt.Errorf("cannot get the latest release version: %s", err)
}
version = version[1:]
}
return version, nil
}

func installBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version, binaryFilePrefix string, dockerNetwork string, githubRepo string) {
defer wg.Done()

Expand All @@ -471,21 +482,17 @@ func installBinary(wg *sync.WaitGroup, errorChan chan<- error, dir, version, bin
archiveExt = "zip"
}

if version == daprLatestVersion {
var err error
version, err = cli_ver.GetLatestRelease(cli_ver.DaprGitHubOrg, githubRepo)
if err != nil {
errorChan <- fmt.Errorf("cannot get the latest release version: %s", err)
return
}
version = version[1:]
v, err := overrideLastestVersion(version, githubRepo)
if err != nil {
errorChan <- err
return
}

fileURL := fmt.Sprintf(
"https://github.com/%s/%s/releases/download/v%s/%s_%s_%s.%s",
cli_ver.DaprGitHubOrg,
githubRepo,
version,
v,
binaryFilePrefix,
runtime.GOOS,
runtime.GOARCH,
Expand Down

0 comments on commit 49afc98

Please sign in to comment.