Skip to content

Commit 85b8d3b

Browse files
authored
feat(ui): validate admin console and lam port are not the same as manager (#2308)
1 parent 66f52f0 commit 85b8d3b

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

api/internal/managers/installation/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ func (m *installationManager) validateAdminConsolePort(config *types.Installatio
111111
return errors.New("adminConsolePort and localArtifactMirrorPort cannot be equal")
112112
}
113113

114+
if config.AdminConsolePort == m.rc.ManagerPort() {
115+
return errors.New("adminConsolePort cannot be the same as the manager port")
116+
}
117+
114118
return nil
115119
}
116120

@@ -128,6 +132,10 @@ func (m *installationManager) validateLocalArtifactMirrorPort(config *types.Inst
128132
return errors.New("adminConsolePort and localArtifactMirrorPort cannot be equal")
129133
}
130134

135+
if config.LocalArtifactMirrorPort == m.rc.ManagerPort() {
136+
return errors.New("localArtifactMirrorPort cannot be the same as the manager port")
137+
}
138+
131139
return nil
132140
}
133141

api/internal/managers/installation/config_test.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ import (
1313
"github.com/replicatedhq/embedded-cluster/api/types"
1414
ecv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
1515
"github.com/replicatedhq/embedded-cluster/pkg-new/hostutils"
16+
"github.com/replicatedhq/embedded-cluster/pkg/runtimeconfig"
1617
)
1718

1819
func TestValidateConfig(t *testing.T) {
1920
// Create test cases for validation
2021
tests := []struct {
2122
name string
23+
rc runtimeconfig.RuntimeConfig
2224
config *types.InstallationConfig
2325
expectedErr bool
2426
}{
@@ -139,11 +141,52 @@ func TestValidateConfig(t *testing.T) {
139141
},
140142
expectedErr: true,
141143
},
144+
{
145+
name: "same ports for admin console and manager",
146+
rc: func() runtimeconfig.RuntimeConfig {
147+
rc := runtimeconfig.New(nil)
148+
rc.SetManagerPort(8800)
149+
return rc
150+
}(),
151+
config: &types.InstallationConfig{
152+
GlobalCIDR: "10.0.0.0/16",
153+
NetworkInterface: "eth0",
154+
AdminConsolePort: 8800,
155+
LocalArtifactMirrorPort: 8888,
156+
DataDirectory: "/var/lib/embedded-cluster",
157+
},
158+
expectedErr: true,
159+
},
160+
{
161+
name: "same ports for artifact mirror and manager",
162+
rc: func() runtimeconfig.RuntimeConfig {
163+
rc := runtimeconfig.New(nil)
164+
rc.SetManagerPort(8888)
165+
return rc
166+
}(),
167+
config: &types.InstallationConfig{
168+
GlobalCIDR: "10.0.0.0/16",
169+
NetworkInterface: "eth0",
170+
AdminConsolePort: 8800,
171+
LocalArtifactMirrorPort: 8888,
172+
DataDirectory: "/var/lib/embedded-cluster",
173+
},
174+
expectedErr: true,
175+
},
142176
}
143177

144178
for _, tt := range tests {
145179
t.Run(tt.name, func(t *testing.T) {
146-
manager := NewInstallationManager()
180+
var rc runtimeconfig.RuntimeConfig
181+
if tt.rc != nil {
182+
rc = tt.rc
183+
} else {
184+
rc = runtimeconfig.New(nil)
185+
}
186+
rc.SetDataDir(t.TempDir())
187+
188+
manager := NewInstallationManager(WithRuntimeConfig(rc))
189+
147190
err := manager.ValidateConfig(tt.config)
148191

149192
if tt.expectedErr {

pkg/runtimeconfig/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type RuntimeConfig interface {
2626
WriteToDisk() error
2727
LocalArtifactMirrorPort() int
2828
AdminConsolePort() int
29+
ManagerPort() int
2930
HostCABundlePath() string
3031
SetDataDir(dataDir string)
3132
SetLocalArtifactMirrorPort(port int)

pkg/runtimeconfig/mock.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ func (m *MockRuntimeConfig) AdminConsolePort() int {
133133
return args.Int(0)
134134
}
135135

136+
// ManagerPort mocks the ManagerPort method
137+
func (m *MockRuntimeConfig) ManagerPort() int {
138+
args := m.Called()
139+
return args.Int(0)
140+
}
141+
136142
// HostCABundlePath mocks the HostCABundlePath method
137143
func (m *MockRuntimeConfig) HostCABundlePath() string {
138144
args := m.Called()

pkg/runtimeconfig/runtimeconfig.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ func (rc *runtimeConfig) AdminConsolePort() int {
207207
return ecv1beta1.DefaultAdminConsolePort
208208
}
209209

210+
// ManagerPort returns the configured port for the manager or the default if not
211+
// configured.
212+
func (rc *runtimeConfig) ManagerPort() int {
213+
if rc.spec.Manager.Port > 0 {
214+
return rc.spec.Manager.Port
215+
}
216+
return ecv1beta1.DefaultManagerPort
217+
}
218+
210219
// HostCABundlePath returns the path to the host CA bundle.
211220
func (rc *runtimeConfig) HostCABundlePath() string {
212221
return rc.spec.HostCABundlePath

0 commit comments

Comments
 (0)