Skip to content

Commit 77061bf

Browse files
JGAntunesemosbaugh
andauthored
chore(app): add config values types (#2486)
* chore(app): add config value types * chore: fix tests * corresponding frontend changes * corresponding frontend changes * f * f * f * f --------- Co-authored-by: Ethan Mosbaugh <[email protected]>
1 parent 4623ce4 commit 77061bf

File tree

33 files changed

+611
-572
lines changed

33 files changed

+611
-572
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ jobs:
7979
go-version-file: go.mod
8080
cache-dependency-path: "**/*.sum"
8181
- name: Unit tests
82+
env:
83+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8284
run: |
8385
make unit-tests
8486

api/client/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ type Client interface {
1717
SetupLinuxInfra(ignoreHostPreflights bool) (types.Infra, error)
1818
GetLinuxInfraStatus() (types.Infra, error)
1919
GetLinuxAppConfig() (types.AppConfig, error)
20-
GetLinuxAppConfigValues() (map[string]string, error)
21-
PatchLinuxAppConfigValues(values map[string]string) (types.AppConfig, error)
20+
GetLinuxAppConfigValues() (types.AppConfigValues, error)
21+
PatchLinuxAppConfigValues(types.AppConfigValues) (types.AppConfig, error)
2222

2323
GetKubernetesInstallationConfig() (types.KubernetesInstallationConfig, error)
2424
ConfigureKubernetesInstallation(config types.KubernetesInstallationConfig) (types.Status, error)
2525
GetKubernetesInstallationStatus() (types.Status, error)
2626
SetupKubernetesInfra() (types.Infra, error)
2727
GetKubernetesInfraStatus() (types.Infra, error)
2828
GetKubernetesAppConfig() (types.AppConfig, error)
29-
GetKubernetesAppConfigValues() (map[string]string, error)
30-
PatchKubernetesAppConfigValues(values map[string]string) (types.AppConfig, error)
29+
GetKubernetesAppConfigValues() (types.AppConfigValues, error)
30+
PatchKubernetesAppConfigValues(types.AppConfigValues) (types.AppConfig, error)
3131
}
3232

3333
type client struct {

api/client/client_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,10 @@ func TestKubernetesGetAppConfig(t *testing.T) {
709709

710710
func TestLinuxGetAppConfigValues(t *testing.T) {
711711
// Define expected values once
712-
expectedValues := map[string]string{
713-
"test-key1": "test-value1",
714-
"test-key2": "test-value2",
715-
"test-key3": "test-value3",
712+
expectedValues := types.AppConfigValues{
713+
"test-key1": types.AppConfigValue{Value: "test-value1"},
714+
"test-key2": types.AppConfigValue{Value: "test-value2"},
715+
"test-key3": types.AppConfigValue{Value: "test-value3"},
716716
}
717717

718718
// Create a test server
@@ -785,10 +785,10 @@ func TestLinuxGetAppConfigValues(t *testing.T) {
785785

786786
func TestKubernetesGetAppConfigValues(t *testing.T) {
787787
// Define expected values once
788-
expectedValues := map[string]string{
789-
"test-key1": "test-value1",
790-
"test-key2": "test-value2",
791-
"test-key3": "test-value3",
788+
expectedValues := types.AppConfigValues{
789+
"test-key1": types.AppConfigValue{Value: "test-value1"},
790+
"test-key2": types.AppConfigValue{Value: "test-value2"},
791+
"test-key3": types.AppConfigValue{Value: "test-value3"},
792792
}
793793

794794
// Create a test server
@@ -895,8 +895,8 @@ func TestLinuxPatchAppConfigValues(t *testing.T) {
895895
require.NoError(t, err, "Failed to decode request body")
896896

897897
// Verify the request contains expected values
898-
assert.Equal(t, "new-value", req.Values["test-item"])
899-
assert.Equal(t, "required-value", req.Values["required-item"])
898+
assert.Equal(t, "new-value", req.Values["test-item"].Value)
899+
assert.Equal(t, "required-value", req.Values["required-item"].Value)
900900

901901
// Return successful response
902902
w.WriteHeader(http.StatusOK)
@@ -906,9 +906,9 @@ func TestLinuxPatchAppConfigValues(t *testing.T) {
906906

907907
// Test successful set
908908
c := New(server.URL, WithToken("test-token"))
909-
configValues := map[string]string{
910-
"test-item": "new-value",
911-
"required-item": "required-value",
909+
configValues := types.AppConfigValues{
910+
"test-item": types.AppConfigValue{Value: "new-value"},
911+
"required-item": types.AppConfigValue{Value: "required-value"},
912912
}
913913
config, err := c.PatchLinuxAppConfigValues(configValues)
914914
require.NoError(t, err)
@@ -971,8 +971,8 @@ func TestKubernetesPatchAppConfigValues(t *testing.T) {
971971
require.NoError(t, err, "Failed to decode request body")
972972

973973
// Verify the request contains expected values
974-
assert.Equal(t, "new-value", req.Values["test-item"])
975-
assert.Equal(t, "required-value", req.Values["required-item"])
974+
assert.Equal(t, "new-value", req.Values["test-item"].Value)
975+
assert.Equal(t, "required-value", req.Values["required-item"].Value)
976976

977977
// Return successful response
978978
w.WriteHeader(http.StatusOK)
@@ -982,9 +982,9 @@ func TestKubernetesPatchAppConfigValues(t *testing.T) {
982982

983983
// Test successful set
984984
c := New(server.URL, WithToken("test-token"))
985-
configValues := map[string]string{
986-
"test-item": "new-value",
987-
"required-item": "required-value",
985+
configValues := types.AppConfigValues{
986+
"test-item": types.AppConfigValue{Value: "new-value"},
987+
"required-item": types.AppConfigValue{Value: "required-value"},
988988
}
989989
config, err := c.PatchKubernetesAppConfigValues(configValues)
990990
assert.NoError(t, err)

api/client/install.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func (c *client) GetLinuxAppConfig() (types.AppConfig, error) {
322322
return config, nil
323323
}
324324

325-
func (c *client) GetLinuxAppConfigValues() (map[string]string, error) {
325+
func (c *client) GetLinuxAppConfigValues() (types.AppConfigValues, error) {
326326
req, err := http.NewRequest("GET", c.apiURL+"/api/linux/install/app/config/values", nil)
327327
if err != nil {
328328
return nil, err
@@ -349,7 +349,7 @@ func (c *client) GetLinuxAppConfigValues() (map[string]string, error) {
349349
return response.Values, nil
350350
}
351351

352-
func (c *client) PatchLinuxAppConfigValues(values map[string]string) (types.AppConfig, error) {
352+
func (c *client) PatchLinuxAppConfigValues(values types.AppConfigValues) (types.AppConfig, error) {
353353
req := types.PatchAppConfigValuesRequest{
354354
Values: values,
355355
}
@@ -411,7 +411,7 @@ func (c *client) GetKubernetesAppConfig() (types.AppConfig, error) {
411411
return config, nil
412412
}
413413

414-
func (c *client) GetKubernetesAppConfigValues() (map[string]string, error) {
414+
func (c *client) GetKubernetesAppConfigValues() (types.AppConfigValues, error) {
415415
req, err := http.NewRequest("GET", c.apiURL+"/api/kubernetes/install/app/config/values", nil)
416416
if err != nil {
417417
return nil, err
@@ -438,7 +438,7 @@ func (c *client) GetKubernetesAppConfigValues() (map[string]string, error) {
438438
return response.Values, nil
439439
}
440440

441-
func (c *client) PatchKubernetesAppConfigValues(values map[string]string) (types.AppConfig, error) {
441+
func (c *client) PatchKubernetesAppConfigValues(values types.AppConfigValues) (types.AppConfig, error) {
442442
request := types.PatchAppConfigValuesRequest{
443443
Values: values,
444444
}

api/controllers/kubernetes/install/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (c *InstallController) GetAppConfig(ctx context.Context) (kotsv1beta1.Confi
1313
return c.appConfigManager.GetConfig()
1414
}
1515

16-
func (c *InstallController) PatchAppConfigValues(ctx context.Context, values map[string]string) (finalErr error) {
16+
func (c *InstallController) PatchAppConfigValues(ctx context.Context, values types.AppConfigValues) (finalErr error) {
1717
lock, err := c.stateMachine.AcquireLock()
1818
if err != nil {
1919
return types.NewConflictError(err)
@@ -60,6 +60,6 @@ func (c *InstallController) PatchAppConfigValues(ctx context.Context, values map
6060
return nil
6161
}
6262

63-
func (c *InstallController) GetAppConfigValues(ctx context.Context, maskPasswords bool) (map[string]string, error) {
63+
func (c *InstallController) GetAppConfigValues(ctx context.Context, maskPasswords bool) (types.AppConfigValues, error) {
6464
return c.appConfigManager.GetConfigValues(maskPasswords)
6565
}

api/controllers/kubernetes/install/app_test.go

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
appconfig "github.com/replicatedhq/embedded-cluster/api/internal/managers/app/config"
99
"github.com/replicatedhq/embedded-cluster/api/internal/statemachine"
1010
"github.com/replicatedhq/embedded-cluster/api/internal/store"
11+
"github.com/replicatedhq/embedded-cluster/api/types"
1112
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
1213
"github.com/replicatedhq/kotskinds/multitype"
1314
"github.com/stretchr/testify/assert"
@@ -39,90 +40,90 @@ func TestInstallController_PatchAppConfigValues(t *testing.T) {
3940

4041
tests := []struct {
4142
name string
42-
values map[string]string
43+
values types.AppConfigValues
4344
currentState statemachine.State
4445
expectedState statemachine.State
4546
setupMocks func(*appconfig.MockAppConfigManager, *store.MockStore)
4647
expectedErr bool
4748
}{
4849
{
4950
name: "successful set app config values",
50-
values: map[string]string{
51-
"test-item": "new-value",
51+
values: types.AppConfigValues{
52+
"test-item": types.AppConfigValue{Value: "new-item"},
5253
},
5354
currentState: StateNew,
5455
expectedState: StateApplicationConfigured,
5556
setupMocks: func(am *appconfig.MockAppConfigManager, st *store.MockStore) {
5657
mock.InOrder(
57-
am.On("ValidateConfigValues", map[string]string{"test-item": "new-value"}).Return(nil),
58-
am.On("PatchConfigValues", map[string]string{"test-item": "new-value"}).Return(nil),
58+
am.On("ValidateConfigValues", types.AppConfigValues{"test-item": types.AppConfigValue{Value: "new-item"}}).Return(nil),
59+
am.On("PatchConfigValues", types.AppConfigValues{"test-item": types.AppConfigValue{Value: "new-item"}}).Return(nil),
5960
)
6061
},
6162
expectedErr: false,
6263
},
6364
{
6465
name: "successful set app config values from application configuration failed state",
65-
values: map[string]string{
66-
"test-item": "new-value",
66+
values: types.AppConfigValues{
67+
"test-item": types.AppConfigValue{Value: "new-item"},
6768
},
6869
currentState: StateApplicationConfigurationFailed,
6970
expectedState: StateApplicationConfigured,
7071
setupMocks: func(am *appconfig.MockAppConfigManager, st *store.MockStore) {
7172
mock.InOrder(
72-
am.On("ValidateConfigValues", map[string]string{"test-item": "new-value"}).Return(nil),
73-
am.On("PatchConfigValues", map[string]string{"test-item": "new-value"}).Return(nil),
73+
am.On("ValidateConfigValues", types.AppConfigValues{"test-item": types.AppConfigValue{Value: "new-item"}}).Return(nil),
74+
am.On("PatchConfigValues", types.AppConfigValues{"test-item": types.AppConfigValue{Value: "new-item"}}).Return(nil),
7475
)
7576
},
7677
expectedErr: false,
7778
},
7879
{
7980
name: "successful set app config values from application configured state",
80-
values: map[string]string{
81-
"test-item": "new-value",
81+
values: types.AppConfigValues{
82+
"test-item": types.AppConfigValue{Value: "new-item"},
8283
},
8384
currentState: StateApplicationConfigured,
8485
expectedState: StateApplicationConfigured,
8586
setupMocks: func(am *appconfig.MockAppConfigManager, st *store.MockStore) {
8687
mock.InOrder(
87-
am.On("ValidateConfigValues", map[string]string{"test-item": "new-value"}).Return(nil),
88-
am.On("PatchConfigValues", map[string]string{"test-item": "new-value"}).Return(nil),
88+
am.On("ValidateConfigValues", types.AppConfigValues{"test-item": types.AppConfigValue{Value: "new-item"}}).Return(nil),
89+
am.On("PatchConfigValues", types.AppConfigValues{"test-item": types.AppConfigValue{Value: "new-item"}}).Return(nil),
8990
)
9091
},
9192
expectedErr: false,
9293
},
9394
{
9495
name: "validation error",
95-
values: map[string]string{
96-
"test-item": "invalid-value",
96+
values: types.AppConfigValues{
97+
"test-item": types.AppConfigValue{Value: "invalid-value"},
9798
},
9899
currentState: StateNew,
99100
expectedState: StateApplicationConfigurationFailed,
100101
setupMocks: func(am *appconfig.MockAppConfigManager, st *store.MockStore) {
101102
mock.InOrder(
102-
am.On("ValidateConfigValues", map[string]string{"test-item": "invalid-value"}).Return(errors.New("validation error")),
103+
am.On("ValidateConfigValues", types.AppConfigValues{"test-item": types.AppConfigValue{Value: "invalid-value"}}).Return(errors.New("validation error")),
103104
)
104105
},
105106
expectedErr: true,
106107
},
107108
{
108109
name: "set config values error",
109-
values: map[string]string{
110-
"test-item": "new-value",
110+
values: types.AppConfigValues{
111+
"test-item": types.AppConfigValue{Value: "new-item"},
111112
},
112113
currentState: StateNew,
113114
expectedState: StateApplicationConfigurationFailed,
114115
setupMocks: func(am *appconfig.MockAppConfigManager, st *store.MockStore) {
115116
mock.InOrder(
116-
am.On("ValidateConfigValues", map[string]string{"test-item": "new-value"}).Return(nil),
117-
am.On("PatchConfigValues", map[string]string{"test-item": "new-value"}).Return(errors.New("set config error")),
117+
am.On("ValidateConfigValues", types.AppConfigValues{"test-item": types.AppConfigValue{Value: "new-item"}}).Return(nil),
118+
am.On("PatchConfigValues", types.AppConfigValues{"test-item": types.AppConfigValue{Value: "new-item"}}).Return(errors.New("set config error")),
118119
)
119120
},
120121
expectedErr: true,
121122
},
122123
{
123124
name: "invalid state transition",
124-
values: map[string]string{
125-
"test-item": "new-value",
125+
values: types.AppConfigValues{
126+
"test-item": types.AppConfigValue{Value: "new-item"},
126127
},
127128
currentState: StateInfrastructureInstalling,
128129
expectedState: StateInfrastructureInstalling,
@@ -195,21 +196,21 @@ func TestInstallController_GetAppConfigValues(t *testing.T) {
195196
tests := []struct {
196197
name string
197198
setupMocks func(*appconfig.MockAppConfigManager, *store.MockStore)
198-
expectedValues map[string]string
199+
expectedValues types.AppConfigValues
199200
expectedErr bool
200201
}{
201202
{
202203
name: "successful get app config values",
203204
setupMocks: func(am *appconfig.MockAppConfigManager, st *store.MockStore) {
204-
expectedValues := map[string]string{
205-
"test-item": "test-value",
206-
"another-item": "another-value",
205+
expectedValues := types.AppConfigValues{
206+
"test-item": types.AppConfigValue{Value: "test-value"},
207+
"another-item": types.AppConfigValue{Value: "another-value"},
207208
}
208209
am.On("GetConfigValues", false).Return(expectedValues, nil)
209210
},
210-
expectedValues: map[string]string{
211-
"test-item": "test-value",
212-
"another-item": "another-value",
211+
expectedValues: types.AppConfigValues{
212+
"test-item": types.AppConfigValue{Value: "test-value"},
213+
"another-item": types.AppConfigValue{Value: "another-value"},
213214
},
214215
expectedErr: false,
215216
},
@@ -224,9 +225,9 @@ func TestInstallController_GetAppConfigValues(t *testing.T) {
224225
{
225226
name: "empty config values",
226227
setupMocks: func(am *appconfig.MockAppConfigManager, st *store.MockStore) {
227-
am.On("GetConfigValues", false).Return(map[string]string{}, nil)
228+
am.On("GetConfigValues", false).Return(types.AppConfigValues{}, nil)
228229
},
229-
expectedValues: map[string]string{},
230+
expectedValues: types.AppConfigValues{},
230231
expectedErr: false,
231232
},
232233
}

api/controllers/kubernetes/install/controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ type Controller interface {
3030
SetupInfra(ctx context.Context) error
3131
GetInfra(ctx context.Context) (types.Infra, error)
3232
GetAppConfig(ctx context.Context) (kotsv1beta1.Config, error)
33-
PatchAppConfigValues(ctx context.Context, values map[string]string) error
34-
GetAppConfigValues(ctx context.Context, maskPasswords bool) (map[string]string, error)
33+
PatchAppConfigValues(ctx context.Context, values types.AppConfigValues) error
34+
GetAppConfigValues(ctx context.Context, maskPasswords bool) (types.AppConfigValues, error)
3535
}
3636

3737
var _ Controller = (*InstallController)(nil)
@@ -47,7 +47,7 @@ type InstallController struct {
4747
tlsConfig types.TLSConfig
4848
license []byte
4949
airgapBundle string
50-
configValues map[string]string
50+
configValues types.AppConfigValues
5151
endUserConfig *ecv1beta1.Config
5252
store store.Store
5353
ki kubernetesinstallation.Installation
@@ -112,7 +112,7 @@ func WithAirgapBundle(airgapBundle string) InstallControllerOption {
112112
}
113113
}
114114

115-
func WithConfigValues(configValues map[string]string) InstallControllerOption {
115+
func WithConfigValues(configValues types.AppConfigValues) InstallControllerOption {
116116
return func(c *InstallController) {
117117
c.configValues = configValues
118118
}

api/controllers/kubernetes/install/controller_mock.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ func (m *MockController) GetAppConfig(ctx context.Context) (kotsv1beta1.Config,
6161
}
6262

6363
// PatchAppConfigValues mocks the PatchAppConfigValues method
64-
func (m *MockController) PatchAppConfigValues(ctx context.Context, values map[string]string) error {
64+
func (m *MockController) PatchAppConfigValues(ctx context.Context, values types.AppConfigValues) error {
6565
args := m.Called(ctx, values)
6666
return args.Error(0)
6767
}
6868

6969
// GetAppConfigValues mocks the GetAppConfigValues method
70-
func (m *MockController) GetAppConfigValues(ctx context.Context, maskPasswords bool) (map[string]string, error) {
70+
func (m *MockController) GetAppConfigValues(ctx context.Context, maskPasswords bool) (types.AppConfigValues, error) {
7171
args := m.Called(ctx, maskPasswords)
7272
if args.Get(0) == nil {
7373
return nil, args.Error(1)
7474
}
75-
return args.Get(0).(map[string]string), args.Error(1)
75+
return args.Get(0).(types.AppConfigValues), args.Error(1)
7676
}

api/controllers/linux/install/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (c *InstallController) GetAppConfig(ctx context.Context) (kotsv1beta1.Confi
1313
return c.appConfigManager.GetConfig()
1414
}
1515

16-
func (c *InstallController) PatchAppConfigValues(ctx context.Context, values map[string]string) (finalErr error) {
16+
func (c *InstallController) PatchAppConfigValues(ctx context.Context, values types.AppConfigValues) (finalErr error) {
1717
lock, err := c.stateMachine.AcquireLock()
1818
if err != nil {
1919
return types.NewConflictError(err)
@@ -60,6 +60,6 @@ func (c *InstallController) PatchAppConfigValues(ctx context.Context, values map
6060
return nil
6161
}
6262

63-
func (c *InstallController) GetAppConfigValues(ctx context.Context, maskPasswords bool) (map[string]string, error) {
63+
func (c *InstallController) GetAppConfigValues(ctx context.Context, maskPasswords bool) (types.AppConfigValues, error) {
6464
return c.appConfigManager.GetConfigValues(maskPasswords)
6565
}

0 commit comments

Comments
 (0)