Skip to content

Commit 205332c

Browse files
committed
Air-gapped environment
Signed-off-by: ytimocin <[email protected]>
1 parent 3111acf commit 205332c

File tree

3 files changed

+143
-12
lines changed

3 files changed

+143
-12
lines changed

pkg/cli/cmd/install/kubernetes/kubernetes.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,19 @@ rad install kubernetes --reinstall
7575

7676
commonflags.AddKubeContextFlagVar(cmd, &runner.KubeContext)
7777
cmd.Flags().BoolVar(&runner.Reinstall, "reinstall", false, "Specify to force reinstallation of Radius")
78+
7879
cmd.Flags().StringVar(&runner.Chart, "chart", "", "Specify a file path to a helm chart to install Radius from")
7980
cmd.Flags().StringArrayVar(&runner.Set, "set", []string{}, "Set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
8081
cmd.Flags().StringArrayVar(&runner.SetFile, "set-file", []string{}, "Set values from files on the command line (can specify multiple or separate files with commas: key1=filename1,key2=filename2)")
8182

83+
cmd.Flags().StringVar(&runner.ContourChart, "contour-chart", "", "Specify a local file path to a helm chart to install Contour from")
84+
cmd.Flags().StringArrayVar(&runner.ContourSet, "contour-set", []string{}, "Set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
85+
cmd.Flags().StringArrayVar(&runner.ContourSetFile, "contour-set-file", []string{}, "Set values from files on the command line (can specify multiple or separate files with commas: key1=filename1,key2=filename2)")
86+
87+
cmd.Flags().StringVar(&runner.DaprChart, "dapr-chart", "", "Specify a local file path to a helm chart to install Dapr from")
88+
cmd.Flags().StringArrayVar(&runner.DaprSet, "dapr-set", []string{}, "Set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2)")
89+
cmd.Flags().StringArrayVar(&runner.DaprSetFile, "dapr-set-file", []string{}, "Set values from files on the command line (can specify multiple or separate files with commas: key1=filename1,key2=filename2)")
90+
8291
return cmd, runner
8392
}
8493

@@ -88,10 +97,23 @@ type Runner struct {
8897
Output output.Interface
8998

9099
KubeContext string
91-
Chart string
92-
Reinstall bool
93-
Set []string
94-
SetFile []string
100+
101+
// Radius
102+
Chart string
103+
Set []string
104+
SetFile []string
105+
106+
// Contour
107+
ContourChart string
108+
ContourSet []string
109+
ContourSetFile []string
110+
111+
// Dapr
112+
DaprChart string
113+
DaprSet []string
114+
DaprSetFile []string
115+
116+
Reinstall bool
95117
}
96118

97119
// NewRunner creates an instance of the runner for the `rad install kubernetes` command.
@@ -125,6 +147,16 @@ func (r *Runner) Run(ctx context.Context) error {
125147
SetArgs: r.Set,
126148
SetFileArgs: r.SetFile,
127149
},
150+
Contour: helm.ContourOptions{
151+
ChartPath: r.ContourChart,
152+
SetArgs: r.ContourSet,
153+
SetFileArgs: r.ContourSetFile,
154+
},
155+
Dapr: helm.ChartOptions{
156+
ChartPath: r.DaprChart,
157+
SetArgs: r.DaprSet,
158+
SetFileArgs: r.DaprSetFile,
159+
},
128160
}
129161

130162
state, err := r.Helm.CheckRadiusInstall(r.KubeContext)

pkg/cli/helm/cluster.go

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ const (
3636
)
3737

3838
type CLIClusterOptions struct {
39-
Radius ChartOptions
39+
Radius ChartOptions
40+
Contour ContourOptions
41+
Dapr ChartOptions
4042
}
4143

4244
type ClusterOptions struct {
43-
Contour ContourOptions
4445
Radius ChartOptions
46+
Contour ContourOptions
4547
Dapr ChartOptions
4648
}
4749

@@ -64,6 +66,7 @@ func NewDefaultClusterOptions() ClusterOptions {
6466
return ClusterOptions{
6567
Contour: ContourOptions{
6668
ChartVersion: ContourChartDefaultVersion,
69+
ChartRepo: contourHelmRepo,
6770
},
6871
Radius: ChartOptions{
6972
ChartVersion: chartVersion,
@@ -85,7 +88,7 @@ func NewDefaultClusterOptions() ClusterOptions {
8588
func PopulateDefaultClusterOptions(cliOptions CLIClusterOptions) ClusterOptions {
8689
options := NewDefaultClusterOptions()
8790

88-
// If any of the CLI options are provided, override the default options.
91+
// If any of the Radius CLI options are provided, override the default options.
8992
if cliOptions.Radius.Reinstall {
9093
options.Radius.Reinstall = cliOptions.Radius.Reinstall
9194
}
@@ -94,6 +97,10 @@ func PopulateDefaultClusterOptions(cliOptions CLIClusterOptions) ClusterOptions
9497
options.Radius.ChartPath = cliOptions.Radius.ChartPath
9598
}
9699

100+
if cliOptions.Radius.ChartRepo != "" {
101+
options.Radius.ChartRepo = cliOptions.Radius.ChartRepo
102+
}
103+
97104
if len(cliOptions.Radius.SetArgs) > 0 {
98105
options.Radius.SetArgs = cliOptions.Radius.SetArgs
99106
}
@@ -102,6 +109,48 @@ func PopulateDefaultClusterOptions(cliOptions CLIClusterOptions) ClusterOptions
102109
options.Radius.SetFileArgs = cliOptions.Radius.SetFileArgs
103110
}
104111

112+
// Apply Contour overrides
113+
if cliOptions.Contour.ChartVersion != "" {
114+
options.Contour.ChartVersion = cliOptions.Contour.ChartVersion
115+
}
116+
117+
if cliOptions.Contour.ChartRepo != "" {
118+
options.Contour.ChartRepo = cliOptions.Contour.ChartRepo
119+
}
120+
121+
if cliOptions.Contour.ChartPath != "" {
122+
options.Contour.ChartPath = cliOptions.Contour.ChartPath
123+
}
124+
125+
if len(cliOptions.Contour.SetArgs) > 0 {
126+
options.Contour.SetArgs = cliOptions.Contour.SetArgs
127+
}
128+
129+
if len(cliOptions.Contour.SetFileArgs) > 0 {
130+
options.Contour.SetFileArgs = cliOptions.Contour.SetFileArgs
131+
}
132+
133+
// Apply Dapr overrides
134+
if cliOptions.Dapr.ChartRepo != "" {
135+
options.Dapr.ChartRepo = cliOptions.Dapr.ChartRepo
136+
}
137+
138+
if cliOptions.Dapr.ChartVersion != "" {
139+
options.Dapr.ChartVersion = cliOptions.Dapr.ChartVersion
140+
}
141+
142+
if cliOptions.Dapr.ChartPath != "" {
143+
options.Dapr.ChartPath = cliOptions.Dapr.ChartPath
144+
}
145+
146+
if len(cliOptions.Dapr.SetArgs) > 0 {
147+
options.Dapr.SetArgs = cliOptions.Dapr.SetArgs
148+
}
149+
150+
if len(cliOptions.Dapr.SetFileArgs) > 0 {
151+
options.Dapr.SetFileArgs = cliOptions.Dapr.SetFileArgs
152+
}
153+
105154
return options
106155
}
107156

pkg/cli/helm/contourclient.go

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ import (
2020
_ "embed"
2121
"errors"
2222
"fmt"
23+
"os"
24+
"path/filepath"
25+
"runtime"
2326
"strings"
2427

2528
helm "helm.sh/helm/v3/pkg/action"
2629
"helm.sh/helm/v3/pkg/chart"
30+
"helm.sh/helm/v3/pkg/chart/loader"
2731
"helm.sh/helm/v3/pkg/storage/driver"
32+
"helm.sh/helm/v3/pkg/strvals"
2833
"k8s.io/cli-runtime/pkg/genericclioptions"
2934

3035
"github.com/radius-project/radius/pkg/cli/output"
@@ -36,11 +41,15 @@ const (
3641
)
3742

3843
type ContourOptions struct {
44+
ChartRepo string
45+
ChartPath string
3946
ChartVersion string
4047
HostNetwork bool
48+
SetArgs []string
49+
SetFileArgs []string
4150
}
4251

43-
// // ApplyContourHelmChart checks if a Contour Helm chart has been installed, and if not, installs it with the given
52+
// ApplyContourHelmChart checks if a Contour Helm chart has been installed, and if not, installs it with the given
4453
// options. If an error occurs, it returns an error with the Helm output.
4554
func ApplyContourHelmChart(options ContourOptions, kubeContext string) error {
4655
// For capturing output from helm.
@@ -56,9 +65,24 @@ func ApplyContourHelmChart(options ContourOptions, kubeContext string) error {
5665
return fmt.Errorf("failed to get helm config, err: %w, helm output: %s", err, helmOutput.String())
5766
}
5867

59-
helmChart, err := helmChartFromContainerRegistry(options.ChartVersion, helmConf, contourHelmRepo, contourReleaseName)
60-
if err != nil {
61-
return fmt.Errorf("failed to get contour chart, err: %w, helm output: %s", err, helmOutput.String())
68+
var helmChart *chart.Chart
69+
if options.ChartPath == "" {
70+
// Use provided repo URL if available, otherwise use default
71+
repo := options.ChartRepo
72+
if repo == "" {
73+
repo = contourHelmRepo
74+
}
75+
76+
helmChart, err = helmChartFromContainerRegistry(options.ChartVersion, helmConf, repo, contourReleaseName)
77+
if err != nil {
78+
return fmt.Errorf("failed to load contour chart, err: %w, helm output: %s", err, helmOutput.String())
79+
}
80+
} else {
81+
// Load chart from local path
82+
helmChart, err = loader.Load(options.ChartPath)
83+
if err != nil {
84+
return fmt.Errorf("failed to load contour chart, err: %w, helm output: %s", err, helmOutput.String())
85+
}
6286
}
6387

6488
// https://helm.sh/docs/chart_best_practices/custom_resource_definitions/#method-1-let-helm-do-it-for-you
@@ -93,10 +117,36 @@ func ApplyContourHelmChart(options ContourOptions, kubeContext string) error {
93117
// LoadBalancer service ports to 8080 and 8443 so that they don't conflict with Envoy while using Host Networking. It
94118
// returns an error if any of the nodes in the chart values are not found.
95119
func AddContourValues(helmChart *chart.Chart, options ContourOptions) error {
120+
values := helmChart.Values
121+
122+
// Parse --set arguments in order so that the last one wins.
123+
for _, arg := range options.SetArgs {
124+
err := strvals.ParseInto(arg, values)
125+
if err != nil {
126+
return err
127+
}
128+
}
129+
130+
for _, arg := range options.SetFileArgs {
131+
if runtime.GOOS == "windows" {
132+
arg = filepath.ToSlash(arg)
133+
}
134+
135+
reader := func(rs []rune) (any, error) {
136+
data, err := os.ReadFile(string(rs))
137+
return string(data), err
138+
}
139+
140+
err := strvals.ParseIntoFile(arg, values, reader)
141+
if err != nil {
142+
return err
143+
}
144+
}
145+
96146
if options.HostNetwork {
97147
// https://projectcontour.io/docs/main/deploy-options/#host-networking
98148
// https://github.com/bitnami/charts/blob/7550513a4f491bb999f95027a7bfcc35ff076c33/bitnami/contour/values.yaml#L605
99-
envoyNode := helmChart.Values["envoy"].(map[string]any)
149+
envoyNode := values["envoy"].(map[string]any)
100150
if envoyNode == nil {
101151
return fmt.Errorf("envoy node not found in chart values")
102152
}

0 commit comments

Comments
 (0)