Skip to content

Commit 8d7b74e

Browse files
authored
feat(kubernetes): adminconsole install (#2402)
* feat(kubernetes): adminconsole install * f * f * f * f * f * f * f * f * f * f * f * f
1 parent db9bcbe commit 8d7b74e

Some content is hidden

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

45 files changed

+795
-169
lines changed

api/controllers/linux/install/controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type InstallController struct {
5252
airgapBundle string
5353
configValues string
5454
endUserConfig *ecv1beta1.Config
55+
clusterID string
5556
store store.Store
5657
rc runtimeconfig.RuntimeConfig
5758
stateMachine statemachine.Interface
@@ -134,6 +135,12 @@ func WithEndUserConfig(endUserConfig *ecv1beta1.Config) InstallControllerOption
134135
}
135136
}
136137

138+
func WithClusterID(clusterID string) InstallControllerOption {
139+
return func(c *InstallController) {
140+
c.clusterID = clusterID
141+
}
142+
}
143+
137144
func WithAllowIgnoreHostPreflights(allowIgnoreHostPreflights bool) InstallControllerOption {
138145
return func(c *InstallController) {
139146
c.allowIgnoreHostPreflights = allowIgnoreHostPreflights
@@ -225,6 +232,7 @@ func NewInstallController(opts ...InstallControllerOption) (*InstallController,
225232
infra.WithConfigValues(controller.configValues),
226233
infra.WithReleaseData(controller.releaseData),
227234
infra.WithEndUserConfig(controller.endUserConfig),
235+
infra.WithClusterID(controller.clusterID),
228236
)
229237
}
230238

api/internal/handlers/linux/linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func New(cfg types.APIConfig, opts ...Option) (*Handler, error) {
7878
install.WithAirgapBundle(h.cfg.AirgapBundle),
7979
install.WithConfigValues(h.cfg.ConfigValues),
8080
install.WithEndUserConfig(h.cfg.EndUserConfig),
81+
install.WithClusterID(h.cfg.ClusterID),
8182
install.WithAllowIgnoreHostPreflights(h.cfg.AllowIgnoreHostPreflights),
8283
)
8384
if err != nil {

api/internal/managers/linux/infra/install.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ func (m *infraManager) recordInstallation(ctx context.Context, kcli client.Clien
225225
// record the installation
226226
logFn("recording installation")
227227
in, err := kubeutils.RecordInstallation(ctx, kcli, kubeutils.RecordInstallationOptions{
228+
ClusterID: m.clusterID,
228229
IsAirgap: m.airgapBundle != "",
229230
License: license,
230231
ConfigSpec: m.getECConfigSpec(),
@@ -290,6 +291,7 @@ func (m *infraManager) getAddonInstallOpts(license *kotsv1beta1.License, rc runt
290291
ecDomains := utils.GetDomains(m.releaseData)
291292

292293
opts := addons.InstallOptions{
294+
ClusterID: m.clusterID,
293295
AdminConsolePwd: m.password,
294296
AdminConsolePort: rc.AdminConsolePort(),
295297
License: license,
@@ -318,6 +320,7 @@ func (m *infraManager) getAddonInstallOpts(license *kotsv1beta1.License, rc runt
318320
AppSlug: license.Spec.AppSlug,
319321
License: m.license,
320322
Namespace: constants.KotsadmNamespace,
323+
ClusterID: m.clusterID,
321324
AirgapBundle: m.airgapBundle,
322325
ConfigValuesFile: m.configValues,
323326
ReplicatedAppEndpoint: netutils.MaybeAddHTTPS(ecDomains.ReplicatedAppDomain),

api/internal/managers/linux/infra/manager.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type infraManager struct {
3636
configValues string
3737
releaseData *release.ReleaseData
3838
endUserConfig *ecv1beta1.Config
39+
clusterID string
3940
logger logrus.FieldLogger
4041
k0scli k0s.K0sInterface
4142
kcli client.Client
@@ -102,6 +103,12 @@ func WithEndUserConfig(endUserConfig *ecv1beta1.Config) InfraManagerOption {
102103
}
103104
}
104105

106+
func WithClusterID(clusterID string) InfraManagerOption {
107+
return func(c *infraManager) {
108+
c.clusterID = clusterID
109+
}
110+
}
111+
105112
func WithK0s(k0s k0s.K0sInterface) InfraManagerOption {
106113
return func(c *infraManager) {
107114
c.k0scli = k0s

api/types/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type APIConfig struct {
1717
ConfigValues string
1818
ReleaseData *release.ReleaseData
1919
EndUserConfig *ecv1beta1.Config
20+
ClusterID string
2021

2122
LinuxConfig
2223
KubernetesConfig

cmd/installer/cli/api_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func Test_serveAPI(t *testing.T) {
6363
Spec: kotsv1beta1.ApplicationSpec{},
6464
},
6565
},
66+
ClusterID: "123",
6667
},
6768
ManagerPort: portInt,
6869
Logger: apilogger.NewDiscardLogger(),

cmd/installer/cli/enable_ha.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func runEnableHA(ctx context.Context, rc runtimeconfig.RuntimeConfig) error {
111111
defer loading.Close()
112112

113113
opts := addons.EnableHAOptions{
114+
ClusterID: in.Spec.ClusterID,
114115
AdminConsolePort: rc.AdminConsolePort(),
115116
IsAirgap: in.Spec.AirGap,
116117
IsMultiNodeEnabled: in.Spec.LicenseInfo != nil && in.Spec.LicenseInfo.IsMultiNodeEnabled,

cmd/installer/cli/install.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"time"
1515

1616
"github.com/AlecAivazis/survey/v2/terminal"
17+
"github.com/google/uuid"
1718
k0sv1beta1 "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
1819
apitypes "github.com/replicatedhq/embedded-cluster/api/types"
1920
"github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
@@ -37,7 +38,6 @@ import (
3738
"github.com/replicatedhq/embedded-cluster/pkg/helpers"
3839
"github.com/replicatedhq/embedded-cluster/pkg/kubernetesinstallation"
3940
"github.com/replicatedhq/embedded-cluster/pkg/kubeutils"
40-
"github.com/replicatedhq/embedded-cluster/pkg/metrics"
4141
"github.com/replicatedhq/embedded-cluster/pkg/netutils"
4242
"github.com/replicatedhq/embedded-cluster/pkg/prompts"
4343
"github.com/replicatedhq/embedded-cluster/pkg/release"
@@ -87,6 +87,7 @@ type InstallCmdFlags struct {
8787
}
8888

8989
type installConfig struct {
90+
clusterID string
9091
license *kotsv1beta1.License
9192
licenseBytes []byte
9293
tlsCert tls.Certificate
@@ -129,10 +130,9 @@ func InstallCmd(ctx context.Context, appSlug, appTitle string) *cobra.Command {
129130
return err
130131
}
131132

132-
clusterID := metrics.ClusterID()
133133
installReporter := newInstallReporter(
134-
replicatedAppURL(), clusterID, cmd.CalledAs(), flagsToStringSlice(cmd.Flags()),
135-
flags.license.Spec.LicenseID, flags.license.Spec.AppSlug,
134+
replicatedAppURL(), cmd.CalledAs(), flagsToStringSlice(cmd.Flags()),
135+
flags.license.Spec.LicenseID, flags.clusterID, flags.license.Spec.AppSlug,
136136
)
137137
installReporter.ReportInstallationStarted(ctx)
138138

@@ -378,6 +378,8 @@ func preRunInstall(cmd *cobra.Command, flags *InstallCmdFlags, rc runtimeconfig.
378378
return fmt.Errorf(`invalid --target (must be one of: "linux", "kubernetes")`)
379379
}
380380

381+
flags.clusterID = uuid.New().String()
382+
381383
if err := preRunInstallCommon(cmd, flags, rc, ki); err != nil {
382384
return err
383385
}
@@ -562,7 +564,10 @@ func cidrConfigFromCmd(cmd *cobra.Command) (*newconfig.CIDRConfig, error) {
562564
return cidrCfg, nil
563565
}
564566

565-
func runManagerExperienceInstall(ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, ki kubernetesinstallation.Installation, installReporter *InstallReporter, appTitle string) (finalErr error) {
567+
func runManagerExperienceInstall(
568+
ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, ki kubernetesinstallation.Installation,
569+
installReporter *InstallReporter, appTitle string,
570+
) (finalErr error) {
566571
// this is necessary because the api listens on all interfaces,
567572
// and we only know the interface to use when the user selects it in the ui
568573
ipAddresses, err := netutils.ListAllValidIPAddresses()
@@ -631,6 +636,7 @@ func runManagerExperienceInstall(ctx context.Context, flags InstallCmdFlags, rc
631636
ConfigValues: flags.configValues,
632637
ReleaseData: release.GetReleaseData(),
633638
EndUserConfig: eucfg,
639+
ClusterID: flags.clusterID,
634640

635641
LinuxConfig: apitypes.LinuxConfig{
636642
RuntimeConfig: rc,
@@ -697,7 +703,7 @@ func runInstall(ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.Run
697703
errCh := kubeutils.WaitForKubernetes(ctx, kcli)
698704
defer logKubernetesErrors(errCh)
699705

700-
in, err := recordInstallation(ctx, kcli, flags, rc, flags.license)
706+
in, err := recordInstallation(ctx, kcli, flags, rc)
701707
if err != nil {
702708
return fmt.Errorf("unable to record installation: %w", err)
703709
}
@@ -733,7 +739,7 @@ func runInstall(ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.Run
733739
defer hcli.Close()
734740

735741
logrus.Debugf("installing addons")
736-
if err := installAddons(ctx, kcli, mcli, hcli, rc, flags); err != nil {
742+
if err := installAddons(ctx, kcli, mcli, hcli, flags, rc); err != nil {
737743
return err
738744
}
739745

@@ -771,6 +777,7 @@ func getAddonInstallOpts(flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig,
771777
}
772778

773779
opts := &addons.InstallOptions{
780+
ClusterID: flags.clusterID,
774781
AdminConsolePwd: flags.adminConsolePassword,
775782
AdminConsolePort: rc.AdminConsolePort(),
776783
License: flags.license,
@@ -794,6 +801,7 @@ func getAddonInstallOpts(flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig,
794801
AppSlug: flags.license.Spec.AppSlug,
795802
License: flags.licenseBytes,
796803
Namespace: constants.KotsadmNamespace,
804+
ClusterID: flags.clusterID,
797805
AirgapBundle: flags.airgapBundle,
798806
ConfigValuesFile: flags.configValues,
799807
ReplicatedAppEndpoint: replicatedAppURL(),
@@ -1068,7 +1076,7 @@ func installAndStartCluster(ctx context.Context, flags InstallCmdFlags, rc runti
10681076
return cfg, nil
10691077
}
10701078

1071-
func installAddons(ctx context.Context, kcli client.Client, mcli metadata.Interface, hcli helm.Client, rc runtimeconfig.RuntimeConfig, flags InstallCmdFlags) error {
1079+
func installAddons(ctx context.Context, kcli client.Client, mcli metadata.Interface, hcli helm.Client, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig) error {
10721080
progressChan := make(chan addontypes.AddOnProgress)
10731081
defer close(progressChan)
10741082

@@ -1294,7 +1302,7 @@ func waitForNode(ctx context.Context) error {
12941302
}
12951303

12961304
func recordInstallation(
1297-
ctx context.Context, kcli client.Client, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, license *kotsv1beta1.License,
1305+
ctx context.Context, kcli client.Client, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig,
12981306
) (*ecv1beta1.Installation, error) {
12991307
// get the embedded cluster config
13001308
cfg := release.GetEmbeddedClusterConfig()
@@ -1311,8 +1319,9 @@ func recordInstallation(
13111319

13121320
// record the installation
13131321
installation, err := kubeutils.RecordInstallation(ctx, kcli, kubeutils.RecordInstallationOptions{
1322+
ClusterID: flags.clusterID,
13141323
IsAirgap: flags.isAirgap,
1315-
License: license,
1324+
License: flags.license,
13161325
ConfigSpec: cfgspec,
13171326
MetricsBaseURL: replicatedAppURL(),
13181327
RuntimeConfig: rc.Get(),

cmd/installer/cli/join.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func JoinCmd(ctx context.Context, appSlug, appTitle string) *cobra.Command {
7878
return fmt.Errorf("unable to get join token: %w", err)
7979
}
8080
joinReporter := newJoinReporter(
81-
jcmd.InstallationSpec.MetricsBaseURL, jcmd.ClusterID, cmd.CalledAs(), flagsToStringSlice(cmd.Flags()),
81+
jcmd.InstallationSpec.MetricsBaseURL, jcmd.ClusterID.String(), cmd.CalledAs(), flagsToStringSlice(cmd.Flags()),
8282
)
8383
joinReporter.ReportJoinStarted(ctx)
8484

@@ -657,6 +657,7 @@ func maybeEnableHA(ctx context.Context, kcli client.Client, mcli metadata.Interf
657657
defer loading.Close()
658658

659659
opts := addons.EnableHAOptions{
660+
ClusterID: jcmd.InstallationSpec.ClusterID,
660661
AdminConsolePort: rc.AdminConsolePort(),
661662
IsAirgap: jcmd.InstallationSpec.AirGap,
662663
IsMultiNodeEnabled: jcmd.InstallationSpec.LicenseInfo != nil && jcmd.InstallationSpec.LicenseInfo.IsMultiNodeEnabled,

cmd/installer/cli/metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type InstallReporter struct {
1616
appSlug string
1717
}
1818

19-
func newInstallReporter(baseURL string, clusterID uuid.UUID, cmd string, args []string, licenseID string, appSlug string) *InstallReporter {
19+
func newInstallReporter(baseURL string, cmd string, args []string, licenseID string, clusterID string, appSlug string) *InstallReporter {
2020
executionID := uuid.New().String()
2121
reporter := metrics.NewReporter(executionID, baseURL, clusterID, cmd, args)
2222
return &InstallReporter{
@@ -54,7 +54,7 @@ type JoinReporter struct {
5454
reporter metrics.ReporterInterface
5555
}
5656

57-
func newJoinReporter(baseURL string, clusterID uuid.UUID, cmd string, flags []string) *JoinReporter {
57+
func newJoinReporter(baseURL string, clusterID string, cmd string, flags []string) *JoinReporter {
5858
executionID := uuid.New().String()
5959
reporter := metrics.NewReporter(executionID, baseURL, clusterID, cmd, flags)
6060
return &JoinReporter{

0 commit comments

Comments
 (0)