Skip to content

Commit e1dd9be

Browse files
authored
add 'pod-cidr' and 'service-cidr' install/restore flags (#728)
* add 'pod-cidr' and 'service-cidr' install/restore flags * f * add custom CIDR test * range sizes * skip more tests * change test IPs * f * f * +x * f * implement pod/service cidr check * set calico IP detection method to 'kubernetes internal ip' * that would be silly * induce test failure * wait for goldpinger properly * undo intentional breakage, enable multinode test * f * improve goldpinger wait failure case * add test combining custom CIDR and proxy * describe goldpinger pods on failure * wide output * update operator to v0.36.3 * update join command response * update pod CIDR on join * f * populate network in install * admin console image override * override service cidr * that was not the right solution * test with only worker nodes * return to testing with controllers * debug * f * k0s says this is a hack * skip join config overrides * join cidrs * remove cidr flag * slight refactor * 4 nodes for default cidr test * remove server certs on join to force regeneration * /etc/k0s/k0s.yaml * better /etc/k0s/k0s.yaml * f * cleanup and reenable tests * airgap upgrade test * use all additional args in airgap install * use proper IP range for registry service * operator fix for airgap installs * f * use released operator * override configs before joining node to cluster * cleanup unneeded comment * backup with different cidrs * what is this file * correct unmarshal function * ? * check installation object * ??? * ????? * are you kidding me * include custom CIDRs in restore command * support arbitrary args in restore-installation-airgap.exp * postmerge compile fixes * f * cfg passthrough * remove backup store validation for testing * fix --proxy flag * another test * what is being symlinked * where is this failing * areyoukiddingme * reenable backup store validation * ensure I'm creating the right cluster to begin with * operator image override * skip restoring installation to see if registry restores properly without it * remove ECO image override * update ECO again * use released operator version * small fixups * reenable all the tests * f * minor test cleanups * move non-proxied custom cidr test out of the proxy test file * use released kots v1.111.0
1 parent f1a0e01 commit e1dd9be

File tree

21 files changed

+634
-110
lines changed

21 files changed

+634
-110
lines changed

.github/workflows/pull-request.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ jobs:
212212
- TestMaterialize
213213
- TestLocalArtifactMirror
214214
- TestSingleNodeAirgapUpgrade
215+
- TestSingleNodeAirgapUpgradeCustomCIDR
215216
- TestInstallSnapshotFromReplicatedApp
216217
- TestMultiNodeAirgapUpgrade
217218
- TestSingleNodeDisasterRecovery
@@ -224,6 +225,8 @@ jobs:
224225
- TestProxiedEnvironment
225226
- TestMultiNodeHADisasterRecovery
226227
- TestMultiNodeAirgapHADisasterRecovery
228+
- TestCustomCIDR
229+
- TestProxiedCustomCIDR
227230
include:
228231
- test: TestMultiNodeAirgapUpgrade
229232
runner: embedded-cluster

.github/workflows/release-dev.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ jobs:
164164
- TestMaterialize
165165
- TestLocalArtifactMirror
166166
- TestSingleNodeAirgapUpgrade
167+
- TestSingleNodeAirgapUpgradeCustomCIDR
167168
- TestInstallSnapshotFromReplicatedApp
168169
- TestMultiNodeAirgapUpgrade
169170
- TestSingleNodeDisasterRecovery
@@ -176,6 +177,8 @@ jobs:
176177
- TestProxiedEnvironment
177178
- TestMultiNodeHADisasterRecovery
178179
- TestMultiNodeAirgapHADisasterRecovery
180+
- TestCustomCIDR
181+
- TestProxiedCustomCIDR
179182
include:
180183
- test: TestMultiNodeAirgapUpgrade
181184
runner: embedded-cluster

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ UNAME := $(shell uname)
33
ARCH := $(shell uname -m)
44
APP_NAME = embedded-cluster
55
ADMIN_CONSOLE_CHART_REPO_OVERRIDE =
6-
ADMIN_CONSOLE_CHART_VERSION = 1.109.13
6+
ADMIN_CONSOLE_CHART_VERSION = 1.111.0
77
ADMIN_CONSOLE_IMAGE_OVERRIDE =
88
ADMIN_CONSOLE_MIGRATIONS_IMAGE_OVERRIDE =
9-
EMBEDDED_OPERATOR_CHART_VERSION = 0.36.2
9+
EMBEDDED_OPERATOR_CHART_URL = oci://registry.replicated.com/library
10+
EMBEDDED_OPERATOR_CHART_NAME = embedded-cluster-operator
11+
EMBEDDED_OPERATOR_CHART_VERSION = 0.36.5
1012
EMBEDDED_OPERATOR_UTILS_IMAGE = busybox:1.36.1
1113
EMBEDDED_CLUSTER_OPERATOR_IMAGE_OVERRIDE =
1214
OPENEBS_CHART_VERSION = 4.1.0

cmd/embedded-cluster/install.go

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
11+
ecv1beta1 "github.com/replicatedhq/embedded-cluster-kinds/apis/v1beta1"
1112
"github.com/sirupsen/logrus"
1213
"github.com/urfave/cli/v2"
1314
k8syaml "sigs.k8s.io/yaml"
@@ -313,15 +314,21 @@ func materializeFiles(c *cli.Context) error {
313314
// createK0sConfig creates a new k0s.yaml configuration file. The file is saved in the
314315
// global location (as returned by defaults.PathToK0sConfig()). If a file already sits
315316
// there, this function returns an error.
316-
func ensureK0sConfig(c *cli.Context) error {
317+
func ensureK0sConfig(c *cli.Context) (*k0sconfig.ClusterConfig, error) {
317318
cfgpath := defaults.PathToK0sConfig()
318319
if _, err := os.Stat(cfgpath); err == nil {
319-
return fmt.Errorf("configuration file already exists")
320+
return nil, fmt.Errorf("configuration file already exists")
320321
}
321322
if err := os.MkdirAll(filepath.Dir(cfgpath), 0755); err != nil {
322-
return fmt.Errorf("unable to create directory: %w", err)
323+
return nil, fmt.Errorf("unable to create directory: %w", err)
323324
}
324325
cfg := config.RenderK0sConfig()
326+
if c.String("pod-cidr") != "" {
327+
cfg.Spec.Network.PodCIDR = c.String("pod-cidr")
328+
}
329+
if c.String("service-cidr") != "" {
330+
cfg.Spec.Network.ServiceCIDR = c.String("service-cidr")
331+
}
325332
opts := []addons.Option{}
326333
if c.Bool("no-prompt") {
327334
opts = append(opts, addons.WithoutPrompt())
@@ -333,17 +340,21 @@ func ensureK0sConfig(c *cli.Context) error {
333340
opts = append(opts, addons.WithAirgapBundle(ab))
334341
}
335342
if c.Bool("proxy") {
336-
opts = append(opts, addons.WithProxyFromEnv())
343+
opts = append(opts, addons.WithProxyFromEnv(cfg.Spec.Network.PodCIDR, cfg.Spec.Network.ServiceCIDR))
337344
}
338345
if c.String("http-proxy") != "" || c.String("https-proxy") != "" || c.String("no-proxy") != "" {
339-
opts = append(opts, addons.WithProxyFromArgs(c.String("http-proxy"), c.String("https-proxy"), c.String("no-proxy")))
346+
opts = append(opts, addons.WithProxyFromArgs(c.String("http-proxy"), c.String("https-proxy"), c.String("no-proxy"), cfg.Spec.Network.PodCIDR, cfg.Spec.Network.ServiceCIDR))
340347
}
348+
opts = append(opts, addons.WithNetwork(&ecv1beta1.NetworkSpec{
349+
PodCIDR: cfg.Spec.Network.PodCIDR,
350+
ServiceCIDR: cfg.Spec.Network.ServiceCIDR,
351+
}))
341352
if err := config.UpdateHelmConfigs(cfg, opts...); err != nil {
342-
return fmt.Errorf("unable to update helm configs: %w", err)
353+
return nil, fmt.Errorf("unable to update helm configs: %w", err)
343354
}
344355
var err error
345356
if cfg, err = applyUnsupportedOverrides(c, cfg); err != nil {
346-
return fmt.Errorf("unable to apply unsupported overrides: %w", err)
357+
return nil, fmt.Errorf("unable to apply unsupported overrides: %w", err)
347358
}
348359
if c.String("airgap-bundle") != "" {
349360
// update the k0s config to install with airgap
@@ -352,17 +363,18 @@ func ensureK0sConfig(c *cli.Context) error {
352363
}
353364
data, err := k8syaml.Marshal(cfg)
354365
if err != nil {
355-
return fmt.Errorf("unable to marshal config: %w", err)
366+
return nil, fmt.Errorf("unable to marshal config: %w", err)
356367
}
357368
fp, err := os.OpenFile(cfgpath, os.O_RDWR|os.O_CREATE, 0600)
358369
if err != nil {
359-
return fmt.Errorf("unable to create config file: %w", err)
370+
return nil, fmt.Errorf("unable to create config file: %w", err)
360371
}
361372
defer fp.Close()
362373
if _, err := fp.Write(data); err != nil {
363-
return fmt.Errorf("unable to write config file: %w", err)
374+
return nil, fmt.Errorf("unable to write config file: %w", err)
364375
}
365-
return nil
376+
377+
return cfg, nil
366378
}
367379

368380
// applyUnsupportedOverrides applies overrides to the k0s configuration. Applies first the
@@ -438,19 +450,20 @@ func waitForK0s() error {
438450
}
439451

440452
// installAndWaitForK0s installs the k0s binary and waits for it to be ready
441-
func installAndWaitForK0s(c *cli.Context) error {
453+
func installAndWaitForK0s(c *cli.Context) (*k0sconfig.ClusterConfig, error) {
442454
loading := spinner.Start()
443455
defer loading.Close()
444456
loading.Infof("Installing %s node", defaults.BinaryName())
445457
logrus.Debugf("creating k0s configuration file")
446-
if err := ensureK0sConfig(c); err != nil {
458+
cfg, err := ensureK0sConfig(c)
459+
if err != nil {
447460
err := fmt.Errorf("unable to create config file: %w", err)
448461
metrics.ReportApplyFinished(c, err)
449-
return err
462+
return nil, err
450463
}
451-
var proxy *Proxy
464+
var proxy *ecv1beta1.ProxySpec
452465
if c.String("http-proxy") != "" || c.String("https-proxy") != "" || c.String("no-proxy") != "" {
453-
proxy = &Proxy{
466+
proxy = &ecv1beta1.ProxySpec{
454467
HTTPProxy: c.String("http-proxy"),
455468
HTTPSProxy: c.String("https-proxy"),
456469
NoProxy: strings.Join(append(defaults.DefaultNoProxy, c.String("no-proxy")), ","),
@@ -460,28 +473,28 @@ func installAndWaitForK0s(c *cli.Context) error {
460473
if err := createSystemdUnitFiles(false, proxy); err != nil {
461474
err := fmt.Errorf("unable to create systemd unit files: %w", err)
462475
metrics.ReportApplyFinished(c, err)
463-
return err
476+
return nil, err
464477
}
465478

466479
logrus.Debugf("installing k0s")
467480
if err := installK0s(); err != nil {
468481
err := fmt.Errorf("unable update cluster: %w", err)
469482
metrics.ReportApplyFinished(c, err)
470-
return err
483+
return nil, err
471484
}
472485
loading.Infof("Waiting for %s node to be ready", defaults.BinaryName())
473486
logrus.Debugf("waiting for k0s to be ready")
474487
if err := waitForK0s(); err != nil {
475488
err := fmt.Errorf("unable to wait for node: %w", err)
476489
metrics.ReportApplyFinished(c, err)
477-
return err
490+
return nil, err
478491
}
479492
loading.Infof("Node installation finished!")
480-
return nil
493+
return cfg, nil
481494
}
482495

483496
// runOutro calls Outro() in all enabled addons by means of Applier.
484-
func runOutro(c *cli.Context, adminConsolePwd string) error {
497+
func runOutro(c *cli.Context, cfg *k0sconfig.ClusterConfig, adminConsolePwd string) error {
485498
os.Setenv("KUBECONFIG", defaults.PathToKubeConfig())
486499
opts := []addons.Option{}
487500

@@ -506,8 +519,12 @@ func runOutro(c *cli.Context, adminConsolePwd string) error {
506519
}
507520
opts = append(opts, addons.WithAdminConsolePassword(adminConsolePwd))
508521
if c.String("http-proxy") != "" || c.String("https-proxy") != "" || c.String("no-proxy") != "" {
509-
opts = append(opts, addons.WithProxyFromArgs(c.String("http-proxy"), c.String("https-proxy"), c.String("no-proxy")))
522+
opts = append(opts, addons.WithProxyFromArgs(c.String("http-proxy"), c.String("https-proxy"), c.String("no-proxy"), cfg.Spec.Network.PodCIDR, cfg.Spec.Network.ServiceCIDR))
510523
}
524+
opts = append(opts, addons.WithNetwork(&ecv1beta1.NetworkSpec{
525+
PodCIDR: cfg.Spec.Network.PodCIDR,
526+
ServiceCIDR: cfg.Spec.Network.ServiceCIDR,
527+
}))
511528
return addons.NewApplier(opts...).Outro(c.Context)
512529
}
513530

@@ -588,6 +605,16 @@ var installCommand = &cli.Command{
588605
Usage: "Use the system proxy settings for the install operation. These variables are currently only passed through to Velero and the Admin Console.",
589606
Hidden: true,
590607
},
608+
&cli.StringFlag{
609+
Name: "pod-cidr",
610+
Usage: "pod CIDR range to use for the installation",
611+
Hidden: false,
612+
},
613+
&cli.StringFlag{
614+
Name: "service-cidr",
615+
Usage: "service CIDR range to use for the installation",
616+
Hidden: false,
617+
},
591618
&cli.BoolFlag{
592619
Name: "skip-host-preflights",
593620
Usage: "Skip host preflight checks. This is not recommended unless you are sure your system is compatible.",
@@ -638,11 +665,12 @@ var installCommand = &cli.Command{
638665
metrics.ReportApplyFinished(c, err)
639666
return err
640667
}
641-
if err := installAndWaitForK0s(c); err != nil {
668+
cfg, err := installAndWaitForK0s(c)
669+
if err != nil {
642670
return err
643671
}
644672
logrus.Debugf("running outro")
645-
if err := runOutro(c, adminConsolePwd); err != nil {
673+
if err := runOutro(c, cfg, adminConsolePwd); err != nil {
646674
metrics.ReportApplyFinished(c, err)
647675
return err
648676
}

cmd/embedded-cluster/join.go

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/google/uuid"
1414
"github.com/k0sproject/dig"
1515
k0sconfig "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
16+
ecv1beta1 "github.com/replicatedhq/embedded-cluster-kinds/apis/v1beta1"
1617
"github.com/sirupsen/logrus"
1718
"github.com/urfave/cli/v2"
1819
"gopkg.in/yaml.v2"
@@ -33,22 +34,17 @@ import (
3334
"github.com/replicatedhq/embedded-cluster/pkg/spinner"
3435
)
3536

36-
type Proxy struct {
37-
HTTPProxy string `json:"httpProxy"`
38-
HTTPSProxy string `json:"httpsProxy"`
39-
NoProxy string `json:"noProxy"`
40-
}
41-
4237
// JoinCommandResponse is the response from the kots api we use to fetch the k0s join token.
4338
type JoinCommandResponse struct {
44-
K0sJoinCommand string `json:"k0sJoinCommand"`
45-
K0sToken string `json:"k0sToken"`
46-
ClusterID uuid.UUID `json:"clusterID"`
47-
K0sUnsupportedOverrides string `json:"k0sUnsupportedOverrides"`
48-
EndUserK0sConfigOverrides string `json:"endUserK0sConfigOverrides"`
49-
MetricsBaseURL string `json:"metricsBaseURL"`
50-
AirgapRegistryAddress string `json:"airgapRegistryAddress"`
51-
Proxy *Proxy `json:"proxy"`
39+
K0sJoinCommand string `json:"k0sJoinCommand"`
40+
K0sToken string `json:"k0sToken"`
41+
ClusterID uuid.UUID `json:"clusterID"`
42+
K0sUnsupportedOverrides string `json:"k0sUnsupportedOverrides"`
43+
EndUserK0sConfigOverrides string `json:"endUserK0sConfigOverrides"`
44+
MetricsBaseURL string `json:"metricsBaseURL"`
45+
AirgapRegistryAddress string `json:"airgapRegistryAddress"`
46+
Proxy *ecv1beta1.ProxySpec `json:"proxy"`
47+
Network *ecv1beta1.NetworkSpec `json:"network"`
5248
}
5349

5450
// extractK0sConfigOverridePatch parses the provided override and returns a dig.Mapping that
@@ -241,11 +237,10 @@ var joinCommand = &cli.Command{
241237
return err
242238
}
243239

244-
logrus.Debugf("joining node to cluster")
245-
if err := runK0sInstallCommand(jcmd.K0sJoinCommand); err != nil {
246-
err := fmt.Errorf("unable to join node to cluster: %w", err)
240+
logrus.Debugf("overriding network configuration")
241+
if err := applyNetworkConfiguration(jcmd); err != nil {
242+
err := fmt.Errorf("unable to apply network configuration: %w", err)
247243
metrics.ReportJoinFailed(c.Context, jcmd.MetricsBaseURL, jcmd.ClusterID, err)
248-
return err
249244
}
250245

251246
logrus.Debugf("applying configuration overrides")
@@ -255,6 +250,13 @@ var joinCommand = &cli.Command{
255250
return err
256251
}
257252

253+
logrus.Debugf("joining node to cluster")
254+
if err := runK0sInstallCommand(jcmd.K0sJoinCommand); err != nil {
255+
err := fmt.Errorf("unable to join node to cluster: %w", err)
256+
metrics.ReportJoinFailed(c.Context, jcmd.MetricsBaseURL, jcmd.ClusterID, err)
257+
return err
258+
}
259+
258260
if err := startAndWaitForK0s(c, jcmd); err != nil {
259261
return err
260262
}
@@ -297,6 +299,24 @@ var joinCommand = &cli.Command{
297299
},
298300
}
299301

302+
func applyNetworkConfiguration(jcmd *JoinCommandResponse) error {
303+
if jcmd.Network != nil {
304+
clusterSpec := k0sconfig.DefaultClusterConfig()
305+
clusterSpec.Spec.Network.PodCIDR = jcmd.Network.PodCIDR
306+
clusterSpec.Spec.Network.ServiceCIDR = jcmd.Network.ServiceCIDR
307+
clusterSpecYaml, err := k8syaml.Marshal(clusterSpec)
308+
309+
if err != nil {
310+
return fmt.Errorf("unable to marshal cluster spec: %w", err)
311+
}
312+
err = os.WriteFile(defaults.PathToK0sConfig(), clusterSpecYaml, 0644)
313+
if err != nil {
314+
return fmt.Errorf("unable to write cluster spec to /etc/k0s/k0s.yaml: %w", err)
315+
}
316+
}
317+
return nil
318+
}
319+
300320
// applyJoinConfigurationOverrides applies both config overrides received from the kots api.
301321
// Applies first the EmbeddedOverrides and then the EndUserOverrides.
302322
func applyJoinConfigurationOverrides(jcmd *JoinCommandResponse) error {
@@ -419,6 +439,7 @@ func runK0sInstallCommand(fullcmd string) error {
419439
if strings.Contains(fullcmd, "controller") {
420440
args = append(args, "--disable-components", "konnectivity-server", "--enable-dynamic-config")
421441
}
442+
422443
if _, err := helpers.RunCommand(args[0], args[1:]...); err != nil {
423444
return err
424445
}

0 commit comments

Comments
 (0)