Skip to content

Commit b824d77

Browse files
authored
feat: Refactor addons package to decouple from runtimeconfig (#2372)
* refactor addons package to decouple from runtimeconfig * f * f * f * f * f
1 parent 970352f commit b824d77

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+660
-498
lines changed

api/integration/install_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/replicatedhq/embedded-cluster/api/pkg/logger"
2929
"github.com/replicatedhq/embedded-cluster/api/types"
3030
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
31+
"github.com/replicatedhq/embedded-cluster/pkg-new/constants"
3132
"github.com/replicatedhq/embedded-cluster/pkg-new/hostutils"
3233
"github.com/replicatedhq/embedded-cluster/pkg-new/k0s"
3334
"github.com/replicatedhq/embedded-cluster/pkg/helm"
@@ -1334,11 +1335,11 @@ func TestPostSetupInfra(t *testing.T) {
13341335

13351336
// Verify kotsadm namespace and kotsadm-password secret were created
13361337
var gotKotsadmNamespace corev1.Namespace
1337-
err = fakeKcli.Get(t.Context(), client.ObjectKey{Name: runtimeconfig.KotsadmNamespace}, &gotKotsadmNamespace)
1338+
err = fakeKcli.Get(t.Context(), client.ObjectKey{Name: constants.KotsadmNamespace}, &gotKotsadmNamespace)
13381339
require.NoError(t, err)
13391340

13401341
var gotKotsadmPasswordSecret corev1.Secret
1341-
err = fakeKcli.Get(t.Context(), client.ObjectKey{Namespace: runtimeconfig.KotsadmNamespace, Name: "kotsadm-password"}, &gotKotsadmPasswordSecret)
1342+
err = fakeKcli.Get(t.Context(), client.ObjectKey{Namespace: constants.KotsadmNamespace, Name: "kotsadm-password"}, &gotKotsadmPasswordSecret)
13421343
require.NoError(t, err)
13431344
assert.NotEmpty(t, gotKotsadmPasswordSecret.Data["passwordBcrypt"])
13441345

api/internal/managers/infra/install.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/replicatedhq/embedded-cluster/api/types"
1111
"github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
1212
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
13+
"github.com/replicatedhq/embedded-cluster/pkg-new/constants"
1314
ecmetadata "github.com/replicatedhq/embedded-cluster/pkg-new/metadata"
1415
"github.com/replicatedhq/embedded-cluster/pkg/addons"
1516
"github.com/replicatedhq/embedded-cluster/pkg/addons/registry"
@@ -74,10 +75,7 @@ func (m *infraManager) Install(ctx context.Context, rc runtimeconfig.RuntimeConf
7475
func (m *infraManager) initComponentsList(license *kotsv1beta1.License, rc runtimeconfig.RuntimeConfig) error {
7576
components := []types.InfraComponent{{Name: K0sComponentName}}
7677

77-
addOns := addons.GetAddOnsForInstall(rc, addons.InstallOptions{
78-
IsAirgap: m.airgapBundle != "",
79-
DisasterRecoveryEnabled: license.Spec.IsDisasterRecoverySupported,
80-
})
78+
addOns := addons.GetAddOnsForInstall(m.getAddonInstallOpts(license, rc))
8179
for _, addOn := range addOns {
8280
components = append(components, types.InfraComponent{Name: addOn.Name()})
8381
}
@@ -274,7 +272,7 @@ func (m *infraManager) installAddOns(ctx context.Context, kcli client.Client, mc
274272
addons.WithKubernetesClient(kcli),
275273
addons.WithMetadataClient(mcli),
276274
addons.WithHelmClient(hcli),
277-
addons.WithRuntimeConfig(rc),
275+
addons.WithDomains(utils.GetDomains(m.releaseData)),
278276
addons.WithProgressChannel(progressChan),
279277
)
280278

@@ -293,6 +291,7 @@ func (m *infraManager) getAddonInstallOpts(license *kotsv1beta1.License, rc runt
293291

294292
opts := addons.InstallOptions{
295293
AdminConsolePwd: m.password,
294+
AdminConsolePort: rc.AdminConsolePort(),
296295
License: license,
297296
IsAirgap: m.airgapBundle != "",
298297
TLSCertBytes: m.tlsConfig.CertBytes,
@@ -302,6 +301,12 @@ func (m *infraManager) getAddonInstallOpts(license *kotsv1beta1.License, rc runt
302301
IsMultiNodeEnabled: license.Spec.IsEmbeddedClusterMultiNodeEnabled,
303302
EmbeddedConfigSpec: m.getECConfigSpec(),
304303
EndUserConfigSpec: m.getEndUserConfigSpec(),
304+
ProxySpec: rc.ProxySpec(),
305+
HostCABundlePath: rc.HostCABundlePath(),
306+
DataDir: rc.EmbeddedClusterHomeDirectory(),
307+
K0sDataDir: rc.EmbeddedClusterK0sSubDir(),
308+
OpenEBSDataDir: rc.EmbeddedClusterOpenEBSLocalSubDir(),
309+
ServiceCIDR: rc.ServiceCIDR(),
305310
}
306311

307312
if m.kotsInstaller != nil { // used for testing
@@ -312,7 +317,7 @@ func (m *infraManager) getAddonInstallOpts(license *kotsv1beta1.License, rc runt
312317
RuntimeConfig: rc,
313318
AppSlug: license.Spec.AppSlug,
314319
License: m.license,
315-
Namespace: runtimeconfig.KotsadmNamespace,
320+
Namespace: constants.KotsadmNamespace,
316321
AirgapBundle: m.airgapBundle,
317322
ConfigValuesFile: m.configValues,
318323
ReplicatedAppEndpoint: netutils.MaybeAddHTTPS(ecDomains.ReplicatedAppDomain),

cmd/installer/cli/adminconsole_resetpassword.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88

99
"github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
10+
"github.com/replicatedhq/embedded-cluster/pkg/dryrun"
1011
"github.com/replicatedhq/embedded-cluster/pkg/prompts"
1112
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
1213
rcutil "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig/util"
@@ -22,7 +23,8 @@ func AdminConsoleResetPasswordCmd(ctx context.Context, name string) *cobra.Comma
2223
Args: cobra.MaximumNArgs(1),
2324
Short: fmt.Sprintf("Reset the %s Admin Console password. If no password is provided, you will be prompted to enter a new one.", name),
2425
PreRunE: func(cmd *cobra.Command, args []string) error {
25-
if os.Getuid() != 0 {
26+
// Skip root check if dryrun mode is enabled
27+
if !dryrun.Enabled() && os.Getuid() != 0 {
2628
return fmt.Errorf("reset-password command must be run as root")
2729
}
2830

cmd/installer/cli/enable_ha.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import (
55
"fmt"
66
"os"
77

8+
"github.com/replicatedhq/embedded-cluster/pkg-new/domains"
89
"github.com/replicatedhq/embedded-cluster/pkg/addons"
10+
"github.com/replicatedhq/embedded-cluster/pkg/dryrun"
911
"github.com/replicatedhq/embedded-cluster/pkg/helm"
1012
"github.com/replicatedhq/embedded-cluster/pkg/kubeutils"
13+
"github.com/replicatedhq/embedded-cluster/pkg/release"
1114
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
1215
rcutil "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig/util"
1316
"github.com/replicatedhq/embedded-cluster/pkg/spinner"
@@ -24,7 +27,8 @@ func EnableHACmd(ctx context.Context, name string) *cobra.Command {
2427
Use: "enable-ha",
2528
Short: fmt.Sprintf("Enable high availability for the %s cluster", name),
2629
PreRunE: func(cmd *cobra.Command, args []string) error {
27-
if os.Getuid() != 0 {
30+
// Skip root check if dryrun mode is enabled
31+
if !dryrun.Enabled() && os.Getuid() != 0 {
2832
return fmt.Errorf("enable-ha command must be run as root")
2933
}
3034

@@ -91,7 +95,7 @@ func runEnableHA(ctx context.Context, rc runtimeconfig.RuntimeConfig) error {
9195
addons.WithKubernetesClientSet(kclient),
9296
addons.WithMetadataClient(mcli),
9397
addons.WithHelmClient(hcli),
94-
addons.WithRuntimeConfig(rc),
98+
addons.WithDomains(domains.GetDomains(in.Spec.Config, release.GetChannelRelease())),
9599
)
96100

97101
canEnableHA, reason, err := addOns.CanEnableHA(ctx)
@@ -106,5 +110,19 @@ func runEnableHA(ctx context.Context, rc runtimeconfig.RuntimeConfig) error {
106110
loading := spinner.Start()
107111
defer loading.Close()
108112

109-
return addOns.EnableHA(ctx, in.Spec, loading)
113+
opts := addons.EnableHAOptions{
114+
AdminConsolePort: rc.AdminConsolePort(),
115+
IsAirgap: in.Spec.AirGap,
116+
IsMultiNodeEnabled: in.Spec.LicenseInfo != nil && in.Spec.LicenseInfo.IsMultiNodeEnabled,
117+
EmbeddedConfigSpec: in.Spec.Config,
118+
EndUserConfigSpec: nil, // TODO: add support for end user config spec
119+
ProxySpec: rc.ProxySpec(),
120+
HostCABundlePath: rc.HostCABundlePath(),
121+
DataDir: rc.EmbeddedClusterHomeDirectory(),
122+
K0sDataDir: rc.EmbeddedClusterK0sSubDir(),
123+
SeaweedFSDataDir: rc.EmbeddedClusterSeaweedFSSubDir(),
124+
ServiceCIDR: rc.ServiceCIDR(),
125+
}
126+
127+
return addOns.EnableHA(ctx, opts, loading)
110128
}

cmd/installer/cli/install.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
2020
"github.com/replicatedhq/embedded-cluster/pkg-new/cloudutils"
2121
newconfig "github.com/replicatedhq/embedded-cluster/pkg-new/config"
22+
"github.com/replicatedhq/embedded-cluster/pkg-new/constants"
23+
"github.com/replicatedhq/embedded-cluster/pkg-new/domains"
2224
"github.com/replicatedhq/embedded-cluster/pkg-new/hostutils"
2325
"github.com/replicatedhq/embedded-cluster/pkg-new/k0s"
2426
ecmetadata "github.com/replicatedhq/embedded-cluster/pkg-new/metadata"
@@ -740,6 +742,7 @@ func getAddonInstallOpts(flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig,
740742

741743
opts := &addons.InstallOptions{
742744
AdminConsolePwd: flags.adminConsolePassword,
745+
AdminConsolePort: rc.AdminConsolePort(),
743746
License: flags.license,
744747
IsAirgap: flags.airgapBundle != "",
745748
TLSCertBytes: flags.tlsCertBytes,
@@ -749,12 +752,18 @@ func getAddonInstallOpts(flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig,
749752
IsMultiNodeEnabled: flags.license.Spec.IsEmbeddedClusterMultiNodeEnabled,
750753
EmbeddedConfigSpec: embCfgSpec,
751754
EndUserConfigSpec: euCfgSpec,
755+
ProxySpec: rc.ProxySpec(),
756+
HostCABundlePath: rc.HostCABundlePath(),
757+
DataDir: rc.EmbeddedClusterHomeDirectory(),
758+
K0sDataDir: rc.EmbeddedClusterK0sSubDir(),
759+
OpenEBSDataDir: rc.EmbeddedClusterOpenEBSLocalSubDir(),
760+
ServiceCIDR: rc.ServiceCIDR(),
752761
KotsInstaller: func() error {
753762
opts := kotscli.InstallOptions{
754763
RuntimeConfig: rc,
755764
AppSlug: flags.license.Spec.AppSlug,
756765
License: flags.licenseBytes,
757-
Namespace: runtimeconfig.KotsadmNamespace,
766+
Namespace: constants.KotsadmNamespace,
758767
AirgapBundle: flags.airgapBundle,
759768
ConfigValuesFile: flags.configValues,
760769
ReplicatedAppEndpoint: replicatedAppURL(),
@@ -1046,7 +1055,7 @@ func installAddons(ctx context.Context, kcli client.Client, mcli metadata.Interf
10461055
addons.WithKubernetesClient(kcli),
10471056
addons.WithMetadataClient(mcli),
10481057
addons.WithHelmClient(hcli),
1049-
addons.WithRuntimeConfig(rc),
1058+
addons.WithDomains(getDomains()),
10501059
addons.WithProgressChannel(progressChan),
10511060
)
10521061

@@ -1062,6 +1071,15 @@ func installAddons(ctx context.Context, kcli client.Client, mcli metadata.Interf
10621071
return nil
10631072
}
10641073

1074+
func getDomains() ecv1beta1.Domains {
1075+
var embCfgSpec *ecv1beta1.ConfigSpec
1076+
if embCfg := release.GetEmbeddedClusterConfig(); embCfg != nil {
1077+
embCfgSpec = &embCfg.Spec
1078+
}
1079+
1080+
return domains.GetDomains(embCfgSpec, release.GetChannelRelease())
1081+
}
1082+
10651083
func installExtensions(ctx context.Context, hcli helm.Client) error {
10661084
progressChan := make(chan extensions.ExtensionsProgress)
10671085
defer close(progressChan)
@@ -1213,20 +1231,12 @@ func validateAdminConsolePassword(password, passwordCheck string) bool {
12131231
}
12141232

12151233
func replicatedAppURL() string {
1216-
var embCfgSpec *ecv1beta1.ConfigSpec
1217-
if embCfg := release.GetEmbeddedClusterConfig(); embCfg != nil {
1218-
embCfgSpec = &embCfg.Spec
1219-
}
1220-
domains := runtimeconfig.GetDomains(embCfgSpec)
1234+
domains := getDomains()
12211235
return netutils.MaybeAddHTTPS(domains.ReplicatedAppDomain)
12221236
}
12231237

12241238
func proxyRegistryURL() string {
1225-
var embCfgSpec *ecv1beta1.ConfigSpec
1226-
if embCfg := release.GetEmbeddedClusterConfig(); embCfg != nil {
1227-
embCfgSpec = &embCfg.Spec
1228-
}
1229-
domains := runtimeconfig.GetDomains(embCfgSpec)
1239+
domains := getDomains()
12301240
return netutils.MaybeAddHTTPS(domains.ProxyRegistryDomain)
12311241
}
12321242

cmd/installer/cli/join.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import (
1414
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
1515
"github.com/replicatedhq/embedded-cluster/kinds/types/join"
1616
newconfig "github.com/replicatedhq/embedded-cluster/pkg-new/config"
17+
"github.com/replicatedhq/embedded-cluster/pkg-new/domains"
1718
"github.com/replicatedhq/embedded-cluster/pkg-new/hostutils"
1819
"github.com/replicatedhq/embedded-cluster/pkg-new/k0s"
1920
"github.com/replicatedhq/embedded-cluster/pkg-new/preflights"
2021
"github.com/replicatedhq/embedded-cluster/pkg/addons"
2122
"github.com/replicatedhq/embedded-cluster/pkg/airgap"
2223
"github.com/replicatedhq/embedded-cluster/pkg/config"
24+
"github.com/replicatedhq/embedded-cluster/pkg/dryrun"
2325
"github.com/replicatedhq/embedded-cluster/pkg/helm"
2426
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
2527
"github.com/replicatedhq/embedded-cluster/pkg/kotsadm"
@@ -111,7 +113,8 @@ func JoinCmd(ctx context.Context, name string) *cobra.Command {
111113
}
112114

113115
func preRunJoin(flags *JoinCmdFlags) error {
114-
if os.Getuid() != 0 {
116+
// Skip root check if dryrun mode is enabled
117+
if !dryrun.Enabled() && os.Getuid() != 0 {
115118
return fmt.Errorf("join command must be run as root")
116119
}
117120

@@ -451,7 +454,7 @@ func installK0sBinary(rc runtimeconfig.RuntimeConfig) error {
451454
}
452455

453456
func applyNetworkConfiguration(rc runtimeconfig.RuntimeConfig, jcmd *join.JoinCommandResponse) error {
454-
domains := runtimeconfig.GetDomains(jcmd.InstallationSpec.Config)
457+
domains := domains.GetDomains(jcmd.InstallationSpec.Config, release.GetChannelRelease())
455458
clusterSpec := config.RenderK0sConfig(domains.ProxyRegistryDomain)
456459

457460
address, err := netutils.FirstValidAddress(rc.NetworkInterface())
@@ -617,7 +620,7 @@ func maybeEnableHA(ctx context.Context, kcli client.Client, mcli metadata.Interf
617620
addons.WithKubernetesClientSet(kclient),
618621
addons.WithMetadataClient(mcli),
619622
addons.WithHelmClient(hcli),
620-
addons.WithRuntimeConfig(rc),
623+
addons.WithDomains(getDomains()),
621624
)
622625

623626
canEnableHA, _, err := addOns.CanEnableHA(ctx)
@@ -653,5 +656,19 @@ func maybeEnableHA(ctx context.Context, kcli client.Client, mcli metadata.Interf
653656
loading := spinner.Start()
654657
defer loading.Close()
655658

656-
return addOns.EnableHA(ctx, jcmd.InstallationSpec, loading)
659+
opts := addons.EnableHAOptions{
660+
AdminConsolePort: rc.AdminConsolePort(),
661+
IsAirgap: jcmd.InstallationSpec.AirGap,
662+
IsMultiNodeEnabled: jcmd.InstallationSpec.LicenseInfo != nil && jcmd.InstallationSpec.LicenseInfo.IsMultiNodeEnabled,
663+
EmbeddedConfigSpec: jcmd.InstallationSpec.Config,
664+
EndUserConfigSpec: nil, // TODO: add support for end user config spec
665+
ProxySpec: rc.ProxySpec(),
666+
HostCABundlePath: rc.HostCABundlePath(),
667+
DataDir: rc.EmbeddedClusterHomeDirectory(),
668+
K0sDataDir: rc.EmbeddedClusterK0sSubDir(),
669+
SeaweedFSDataDir: rc.EmbeddedClusterSeaweedFSSubDir(),
670+
ServiceCIDR: rc.ServiceCIDR(),
671+
}
672+
673+
return addOns.EnableHA(ctx, opts, loading)
657674
}

cmd/installer/cli/join_printcommand.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77

88
"github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
9+
"github.com/replicatedhq/embedded-cluster/pkg/dryrun"
910
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
1011
rcutil "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig/util"
1112
"github.com/spf13/cobra"
@@ -18,7 +19,8 @@ func JoinPrintCommandCmd(ctx context.Context, name string) *cobra.Command {
1819
Use: "print-command",
1920
Short: fmt.Sprintf("Print controller join command for %s", name),
2021
PreRunE: func(cmd *cobra.Command, args []string) error {
21-
if os.Getuid() != 0 {
22+
// Skip root check if dryrun mode is enabled
23+
if !dryrun.Enabled() && os.Getuid() != 0 {
2224
return fmt.Errorf("print-command command must be run as root")
2325
}
2426

cmd/installer/cli/join_runpreflights.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/replicatedhq/embedded-cluster/kinds/types/join"
99
newconfig "github.com/replicatedhq/embedded-cluster/pkg-new/config"
10+
"github.com/replicatedhq/embedded-cluster/pkg-new/domains"
1011
"github.com/replicatedhq/embedded-cluster/pkg-new/hostutils"
1112
"github.com/replicatedhq/embedded-cluster/pkg-new/preflights"
1213
"github.com/replicatedhq/embedded-cluster/pkg/kotsadm"
@@ -101,7 +102,7 @@ func runJoinPreflights(ctx context.Context, jcmd *join.JoinCommandResponse, flag
101102
return fmt.Errorf("unable to find first valid address: %w", err)
102103
}
103104

104-
domains := runtimeconfig.GetDomains(jcmd.InstallationSpec.Config)
105+
domains := domains.GetDomains(jcmd.InstallationSpec.Config, release.GetChannelRelease())
105106

106107
hpf, err := preflights.Prepare(ctx, preflights.PrepareOptions{
107108
HostPreflightSpec: release.GetHostPreflights(),

cmd/installer/cli/materialize.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/replicatedhq/embedded-cluster/cmd/installer/goods"
99
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
10+
"github.com/replicatedhq/embedded-cluster/pkg/dryrun"
1011
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
1112
"github.com/spf13/cobra"
1213
)
@@ -20,7 +21,8 @@ func MaterializeCmd(ctx context.Context, name string) *cobra.Command {
2021
Short: "Materialize embedded assets into the data directory",
2122
Hidden: true,
2223
PreRunE: func(cmd *cobra.Command, args []string) error {
23-
if os.Getuid() != 0 {
24+
// Skip root check if dryrun mode is enabled
25+
if !dryrun.Enabled() && os.Getuid() != 0 {
2426
return fmt.Errorf("materialize command must be run as root")
2527
}
2628

cmd/installer/cli/reset_firewalld.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77

88
"github.com/replicatedhq/embedded-cluster/pkg-new/hostutils"
9+
"github.com/replicatedhq/embedded-cluster/pkg/dryrun"
910
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
1011
rcutil "github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig/util"
1112
"github.com/sirupsen/logrus"
@@ -20,7 +21,8 @@ func ResetFirewalldCmd(ctx context.Context, name string) *cobra.Command {
2021
Short: "Remove %s firewalld configuration from the current node",
2122
Hidden: true,
2223
PreRunE: func(cmd *cobra.Command, args []string) error {
23-
if os.Getuid() != 0 {
24+
// Skip root check if dryrun mode is enabled
25+
if !dryrun.Enabled() && os.Getuid() != 0 {
2426
return fmt.Errorf("reset firewalld command must be run as root")
2527
}
2628

0 commit comments

Comments
 (0)