Skip to content

Commit 47bfdc7

Browse files
author
Moritz Clasmeier
committed
Make central's exposure a pointer
1 parent c9eb6ac commit 47bfdc7

5 files changed

Lines changed: 55 additions & 29 deletions

File tree

cmd/deploy.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Examples:
186186
if err := yaml.Unmarshal([]byte(val), &exposure); err != nil {
187187
return err
188188
}
189-
settings.Central.Exposure = exposure
189+
settings.Central.Exposure = ptr.To(exposure)
190190
return nil
191191
},
192192
), "exposure", "Central exposure backend (loadbalancer, none)")
@@ -432,11 +432,11 @@ func runDeploy(cmd *cobra.Command, args []string) error {
432432
return errors.New("cannot use --envrc with central port-forwarding enabled. The --envrc flag is for non-interactive mode with remote cluster access")
433433
}
434434

435-
if envrc != "" && deploySettings.Central.Exposure == types.ExposureNone {
436-
return errors.New("cannot use --envrc with --exposure=none. The --envrc flag requires a remotely accessible endpoint (e.g., --exposure=loadbalancer)")
435+
if envrc != "" && !deploySettings.Central.ExposureEnabled() {
436+
return errors.New("cannot use --envrc without central exposure. The --envrc flag requires a remotely accessible endpoint (e.g., --exposure=loadbalancer)")
437437
}
438438

439-
if !deploySettings.Central.PortForwardingSet() && deploySettings.Central.Exposure == types.ExposureNone {
439+
if !deploySettings.Central.PortForwardingSet() && !deploySettings.Central.ExposureEnabled() {
440440
log.Info("Enabling port-forwarding due to no exposure")
441441
deploySettings.Central.PortForwarding = ptr.To(true)
442442
}
@@ -446,7 +446,7 @@ func runDeploy(cmd *cobra.Command, args []string) error {
446446
if deploySettings.Central.PortForwardingEnabled() {
447447
return errors.New("containerized mode does not support port-forwarding")
448448
}
449-
if deploySettings.Central.Exposure == types.ExposureNone {
449+
if !deploySettings.Central.ExposureEnabled() {
450450
return errors.New("containerized mode requires Central exposure")
451451
}
452452

internal/clusterdefaults/clusterdefaults_test.go

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,76 +6,88 @@ import (
66
"github.com/stackrox/roxie/internal/deployer"
77
"github.com/stackrox/roxie/internal/logger"
88
"github.com/stackrox/roxie/internal/types"
9+
"github.com/stretchr/testify/assert"
910
"github.com/stretchr/testify/require"
11+
"k8s.io/utils/ptr"
1012
)
1113

1214
func TestClusterDefaults(t *testing.T) {
1315
tests := []struct {
1416
name string
1517
clusterType types.ClusterType
1618
wantResourceProfile types.ResourceProfile
17-
wantExposure types.Exposure
18-
wantPortForwarding bool
19+
wantExposure *types.Exposure
20+
wantPortForwarding *bool
1921
}{
2022
{
2123
name: "kind cluster with default params",
2224
clusterType: types.ClusterTypeKind,
2325
wantResourceProfile: types.ResourceProfileSmall,
24-
wantExposure: types.ExposureNone,
25-
wantPortForwarding: true,
26+
wantExposure: ptr.To(types.ExposureNone),
27+
wantPortForwarding: ptr.To(true),
2628
},
2729
{
2830
name: "kind cluster with already correct params",
2931
clusterType: types.ClusterTypeKind,
3032
wantResourceProfile: types.ResourceProfileSmall,
31-
wantExposure: types.ExposureNone,
32-
wantPortForwarding: true,
33+
wantExposure: ptr.To(types.ExposureNone),
34+
wantPortForwarding: ptr.To(true),
3335
},
3436
{
3537
name: "kind cluster with partial match",
3638
clusterType: types.ClusterTypeKind,
3739
wantResourceProfile: types.ResourceProfileSmall,
38-
wantExposure: types.ExposureNone,
39-
wantPortForwarding: true,
40+
wantExposure: ptr.To(types.ExposureNone),
41+
wantPortForwarding: ptr.To(true),
4042
},
4143
{
4244
name: "unknown cluster type",
4345
clusterType: types.ClusterTypeUnknown,
4446
wantResourceProfile: types.ResourceProfileAcsDefaults,
45-
wantExposure: types.ExposureNone,
46-
wantPortForwarding: false,
47+
wantExposure: nil,
48+
wantPortForwarding: nil,
4749
},
4850
{
4951
name: "minikube cluster",
5052
clusterType: types.ClusterTypeMinikube,
5153
wantResourceProfile: types.ResourceProfileSmall,
52-
wantExposure: types.ExposureNone,
53-
wantPortForwarding: true,
54+
wantExposure: ptr.To(types.ExposureNone),
55+
wantPortForwarding: ptr.To(true),
5456
},
5557
{
5658
name: "crc cluster",
5759
clusterType: types.ClusterTypeCRC,
5860
wantResourceProfile: types.ResourceProfileSmall,
59-
wantExposure: types.ExposureNone,
60-
wantPortForwarding: true,
61+
wantExposure: ptr.To(types.ExposureNone),
62+
wantPortForwarding: ptr.To(true),
6163
},
6264
}
6365

6466
for _, tt := range tests {
6567
t.Run(tt.name, func(t *testing.T) {
66-
config := deployer.Config{}
68+
config := deployer.NewConfig()
6769
err := ApplyClusterDefaults(logger.New(), tt.clusterType, &config)
6870
require.NoError(t, err)
6971

7072
gotResourceProfile := ResolveAutoResourceProfile(tt.clusterType)
7173
if gotResourceProfile != tt.wantResourceProfile {
7274
t.Errorf("Apply() resources = %v, want %v", gotResourceProfile, tt.wantResourceProfile)
7375
}
74-
if config.Central.Exposure != tt.wantExposure {
75-
t.Errorf("Apply() exposure = %v, want %v", config.Central.Exposure, tt.wantExposure)
76+
77+
if tt.wantExposure == nil {
78+
assert.Nil(t, config.Central.Exposure, "central exposure is not nil")
79+
} else {
80+
require.NotNil(t, config.Central.Exposure, "central exposure is nil")
81+
assert.Equal(t, *tt.wantExposure, *config.Central.Exposure,
82+
"exposure = %v, want %v", *config.Central.Exposure, *tt.wantExposure)
7683
}
77-
if config.Central.PortForwardingEnabled() != tt.wantPortForwarding {
78-
t.Errorf("Apply() portForward = %v, want %v", config.Central.PortForwardingEnabled(), tt.wantPortForwarding)
84+
85+
if tt.wantPortForwarding == nil {
86+
assert.Nil(t, config.Central.PortForwarding, "central port forwarding is not nil")
87+
} else {
88+
require.NotNil(t, config.Central.PortForwarding, "central port forwarding is nil")
89+
assert.Equal(t, *tt.wantPortForwarding, *config.Central.PortForwarding,
90+
"portForward = %v, want %v", *config.Central.PortForwarding, *tt.wantPortForwarding)
7991
}
8092
})
8193
}

internal/deployer/config.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ type CentralConfig struct {
158158
Namespace string `yaml:"namespace"`
159159
ResourceProfile types.ResourceProfile `yaml:"resourceProfile"`
160160
PauseReconciliation bool `yaml:"pauseReconciliation"`
161-
Exposure types.Exposure `yaml:"exposure"`
161+
Exposure *types.Exposure `yaml:"exposure"`
162162
DeployTimeout time.Duration `yaml:"deployTimeout"`
163163
PortForwarding *bool `yaml:"portForwarding"`
164164
EarlyReadiness bool `yaml:"earlyReadiness"`
@@ -173,6 +173,21 @@ func (c *CentralConfig) PortForwardingEnabled() bool {
173173
return c.PortForwarding != nil && *c.PortForwarding
174174
}
175175

176+
func (c *CentralConfig) ExposureSet() bool {
177+
return c.Exposure != nil
178+
}
179+
180+
func (c *CentralConfig) ExposureEnabled() bool {
181+
return c.Exposure != nil && *c.Exposure != types.ExposureNone
182+
}
183+
184+
func (c *CentralConfig) GetExposure() types.Exposure {
185+
if c.Exposure == nil {
186+
return types.ExposureNone
187+
}
188+
return *c.Exposure
189+
}
190+
176191
type SecuredClusterConfig struct {
177192
Namespace string `yaml:"namespace"`
178193
ResourceProfile types.ResourceProfile `yaml:"resourceProfile"`
@@ -200,7 +215,6 @@ func DefaultCentralConfig() CentralConfig {
200215
return CentralConfig{
201216
DeployTimeout: DefaultCentralWaitTimeout,
202217
Namespace: "acs-central",
203-
Exposure: types.ExposureLoadBalancer,
204218
Spec: map[string]interface{}{
205219
"central": map[string]interface{}{
206220
"telemetry": map[string]interface{}{

internal/deployer/deploy_via_operator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ func (d *Deployer) fetchCentralCACert(ctx context.Context) error {
528528

529529
// configureCentralEndpoint configures the central endpoint in the Deployer based on exposure settings.
530530
func (d *Deployer) configureCentralEndpoint(ctx context.Context) error {
531-
exposure := d.config.Central.Exposure
531+
exposure := d.config.Central.GetExposure()
532532
if d.config.Central.PortForwardingEnabled() {
533533
// Start port-forward for CLI tool access via localhost:8443
534534
serviceName := "central"

internal/deployer/deployer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ func (d *Deployer) PrintCentralDeploymentSummary() {
828828
component := "Central"
829829
mainImageTag := d.config.Roxie.Version
830830
olm := d.config.Operator.DeployViaOlm
831-
exposure := d.config.Central.Exposure
831+
exposure := d.config.Central.GetExposure()
832832
portForwarding := d.config.Central.PortForwardingEnabled()
833833
log := d.logger
834834
kubeContext := d.kubeContext
@@ -1073,7 +1073,7 @@ func (d *Deployer) GetCentralDeploymentInfo() CentralDeploymentInfo {
10731073
Endpoint: d.centralEndpoint,
10741074
Password: d.centralPassword,
10751075
KubeContext: d.kubeContext,
1076-
Exposure: d.config.Central.Exposure,
1076+
Exposure: d.config.Central.GetExposure(),
10771077
CACertFile: d.roxCACertFile,
10781078
}
10791079
}

0 commit comments

Comments
 (0)