Skip to content

Commit 1b005d5

Browse files
committed
manager port
1 parent dd0b50d commit 1b005d5

File tree

6 files changed

+82
-66
lines changed

6 files changed

+82
-66
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ list-distros:
337337
.PHONY: create-node%
338338
create-node%: DISTRO = debian-bookworm
339339
create-node%: NODE_PORT = 30000
340-
create-node%: GUIDED_EXPERIENCE_NODE_PORT = 30080
340+
create-node%: MANAGER_NODE_PORT = 30080
341341
create-node%: K0S_DATA_DIR = /var/lib/embedded-cluster/k0s
342342
create-node%:
343343
@docker run -d \
@@ -349,7 +349,7 @@ create-node%:
349349
-v $(shell pwd):/replicatedhq/embedded-cluster \
350350
-v $(shell dirname $(shell pwd))/kots:/replicatedhq/kots \
351351
$(if $(filter node0,node$*),-p $(NODE_PORT):$(NODE_PORT)) \
352-
$(if $(filter node0,node$*),-p $(GUIDED_EXPERIENCE_NODE_PORT):$(GUIDED_EXPERIENCE_NODE_PORT)) \
352+
$(if $(filter node0,node$*),-p $(MANAGER_NODE_PORT):$(MANAGER_NODE_PORT)) \
353353
$(if $(filter node0,node$*),-p 30003:30003) \
354354
-e EC_PUBLIC_ADDRESS=localhost \
355355
replicated/ec-distro:$(DISTRO)

cmd/installer/cli/install.go

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ type InstallCmdFlags struct {
7070
dataDir string
7171
licenseFile string
7272
localArtifactMirrorPort int
73-
guidedUI bool
7473
assumeYes bool
7574
overrides string
7675
privateCAs []string
@@ -82,6 +81,10 @@ type InstallCmdFlags struct {
8281
license *kotsv1beta1.License
8382
proxy *ecv1beta1.ProxySpec
8483
cidrCfg *newconfig.CIDRConfig
84+
85+
// guided UI flags
86+
managerPort int
87+
guidedUI bool
8588
}
8689

8790
// InstallCmd returns a cobra command for installing the embedded cluster.
@@ -146,6 +149,9 @@ func InstallCmd(ctx context.Context, name string) *cobra.Command {
146149
if err := addInstallAdminConsoleFlags(cmd, &flags); err != nil {
147150
panic(err)
148151
}
152+
if err := addGuidedUIFlags(cmd, &flags); err != nil {
153+
panic(err)
154+
}
149155

150156
cmd.AddCommand(InstallRunPreflightsCmd(ctx, name))
151157

@@ -157,7 +163,6 @@ func addInstallFlags(cmd *cobra.Command, flags *InstallCmdFlags) error {
157163
cmd.Flags().StringVar(&flags.dataDir, "data-dir", ecv1beta1.DefaultDataDir, "Path to the data directory")
158164
cmd.Flags().IntVar(&flags.localArtifactMirrorPort, "local-artifact-mirror-port", ecv1beta1.DefaultLocalArtifactMirrorPort, "Port on which the Local Artifact Mirror will be served")
159165
cmd.Flags().StringVar(&flags.networkInterface, "network-interface", "", "The network interface to use for the cluster")
160-
cmd.Flags().BoolVarP(&flags.guidedUI, "guided-ui", "g", false, "Run the installation in guided UI mode.")
161166
cmd.Flags().BoolVarP(&flags.assumeYes, "yes", "y", false, "Assume yes to all prompts.")
162167
cmd.Flags().SetNormalizeFunc(normalizeNoPromptToYes)
163168

@@ -199,6 +204,20 @@ func addInstallAdminConsoleFlags(cmd *cobra.Command, flags *InstallCmdFlags) err
199204
return nil
200205
}
201206

207+
func addGuidedUIFlags(cmd *cobra.Command, flags *InstallCmdFlags) error {
208+
cmd.Flags().BoolVarP(&flags.guidedUI, "guided-ui", "g", false, "Run the installation in guided UI mode.")
209+
cmd.Flags().IntVar(&flags.managerPort, "manager-port", ecv1beta1.DefaultManagerPort, "Port on which the Manager will be served")
210+
211+
if err := cmd.Flags().MarkHidden("guided-ui"); err != nil {
212+
return err
213+
}
214+
if err := cmd.Flags().MarkHidden("manager-port"); err != nil {
215+
return err
216+
}
217+
218+
return nil
219+
}
220+
202221
func preRunInstall(cmd *cobra.Command, flags *InstallCmdFlags) error {
203222
if os.Getuid() != 0 {
204223
return fmt.Errorf("install command must be run as root")
@@ -235,19 +254,17 @@ func preRunInstall(cmd *cobra.Command, flags *InstallCmdFlags) error {
235254
return err
236255
}
237256

238-
// TODO: implement guided UI
239257
if flags.guidedUI {
240258
configChan := make(chan *apitypes.InstallationConfig)
241259
defer close(configChan)
242260

243-
if err := preRunInstallAPI(cmd.Context(), flags.adminConsolePassword, configChan); err != nil {
261+
if err := preRunInstallAPI(cmd.Context(), flags.adminConsolePassword, flags.managerPort, configChan); err != nil {
244262
return fmt.Errorf("unable to start install API: %w", err)
245263
}
246264

247-
// TODO: fix this message to have the correct address
248-
logrus.Info("")
249-
logrus.Info("Visit http://localhost:30080/ to configure your cluster")
265+
// TODO: fix this message
250266
logrus.Info("")
267+
logrus.Infof("Visit %s to configure your cluster", getManagerURL(flags.managerPort))
251268

252269
installConfig, ok := <-configChan
253270
if !ok {
@@ -281,9 +298,6 @@ func preRunInstall(cmd *cobra.Command, flags *InstallCmdFlags) error {
281298
flags.dataDir = installConfig.DataDirectory
282299
flags.localArtifactMirrorPort = installConfig.LocalArtifactMirrorPort
283300

284-
runtimeconfig.SetDataDir(installConfig.DataDirectory)
285-
runtimeconfig.SetLocalArtifactMirrorPort(installConfig.LocalArtifactMirrorPort)
286-
runtimeconfig.SetAdminConsolePort(installConfig.AdminConsolePort)
287301
} else {
288302
proxy, err := parseProxyFlags(cmd)
289303
if err != nil {
@@ -310,9 +324,19 @@ func preRunInstall(cmd *cobra.Command, flags *InstallCmdFlags) error {
310324
}
311325
}
312326

313-
runtimeconfig.ApplyFlags(cmd.Flags())
327+
if flags.localArtifactMirrorPort != 0 && flags.adminConsolePort != 0 {
328+
if flags.localArtifactMirrorPort == flags.adminConsolePort {
329+
return fmt.Errorf("local artifact mirror port cannot be the same as admin console port")
330+
}
331+
}
314332
}
315333

334+
// TODO: validate that a single port isn't used for multiple services
335+
runtimeconfig.SetDataDir(flags.dataDir)
336+
runtimeconfig.SetManagerPort(flags.managerPort)
337+
runtimeconfig.SetLocalArtifactMirrorPort(flags.localArtifactMirrorPort)
338+
runtimeconfig.SetAdminConsolePort(flags.adminConsolePort)
339+
316340
os.Setenv("KUBECONFIG", runtimeconfig.PathToKubeConfig()) // this is needed for restore as well since it shares this function
317341
os.Setenv("TMPDIR", runtimeconfig.EmbeddedClusterTmpSubDir())
318342

@@ -336,13 +360,13 @@ func preRunInstall(cmd *cobra.Command, flags *InstallCmdFlags) error {
336360
return nil
337361
}
338362

339-
func preRunInstallAPI(ctx context.Context, password string, configChan chan<- *apitypes.InstallationConfig) error {
363+
func preRunInstallAPI(ctx context.Context, password string, managerPort int, configChan chan<- *apitypes.InstallationConfig) error {
340364
logger, err := api.NewLogger()
341365
if err != nil {
342366
logrus.Warnf("Unable to setup API logging: %v", err)
343367
}
344368

345-
listener, err := net.Listen("tcp", ":30080") // TODO: make this configurable
369+
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", managerPort))
346370
if err != nil {
347371
return fmt.Errorf("unable to create listener: %w", err)
348372
}
@@ -548,7 +572,7 @@ func runInstall(ctx context.Context, name string, flags InstallCmdFlags, metrics
548572
}
549573

550574
if flags.guidedUI {
551-
if err := markUIInstallComplete(ctx, flags.adminConsolePassword); err != nil {
575+
if err := markUIInstallComplete(flags.adminConsolePassword, flags.managerPort); err != nil {
552576
return fmt.Errorf("unable to mark ui install complete: %w", err)
553577
}
554578
} else {
@@ -560,8 +584,8 @@ func runInstall(ctx context.Context, name string, flags InstallCmdFlags, metrics
560584
return nil
561585
}
562586

563-
func markUIInstallComplete(ctx context.Context, password string) error {
564-
apiClient := apiclient.New("http://localhost:30080") // TODO: make this configurable
587+
func markUIInstallComplete(password string, managerPort int) error {
588+
apiClient := apiclient.New(fmt.Sprintf("http://localhost:%d", managerPort))
565589
if err := apiClient.Login(password); err != nil {
566590
return fmt.Errorf("unable to login: %w", err)
567591
}
@@ -1489,14 +1513,31 @@ func printSuccessMessage(license *kotsv1beta1.License, networkInterface string)
14891513
return nil
14901514
}
14911515

1516+
func getManagerURL(port int) string {
1517+
ipaddr := runtimeconfig.TryDiscoverPublicIP()
1518+
if ipaddr == "" {
1519+
if addr := os.Getenv("EC_PUBLIC_ADDRESS"); addr != "" {
1520+
ipaddr = addr
1521+
} else {
1522+
logrus.Errorf("Unable to determine node IP address")
1523+
ipaddr = "NODE-IP-ADDRESS"
1524+
}
1525+
}
1526+
return fmt.Sprintf("http://%s:%v", ipaddr, port)
1527+
}
1528+
14921529
func getAdminConsoleURL(networkInterface string, port int) string {
14931530
ipaddr := runtimeconfig.TryDiscoverPublicIP()
14941531
if ipaddr == "" {
14951532
var err error
14961533
ipaddr, err = netutils.FirstValidAddress(networkInterface)
14971534
if err != nil {
1498-
logrus.Errorf("Unable to determine node IP address: %v", err)
1499-
ipaddr = "NODE-IP-ADDRESS"
1535+
if addr := os.Getenv("EC_PUBLIC_ADDRESS"); addr != "" {
1536+
ipaddr = addr
1537+
} else {
1538+
logrus.Errorf("Unable to determine node IP address: %v", err)
1539+
ipaddr = "NODE-IP-ADDRESS"
1540+
}
15001541
}
15011542
}
15021543
return fmt.Sprintf("http://%s:%v", ipaddr, port)

cmd/installer/cli/materialize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func MaterializeCmd(ctx context.Context, name string) *cobra.Command {
2525
return fmt.Errorf("materialize command must be run as root")
2626
}
2727

28-
runtimeconfig.ApplyFlags(cmd.Flags())
28+
runtimeconfig.SetDataDir(dataDir)
2929
os.Setenv("TMPDIR", runtimeconfig.EmbeddedClusterTmpSubDir())
3030

3131
return nil

kinds/apis/v1beta1/installation_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ type LocalArtifactMirrorSpec struct {
104104
Port int `json:"port,omitempty"`
105105
}
106106

107+
// ManagerSpec holds the manager configuration.
108+
type ManagerSpec struct {
109+
// Port holds the port on which the manager will be served.
110+
Port int `json:"port,omitempty"`
111+
}
112+
107113
// LicenseInfo holds information about the license used to install the cluster.
108114
type LicenseInfo struct {
109115
IsDisasterRecoverySupported bool `json:"isDisasterRecoverySupported,omitempty"`

kinds/apis/v1beta1/runtimeconfig_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const (
99
DefaultAdminConsolePort = 30000
1010
DefaultLocalArtifactMirrorPort = 50000
1111
DefaultNetworkCIDR = "10.244.0.0/16"
12+
DefaultManagerPort = 30080
1213
)
1314

1415
// RuntimeConfigSpec defines the configuration for the Embedded Cluster at runtime.
@@ -29,6 +30,8 @@ type RuntimeConfigSpec struct {
2930
AdminConsole AdminConsoleSpec `json:"adminConsole,omitempty"`
3031
// LocalArtifactMirrorPort holds the Local Artifact Mirror configuration.
3132
LocalArtifactMirror LocalArtifactMirrorSpec `json:"localArtifactMirror,omitempty"`
33+
// Manager holds the Manager configuration.
34+
Manager ManagerSpec `json:"manager,omitempty"`
3235
}
3336

3437
func (c *RuntimeConfigSpec) UnmarshalJSON(data []byte) error {
@@ -53,6 +56,7 @@ func runtimeConfigSetDefaults(c *RuntimeConfigSpec) {
5356
}
5457
adminConsoleSpecSetDefaults(&c.AdminConsole)
5558
localArtifactMirrorSpecSetDefaults(&c.LocalArtifactMirror)
59+
managerSpecSetDefaults(&c.Manager)
5660
}
5761

5862
func adminConsoleSpecSetDefaults(s *AdminConsoleSpec) {
@@ -66,3 +70,9 @@ func localArtifactMirrorSpecSetDefaults(s *LocalArtifactMirrorSpec) {
6670
s.Port = DefaultLocalArtifactMirrorPort
6771
}
6872
}
73+
74+
func managerSpecSetDefaults(s *ManagerSpec) {
75+
if s.Port == 0 {
76+
s.Port = DefaultManagerPort
77+
}
78+
}

pkg/runtimeconfig/runtimeconfig.go

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
99
"github.com/sirupsen/logrus"
10-
"github.com/spf13/pflag"
1110
"sigs.k8s.io/yaml"
1211
)
1312

@@ -216,50 +215,10 @@ func SetAdminConsolePort(port int) {
216215
runtimeConfig.AdminConsole.Port = port
217216
}
218217

219-
func SetHostCABundlePath(hostCABundlePath string) {
220-
runtimeConfig.HostCABundlePath = hostCABundlePath
221-
}
222-
223-
func ApplyFlags(flags *pflag.FlagSet) error {
224-
if flags.Lookup("data-dir") != nil {
225-
dd, err := flags.GetString("data-dir")
226-
if err != nil {
227-
return fmt.Errorf("get data-dir flag: %w", err)
228-
}
229-
SetDataDir(dd)
230-
}
231-
232-
if flags.Lookup("local-artifact-mirror-port") != nil {
233-
lap, err := flags.GetInt("local-artifact-mirror-port")
234-
if err != nil {
235-
return fmt.Errorf("get local-artifact-mirror-port flag: %w", err)
236-
}
237-
SetLocalArtifactMirrorPort(lap)
238-
}
239-
240-
if flags.Lookup("admin-console-port") != nil {
241-
ap, err := flags.GetInt("admin-console-port")
242-
if err != nil {
243-
return fmt.Errorf("get admin-console-port flag: %w", err)
244-
}
245-
SetAdminConsolePort(ap)
246-
}
247-
248-
if err := validate(); err != nil {
249-
return err
250-
}
251-
252-
return nil
218+
func SetManagerPort(port int) {
219+
runtimeConfig.Manager.Port = port
253220
}
254221

255-
func validate() error {
256-
lamPort := LocalArtifactMirrorPort()
257-
acPort := AdminConsolePort()
258-
259-
if lamPort != 0 && acPort != 0 {
260-
if lamPort == acPort {
261-
return fmt.Errorf("local artifact mirror port cannot be the same as admin console port")
262-
}
263-
}
264-
return nil
222+
func SetHostCABundlePath(hostCABundlePath string) {
223+
runtimeConfig.HostCABundlePath = hostCABundlePath
265224
}

0 commit comments

Comments
 (0)