Skip to content

Commit 85c2543

Browse files
authored
feat: add BaseDomain to config and update related subroutines (#51)
1 parent 1286a61 commit 85c2543

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ type Config struct {
88
APIExportEndpointSliceName string `mapstructure:"api-export-endpoint-slice-name"`
99
CoreModulePath string `mapstructure:"core-module-path"`
1010
WorkspaceDir string `mapstructure:"workspace-dir" default:"/operator/"`
11+
BaseDomain string `mapstructure:"base-domain" default:"portal.dev.local"`
1112
}

internal/controller/initializer_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func NewLogicalClusterReconciler(log *logger.Logger, restCfg *rest.Config, cl, o
2626
lifecycle: lifecyclecontrollerruntime.NewLifecycleManager(
2727
[]lifecyclesubroutine.Subroutine{
2828
subroutine.NewWorkspaceInitializer(cl, orgClient, restCfg, cfg),
29-
subroutine.NewRealmSubroutine(inClusterClient),
29+
subroutine.NewRealmSubroutine(inClusterClient, cfg.BaseDomain),
3030
},
3131
"logicalcluster",
3232
"LogicalClusterReconciler",

internal/subroutine/realm.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ var (
3131
)
3232

3333
type realmSubroutine struct {
34-
k8s client.Client
34+
k8s client.Client
35+
baseDomain string
3536
}
3637

37-
func NewRealmSubroutine(k8s client.Client) *realmSubroutine {
38+
func NewRealmSubroutine(k8s client.Client, baseDomain string) *realmSubroutine {
3839
return &realmSubroutine{
39-
k8s: k8s,
40+
k8s,
41+
baseDomain,
4042
}
4143
}
4244

@@ -93,6 +95,9 @@ func (r *realmSubroutine) Process(ctx context.Context, instance lifecycleruntime
9395
"client": map[string]interface{}{
9496
"name": workspaceName,
9597
"displayName": workspaceName,
98+
"validRedirectUris": []string{
99+
fmt.Sprintf("https://%s.%s/callback*", workspaceName, r.baseDomain),
100+
},
96101
},
97102
},
98103
"keycloakConfig": map[string]interface{}{

internal/subroutine/realm_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ spec:
3535
releaseName: placeholder
3636
values: {}
3737
`
38+
baseDomain = "portal.dev.local"
3839
)
3940

4041
func newClientMock(t *testing.T, setup func(m *mocks.MockClient)) *mocks.MockClient {
@@ -174,7 +175,7 @@ func TestRealmSubroutine_ProcessAndFinalize(t *testing.T) {
174175

175176
repository, helmRelease = trim(repoYAML), trim(helmReleaseYAML)
176177

177-
rs := NewRealmSubroutine(clientMock)
178+
rs := NewRealmSubroutine(clientMock, baseDomain)
178179
lc := &kcpv1alpha1.LogicalCluster{}
179180
lc.Annotations = map[string]string{"kcp.io/path": "root:orgs:test"}
180181
res, opErr := rs.Process(context.Background(), lc)
@@ -190,7 +191,7 @@ func TestRealmSubroutine_ProcessAndFinalize(t *testing.T) {
190191
})
191192

192193
repository, helmRelease = trim(repoYAML), trim(helmReleaseYAML)
193-
rs := NewRealmSubroutine(clientMock)
194+
rs := NewRealmSubroutine(clientMock, baseDomain)
194195
lc := &kcpv1alpha1.LogicalCluster{}
195196
lc.Annotations = map[string]string{"kcp.io/path": "root:orgs:test"}
196197
res, opErr := rs.Process(context.Background(), lc)
@@ -201,7 +202,7 @@ func TestRealmSubroutine_ProcessAndFinalize(t *testing.T) {
201202
t.Run("missing workspace annotation", func(t *testing.T) {
202203
t.Parallel()
203204
clientMock := newClientMock(t, nil)
204-
rs := NewRealmSubroutine(clientMock)
205+
rs := NewRealmSubroutine(clientMock, baseDomain)
205206
lc := &kcpv1alpha1.LogicalCluster{}
206207
res, opErr := rs.Process(context.Background(), lc)
207208
require.NotNil(t, opErr)
@@ -246,7 +247,7 @@ func TestRealmSubroutine_ProcessAndFinalize(t *testing.T) {
246247
t.Run(tc.name, func(t *testing.T) {
247248
t.Parallel()
248249
clientMock := newClientMock(t, tc.setupMocks)
249-
rs := NewRealmSubroutine(clientMock)
250+
rs := NewRealmSubroutine(clientMock, baseDomain)
250251
lc := &kcpv1alpha1.LogicalCluster{}
251252
lc.Annotations = map[string]string{"kcp.io/path": "root:orgs:test"}
252253
res, opErr := rs.Finalize(context.Background(), lc)

0 commit comments

Comments
 (0)