Skip to content

Commit

Permalink
Installing the Dapr Helm Chart via the CLI (#8033)
Browse files Browse the repository at this point in the history
# Description

Installing the Dapr Helm Chart via the CLI

## Type of change

- This pull request adds a feature to install Dapr to its own namespace
by using the rad cli.

Fixes: #8032 

## Contributor checklist
Please verify that the PR meets the following requirements, where
applicable:

- [X] An overview of proposed schema changes is included in a linked
GitHub issue.
- [ ] A design document PR is created in the [design-notes
repository](https://github.com/radius-project/design-notes/), if new
APIs are being introduced.
- [ ] If applicable, design document has been reviewed and approved by
Radius maintainers/approvers.
- [ N/R ] A PR for the [samples
repository](https://github.com/radius-project/samples) is created, if
existing samples are affected by the changes in this PR.
- [ N/R ] A PR for the [documentation
repository](https://github.com/radius-project/docs) is created, if the
changes in this PR affect the documentation or any user facing updates
are made.
- [ N/R ] A PR for the [recipes
repository](https://github.com/radius-project/recipes) is created, if
existing recipes are affected by the changes in this PR.

---------

Signed-off-by: Nick Beenham <[email protected]>
  • Loading branch information
superbeeny authored Nov 21, 2024
1 parent 728f64e commit 9650406
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 130 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/functional-test-cloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ env:
HELM_VER: "v3.12.0"
# KinD cluster version
KIND_VER: "v0.20.0"
# Dapr version
DAPR_VER: "1.12.0"
DAPR_DASHBOARD_VER: "0.14.0"
# Kubectl version
KUBECTL_VER: "v1.25.0"
# Azure Keyvault CSI driver chart version
Expand Down Expand Up @@ -595,10 +592,6 @@ jobs:
service-account-private-key-file: /etc/kubernetes/pki/sa.key
EOF
- name: Install dapr into cluster
run: |
wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash -s ${{ env.DAPR_VER }}
dapr init -k --wait --timeout 600 --runtime-version ${{ env.DAPR_VER }} --dashboard-version ${{ env.DAPR_DASHBOARD_VER }}
- name: Install Azure Keyvault CSI driver chart
run: |
Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/functional-test-noncloud.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ env:
HELM_VER: "v3.15.3"
# KinD cluster version
KIND_VER: "v0.23.0"
# Dapr version
DAPR_VER: "1.12.0"
# Dapr dashboard version
DAPR_DASHBOARD_VER: "0.14.0"
# Kubectl version
KUBECTL_VER: "v1.30.0"

Expand Down Expand Up @@ -263,11 +259,6 @@ jobs:
registry-server: ${{ env.LOCAL_REGISTRY_SERVER }}
registry-port: ${{ env.LOCAL_REGISTRY_PORT }}

- name: Install dapr into cluster
run: |
wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash -s ${{ env.DAPR_VER }}
dapr init -k --wait --timeout 600 --runtime-version ${{ env.DAPR_VER }} --dashboard-version ${{ env.DAPR_DASHBOARD_VER }}
- name: Install Radius
run: |
export PATH=$GITHUB_WORKSPACE/bin:$PATH
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/cmd/install/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
// to the cli version. It then returns any errors that occur during the installation.
func (r *Runner) Run(ctx context.Context) error {
cliOptions := helm.CLIClusterOptions{
Radius: helm.RadiusOptions{
Radius: helm.ChartOptions{
Reinstall: r.Reinstall,
ChartPath: r.Chart,
SetArgs: r.Set,
Expand All @@ -132,13 +132,13 @@ func (r *Runner) Run(ctx context.Context) error {
return err
}

if state.Installed && !r.Reinstall {
if state.RadiusInstalled && !r.Reinstall {
r.Output.LogInfo("Found existing Radius installation. Use '--reinstall' to force reinstallation.")
return nil
}

version := version.Version()
if state.Installed {
if state.RadiusInstalled {
r.Output.LogInfo("Reinstalling Radius version %s to namespace: %s...", version, helm.RadiusSystemNamespace)
} else {
r.Output.LogInfo("Installing Radius version %s to namespace: %s...", version, helm.RadiusSystemNamespace)
Expand Down
8 changes: 4 additions & 4 deletions pkg/cli/cmd/install/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Test_Run(t *testing.T) {
Times(1)

expectedOptions := helm.PopulateDefaultClusterOptions(helm.CLIClusterOptions{
Radius: helm.RadiusOptions{
Radius: helm.ChartOptions{
ChartPath: "test-chart",
SetArgs: []string{"foo=bar", "bar=baz"},
},
Expand Down Expand Up @@ -109,7 +109,7 @@ func Test_Run(t *testing.T) {
}

helmMock.EXPECT().CheckRadiusInstall("test-context").
Return(helm.InstallState{Installed: true, Version: "test-version"}, nil).
Return(helm.InstallState{RadiusInstalled: true, RadiusVersion: "test-version"}, nil).
Times(1)

err := runner.Run(ctx)
Expand Down Expand Up @@ -139,11 +139,11 @@ func Test_Run(t *testing.T) {
}

helmMock.EXPECT().CheckRadiusInstall("test-context").
Return(helm.InstallState{Installed: true, Version: "test-version"}, nil).
Return(helm.InstallState{RadiusInstalled: true, RadiusVersion: "test-version"}, nil).
Times(1)

expectedOptions := helm.PopulateDefaultClusterOptions(helm.CLIClusterOptions{
Radius: helm.RadiusOptions{
Radius: helm.ChartOptions{
ChartPath: "test-chart",
SetArgs: []string{"foo=bar", "bar=baz"},
Reinstall: true,
Expand Down
6 changes: 3 additions & 3 deletions pkg/cli/cmd/radinit/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func (r *Runner) enterClusterOptions(options *initOptions) error {
if err != nil {
return clierrors.MessageWithCause(err, "Unable to verify Radius installation.")
}
options.Cluster.Install = !state.Installed
options.Cluster.Install = !state.RadiusInstalled || !state.DaprInstalled

if state.Installed {
if state.RadiusInstalled && state.DaprInstalled {
options.Cluster.Install = false
options.Cluster.Version = state.Version
options.Cluster.Version = state.RadiusVersion
}

if options.Cluster.Install {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/radinit/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (r *Runner) Run(ctx context.Context) error {

if r.Options.Cluster.Install {
cliOptions := helm.CLIClusterOptions{
Radius: helm.RadiusOptions{
Radius: helm.ChartOptions{
SetArgs: r.Options.SetValues,
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/cmd/radinit/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,13 +1064,13 @@ func initSelectCloudProvider(prompter *prompt.MockInterface, value string) {
func initHelmMockRadiusInstalled(helmMock *helm.MockInterface) {
helmMock.EXPECT().
CheckRadiusInstall(gomock.Any()).
Return(helm.InstallState{Installed: true, Version: "test-version"}, nil).Times(1)
Return(helm.InstallState{RadiusInstalled: true, RadiusVersion: "test-version", DaprInstalled: true, DaprVersion: "test-version"}, nil).Times(1)
}

func initHelmMockRadiusNotInstalled(helmMock *helm.MockInterface) {
helmMock.EXPECT().
CheckRadiusInstall(gomock.Any()).
Return(helm.InstallState{Installed: false}, nil).Times(1)
Return(helm.InstallState{RadiusInstalled: false}, nil).Times(1)
}

func setExistingEnvironments(clientMock *clients.MockApplicationsManagementClient, environments []corerp.EnvironmentResource) {
Expand Down
15 changes: 13 additions & 2 deletions pkg/cli/cmd/uninstall/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package kubernetes

import (
"context"

"github.com/radius-project/radius/pkg/cli/kubernetes"

"github.com/radius-project/radius/pkg/cli/cmd/commonflags"
Expand Down Expand Up @@ -91,13 +92,23 @@ func (r *Runner) Run(ctx context.Context) error {
if err != nil {
return err
}
if !state.Installed {
if !state.RadiusInstalled {
r.Output.LogInfo("Radius is not installed on the Kubernetes cluster")
return nil
}

r.Output.LogInfo("Uninstalling Radius...")
err = r.Helm.UninstallRadius(ctx, r.KubeContext)
err = r.Helm.UninstallRadius(ctx, helm.ClusterOptions{
Radius: helm.ChartOptions{
Namespace: helm.RadiusSystemNamespace,
ReleaseName: helm.NewDefaultClusterOptions().Radius.ReleaseName,
},
Dapr: helm.ChartOptions{
Namespace: helm.DaprSystemNamespace,
ReleaseName: helm.NewDefaultClusterOptions().Dapr.ReleaseName,
},
}, r.KubeContext)

if err != nil {
return err
}
Expand Down
31 changes: 25 additions & 6 deletions pkg/cli/cmd/uninstall/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ package kubernetes

import (
"context"
"github.com/radius-project/radius/pkg/cli/kubernetes"
"testing"

"github.com/radius-project/radius/pkg/cli/kubernetes"

"github.com/radius-project/radius/pkg/cli/helm"
"github.com/radius-project/radius/pkg/cli/output"
"github.com/radius-project/radius/test/radcli"
Expand Down Expand Up @@ -68,10 +69,19 @@ func Test_Run(t *testing.T) {
}

helmMock.EXPECT().CheckRadiusInstall("test-context").
Return(helm.InstallState{Installed: true, Version: "test-version"}, nil).
Return(helm.InstallState{RadiusInstalled: true, RadiusVersion: "test-version", DaprInstalled: true, DaprVersion: "test-version"}, nil).
Times(1)

helmMock.EXPECT().UninstallRadius(ctx, "test-context").
helmMock.EXPECT().UninstallRadius(ctx, helm.ClusterOptions{
Radius: helm.ChartOptions{
Namespace: "radius-system",
ReleaseName: "radius",
},
Dapr: helm.ChartOptions{
Namespace: "dapr-system",
ReleaseName: "dapr",
},
}, "test-context").
Return(nil).
Times(1)

Expand Down Expand Up @@ -116,7 +126,7 @@ func Test_Run(t *testing.T) {
}
require.Equal(t, expectedWrites, outputMock.Writes)
})
t.Run("Success: Installed -> Uninstalled -> Purge)", func(t *testing.T) {
t.Run("Success: Installed -> Uninstalled -> Purge", func(t *testing.T) {
ctrl := gomock.NewController(t)
helmMock := helm.NewMockInterface(ctrl)
outputMock := &output.MockOutput{}
Expand All @@ -133,10 +143,19 @@ func Test_Run(t *testing.T) {
}

helmMock.EXPECT().CheckRadiusInstall("test-context").
Return(helm.InstallState{Installed: true, Version: "test-version"}, nil).
Return(helm.InstallState{RadiusInstalled: true, RadiusVersion: "test-version", DaprInstalled: true, DaprVersion: "test-version"}, nil).
Times(1)

helmMock.EXPECT().UninstallRadius(ctx, "test-context").
helmMock.EXPECT().UninstallRadius(ctx, helm.ClusterOptions{
Radius: helm.ChartOptions{
Namespace: "radius-system",
ReleaseName: "radius",
},
Dapr: helm.ChartOptions{
Namespace: "dapr-system",
ReleaseName: "dapr",
},
}, "test-context").
Return(nil).
Times(1)

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/workspace/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
}

state, err := r.HelmInterface.CheckRadiusInstall(context)
if !state.Installed || err != nil {
if !state.RadiusInstalled || err != nil {
return fmt.Errorf("unable to create workspace %q. Radius control plane not installed on target platform. Run 'rad install' and try again", workspaceName)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/cli/cmd/workspace/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func Test_Validate(t *testing.T) {
ConfigureMocks: func(mocks radcli.ValidateMocks) {
// We have a valid kubernetes context, but Radius is not installed
mocks.Kubernetes.EXPECT().GetKubeContext().Return(getTestKubeConfig(), nil).Times(1)
mocks.Helm.EXPECT().CheckRadiusInstall(gomock.Any()).Return(helm.InstallState{Installed: false}, nil).Times(1)
mocks.Helm.EXPECT().CheckRadiusInstall(gomock.Any()).Return(helm.InstallState{RadiusInstalled: false}, nil).Times(1)
},
},
{
Expand All @@ -84,7 +84,7 @@ func Test_Validate(t *testing.T) {
ConfigureMocks: func(mocks radcli.ValidateMocks) {
// We have a valid kubernetes context with Radius installed
mocks.Kubernetes.EXPECT().GetKubeContext().Return(getTestKubeConfig(), nil).Times(1)
mocks.Helm.EXPECT().CheckRadiusInstall(gomock.Any()).Return(helm.InstallState{Installed: true}, nil).Times(1)
mocks.Helm.EXPECT().CheckRadiusInstall(gomock.Any()).Return(helm.InstallState{RadiusInstalled: true}, nil).Times(1)

// Resource group does not exist
mocks.ApplicationManagementClient.EXPECT().GetResourceGroup(gomock.Any(), "local", "rg1").Return(ucp.ResourceGroupResource{}, errors.New("group does not exist")).Times(1)
Expand All @@ -101,7 +101,7 @@ func Test_Validate(t *testing.T) {
ConfigureMocks: func(mocks radcli.ValidateMocks) {
// We have a valid kubernetes context with Radius installed
mocks.Kubernetes.EXPECT().GetKubeContext().Return(getTestKubeConfig(), nil).Times(1)
mocks.Helm.EXPECT().CheckRadiusInstall(gomock.Any()).Return(helm.InstallState{Installed: true}, nil).Times(1)
mocks.Helm.EXPECT().CheckRadiusInstall(gomock.Any()).Return(helm.InstallState{RadiusInstalled: true}, nil).Times(1)

// Resource group exists but environment does not
mocks.ApplicationManagementClient.EXPECT().GetResourceGroup(gomock.Any(), "local", "rg1").Return(ucp.ResourceGroupResource{}, nil).Times(1)
Expand All @@ -119,7 +119,7 @@ func Test_Validate(t *testing.T) {
ConfigureMocks: func(mocks radcli.ValidateMocks) {
// We have a valid kubernetes context with Radius installed
mocks.Kubernetes.EXPECT().GetKubeContext().Return(getTestKubeConfig(), nil).Times(1)
mocks.Helm.EXPECT().CheckRadiusInstall(gomock.Any()).Return(helm.InstallState{Installed: true}, nil).Times(1)
mocks.Helm.EXPECT().CheckRadiusInstall(gomock.Any()).Return(helm.InstallState{RadiusInstalled: true}, nil).Times(1)

// Resource group and environment exist
mocks.ApplicationManagementClient.EXPECT().GetResourceGroup(gomock.Any(), "local", "rg1").Return(ucp.ResourceGroupResource{}, nil).Times(1)
Expand Down
Loading

0 comments on commit 9650406

Please sign in to comment.