mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
cleanup: replace TypeToPtr helper methods with pointer.Of (#14151)
Bumping compile time requirement to go 1.18 allows us to simplify our pointer helper methods.
This commit is contained in:
committed by
GitHub
parent
b9fec224ba
commit
c4be2c6078
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/hashicorp/nomad/client/allocrunner/taskrunner/interfaces"
|
||||
"github.com/hashicorp/nomad/client/config"
|
||||
"github.com/hashicorp/nomad/client/taskenv"
|
||||
"github.com/hashicorp/nomad/helper"
|
||||
"github.com/hashicorp/nomad/helper/pointer"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
@@ -611,7 +611,7 @@ func parseTemplateConfigs(config *TaskTemplateManagerConfig) (map[*ctconf.Templa
|
||||
}
|
||||
|
||||
ct.Wait = &ctconf.WaitConfig{
|
||||
Enabled: helper.BoolToPtr(true),
|
||||
Enabled: pointer.Of(true),
|
||||
Min: tmpl.Wait.Min,
|
||||
Max: tmpl.Wait.Max,
|
||||
}
|
||||
@@ -723,7 +723,7 @@ func newRunnerConfig(config *TaskTemplateManagerConfig,
|
||||
if cc.ConsulConfig.EnableSSL != nil && *cc.ConsulConfig.EnableSSL {
|
||||
verify := cc.ConsulConfig.VerifySSL != nil && *cc.ConsulConfig.VerifySSL
|
||||
conf.Consul.SSL = &ctconf.SSLConfig{
|
||||
Enabled: helper.BoolToPtr(true),
|
||||
Enabled: pointer.Of(true),
|
||||
Verify: &verify,
|
||||
Cert: &cc.ConsulConfig.CertFile,
|
||||
Key: &cc.ConsulConfig.KeyFile,
|
||||
@@ -738,7 +738,7 @@ func newRunnerConfig(config *TaskTemplateManagerConfig,
|
||||
}
|
||||
|
||||
conf.Consul.Auth = &ctconf.AuthConfig{
|
||||
Enabled: helper.BoolToPtr(true),
|
||||
Enabled: pointer.Of(true),
|
||||
Username: &parts[0],
|
||||
Password: &parts[1],
|
||||
}
|
||||
@@ -767,7 +767,7 @@ func newRunnerConfig(config *TaskTemplateManagerConfig,
|
||||
// Set up the Vault config
|
||||
// Always set these to ensure nothing is picked up from the environment
|
||||
emptyStr := ""
|
||||
conf.Vault.RenewToken = helper.BoolToPtr(false)
|
||||
conf.Vault.RenewToken = pointer.Of(false)
|
||||
conf.Vault.Token = &emptyStr
|
||||
if cc.VaultConfig != nil && cc.VaultConfig.IsEnabled() {
|
||||
conf.Vault.Address = &cc.VaultConfig.Addr
|
||||
@@ -786,7 +786,7 @@ func newRunnerConfig(config *TaskTemplateManagerConfig,
|
||||
skipVerify := cc.VaultConfig.TLSSkipVerify != nil && *cc.VaultConfig.TLSSkipVerify
|
||||
verify := !skipVerify
|
||||
conf.Vault.SSL = &ctconf.SSLConfig{
|
||||
Enabled: helper.BoolToPtr(true),
|
||||
Enabled: pointer.Of(true),
|
||||
Verify: &verify,
|
||||
Cert: &cc.VaultConfig.TLSCertFile,
|
||||
Key: &cc.VaultConfig.TLSKeyFile,
|
||||
@@ -796,8 +796,8 @@ func newRunnerConfig(config *TaskTemplateManagerConfig,
|
||||
}
|
||||
} else {
|
||||
conf.Vault.SSL = &ctconf.SSLConfig{
|
||||
Enabled: helper.BoolToPtr(false),
|
||||
Verify: helper.BoolToPtr(false),
|
||||
Enabled: pointer.Of(false),
|
||||
Verify: pointer.Of(false),
|
||||
Cert: &emptyStr,
|
||||
Key: &emptyStr,
|
||||
CaCert: &emptyStr,
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
"github.com/hashicorp/nomad/client/config"
|
||||
"github.com/hashicorp/nomad/client/taskenv"
|
||||
"github.com/hashicorp/nomad/helper"
|
||||
"github.com/hashicorp/nomad/helper/pointer"
|
||||
"github.com/hashicorp/nomad/helper/testlog"
|
||||
"github.com/hashicorp/nomad/helper/uuid"
|
||||
"github.com/hashicorp/nomad/nomad/mock"
|
||||
@@ -156,7 +156,7 @@ func newTestHarness(t *testing.T, templates []*structs.Template, consul, vault b
|
||||
TemplateConfig: &config.ClientTemplateConfig{
|
||||
FunctionDenylist: config.DefaultTemplateFunctionDenylist,
|
||||
DisableSandbox: false,
|
||||
ConsulRetry: &config.RetryConfig{Backoff: helper.TimeToPtr(10 * time.Millisecond)},
|
||||
ConsulRetry: &config.RetryConfig{Backoff: pointer.Of(10 * time.Millisecond)},
|
||||
}},
|
||||
emitRate: DefaultMaxTemplateEventRate,
|
||||
}
|
||||
@@ -1489,7 +1489,7 @@ func TestTaskTemplateManager_Config_ServerName(t *testing.T) {
|
||||
c := config.DefaultConfig()
|
||||
c.Node = mock.Node()
|
||||
c.VaultConfig = &sconfig.VaultConfig{
|
||||
Enabled: helper.BoolToPtr(true),
|
||||
Enabled: pointer.Of(true),
|
||||
Addr: "https://localhost/",
|
||||
TLSServerName: "notlocalhost",
|
||||
}
|
||||
@@ -1517,7 +1517,7 @@ func TestTaskTemplateManager_Config_VaultNamespace(t *testing.T) {
|
||||
c := config.DefaultConfig()
|
||||
c.Node = mock.Node()
|
||||
c.VaultConfig = &sconfig.VaultConfig{
|
||||
Enabled: helper.BoolToPtr(true),
|
||||
Enabled: pointer.Of(true),
|
||||
Addr: "https://localhost/",
|
||||
TLSServerName: "notlocalhost",
|
||||
Namespace: testNS,
|
||||
@@ -1548,7 +1548,7 @@ func TestTaskTemplateManager_Config_VaultNamespace_TaskOverride(t *testing.T) {
|
||||
c := config.DefaultConfig()
|
||||
c.Node = mock.Node()
|
||||
c.VaultConfig = &sconfig.VaultConfig{
|
||||
Enabled: helper.BoolToPtr(true),
|
||||
Enabled: pointer.Of(true),
|
||||
Addr: "https://localhost/",
|
||||
TLSServerName: "notlocalhost",
|
||||
Namespace: testNS,
|
||||
@@ -1934,7 +1934,7 @@ func TestTaskTemplateManager_ClientTemplateConfig_Set(t *testing.T) {
|
||||
clientConfig.Node = mock.Node()
|
||||
|
||||
clientConfig.VaultConfig = &sconfig.VaultConfig{
|
||||
Enabled: helper.BoolToPtr(true),
|
||||
Enabled: pointer.Of(true),
|
||||
Namespace: testNS,
|
||||
}
|
||||
|
||||
@@ -1944,18 +1944,18 @@ func TestTaskTemplateManager_ClientTemplateConfig_Set(t *testing.T) {
|
||||
|
||||
// helper to reduce boilerplate
|
||||
waitConfig := &config.WaitConfig{
|
||||
Min: helper.TimeToPtr(5 * time.Second),
|
||||
Max: helper.TimeToPtr(10 * time.Second),
|
||||
Min: pointer.Of(5 * time.Second),
|
||||
Max: pointer.Of(10 * time.Second),
|
||||
}
|
||||
// helper to reduce boilerplate
|
||||
retryConfig := &config.RetryConfig{
|
||||
Attempts: helper.IntToPtr(5),
|
||||
Backoff: helper.TimeToPtr(5 * time.Second),
|
||||
MaxBackoff: helper.TimeToPtr(20 * time.Second),
|
||||
Attempts: pointer.Of(5),
|
||||
Backoff: pointer.Of(5 * time.Second),
|
||||
MaxBackoff: pointer.Of(20 * time.Second),
|
||||
}
|
||||
|
||||
clientConfig.TemplateConfig.MaxStale = helper.TimeToPtr(5 * time.Second)
|
||||
clientConfig.TemplateConfig.BlockQueryWaitTime = helper.TimeToPtr(60 * time.Second)
|
||||
clientConfig.TemplateConfig.MaxStale = pointer.Of(5 * time.Second)
|
||||
clientConfig.TemplateConfig.BlockQueryWaitTime = pointer.Of(60 * time.Second)
|
||||
clientConfig.TemplateConfig.Wait = waitConfig.Copy()
|
||||
clientConfig.TemplateConfig.ConsulRetry = retryConfig.Copy()
|
||||
clientConfig.TemplateConfig.VaultRetry = retryConfig.Copy()
|
||||
@@ -1966,8 +1966,8 @@ func TestTaskTemplateManager_ClientTemplateConfig_Set(t *testing.T) {
|
||||
allocWithOverride.Job.TaskGroups[0].Tasks[0].Templates = []*structs.Template{
|
||||
{
|
||||
Wait: &structs.WaitConfig{
|
||||
Min: helper.TimeToPtr(2 * time.Second),
|
||||
Max: helper.TimeToPtr(12 * time.Second),
|
||||
Min: pointer.Of(2 * time.Second),
|
||||
Max: pointer.Of(12 * time.Second),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1982,8 +1982,8 @@ func TestTaskTemplateManager_ClientTemplateConfig_Set(t *testing.T) {
|
||||
{
|
||||
"basic-wait-config",
|
||||
&config.ClientTemplateConfig{
|
||||
MaxStale: helper.TimeToPtr(5 * time.Second),
|
||||
BlockQueryWaitTime: helper.TimeToPtr(60 * time.Second),
|
||||
MaxStale: pointer.Of(5 * time.Second),
|
||||
BlockQueryWaitTime: pointer.Of(60 * time.Second),
|
||||
Wait: waitConfig.Copy(),
|
||||
ConsulRetry: retryConfig.Copy(),
|
||||
VaultRetry: retryConfig.Copy(),
|
||||
@@ -1996,8 +1996,8 @@ func TestTaskTemplateManager_ClientTemplateConfig_Set(t *testing.T) {
|
||||
},
|
||||
&config.Config{
|
||||
TemplateConfig: &config.ClientTemplateConfig{
|
||||
MaxStale: helper.TimeToPtr(5 * time.Second),
|
||||
BlockQueryWaitTime: helper.TimeToPtr(60 * time.Second),
|
||||
MaxStale: pointer.Of(5 * time.Second),
|
||||
BlockQueryWaitTime: pointer.Of(60 * time.Second),
|
||||
Wait: waitConfig.Copy(),
|
||||
ConsulRetry: retryConfig.Copy(),
|
||||
VaultRetry: retryConfig.Copy(),
|
||||
@@ -2006,17 +2006,17 @@ func TestTaskTemplateManager_ClientTemplateConfig_Set(t *testing.T) {
|
||||
},
|
||||
&templateconfig.TemplateConfig{
|
||||
Wait: &templateconfig.WaitConfig{
|
||||
Enabled: helper.BoolToPtr(true),
|
||||
Min: helper.TimeToPtr(5 * time.Second),
|
||||
Max: helper.TimeToPtr(10 * time.Second),
|
||||
Enabled: pointer.Of(true),
|
||||
Min: pointer.Of(5 * time.Second),
|
||||
Max: pointer.Of(10 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"template-override",
|
||||
&config.ClientTemplateConfig{
|
||||
MaxStale: helper.TimeToPtr(5 * time.Second),
|
||||
BlockQueryWaitTime: helper.TimeToPtr(60 * time.Second),
|
||||
MaxStale: pointer.Of(5 * time.Second),
|
||||
BlockQueryWaitTime: pointer.Of(60 * time.Second),
|
||||
Wait: waitConfig.Copy(),
|
||||
ConsulRetry: retryConfig.Copy(),
|
||||
VaultRetry: retryConfig.Copy(),
|
||||
@@ -2029,8 +2029,8 @@ func TestTaskTemplateManager_ClientTemplateConfig_Set(t *testing.T) {
|
||||
},
|
||||
&config.Config{
|
||||
TemplateConfig: &config.ClientTemplateConfig{
|
||||
MaxStale: helper.TimeToPtr(5 * time.Second),
|
||||
BlockQueryWaitTime: helper.TimeToPtr(60 * time.Second),
|
||||
MaxStale: pointer.Of(5 * time.Second),
|
||||
BlockQueryWaitTime: pointer.Of(60 * time.Second),
|
||||
Wait: waitConfig.Copy(),
|
||||
ConsulRetry: retryConfig.Copy(),
|
||||
VaultRetry: retryConfig.Copy(),
|
||||
@@ -2039,21 +2039,21 @@ func TestTaskTemplateManager_ClientTemplateConfig_Set(t *testing.T) {
|
||||
},
|
||||
&templateconfig.TemplateConfig{
|
||||
Wait: &templateconfig.WaitConfig{
|
||||
Enabled: helper.BoolToPtr(true),
|
||||
Min: helper.TimeToPtr(2 * time.Second),
|
||||
Max: helper.TimeToPtr(12 * time.Second),
|
||||
Enabled: pointer.Of(true),
|
||||
Min: pointer.Of(2 * time.Second),
|
||||
Max: pointer.Of(12 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"bounds-override",
|
||||
&config.ClientTemplateConfig{
|
||||
MaxStale: helper.TimeToPtr(5 * time.Second),
|
||||
BlockQueryWaitTime: helper.TimeToPtr(60 * time.Second),
|
||||
MaxStale: pointer.Of(5 * time.Second),
|
||||
BlockQueryWaitTime: pointer.Of(60 * time.Second),
|
||||
Wait: waitConfig.Copy(),
|
||||
WaitBounds: &config.WaitConfig{
|
||||
Min: helper.TimeToPtr(3 * time.Second),
|
||||
Max: helper.TimeToPtr(11 * time.Second),
|
||||
Min: pointer.Of(3 * time.Second),
|
||||
Max: pointer.Of(11 * time.Second),
|
||||
},
|
||||
ConsulRetry: retryConfig.Copy(),
|
||||
VaultRetry: retryConfig.Copy(),
|
||||
@@ -2066,20 +2066,20 @@ func TestTaskTemplateManager_ClientTemplateConfig_Set(t *testing.T) {
|
||||
Templates: []*structs.Template{
|
||||
{
|
||||
Wait: &structs.WaitConfig{
|
||||
Min: helper.TimeToPtr(2 * time.Second),
|
||||
Max: helper.TimeToPtr(12 * time.Second),
|
||||
Min: pointer.Of(2 * time.Second),
|
||||
Max: pointer.Of(12 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&config.Config{
|
||||
TemplateConfig: &config.ClientTemplateConfig{
|
||||
MaxStale: helper.TimeToPtr(5 * time.Second),
|
||||
BlockQueryWaitTime: helper.TimeToPtr(60 * time.Second),
|
||||
MaxStale: pointer.Of(5 * time.Second),
|
||||
BlockQueryWaitTime: pointer.Of(60 * time.Second),
|
||||
Wait: waitConfig.Copy(),
|
||||
WaitBounds: &config.WaitConfig{
|
||||
Min: helper.TimeToPtr(3 * time.Second),
|
||||
Max: helper.TimeToPtr(11 * time.Second),
|
||||
Min: pointer.Of(3 * time.Second),
|
||||
Max: pointer.Of(11 * time.Second),
|
||||
},
|
||||
ConsulRetry: retryConfig.Copy(),
|
||||
VaultRetry: retryConfig.Copy(),
|
||||
@@ -2088,9 +2088,9 @@ func TestTaskTemplateManager_ClientTemplateConfig_Set(t *testing.T) {
|
||||
},
|
||||
&templateconfig.TemplateConfig{
|
||||
Wait: &templateconfig.WaitConfig{
|
||||
Enabled: helper.BoolToPtr(true),
|
||||
Min: helper.TimeToPtr(3 * time.Second),
|
||||
Max: helper.TimeToPtr(11 * time.Second),
|
||||
Enabled: pointer.Of(true),
|
||||
Min: pointer.Of(3 * time.Second),
|
||||
Max: pointer.Of(11 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2159,8 +2159,8 @@ func TestTaskTemplateManager_Template_Wait_Set(t *testing.T) {
|
||||
Templates: []*structs.Template{
|
||||
{
|
||||
Wait: &structs.WaitConfig{
|
||||
Min: helper.TimeToPtr(5 * time.Second),
|
||||
Max: helper.TimeToPtr(10 * time.Second),
|
||||
Min: pointer.Of(5 * time.Second),
|
||||
Max: pointer.Of(10 * time.Second),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user