Skip to content

Commit f829e44

Browse files
committed
address review comments
Signed-off-by: Leonardo Luz Almeida <[email protected]>
1 parent 875a1d7 commit f829e44

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

cmd/controller/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ func main() {
9595
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
9696
Scheme: scheme,
9797
Metrics: metricsserver.Options{
98-
BindAddress: fmt.Sprintf(":%d", config.MetricsAddress()),
98+
BindAddress: config.MetricsAddress(),
9999
SecureServing: config.MetricsSecure(),
100100
TLSOpts: tlsOpts,
101101
},
102102
WebhookServer: webhookServer,
103-
HealthProbeBindAddress: fmt.Sprintf(":%d", config.ControllerHealthProbeAddr()),
103+
HealthProbeBindAddress: config.ControllerHealthProbeAddr(),
104104
LeaderElection: config.EnableLeaderElection(),
105105
LeaderElectionID: "8246dd0c.argoproj-labs.io",
106106
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily

internal/controller/accessrequest_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const (
5555
// managed by this controller
5656
AccessRequestFinalizerName = "accessrequest.ephemeral-access.argoproj-labs.io/finalizer"
5757
roleTemplateField = ".spec.roleTemplateName"
58-
projectField = ".status.TargetProject"
58+
projectField = ".status.targetProject"
5959
)
6060

6161
// +kubebuilder:rbac:groups=ephemeral-access.argoproj-labs.io,resources=accessrequests,verbs=get;list;watch;create;update;patch;delete

internal/controller/config/config.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ type LogConfigurer interface {
2626

2727
// MetricsConfigurer defines the accessor methods for metrics configurations.
2828
type MetricsConfigurer interface {
29-
MetricsAddress() int
29+
MetricsAddress() string
3030
MetricsSecure() bool
3131
}
3232

3333
// ControllerConfigurer defines the accessor methods for the controller's
3434
// configurations.
3535
type ControllerConfigurer interface {
3636
EnableLeaderElection() bool
37-
ControllerHealthProbeAddr() int
37+
ControllerHealthProbeAddr() string
3838
ControllerEnableHTTP2() bool
3939
ControllerRequeueInterval() time.Duration
4040
}
4141

4242
// MetricsAddress acessor method
43-
func (c *Config) MetricsAddress() int {
43+
func (c *Config) MetricsAddress() string {
4444
return c.Metrics.Address
4545
}
4646

@@ -65,7 +65,7 @@ func (c *Config) EnableLeaderElection() bool {
6565
}
6666

6767
// ControllerHealthProbeAddr acessor method
68-
func (c *Config) ControllerHealthProbeAddr() int {
68+
func (c *Config) ControllerHealthProbeAddr() string {
6969
return c.Controller.HealthProbeAddr
7070
}
7171

@@ -92,8 +92,8 @@ type Config struct {
9292
// MetricsConfig defines the metrics configurations
9393
type MetricsConfig struct {
9494
// Address The address the metric endpoint binds to.
95-
// Use the port 8080. If not set, it will be 0 in order to disable the metrics server.
96-
Address int `env:"ADDR, default=0"`
95+
// Use the port :8080. If not set, it will be 0 in order to disable the metrics server
96+
Address string `env:"ADDR, default=0"`
9797
// Secure If set the metrics endpoint is served securely.
9898
Secure bool `env:"SECURE, default=false"`
9999
}
@@ -104,7 +104,7 @@ type ControllerConfig struct {
104104
// Enabling this will ensure there is only one active controller manager.
105105
EnableLeaderElection bool `env:"ENABLE_LEADER_ELECTION, default=false"`
106106
// HealthProbeAddr The address the probe endpoint binds to.
107-
HealthProbeAddr int `env:"HEALTH_PROBE_ADDR, default=8081"`
107+
HealthProbeAddr string `env:"HEALTH_PROBE_ADDR, default=:8081"`
108108
// EnableHTTP2 If set, HTTP/2 will be enabled for the metrics and webhook
109109
// servers.
110110
EnableHTTP2 bool `env:"ENABLE_HTTP2, default=false"`
@@ -129,7 +129,7 @@ type LogConfig struct {
129129

130130
// String prints the config state
131131
func (c *Config) String() string {
132-
return fmt.Sprintf("Metrics: [ Address: %d Secure: %t ] Log [ Level: %s Format: %s ] Controller [ EnableLeaderElection: %t HealthProbeAddress: %d EnableHTTP2: %t RequeueInterval: %s]", c.Metrics.Address, c.Metrics.Secure, c.Log.Level, c.Log.Format, c.Controller.EnableLeaderElection, c.Controller.HealthProbeAddr, c.Controller.EnableHTTP2, c.Controller.RequeueInterval)
132+
return fmt.Sprintf("Metrics: [ Address: %s Secure: %t ] Log [ Level: %s Format: %s ] Controller [ EnableLeaderElection: %t HealthProbeAddress: %s EnableHTTP2: %t RequeueInterval: %s]", c.Metrics.Address, c.Metrics.Secure, c.Log.Level, c.Log.Format, c.Controller.EnableLeaderElection, c.Controller.HealthProbeAddr, c.Controller.EnableHTTP2, c.Controller.RequeueInterval)
133133
}
134134

135135
// ReadEnvConfigs will read all environment variables as defined in the Config

internal/controller/config/config_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ func TestConfiguration(t *testing.T) {
1717
assert.NoError(t, err, "NewConfiguration error")
1818
assert.Equal(t, "info", config.LogLevel())
1919
assert.Equal(t, "text", config.LogFormat())
20-
assert.Equal(t, 0, config.MetricsAddress())
20+
assert.Equal(t, "0", config.MetricsAddress())
2121
assert.Equal(t, false, config.MetricsSecure())
2222
assert.Equal(t, false, config.EnableLeaderElection())
23-
assert.Equal(t, 8081, config.ControllerHealthProbeAddr())
23+
assert.Equal(t, ":8081", config.ControllerHealthProbeAddr())
2424
assert.Equal(t, false, config.ControllerEnableHTTP2())
2525
assert.Equal(t, time.Minute*3, config.ControllerRequeueInterval())
2626
})
2727
t.Run("will validate if env vars are set properly", func(t *testing.T) {
2828
// Given
2929
t.Setenv("EPHEMERAL_LOG_LEVEL", "debug")
3030
t.Setenv("EPHEMERAL_LOG_FORMAT", "json")
31-
t.Setenv("EPHEMERAL_METRICS_ADDR", "9091")
31+
t.Setenv("EPHEMERAL_METRICS_ADDR", ":9091")
3232
t.Setenv("EPHEMERAL_METRICS_SECURE", "true")
3333
t.Setenv("EPHEMERAL_CONTROLLER_ENABLE_LEADER_ELECTION", "true")
34-
t.Setenv("EPHEMERAL_CONTROLLER_HEALTH_PROBE_ADDR", "1313")
34+
t.Setenv("EPHEMERAL_CONTROLLER_HEALTH_PROBE_ADDR", ":1313")
3535
t.Setenv("EPHEMERAL_CONTROLLER_ENABLE_HTTP2", "true")
3636
t.Setenv("EPHEMERAL_CONTROLLER_REQUEUE_INTERVAL", "1s")
3737

@@ -42,10 +42,10 @@ func TestConfiguration(t *testing.T) {
4242
assert.NoError(t, err, "NewConfiguration error")
4343
assert.Equal(t, "debug", config.LogLevel())
4444
assert.Equal(t, "json", config.LogFormat())
45-
assert.Equal(t, 9091, config.MetricsAddress())
45+
assert.Equal(t, ":9091", config.MetricsAddress())
4646
assert.Equal(t, true, config.MetricsSecure())
4747
assert.Equal(t, true, config.EnableLeaderElection())
48-
assert.Equal(t, 1313, config.ControllerHealthProbeAddr())
48+
assert.Equal(t, ":1313", config.ControllerHealthProbeAddr())
4949
assert.Equal(t, true, config.ControllerEnableHTTP2())
5050
assert.Equal(t, time.Second, config.ControllerRequeueInterval())
5151
})

0 commit comments

Comments
 (0)