Skip to content

Commit 9a0ed6f

Browse files
authored
Add Kubernetes install target setup page (#2383)
1 parent ec0f664 commit 9a0ed6f

File tree

103 files changed

+4280
-2013
lines changed

Some content is hidden

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

103 files changed

+4280
-2013
lines changed

api/api.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/replicatedhq/embedded-cluster/api/controllers/auth"
77
"github.com/replicatedhq/embedded-cluster/api/controllers/console"
8+
kubernetesinstall "github.com/replicatedhq/embedded-cluster/api/controllers/kubernetes/install"
89
linuxinstall "github.com/replicatedhq/embedded-cluster/api/controllers/linux/install"
910
"github.com/replicatedhq/embedded-cluster/api/pkg/logger"
1011
"github.com/replicatedhq/embedded-cluster/api/types"
@@ -39,9 +40,10 @@ type API struct {
3940
logger logrus.FieldLogger
4041
metricsReporter metrics.ReporterInterface
4142

42-
authController auth.Controller
43-
consoleController console.Controller
44-
linuxInstallController linuxinstall.Controller
43+
authController auth.Controller
44+
consoleController console.Controller
45+
linuxInstallController linuxinstall.Controller
46+
kubernetesInstallController kubernetesinstall.Controller
4547

4648
handlers handlers
4749
}
@@ -70,6 +72,13 @@ func WithLinuxInstallController(linuxInstallController linuxinstall.Controller)
7072
}
7173
}
7274

75+
// WithKubernetesInstallController configures the kubernetes install controller for the API.
76+
func WithKubernetesInstallController(kubernetesInstallController kubernetesinstall.Controller) Option {
77+
return func(a *API) {
78+
a.kubernetesInstallController = kubernetesInstallController
79+
}
80+
}
81+
7382
// WithLogger configures the logger for the API. If not provided, a default logger will be created.
7483
func WithLogger(logger logrus.FieldLogger) Option {
7584
return func(a *API) {

api/client/client.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import (
1111

1212
type Client interface {
1313
Authenticate(password string) error
14-
GetInstallationConfig() (types.InstallationConfig, error)
15-
GetInstallationStatus() (types.Status, error)
16-
ConfigureInstallation(config types.InstallationConfig) (types.Status, error)
17-
SetupInfra() (types.Infra, error)
18-
GetInfraStatus() (types.Infra, error)
19-
SetInstallStatus(status types.Status) (types.Status, error)
14+
GetLinuxInstallationConfig() (types.LinuxInstallationConfig, error)
15+
GetLinuxInstallationStatus() (types.Status, error)
16+
ConfigureLinuxInstallation(config types.LinuxInstallationConfig) (types.Status, error)
17+
SetupLinuxInfra() (types.LinuxInfra, error)
18+
GetLinuxInfraStatus() (types.LinuxInfra, error)
19+
20+
GetKubernetesInstallationConfig() (types.KubernetesInstallationConfig, error)
21+
ConfigureKubernetesInstallation(config types.KubernetesInstallationConfig) (types.Status, error)
22+
GetKubernetesInstallationStatus() (types.Status, error)
2023
}
2124

2225
type client struct {

api/client/client_test.go

Lines changed: 137 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestLogin(t *testing.T) {
9999
assert.Equal(t, "Invalid password", apiErr.Message)
100100
}
101101

102-
func TestGetInstallationConfig(t *testing.T) {
102+
func TestLinuxGetInstallationConfig(t *testing.T) {
103103
// Create a test server
104104
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
105105
assert.Equal(t, "GET", r.Method)
@@ -110,7 +110,7 @@ func TestGetInstallationConfig(t *testing.T) {
110110

111111
// Return successful response
112112
w.WriteHeader(http.StatusOK)
113-
json.NewEncoder(w).Encode(types.InstallationConfig{
113+
json.NewEncoder(w).Encode(types.LinuxInstallationConfig{
114114
GlobalCIDR: "10.0.0.0/24",
115115
AdminConsolePort: 8080,
116116
})
@@ -119,7 +119,7 @@ func TestGetInstallationConfig(t *testing.T) {
119119

120120
// Test successful get
121121
c := New(server.URL, WithToken("test-token"))
122-
config, err := c.GetInstallationConfig()
122+
config, err := c.GetLinuxInstallationConfig()
123123
assert.NoError(t, err)
124124
assert.Equal(t, "10.0.0.0/24", config.GlobalCIDR)
125125
assert.Equal(t, 8080, config.AdminConsolePort)
@@ -135,17 +135,17 @@ func TestGetInstallationConfig(t *testing.T) {
135135
defer errorServer.Close()
136136

137137
c = New(errorServer.URL, WithToken("test-token"))
138-
config, err = c.GetInstallationConfig()
138+
config, err = c.GetLinuxInstallationConfig()
139139
assert.Error(t, err)
140-
assert.Equal(t, types.InstallationConfig{}, config)
140+
assert.Equal(t, types.LinuxInstallationConfig{}, config)
141141

142142
apiErr, ok := err.(*types.APIError)
143143
require.True(t, ok, "Expected err to be of type *types.APIError")
144144
assert.Equal(t, http.StatusInternalServerError, apiErr.StatusCode)
145145
assert.Equal(t, "Internal Server Error", apiErr.Message)
146146
}
147147

148-
func TestConfigureInstallation(t *testing.T) {
148+
func TestLinuxConfigureInstallation(t *testing.T) {
149149
// Create a test server
150150
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
151151
// Check request method and path
@@ -157,7 +157,7 @@ func TestConfigureInstallation(t *testing.T) {
157157
assert.Equal(t, "Bearer test-token", r.Header.Get("Authorization"))
158158

159159
// Decode request body
160-
var config types.InstallationConfig
160+
var config types.LinuxInstallationConfig
161161
err := json.NewDecoder(r.Body).Decode(&config)
162162
require.NoError(t, err, "Failed to decode request body")
163163

@@ -172,11 +172,11 @@ func TestConfigureInstallation(t *testing.T) {
172172

173173
// Test successful configure
174174
c := New(server.URL, WithToken("test-token"))
175-
config := types.InstallationConfig{
175+
config := types.LinuxInstallationConfig{
176176
GlobalCIDR: "20.0.0.0/24",
177177
LocalArtifactMirrorPort: 9081,
178178
}
179-
status, err := c.ConfigureInstallation(config)
179+
status, err := c.ConfigureLinuxInstallation(config)
180180
assert.NoError(t, err)
181181
assert.Equal(t, types.StateRunning, status.State)
182182
assert.Equal(t, "Configuring installation", status.Description)
@@ -192,7 +192,7 @@ func TestConfigureInstallation(t *testing.T) {
192192
defer errorServer.Close()
193193

194194
c = New(errorServer.URL, WithToken("test-token"))
195-
status, err = c.ConfigureInstallation(config)
195+
status, err = c.ConfigureLinuxInstallation(config)
196196
assert.Error(t, err)
197197
assert.Equal(t, types.Status{}, status)
198198

@@ -202,7 +202,7 @@ func TestConfigureInstallation(t *testing.T) {
202202
assert.Equal(t, "Bad Request", apiErr.Message)
203203
}
204204

205-
func TestSetupInfra(t *testing.T) {
205+
func TestLinuxSetupInfra(t *testing.T) {
206206
// Create a test server
207207
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
208208
assert.Equal(t, "POST", r.Method)
@@ -213,7 +213,7 @@ func TestSetupInfra(t *testing.T) {
213213

214214
// Return successful response
215215
w.WriteHeader(http.StatusOK)
216-
json.NewEncoder(w).Encode(types.Infra{
216+
json.NewEncoder(w).Encode(types.LinuxInfra{
217217
Status: types.Status{
218218
State: types.StateRunning,
219219
Description: "Installing infra",
@@ -224,7 +224,7 @@ func TestSetupInfra(t *testing.T) {
224224

225225
// Test successful setup
226226
c := New(server.URL, WithToken("test-token"))
227-
infra, err := c.SetupInfra()
227+
infra, err := c.SetupLinuxInfra()
228228
assert.NoError(t, err)
229229
assert.Equal(t, types.StateRunning, infra.Status.State)
230230
assert.Equal(t, "Installing infra", infra.Status.Description)
@@ -240,17 +240,17 @@ func TestSetupInfra(t *testing.T) {
240240
defer errorServer.Close()
241241

242242
c = New(errorServer.URL, WithToken("test-token"))
243-
infra, err = c.SetupInfra()
243+
infra, err = c.SetupLinuxInfra()
244244
assert.Error(t, err)
245-
assert.Equal(t, types.Infra{}, infra)
245+
assert.Equal(t, types.LinuxInfra{}, infra)
246246

247247
apiErr, ok := err.(*types.APIError)
248248
require.True(t, ok, "Expected err to be of type *types.APIError")
249249
assert.Equal(t, http.StatusInternalServerError, apiErr.StatusCode)
250250
assert.Equal(t, "Internal Server Error", apiErr.Message)
251251
}
252252

253-
func TestGetInfraStatus(t *testing.T) {
253+
func TestLinuxGetInfraStatus(t *testing.T) {
254254
// Create a test server
255255
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
256256
assert.Equal(t, "GET", r.Method)
@@ -261,7 +261,7 @@ func TestGetInfraStatus(t *testing.T) {
261261

262262
// Return successful response
263263
w.WriteHeader(http.StatusOK)
264-
json.NewEncoder(w).Encode(types.Infra{
264+
json.NewEncoder(w).Encode(types.LinuxInfra{
265265
Status: types.Status{
266266
State: types.StateSucceeded,
267267
Description: "Installation successful",
@@ -272,7 +272,7 @@ func TestGetInfraStatus(t *testing.T) {
272272

273273
// Test successful get
274274
c := New(server.URL, WithToken("test-token"))
275-
infra, err := c.GetInfraStatus()
275+
infra, err := c.GetLinuxInfraStatus()
276276
assert.NoError(t, err)
277277
assert.Equal(t, types.StateSucceeded, infra.Status.State)
278278
assert.Equal(t, "Installation successful", infra.Status.Description)
@@ -288,45 +288,103 @@ func TestGetInfraStatus(t *testing.T) {
288288
defer errorServer.Close()
289289

290290
c = New(errorServer.URL, WithToken("test-token"))
291-
infra, err = c.GetInfraStatus()
291+
infra, err = c.GetLinuxInfraStatus()
292292
assert.Error(t, err)
293-
assert.Equal(t, types.Infra{}, infra)
293+
assert.Equal(t, types.LinuxInfra{}, infra)
294294

295295
apiErr, ok := err.(*types.APIError)
296296
require.True(t, ok, "Expected err to be of type *types.APIError")
297297
assert.Equal(t, http.StatusInternalServerError, apiErr.StatusCode)
298298
assert.Equal(t, "Internal Server Error", apiErr.Message)
299299
}
300300

301-
func TestSetInstallStatus(t *testing.T) {
301+
func TestKubernetesGetInstallationConfig(t *testing.T) {
302302
// Create a test server
303303
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
304+
assert.Equal(t, "GET", r.Method)
305+
assert.Equal(t, "/api/kubernetes/install/installation/config", r.URL.Path)
306+
307+
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
308+
assert.Equal(t, "Bearer test-token", r.Header.Get("Authorization"))
309+
310+
// Return successful response
311+
w.WriteHeader(http.StatusOK)
312+
json.NewEncoder(w).Encode(types.KubernetesInstallationConfig{
313+
HTTPProxy: "http://proxy.example.com",
314+
HTTPSProxy: "https://proxy.example.com",
315+
NoProxy: "localhost,127.0.0.1",
316+
AdminConsolePort: 8080,
317+
})
318+
}))
319+
defer server.Close()
320+
321+
// Test successful get
322+
c := New(server.URL, WithToken("test-token"))
323+
config, err := c.GetKubernetesInstallationConfig()
324+
assert.NoError(t, err)
325+
assert.Equal(t, "http://proxy.example.com", config.HTTPProxy)
326+
assert.Equal(t, "https://proxy.example.com", config.HTTPSProxy)
327+
assert.Equal(t, "localhost,127.0.0.1", config.NoProxy)
328+
assert.Equal(t, 8080, config.AdminConsolePort)
329+
330+
// Test error response
331+
errorServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
332+
w.WriteHeader(http.StatusInternalServerError)
333+
json.NewEncoder(w).Encode(types.APIError{
334+
StatusCode: http.StatusInternalServerError,
335+
Message: "Internal Server Error",
336+
})
337+
}))
338+
defer errorServer.Close()
339+
340+
c = New(errorServer.URL, WithToken("test-token"))
341+
config, err = c.GetKubernetesInstallationConfig()
342+
assert.Error(t, err)
343+
assert.Equal(t, types.KubernetesInstallationConfig{}, config)
344+
345+
apiErr, ok := err.(*types.APIError)
346+
require.True(t, ok, "Expected err to be of type *types.APIError")
347+
assert.Equal(t, http.StatusInternalServerError, apiErr.StatusCode)
348+
assert.Equal(t, "Internal Server Error", apiErr.Message)
349+
}
350+
351+
func TestKubernetesConfigureInstallation(t *testing.T) {
352+
// Create a test server
353+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
354+
// Check request method and path
304355
assert.Equal(t, "POST", r.Method)
305-
assert.Equal(t, "/api/linux/install/status", r.URL.Path)
356+
assert.Equal(t, "/api/kubernetes/install/installation/configure", r.URL.Path)
306357

358+
// Check headers
307359
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
308360
assert.Equal(t, "Bearer test-token", r.Header.Get("Authorization"))
309361

310362
// Decode request body
311-
var status types.Status
312-
err := json.NewDecoder(r.Body).Decode(&status)
363+
var config types.KubernetesInstallationConfig
364+
err := json.NewDecoder(r.Body).Decode(&config)
313365
require.NoError(t, err, "Failed to decode request body")
314366

315367
// Return successful response
316368
w.WriteHeader(http.StatusOK)
317-
json.NewEncoder(w).Encode(status)
369+
json.NewEncoder(w).Encode(types.Status{
370+
State: types.StateSucceeded,
371+
Description: "Installation configured",
372+
})
318373
}))
319374
defer server.Close()
320375

321-
// Test successful set
376+
// Test successful configure
322377
c := New(server.URL, WithToken("test-token"))
323-
status := types.Status{
324-
State: types.StateSucceeded,
325-
Description: "Installation successful",
378+
config := types.KubernetesInstallationConfig{
379+
HTTPProxy: "http://proxy.example.com",
380+
HTTPSProxy: "https://proxy.example.com",
381+
NoProxy: "localhost,127.0.0.1",
382+
AdminConsolePort: 8080,
326383
}
327-
newStatus, err := c.SetInstallStatus(status)
384+
status, err := c.ConfigureKubernetesInstallation(config)
328385
assert.NoError(t, err)
329-
assert.Equal(t, status, newStatus)
386+
assert.Equal(t, types.StateSucceeded, status.State)
387+
assert.Equal(t, "Installation configured", status.Description)
330388

331389
// Test error response
332390
errorServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -339,16 +397,62 @@ func TestSetInstallStatus(t *testing.T) {
339397
defer errorServer.Close()
340398

341399
c = New(errorServer.URL, WithToken("test-token"))
342-
newStatus, err = c.SetInstallStatus(status)
400+
status, err = c.ConfigureKubernetesInstallation(config)
343401
assert.Error(t, err)
344-
assert.Equal(t, types.Status{}, newStatus)
402+
assert.Equal(t, types.Status{}, status)
345403

346404
apiErr, ok := err.(*types.APIError)
347405
require.True(t, ok, "Expected err to be of type *types.APIError")
348406
assert.Equal(t, http.StatusBadRequest, apiErr.StatusCode)
349407
assert.Equal(t, "Bad Request", apiErr.Message)
350408
}
351409

410+
func TestKubernetesGetInstallationStatus(t *testing.T) {
411+
// Create a test server
412+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
413+
assert.Equal(t, "GET", r.Method)
414+
assert.Equal(t, "/api/kubernetes/install/installation/status", r.URL.Path)
415+
416+
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
417+
assert.Equal(t, "Bearer test-token", r.Header.Get("Authorization"))
418+
419+
// Return successful response
420+
w.WriteHeader(http.StatusOK)
421+
json.NewEncoder(w).Encode(types.Status{
422+
State: types.StateSucceeded,
423+
Description: "Installation successful",
424+
})
425+
}))
426+
defer server.Close()
427+
428+
// Test successful get
429+
c := New(server.URL, WithToken("test-token"))
430+
status, err := c.GetKubernetesInstallationStatus()
431+
assert.NoError(t, err)
432+
assert.Equal(t, types.StateSucceeded, status.State)
433+
assert.Equal(t, "Installation successful", status.Description)
434+
435+
// Test error response
436+
errorServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
437+
w.WriteHeader(http.StatusInternalServerError)
438+
json.NewEncoder(w).Encode(types.APIError{
439+
StatusCode: http.StatusInternalServerError,
440+
Message: "Internal Server Error",
441+
})
442+
}))
443+
defer errorServer.Close()
444+
445+
c = New(errorServer.URL, WithToken("test-token"))
446+
status, err = c.GetKubernetesInstallationStatus()
447+
assert.Error(t, err)
448+
assert.Equal(t, types.Status{}, status)
449+
450+
apiErr, ok := err.(*types.APIError)
451+
require.True(t, ok, "Expected err to be of type *types.APIError")
452+
assert.Equal(t, http.StatusInternalServerError, apiErr.StatusCode)
453+
assert.Equal(t, "Internal Server Error", apiErr.Message)
454+
}
455+
352456
func TestErrorFromResponse(t *testing.T) {
353457
// Create a response with an error
354458
resp := &http.Response{

0 commit comments

Comments
 (0)