diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f9c715db..d8b566872 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - (Bugfix) Discover Arango image during ID phase - (Feature) PV Unschedulable condition - (Feature) Features startup logging +- (Maintenance) Generics for type handling ## [1.2.27](https://github.com/arangodb/kube-arangodb/tree/1.2.27) (2023-04-27) - (Feature) Add InSync Cache diff --git a/internal/readme.go b/internal/readme.go index 49098be10..f751963df 100644 --- a/internal/readme.go +++ b/internal/readme.go @@ -83,11 +83,11 @@ func GenerateReadme(root string) error { for _, v := range p.Versions { if err := t.AddRow(map[md.Column]string{ platform: p.Name, - kVersion: util.StringOrDefault(v.KubernetesVersion, ""), - aVersion: util.StringOrDefault(v.ArangoDBVersion, ""), - state: util.StringOrDefault(v.State, ""), - remarks: util.StringOrDefault(v.Remarks, ""), - pRemarks: util.StringOrDefault(v.ProviderRemarks, ""), + kVersion: util.TypeOrDefault[string](v.KubernetesVersion, ""), + aVersion: util.TypeOrDefault[string](v.ArangoDBVersion, ""), + state: util.TypeOrDefault[string](v.State, ""), + remarks: util.TypeOrDefault[string](v.Remarks, ""), + pRemarks: util.TypeOrDefault[string](v.ProviderRemarks, ""), }); err != nil { return err } diff --git a/pkg/apis/backup/v1/backup_spec_backoff_test.go b/pkg/apis/backup/v1/backup_spec_backoff_test.go index e601735f9..24abc46c4 100644 --- a/pkg/apis/backup/v1/backup_spec_backoff_test.go +++ b/pkg/apis/backup/v1/backup_spec_backoff_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -43,9 +43,9 @@ func TestArangoBackupSpecBackOff_Backoff(t *testing.T) { }) t.Run("Custom", func(t *testing.T) { b := &ArangoBackupSpecBackOff{ - MinDelay: util.NewInt(20), - MaxDelay: util.NewInt(120), - Iterations: util.NewInt(10), + MinDelay: util.NewType[int](20), + MaxDelay: util.NewType[int](120), + Iterations: util.NewType[int](10), } assert.Equal(t, 20*time.Second, b.Backoff(0)) @@ -64,9 +64,9 @@ func TestArangoBackupSpecBackOff_Backoff(t *testing.T) { t.Run("Invalid", func(t *testing.T) { b := &ArangoBackupSpecBackOff{ - MinDelay: util.NewInt(-1), - MaxDelay: util.NewInt(-1), - Iterations: util.NewInt(0), + MinDelay: util.NewType[int](-1), + MaxDelay: util.NewType[int](-1), + Iterations: util.NewType[int](0), } assert.Equal(t, 0, b.GetMinDelay()) @@ -78,8 +78,8 @@ func TestArangoBackupSpecBackOff_Backoff(t *testing.T) { t.Run("Max < Min", func(t *testing.T) { b := &ArangoBackupSpecBackOff{ - MinDelay: util.NewInt(50), - MaxDelay: util.NewInt(20), + MinDelay: util.NewType[int](50), + MaxDelay: util.NewType[int](20), } assert.Equal(t, 20, b.GetMinDelay()) diff --git a/pkg/apis/backup/v1/backup_status_backoff_test.go b/pkg/apis/backup/v1/backup_status_backoff_test.go index 9c8d13d77..e334fc6f1 100644 --- a/pkg/apis/backup/v1/backup_status_backoff_test.go +++ b/pkg/apis/backup/v1/backup_status_backoff_test.go @@ -42,8 +42,8 @@ func TestArangoBackupStatusBackOff_Backoff(t *testing.T) { t.Run("Test MaxIterations", func(t *testing.T) { var spec = &ArangoBackupSpecBackOff{ - Iterations: util.NewInt(2), - MaxIterations: util.NewInt(3), + Iterations: util.NewType[int](2), + MaxIterations: util.NewType[int](3), } var status *ArangoBackupStatusBackOff diff --git a/pkg/apis/deployment/v1/authentication_spec.go b/pkg/apis/deployment/v1/authentication_spec.go index 2f5c5cac2..718a97677 100644 --- a/pkg/apis/deployment/v1/authentication_spec.go +++ b/pkg/apis/deployment/v1/authentication_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ const ( // GetJWTSecretName returns the value of jwtSecretName. func (s AuthenticationSpec) GetJWTSecretName() string { - return util.StringOrDefault(s.JWTSecretName) + return util.TypeOrDefault[string](s.JWTSecretName) } // IsAuthenticated returns true if authentication is enabled. @@ -65,14 +65,14 @@ func (s *AuthenticationSpec) SetDefaults(defaultJWTSecretName string) { if s.GetJWTSecretName() == "" { // Note that we don't check for nil here, since even a specified, but empty // string should result in the default value. - s.JWTSecretName = util.NewString(defaultJWTSecretName) + s.JWTSecretName = util.NewType[string](defaultJWTSecretName) } } // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *AuthenticationSpec) SetDefaultsFrom(source AuthenticationSpec) { if s.JWTSecretName == nil { - s.JWTSecretName = util.NewStringOrNil(source.JWTSecretName) + s.JWTSecretName = util.NewTypeOrNil[string](source.JWTSecretName) } } @@ -83,7 +83,7 @@ func (s AuthenticationSpec) ResetImmutableFields(fieldPrefix string, target *Aut var resetFields []string if s.IsAuthenticated() != target.IsAuthenticated() { // Note: You can change the name, but not from empty to non-empty (or reverse). - target.JWTSecretName = util.NewStringOrNil(s.JWTSecretName) + target.JWTSecretName = util.NewTypeOrNil[string](s.JWTSecretName) resetFields = append(resetFields, fieldPrefix+".jwtSecretName") } return resetFields diff --git a/pkg/apis/deployment/v1/authentication_spec_test.go b/pkg/apis/deployment/v1/authentication_spec_test.go index 41e5700ad..6848256cb 100644 --- a/pkg/apis/deployment/v1/authentication_spec_test.go +++ b/pkg/apis/deployment/v1/authentication_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,18 +30,18 @@ import ( func TestAuthenticationSpecValidate(t *testing.T) { // Valid - assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewString("None")}.Validate(false)) - assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewString("foo")}.Validate(false)) - assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewString("foo")}.Validate(true)) + assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}.Validate(false)) + assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}.Validate(false)) + assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}.Validate(true)) // Not valid - assert.Error(t, AuthenticationSpec{JWTSecretName: util.NewString("Foo")}.Validate(false)) + assert.Error(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("Foo")}.Validate(false)) } func TestAuthenticationSpecIsAuthenticated(t *testing.T) { - assert.False(t, AuthenticationSpec{JWTSecretName: util.NewString("None")}.IsAuthenticated()) - assert.True(t, AuthenticationSpec{JWTSecretName: util.NewString("foo")}.IsAuthenticated()) - assert.True(t, AuthenticationSpec{JWTSecretName: util.NewString("")}.IsAuthenticated()) + assert.False(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}.IsAuthenticated()) + assert.True(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}.IsAuthenticated()) + assert.True(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("")}.IsAuthenticated()) } func TestAuthenticationSpecSetDefaults(t *testing.T) { @@ -51,7 +51,7 @@ func TestAuthenticationSpecSetDefaults(t *testing.T) { } assert.Equal(t, "test-jwt", def(AuthenticationSpec{}).GetJWTSecretName()) - assert.Equal(t, "foo", def(AuthenticationSpec{JWTSecretName: util.NewString("foo")}).GetJWTSecretName()) + assert.Equal(t, "foo", def(AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}).GetJWTSecretName()) } func TestAuthenticationSpecResetImmutableFields(t *testing.T) { @@ -63,35 +63,35 @@ func TestAuthenticationSpecResetImmutableFields(t *testing.T) { }{ // Valid "changes" { - AuthenticationSpec{JWTSecretName: util.NewString("None")}, - AuthenticationSpec{JWTSecretName: util.NewString("None")}, - AuthenticationSpec{JWTSecretName: util.NewString("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, nil, }, { - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, nil, }, { - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo2")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo2")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo2")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo2")}, nil, }, // Invalid changes { - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, - AuthenticationSpec{JWTSecretName: util.NewString("None")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, []string{"test.jwtSecretName"}, }, { - AuthenticationSpec{JWTSecretName: util.NewString("None")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, - AuthenticationSpec{JWTSecretName: util.NewString("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, []string{"test.jwtSecretName"}, }, } diff --git a/pkg/apis/deployment/v1/chaos_spec.go b/pkg/apis/deployment/v1/chaos_spec.go index d2c5de544..d2cda1b69 100644 --- a/pkg/apis/deployment/v1/chaos_spec.go +++ b/pkg/apis/deployment/v1/chaos_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -39,12 +39,12 @@ type ChaosSpec struct { // IsEnabled returns the value of enabled. func (s ChaosSpec) IsEnabled() bool { - return util.BoolOrDefault(s.Enabled) + return util.TypeOrDefault[bool](s.Enabled) } // GetInterval returns the value of interval. func (s ChaosSpec) GetInterval() time.Duration { - return util.DurationOrDefault(s.Interval) + return util.TypeOrDefault[time.Duration](s.Interval) } // GetKillPodProbability returns the value of kill-pod-probability. @@ -68,7 +68,7 @@ func (s ChaosSpec) Validate() error { // SetDefaults fills in missing defaults func (s *ChaosSpec) SetDefaults() { if s.GetInterval() == 0 { - s.Interval = util.NewDuration(time.Minute) + s.Interval = util.NewType[time.Duration](time.Minute) } if s.GetKillPodProbability() == 0 { s.KillPodProbability = NewPercent(50) @@ -78,10 +78,10 @@ func (s *ChaosSpec) SetDefaults() { // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *ChaosSpec) SetDefaultsFrom(source ChaosSpec) { if s.Enabled == nil { - s.Enabled = util.NewBoolOrNil(source.Enabled) + s.Enabled = util.NewTypeOrNil[bool](source.Enabled) } if s.Interval == nil { - s.Interval = util.NewDurationOrNil(source.Interval) + s.Interval = util.NewTypeOrNil[time.Duration](source.Interval) } if s.KillPodProbability == nil { s.KillPodProbability = NewPercentOrNil(source.KillPodProbability) diff --git a/pkg/apis/deployment/v1/deployment_metrics_spec.go b/pkg/apis/deployment/v1/deployment_metrics_spec.go index 1d3c14c52..e2f812f48 100644 --- a/pkg/apis/deployment/v1/deployment_metrics_spec.go +++ b/pkg/apis/deployment/v1/deployment_metrics_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -106,7 +106,7 @@ func (s *MetricsSpec) GetPort() uint16 { // IsEnabled returns whether metrics are enabled or not func (s *MetricsSpec) IsEnabled() bool { - return util.BoolOrDefault(s.Enabled, false) + return util.TypeOrDefault[bool](s.Enabled, false) } // HasImage returns whether a image was specified or not @@ -118,22 +118,22 @@ func (s *MetricsSpec) HasImage() bool { // GetImage returns the Image or empty string // Deprecated func (s *MetricsSpec) GetImage() string { - return util.StringOrDefault(s.Image) + return util.TypeOrDefault[string](s.Image) } // SetDefaults sets default values func (s *MetricsSpec) SetDefaults(defaultTokenName string, isAuthenticated bool) { if s.Enabled == nil { - s.Enabled = util.NewBool(false) + s.Enabled = util.NewType[bool](false) } if s.GetJWTTokenSecretName() == "" { - s.Authentication.JWTTokenSecretName = util.NewString(defaultTokenName) + s.Authentication.JWTTokenSecretName = util.NewType[string](defaultTokenName) } } // GetJWTTokenSecretName returns the token secret name or empty string func (s *MetricsSpec) GetJWTTokenSecretName() string { - return util.StringOrDefault(s.Authentication.JWTTokenSecretName) + return util.TypeOrDefault[string](s.Authentication.JWTTokenSecretName) } // HasJWTTokenSecretName returns true if a secret name was specified @@ -144,13 +144,13 @@ func (s *MetricsSpec) HasJWTTokenSecretName() bool { // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *MetricsSpec) SetDefaultsFrom(source MetricsSpec) { if s.Enabled == nil { - s.Enabled = util.NewBoolOrNil(source.Enabled) + s.Enabled = util.NewTypeOrNil[bool](source.Enabled) } if s.Image == nil { - s.Image = util.NewStringOrNil(source.Image) + s.Image = util.NewTypeOrNil[string](source.Image) } if s.Authentication.JWTTokenSecretName == nil { - s.Authentication.JWTTokenSecretName = util.NewStringOrNil(source.Authentication.JWTTokenSecretName) + s.Authentication.JWTTokenSecretName = util.NewTypeOrNil[string](source.Authentication.JWTTokenSecretName) } setStorageDefaultsFromResourceList(&s.Resources.Limits, source.Resources.Limits) setStorageDefaultsFromResourceList(&s.Resources.Requests, source.Resources.Requests) diff --git a/pkg/apis/deployment/v1/deployment_spec.go b/pkg/apis/deployment/v1/deployment_spec.go index 5cd87980c..b8a58d649 100644 --- a/pkg/apis/deployment/v1/deployment_spec.go +++ b/pkg/apis/deployment/v1/deployment_spec.go @@ -217,7 +217,7 @@ func (s *DeploymentSpec) GetAllowMemberRecreation(group ServerGroup) bool { // GetRestoreFrom returns the restore from string or empty string if not set func (s *DeploymentSpec) GetRestoreFrom() string { - return util.StringOrDefault(s.RestoreFrom) + return util.TypeOrDefault[string](s.RestoreFrom) } // HasRestoreFrom returns true if RestoreFrom is set @@ -252,7 +252,7 @@ func (s DeploymentSpec) GetStorageEngine() StorageEngine { // GetImage returns the value of image. func (s DeploymentSpec) GetImage() string { - return util.StringOrDefault(s.Image) + return util.TypeOrDefault[string](s.Image) } // GetSyncImage returns, if set, Sync.Image or the default image. @@ -265,22 +265,22 @@ func (s DeploymentSpec) GetSyncImage() string { // GetImagePullPolicy returns the value of imagePullPolicy. func (s DeploymentSpec) GetImagePullPolicy() core.PullPolicy { - return util.PullPolicyOrDefault(s.ImagePullPolicy) + return util.TypeOrDefault[core.PullPolicy](s.ImagePullPolicy) } // IsDowntimeAllowed returns the value of downtimeAllowed. func (s DeploymentSpec) IsDowntimeAllowed() bool { - return util.BoolOrDefault(s.DowntimeAllowed) + return util.TypeOrDefault[bool](s.DowntimeAllowed) } // IsDisableIPv6 returns the value of disableIPv6. func (s DeploymentSpec) IsDisableIPv6() bool { - return util.BoolOrDefault(s.DisableIPv6) + return util.TypeOrDefault[bool](s.DisableIPv6) } // IsNetworkAttachedVolumes returns the value of networkAttachedVolumes, default false func (s DeploymentSpec) IsNetworkAttachedVolumes() bool { - return util.BoolOrDefault(s.NetworkAttachedVolumes, false) + return util.TypeOrDefault[bool](s.NetworkAttachedVolumes, false) } // GetListenAddr returns "[::]" or "0.0.0.0" depending on IsDisableIPv6 @@ -353,10 +353,10 @@ func (s *DeploymentSpec) SetDefaults(deploymentName string) { s.StorageEngine = NewStorageEngine(StorageEngineRocksDB) } if s.GetImage() == "" && s.IsDevelopment() { - s.Image = util.NewString(DefaultImage) + s.Image = util.NewType[string](DefaultImage) } if s.GetImagePullPolicy() == "" { - s.ImagePullPolicy = util.NewPullPolicy(core.PullIfNotPresent) + s.ImagePullPolicy = util.NewType[core.PullPolicy](core.PullIfNotPresent) } s.ExternalAccess.SetDefaults() s.RocksDB.SetDefaults() @@ -386,20 +386,20 @@ func (s *DeploymentSpec) SetDefaultsFrom(source DeploymentSpec) { s.StorageEngine = NewStorageEngineOrNil(source.StorageEngine) } if s.Image == nil { - s.Image = util.NewStringOrNil(source.Image) + s.Image = util.NewTypeOrNil[string](source.Image) } if s.ImagePullPolicy == nil { - s.ImagePullPolicy = util.NewPullPolicyOrNil(source.ImagePullPolicy) + s.ImagePullPolicy = util.NewTypeOrNil[core.PullPolicy](source.ImagePullPolicy) } if s.DowntimeAllowed == nil { - s.DowntimeAllowed = util.NewBoolOrNil(source.DowntimeAllowed) + s.DowntimeAllowed = util.NewTypeOrNil[bool](source.DowntimeAllowed) } if s.DisableIPv6 == nil { - s.DisableIPv6 = util.NewBoolOrNil(source.DisableIPv6) + s.DisableIPv6 = util.NewTypeOrNil[bool](source.DisableIPv6) } if s.AllowUnsafeUpgrade == nil { - s.AllowUnsafeUpgrade = util.NewBoolOrNil(source.AllowUnsafeUpgrade) + s.AllowUnsafeUpgrade = util.NewTypeOrNil[bool](source.AllowUnsafeUpgrade) } if s.Database == nil { s.Database = source.Database.DeepCopy() @@ -516,7 +516,7 @@ func (s DeploymentSpec) ResetImmutableFields(target *DeploymentSpec) []string { resetFields = append(resetFields, "storageEngine") } if s.IsDisableIPv6() != target.IsDisableIPv6() { - target.DisableIPv6 = util.NewBoolOrNil(s.DisableIPv6) + target.DisableIPv6 = util.NewTypeOrNil[bool](s.DisableIPv6) resetFields = append(resetFields, "disableIPv6") } if l := s.ExternalAccess.ResetImmutableFields("externalAccess", &target.ExternalAccess); l != nil { diff --git a/pkg/apis/deployment/v1/deployment_spec_test.go b/pkg/apis/deployment/v1/deployment_spec_test.go index 48d8f9c6f..da0a7f4c3 100644 --- a/pkg/apis/deployment/v1/deployment_spec_test.go +++ b/pkg/apis/deployment/v1/deployment_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -53,30 +53,30 @@ func TestDeploymentSpecResetImmutableFields(t *testing.T) { }{ // Valid "changes" { - DeploymentSpec{Image: util.NewString("foo")}, - DeploymentSpec{Image: util.NewString("foo2")}, - DeploymentSpec{Image: util.NewString("foo2")}, + DeploymentSpec{Image: util.NewType[string]("foo")}, + DeploymentSpec{Image: util.NewType[string]("foo2")}, + DeploymentSpec{Image: util.NewType[string]("foo2")}, false, nil, }, { - DeploymentSpec{Image: util.NewString("foo")}, - DeploymentSpec{Image: util.NewString("foo2")}, - DeploymentSpec{Image: util.NewString("foo2")}, + DeploymentSpec{Image: util.NewType[string]("foo")}, + DeploymentSpec{Image: util.NewType[string]("foo2")}, + DeploymentSpec{Image: util.NewType[string]("foo2")}, true, nil, }, { - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullAlways)}, - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullNever)}, - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullNever)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullAlways)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullNever)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullNever)}, false, nil, }, { - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullAlways)}, - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullNever)}, - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullNever)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullAlways)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullNever)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullNever)}, true, nil, }, @@ -97,9 +97,9 @@ func TestDeploymentSpecResetImmutableFields(t *testing.T) { []string{"mode", "agents.count"}, }, { - DeploymentSpec{DisableIPv6: util.NewBool(false)}, - DeploymentSpec{DisableIPv6: util.NewBool(true)}, - DeploymentSpec{DisableIPv6: util.NewBool(false)}, + DeploymentSpec{DisableIPv6: util.NewType[bool](false)}, + DeploymentSpec{DisableIPv6: util.NewType[bool](true)}, + DeploymentSpec{DisableIPv6: util.NewType[bool](false)}, false, []string{"disableIPv6"}, }, diff --git a/pkg/apis/deployment/v1/deployment_status.go b/pkg/apis/deployment/v1/deployment_status.go index 261cf6a95..d6f0fcd9a 100644 --- a/pkg/apis/deployment/v1/deployment_status.go +++ b/pkg/apis/deployment/v1/deployment_status.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -139,7 +139,7 @@ func (ds *DeploymentStatus) Equal(other DeploymentStatus) bool { // IsForceReload returns true if ForceStatusReload is set to true func (ds *DeploymentStatus) IsForceReload() bool { - return util.BoolOrDefault(ds.ForceStatusReload, false) + return util.TypeOrDefault[bool](ds.ForceStatusReload, false) } func (ds *DeploymentStatus) IsPlanEmpty() bool { diff --git a/pkg/apis/deployment/v1/external_access_spec.go b/pkg/apis/deployment/v1/external_access_spec.go index de7760a98..842381d69 100644 --- a/pkg/apis/deployment/v1/external_access_spec.go +++ b/pkg/apis/deployment/v1/external_access_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -55,17 +55,17 @@ func (s ExternalAccessSpec) GetType() ExternalAccessType { // GetNodePort returns the value of nodePort. func (s ExternalAccessSpec) GetNodePort() int { - return util.IntOrDefault(s.NodePort) + return util.TypeOrDefault[int](s.NodePort) } // GetLoadBalancerIP returns the value of loadBalancerIP. func (s ExternalAccessSpec) GetLoadBalancerIP() string { - return util.StringOrDefault(s.LoadBalancerIP) + return util.TypeOrDefault[string](s.LoadBalancerIP) } // GetAdvertisedEndpoint returns the advertised endpoint or empty string if none was specified func (s ExternalAccessSpec) GetAdvertisedEndpoint() string { - return util.StringOrDefault(s.AdvertisedEndpoint) + return util.TypeOrDefault[string](s.AdvertisedEndpoint) } // GetManagedServiceNames returns a list of managed service names. @@ -107,10 +107,10 @@ func (s *ExternalAccessSpec) SetDefaultsFrom(source ExternalAccessSpec) { s.Type = NewExternalAccessTypeOrNil(source.Type) } if s.NodePort == nil { - s.NodePort = util.NewIntOrNil(source.NodePort) + s.NodePort = util.NewTypeOrNil[int](source.NodePort) } if s.LoadBalancerIP == nil { - s.LoadBalancerIP = util.NewStringOrNil(source.LoadBalancerIP) + s.LoadBalancerIP = util.NewTypeOrNil[string](source.LoadBalancerIP) } if s.LoadBalancerSourceRanges == nil && len(source.LoadBalancerSourceRanges) > 0 { s.LoadBalancerSourceRanges = append([]string{}, source.LoadBalancerSourceRanges...) diff --git a/pkg/apis/deployment/v1/license_spec.go b/pkg/apis/deployment/v1/license_spec.go index f98584d0b..45648ef6f 100644 --- a/pkg/apis/deployment/v1/license_spec.go +++ b/pkg/apis/deployment/v1/license_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ func (s LicenseSpec) HasSecretName() bool { // GetSecretName returns the license key if set. Empty string otherwise. func (s LicenseSpec) GetSecretName() string { - return util.StringOrDefault(s.SecretName) + return util.TypeOrDefault[string](s.SecretName) } // Validate validates the LicenseSpec @@ -54,6 +54,6 @@ func (s LicenseSpec) Validate() error { // SetDefaultsFrom fills all values not set in s with values from other func (s *LicenseSpec) SetDefaultsFrom(other LicenseSpec) { if !s.HasSecretName() { - s.SecretName = util.NewStringOrNil(other.SecretName) + s.SecretName = util.NewTypeOrNil[string](other.SecretName) } } diff --git a/pkg/apis/deployment/v1/license_spec_test.go b/pkg/apis/deployment/v1/license_spec_test.go index cd32402b5..6d64e5a60 100644 --- a/pkg/apis/deployment/v1/license_spec_test.go +++ b/pkg/apis/deployment/v1/license_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import ( func TestLicenseSpecValidation(t *testing.T) { assert.Nil(t, LicenseSpec{SecretName: nil}.Validate()) - assert.Nil(t, LicenseSpec{SecretName: util.NewString("some-name")}.Validate()) + assert.Nil(t, LicenseSpec{SecretName: util.NewType[string]("some-name")}.Validate()) - assert.Error(t, LicenseSpec{SecretName: util.NewString("@@")}.Validate()) + assert.Error(t, LicenseSpec{SecretName: util.NewType[string]("@@")}.Validate()) } diff --git a/pkg/apis/deployment/v1/recovery_spec.go b/pkg/apis/deployment/v1/recovery_spec.go index 0250d6de4..3d5c211dd 100644 --- a/pkg/apis/deployment/v1/recovery_spec.go +++ b/pkg/apis/deployment/v1/recovery_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,5 +35,5 @@ func (a *ArangoDeploymentRecoverySpec) Get() ArangoDeploymentRecoverySpec { } func (a ArangoDeploymentRecoverySpec) GetAutoRecover() bool { - return util.BoolOrDefault(a.AutoRecover, false) + return util.TypeOrDefault[bool](a.AutoRecover, false) } diff --git a/pkg/apis/deployment/v1/rocksdb_spec.go b/pkg/apis/deployment/v1/rocksdb_spec.go index b9f7fcf6d..f6bca9ca4 100644 --- a/pkg/apis/deployment/v1/rocksdb_spec.go +++ b/pkg/apis/deployment/v1/rocksdb_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ type RocksDBEncryptionSpec struct { // GetKeySecretName returns the value of keySecretName. func (s RocksDBEncryptionSpec) GetKeySecretName() string { - return util.StringOrDefault(s.KeySecretName) + return util.TypeOrDefault[string](s.KeySecretName) } // IsEncrypted returns true when an encryption key secret name is provided, @@ -69,7 +69,7 @@ func (s *RocksDBSpec) SetDefaults() { // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *RocksDBSpec) SetDefaultsFrom(source RocksDBSpec) { if s.Encryption.KeySecretName == nil { - s.Encryption.KeySecretName = util.NewStringOrNil(source.Encryption.KeySecretName) + s.Encryption.KeySecretName = util.NewTypeOrNil[string](source.Encryption.KeySecretName) } } @@ -80,7 +80,7 @@ func (s RocksDBSpec) ResetImmutableFields(fieldPrefix string, target *RocksDBSpe var resetFields []string if s.IsEncrypted() != target.IsEncrypted() { // Note: You can change the name, but not from empty to non-empty (or reverse). - target.Encryption.KeySecretName = util.NewStringOrNil(s.Encryption.KeySecretName) + target.Encryption.KeySecretName = util.NewTypeOrNil[string](s.Encryption.KeySecretName) resetFields = append(resetFields, fieldPrefix+".encryption.keySecretName") } return resetFields diff --git a/pkg/apis/deployment/v1/rocksdb_spec_test.go b/pkg/apis/deployment/v1/rocksdb_spec_test.go index f4170af9a..40f020b32 100644 --- a/pkg/apis/deployment/v1/rocksdb_spec_test.go +++ b/pkg/apis/deployment/v1/rocksdb_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -31,16 +31,16 @@ import ( func TestRocksDBSpecValidate(t *testing.T) { // Valid assert.Nil(t, RocksDBSpec{}.Validate()) - assert.Nil(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}.Validate()) + assert.Nil(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}.Validate()) // Not valid - assert.Error(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("Foo")}}.Validate()) + assert.Error(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("Foo")}}.Validate()) } func TestRocksDBSpecIsEncrypted(t *testing.T) { assert.False(t, RocksDBSpec{}.IsEncrypted()) - assert.False(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("")}}.IsEncrypted()) - assert.True(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}.IsEncrypted()) + assert.False(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("")}}.IsEncrypted()) + assert.True(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}.IsEncrypted()) } func TestRocksDBSpecSetDefaults(t *testing.T) { @@ -67,23 +67,23 @@ func TestRocksDBSpecResetImmutableFields(t *testing.T) { nil, }, { - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, nil, }, { - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo2")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo2")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo2")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo2")}}, nil, }, // Invalid changes { - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, []string{"test.encryption.keySecretName"}, }, } diff --git a/pkg/apis/deployment/v1/server_group_spec.go b/pkg/apis/deployment/v1/server_group_spec.go index 19b7e0650..89384037a 100644 --- a/pkg/apis/deployment/v1/server_group_spec.go +++ b/pkg/apis/deployment/v1/server_group_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -284,17 +284,17 @@ func (s ServerGroupSpec) GetVolumeClaimTemplate() *core.PersistentVolumeClaim { // GetCount returns the value of count. func (s ServerGroupSpec) GetCount() int { - return util.IntOrDefault(s.Count) + return util.TypeOrDefault[int](s.Count) } // GetMinCount returns MinCount or 1 if not set func (s ServerGroupSpec) GetMinCount() int { - return util.IntOrDefault(s.MinCount, 1) + return util.TypeOrDefault[int](s.MinCount, 1) } // GetMaxCount returns MaxCount or func (s ServerGroupSpec) GetMaxCount() int { - return util.IntOrDefault(s.MaxCount, math.MaxInt32) + return util.TypeOrDefault[int](s.MaxCount, math.MaxInt32) } // GetNodeSelector returns the selectors for nodes of this group @@ -315,9 +315,9 @@ func (s ServerGroupSpec) GetArgs() []string { // GetStorageClassName returns the value of storageClassName. func (s ServerGroupSpec) GetStorageClassName() string { if pvc := s.GetVolumeClaimTemplate(); pvc != nil { - return util.StringOrDefault(pvc.Spec.StorageClassName) + return util.TypeOrDefault[string](pvc.Spec.StorageClassName) } - return util.StringOrDefault(s.StorageClassName) + return util.TypeOrDefault[string](s.StorageClassName) } // GetTolerations returns the value of tolerations. @@ -327,7 +327,7 @@ func (s ServerGroupSpec) GetTolerations() []core.Toleration { // GetServiceAccountName returns the value of serviceAccountName. func (s ServerGroupSpec) GetServiceAccountName() string { - return util.StringOrDefault(s.ServiceAccountName) + return util.TypeOrDefault[string](s.ServiceAccountName) } // HasProbesSpec returns true if Probes is non nil @@ -522,12 +522,12 @@ func (s *ServerGroupSpec) SetDefaults(group ServerGroup, used bool, mode Deploym switch group { case ServerGroupSingle: if mode == DeploymentModeSingle { - s.Count = util.NewInt(1) // Single server + s.Count = util.NewType[int](1) // Single server } else { - s.Count = util.NewInt(2) // ActiveFailover + s.Count = util.NewType[int](2) // ActiveFailover } default: - s.Count = util.NewInt(3) + s.Count = util.NewType[int](3) } } else if s.GetCount() > 0 && !used { s.Count = nil @@ -574,25 +574,25 @@ func setStorageDefaultsFromResourceList(s *core.ResourceList, source core.Resour // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *ServerGroupSpec) SetDefaultsFrom(source ServerGroupSpec) { if s.Count == nil { - s.Count = util.NewIntOrNil(source.Count) + s.Count = util.NewTypeOrNil[int](source.Count) } if s.MinCount == nil { - s.MinCount = util.NewIntOrNil(source.MinCount) + s.MinCount = util.NewTypeOrNil[int](source.MinCount) } if s.MaxCount == nil { - s.MaxCount = util.NewIntOrNil(source.MaxCount) + s.MaxCount = util.NewTypeOrNil[int](source.MaxCount) } if s.Args == nil { s.Args = source.Args } if s.StorageClassName == nil { - s.StorageClassName = util.NewStringOrNil(source.StorageClassName) + s.StorageClassName = util.NewTypeOrNil[string](source.StorageClassName) } if s.Tolerations == nil { s.Tolerations = source.Tolerations } if s.ServiceAccountName == nil { - s.ServiceAccountName = util.NewStringOrNil(source.ServiceAccountName) + s.ServiceAccountName = util.NewTypeOrNil[string](source.ServiceAccountName) } if s.NodeSelector == nil { s.NodeSelector = source.NodeSelector @@ -610,7 +610,7 @@ func (s ServerGroupSpec) ResetImmutableFields(group ServerGroup, fieldPrefix str var resetFields []string if group == ServerGroupAgents { if s.GetCount() != target.GetCount() { - target.Count = util.NewIntOrNil(s.Count) + target.Count = util.NewTypeOrNil[int](s.Count) resetFields = append(resetFields, fieldPrefix+".count") } } diff --git a/pkg/apis/deployment/v1/server_group_spec_pod_modes.go b/pkg/apis/deployment/v1/server_group_spec_pod_modes.go index e729844e3..f486e9998 100644 --- a/pkg/apis/deployment/v1/server_group_spec_pod_modes.go +++ b/pkg/apis/deployment/v1/server_group_spec_pod_modes.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -58,7 +58,7 @@ func (s *ServerGroupSpecPodMode) Apply(p *core.PodSpec) { // Default, no change case ServerGroupPIDModePod: // Enable Pod shared namespaces - p.ShareProcessNamespace = util.NewBool(true) + p.ShareProcessNamespace = util.NewType[bool](true) case ServerGroupPIDModeHost: // Enable Host shared namespaces p.HostPID = true diff --git a/pkg/apis/deployment/v1/server_group_spec_test.go b/pkg/apis/deployment/v1/server_group_spec_test.go index 4846450df..45273f0fa 100644 --- a/pkg/apis/deployment/v1/server_group_spec_test.go +++ b/pkg/apis/deployment/v1/server_group_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,55 +30,55 @@ import ( func TestServerGroupSpecValidateCount(t *testing.T) { // Valid - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction)) - - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(2), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6), MinCount: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(5), MinCount: util.NewInt(5), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](6)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction)) + + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2), MinCount: util.NewType[int](2), MaxCount: util.NewType[int](5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1), MaxCount: util.NewType[int](5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](6), MinCount: util.NewType[int](2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](5), MinCount: util.NewType[int](5), MaxCount: util.NewType[int](5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) // Invalid - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction)) - - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(5), MaxCount: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(6), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), MinCount: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction)) + + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](2), MinCount: util.NewType[int](5), MaxCount: util.NewType[int](1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](6), MaxCount: util.NewType[int](5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), MinCount: util.NewType[int](2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) } @@ -120,13 +120,13 @@ func TestServerGroupSpecDefault(t *testing.T) { func TestServerGroupSpecValidateArgs(t *testing.T) { // Valid - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--master.endpoint"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) // Invalid - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication", "true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint=http://something"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--mq.type=strange"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--server.authentication", "true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--master.endpoint=http://something"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--mq.type=strange"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) } diff --git a/pkg/apis/deployment/v1/sync_authentication_spec.go b/pkg/apis/deployment/v1/sync_authentication_spec.go index 60d5de418..27012c375 100644 --- a/pkg/apis/deployment/v1/sync_authentication_spec.go +++ b/pkg/apis/deployment/v1/sync_authentication_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -34,12 +34,12 @@ type SyncAuthenticationSpec struct { // GetJWTSecretName returns the value of jwtSecretName. func (s SyncAuthenticationSpec) GetJWTSecretName() string { - return util.StringOrDefault(s.JWTSecretName) + return util.TypeOrDefault[string](s.JWTSecretName) } // GetClientCASecretName returns the value of clientCASecretName. func (s SyncAuthenticationSpec) GetClientCASecretName() string { - return util.StringOrDefault(s.ClientCASecretName) + return util.TypeOrDefault[string](s.ClientCASecretName) } // Validate the given spec @@ -58,22 +58,22 @@ func (s *SyncAuthenticationSpec) SetDefaults(defaultJWTSecretName, defaultClient if s.GetJWTSecretName() == "" { // Note that we don't check for nil here, since even a specified, but empty // string should result in the default value. - s.JWTSecretName = util.NewString(defaultJWTSecretName) + s.JWTSecretName = util.NewType[string](defaultJWTSecretName) } if s.GetClientCASecretName() == "" { // Note that we don't check for nil here, since even a specified, but empty // string should result in the default value. - s.ClientCASecretName = util.NewString(defaultClientCASecretName) + s.ClientCASecretName = util.NewType[string](defaultClientCASecretName) } } // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *SyncAuthenticationSpec) SetDefaultsFrom(source SyncAuthenticationSpec) { if s.JWTSecretName == nil { - s.JWTSecretName = util.NewStringOrNil(source.JWTSecretName) + s.JWTSecretName = util.NewTypeOrNil[string](source.JWTSecretName) } if s.ClientCASecretName == nil { - s.ClientCASecretName = util.NewStringOrNil(source.ClientCASecretName) + s.ClientCASecretName = util.NewTypeOrNil[string](source.ClientCASecretName) } } diff --git a/pkg/apis/deployment/v1/sync_monitoring_spec.go b/pkg/apis/deployment/v1/sync_monitoring_spec.go index a3ec07f6a..0828eb1ad 100644 --- a/pkg/apis/deployment/v1/sync_monitoring_spec.go +++ b/pkg/apis/deployment/v1/sync_monitoring_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ type MonitoringSpec struct { // GetTokenSecretName returns the value of tokenSecretName. func (s MonitoringSpec) GetTokenSecretName() string { - return util.StringOrDefault(s.TokenSecretName) + return util.TypeOrDefault[string](s.TokenSecretName) } // Validate the given spec @@ -49,13 +49,13 @@ func (s *MonitoringSpec) SetDefaults(defaultTokenSecretName string) { if s.GetTokenSecretName() == "" { // Note that we don't check for nil here, since even a specified, but empty // string should result in the default value. - s.TokenSecretName = util.NewString(defaultTokenSecretName) + s.TokenSecretName = util.NewType[string](defaultTokenSecretName) } } // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *MonitoringSpec) SetDefaultsFrom(source MonitoringSpec) { if s.TokenSecretName == nil { - s.TokenSecretName = util.NewStringOrNil(source.TokenSecretName) + s.TokenSecretName = util.NewTypeOrNil[string](source.TokenSecretName) } } diff --git a/pkg/apis/deployment/v1/sync_monitoring_spec_test.go b/pkg/apis/deployment/v1/sync_monitoring_spec_test.go index 05754db23..90ec0013a 100644 --- a/pkg/apis/deployment/v1/sync_monitoring_spec_test.go +++ b/pkg/apis/deployment/v1/sync_monitoring_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -31,12 +31,12 @@ import ( func TestMonitoringSpecValidate(t *testing.T) { // Valid assert.Nil(t, MonitoringSpec{TokenSecretName: nil}.Validate()) - assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewString("")}.Validate()) - assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewString("foo")}.Validate()) - assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewString("foo")}.Validate()) + assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewType[string]("")}.Validate()) + assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewType[string]("foo")}.Validate()) + assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewType[string]("foo")}.Validate()) // Not valid - assert.Error(t, MonitoringSpec{TokenSecretName: util.NewString("Foo")}.Validate()) + assert.Error(t, MonitoringSpec{TokenSecretName: util.NewType[string]("Foo")}.Validate()) } func TestMonitoringSpecSetDefaults(t *testing.T) { @@ -51,5 +51,5 @@ func TestMonitoringSpecSetDefaults(t *testing.T) { assert.Equal(t, "", def(MonitoringSpec{}).GetTokenSecretName()) assert.Equal(t, "def2", def2(MonitoringSpec{}).GetTokenSecretName()) - assert.Equal(t, "foo", def(MonitoringSpec{TokenSecretName: util.NewString("foo")}).GetTokenSecretName()) + assert.Equal(t, "foo", def(MonitoringSpec{TokenSecretName: util.NewType[string]("foo")}).GetTokenSecretName()) } diff --git a/pkg/apis/deployment/v1/sync_spec.go b/pkg/apis/deployment/v1/sync_spec.go index 8fb37e423..a5262d012 100644 --- a/pkg/apis/deployment/v1/sync_spec.go +++ b/pkg/apis/deployment/v1/sync_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,12 +38,12 @@ type SyncSpec struct { // IsEnabled returns the value of enabled. func (s SyncSpec) IsEnabled() bool { - return util.BoolOrDefault(s.Enabled) + return util.TypeOrDefault[bool](s.Enabled) } // GetSyncImage returns the syncer image or empty string func (s SyncSpec) GetSyncImage() string { - return util.StringOrDefault(s.Image) + return util.TypeOrDefault[string](s.Image) } // HasSyncImage returns whether a special sync image is set @@ -84,10 +84,10 @@ func (s *SyncSpec) SetDefaults(defaultJWTSecretName, defaultClientAuthCASecretNa // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *SyncSpec) SetDefaultsFrom(source SyncSpec) { if s.Enabled == nil { - s.Enabled = util.NewBoolOrNil(source.Enabled) + s.Enabled = util.NewTypeOrNil[bool](source.Enabled) } if s.Image == nil { - s.Image = util.NewStringOrNil(source.Image) + s.Image = util.NewTypeOrNil[string](source.Image) } s.ExternalAccess.SetDefaultsFrom(source.ExternalAccess) s.Authentication.SetDefaultsFrom(source.Authentication) diff --git a/pkg/apis/deployment/v1/sync_spec_test.go b/pkg/apis/deployment/v1/sync_spec_test.go index bf82c737b..b4bb54226 100644 --- a/pkg/apis/deployment/v1/sync_spec_test.go +++ b/pkg/apis/deployment/v1/sync_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,16 +30,16 @@ import ( func TestSyncSpecValidate(t *testing.T) { // Valid - auth := SyncAuthenticationSpec{JWTSecretName: util.NewString("foo"), ClientCASecretName: util.NewString("foo-client")} - tls := TLSSpec{CASecretName: util.NewString("None")} + auth := SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo"), ClientCASecretName: util.NewType[string]("foo-client")} + tls := TLSSpec{CASecretName: util.NewType[string]("None")} assert.Nil(t, SyncSpec{Authentication: auth}.Validate(DeploymentModeSingle)) assert.Nil(t, SyncSpec{Authentication: auth}.Validate(DeploymentModeActiveFailover)) assert.Nil(t, SyncSpec{Authentication: auth}.Validate(DeploymentModeCluster)) - assert.Nil(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewBool(true)}.Validate(DeploymentModeCluster)) + assert.Nil(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewType[bool](true)}.Validate(DeploymentModeCluster)) // Not valid - assert.Error(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewBool(true)}.Validate(DeploymentModeSingle)) - assert.Error(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewBool(true)}.Validate(DeploymentModeActiveFailover)) + assert.Error(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewType[bool](true)}.Validate(DeploymentModeSingle)) + assert.Error(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewType[bool](true)}.Validate(DeploymentModeActiveFailover)) } func TestSyncSpecSetDefaults(t *testing.T) { @@ -49,11 +49,11 @@ func TestSyncSpecSetDefaults(t *testing.T) { } assert.False(t, def(SyncSpec{}).IsEnabled()) - assert.False(t, def(SyncSpec{Enabled: util.NewBool(false)}).IsEnabled()) - assert.True(t, def(SyncSpec{Enabled: util.NewBool(true)}).IsEnabled()) + assert.False(t, def(SyncSpec{Enabled: util.NewType[bool](false)}).IsEnabled()) + assert.True(t, def(SyncSpec{Enabled: util.NewType[bool](true)}).IsEnabled()) assert.Equal(t, "test-jwt", def(SyncSpec{}).Authentication.GetJWTSecretName()) assert.Equal(t, "test-mon", def(SyncSpec{}).Monitoring.GetTokenSecretName()) - assert.Equal(t, "foo", def(SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo")}}).Authentication.GetJWTSecretName()) + assert.Equal(t, "foo", def(SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}}).Authentication.GetJWTSecretName()) } func TestSyncSpecResetImmutableFields(t *testing.T) { @@ -65,33 +65,33 @@ func TestSyncSpecResetImmutableFields(t *testing.T) { }{ // Valid "changes" { - SyncSpec{Enabled: util.NewBool(false)}, - SyncSpec{Enabled: util.NewBool(true)}, - SyncSpec{Enabled: util.NewBool(true)}, + SyncSpec{Enabled: util.NewType[bool](false)}, + SyncSpec{Enabled: util.NewType[bool](true)}, + SyncSpec{Enabled: util.NewType[bool](true)}, nil, }, { - SyncSpec{Enabled: util.NewBool(true)}, - SyncSpec{Enabled: util.NewBool(false)}, - SyncSpec{Enabled: util.NewBool(false)}, + SyncSpec{Enabled: util.NewType[bool](true)}, + SyncSpec{Enabled: util.NewType[bool](false)}, + SyncSpec{Enabled: util.NewType[bool](false)}, nil, }, { - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("None"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("None"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("None"), ClientCASecretName: util.NewString("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("None"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("None"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("None"), ClientCASecretName: util.NewType[string]("some")}}, nil, }, { - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo"), ClientCASecretName: util.NewString("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo"), ClientCASecretName: util.NewType[string]("some")}}, nil, }, { - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo2"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo2"), ClientCASecretName: util.NewString("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo2"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo2"), ClientCASecretName: util.NewType[string]("some")}}, nil, }, } diff --git a/pkg/apis/deployment/v1/tls_spec.go b/pkg/apis/deployment/v1/tls_spec.go index d25f0fcd4..bf382e0b3 100644 --- a/pkg/apis/deployment/v1/tls_spec.go +++ b/pkg/apis/deployment/v1/tls_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -68,7 +68,7 @@ const ( // GetCASecretName returns the value of caSecretName. func (s TLSSpec) GetCASecretName() string { - return util.StringOrDefault(s.CASecretName) + return util.TypeOrDefault[string](s.CASecretName) } // GetAltNames returns the value of altNames. @@ -132,7 +132,7 @@ func (s *TLSSpec) SetDefaults(defaultCASecretName string) { if s.GetCASecretName() == "" { // Note that we don't check for nil here, since even a specified, but empty // string should result in the default value. - s.CASecretName = util.NewString(defaultCASecretName) + s.CASecretName = util.NewType[string](defaultCASecretName) } if s.GetTTL() == "" { // Note that we don't check for nil here, since even a specified, but zero @@ -144,7 +144,7 @@ func (s *TLSSpec) SetDefaults(defaultCASecretName string) { // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *TLSSpec) SetDefaultsFrom(source TLSSpec) { if s.CASecretName == nil { - s.CASecretName = util.NewStringOrNil(source.CASecretName) + s.CASecretName = util.NewTypeOrNil[string](source.CASecretName) } if s.AltNames == nil { s.AltNames = source.AltNames diff --git a/pkg/apis/deployment/v1/tls_spec_test.go b/pkg/apis/deployment/v1/tls_spec_test.go index e4df3e854..733ad92a0 100644 --- a/pkg/apis/deployment/v1/tls_spec_test.go +++ b/pkg/apis/deployment/v1/tls_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -31,23 +31,23 @@ import ( func TestTLSSpecValidate(t *testing.T) { // Valid - assert.Nil(t, TLSSpec{CASecretName: util.NewString("foo")}.Validate()) - assert.Nil(t, TLSSpec{CASecretName: util.NewString("None")}.Validate()) - assert.Nil(t, TLSSpec{CASecretName: util.NewString("None"), AltNames: []string{}}.Validate()) - assert.Nil(t, TLSSpec{CASecretName: util.NewString("None"), AltNames: []string{"foo"}}.Validate()) - assert.Nil(t, TLSSpec{CASecretName: util.NewString("None"), AltNames: []string{"email@example.com", "127.0.0.1"}}.Validate()) + assert.Nil(t, TLSSpec{CASecretName: util.NewType[string]("foo")}.Validate()) + assert.Nil(t, TLSSpec{CASecretName: util.NewType[string]("None")}.Validate()) + assert.Nil(t, TLSSpec{CASecretName: util.NewType[string]("None"), AltNames: []string{}}.Validate()) + assert.Nil(t, TLSSpec{CASecretName: util.NewType[string]("None"), AltNames: []string{"foo"}}.Validate()) + assert.Nil(t, TLSSpec{CASecretName: util.NewType[string]("None"), AltNames: []string{"email@example.com", "127.0.0.1"}}.Validate()) // Not valid assert.Error(t, TLSSpec{CASecretName: nil}.Validate()) - assert.Error(t, TLSSpec{CASecretName: util.NewString("")}.Validate()) - assert.Error(t, TLSSpec{CASecretName: util.NewString("Foo")}.Validate()) - assert.Error(t, TLSSpec{CASecretName: util.NewString("foo"), AltNames: []string{"@@"}}.Validate()) + assert.Error(t, TLSSpec{CASecretName: util.NewType[string]("")}.Validate()) + assert.Error(t, TLSSpec{CASecretName: util.NewType[string]("Foo")}.Validate()) + assert.Error(t, TLSSpec{CASecretName: util.NewType[string]("foo"), AltNames: []string{"@@"}}.Validate()) } func TestTLSSpecIsSecure(t *testing.T) { - assert.True(t, TLSSpec{CASecretName: util.NewString("")}.IsSecure()) - assert.True(t, TLSSpec{CASecretName: util.NewString("foo")}.IsSecure()) - assert.False(t, TLSSpec{CASecretName: util.NewString("None")}.IsSecure()) + assert.True(t, TLSSpec{CASecretName: util.NewType[string]("")}.IsSecure()) + assert.True(t, TLSSpec{CASecretName: util.NewType[string]("foo")}.IsSecure()) + assert.False(t, TLSSpec{CASecretName: util.NewType[string]("None")}.IsSecure()) } func TestTLSSpecSetDefaults(t *testing.T) { @@ -57,7 +57,7 @@ func TestTLSSpecSetDefaults(t *testing.T) { } assert.Equal(t, "", def(TLSSpec{}).GetCASecretName()) - assert.Equal(t, "foo", def(TLSSpec{CASecretName: util.NewString("foo")}).GetCASecretName()) + assert.Equal(t, "foo", def(TLSSpec{CASecretName: util.NewType[string]("foo")}).GetCASecretName()) assert.Len(t, def(TLSSpec{}).GetAltNames(), 0) assert.Len(t, def(TLSSpec{AltNames: []string{"foo.local"}}).GetAltNames(), 1) assert.Equal(t, defaultTLSTTL, def(TLSSpec{}).GetTTL()) diff --git a/pkg/apis/deployment/v2alpha1/authentication_spec.go b/pkg/apis/deployment/v2alpha1/authentication_spec.go index c7ab9b006..296b3981c 100644 --- a/pkg/apis/deployment/v2alpha1/authentication_spec.go +++ b/pkg/apis/deployment/v2alpha1/authentication_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ const ( // GetJWTSecretName returns the value of jwtSecretName. func (s AuthenticationSpec) GetJWTSecretName() string { - return util.StringOrDefault(s.JWTSecretName) + return util.TypeOrDefault[string](s.JWTSecretName) } // IsAuthenticated returns true if authentication is enabled. @@ -65,14 +65,14 @@ func (s *AuthenticationSpec) SetDefaults(defaultJWTSecretName string) { if s.GetJWTSecretName() == "" { // Note that we don't check for nil here, since even a specified, but empty // string should result in the default value. - s.JWTSecretName = util.NewString(defaultJWTSecretName) + s.JWTSecretName = util.NewType[string](defaultJWTSecretName) } } // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *AuthenticationSpec) SetDefaultsFrom(source AuthenticationSpec) { if s.JWTSecretName == nil { - s.JWTSecretName = util.NewStringOrNil(source.JWTSecretName) + s.JWTSecretName = util.NewTypeOrNil[string](source.JWTSecretName) } } @@ -83,7 +83,7 @@ func (s AuthenticationSpec) ResetImmutableFields(fieldPrefix string, target *Aut var resetFields []string if s.IsAuthenticated() != target.IsAuthenticated() { // Note: You can change the name, but not from empty to non-empty (or reverse). - target.JWTSecretName = util.NewStringOrNil(s.JWTSecretName) + target.JWTSecretName = util.NewTypeOrNil[string](s.JWTSecretName) resetFields = append(resetFields, fieldPrefix+".jwtSecretName") } return resetFields diff --git a/pkg/apis/deployment/v2alpha1/authentication_spec_test.go b/pkg/apis/deployment/v2alpha1/authentication_spec_test.go index 56e1ef277..6f2e854fb 100644 --- a/pkg/apis/deployment/v2alpha1/authentication_spec_test.go +++ b/pkg/apis/deployment/v2alpha1/authentication_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,18 +30,18 @@ import ( func TestAuthenticationSpecValidate(t *testing.T) { // Valid - assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewString("None")}.Validate(false)) - assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewString("foo")}.Validate(false)) - assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewString("foo")}.Validate(true)) + assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}.Validate(false)) + assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}.Validate(false)) + assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}.Validate(true)) // Not valid - assert.Error(t, AuthenticationSpec{JWTSecretName: util.NewString("Foo")}.Validate(false)) + assert.Error(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("Foo")}.Validate(false)) } func TestAuthenticationSpecIsAuthenticated(t *testing.T) { - assert.False(t, AuthenticationSpec{JWTSecretName: util.NewString("None")}.IsAuthenticated()) - assert.True(t, AuthenticationSpec{JWTSecretName: util.NewString("foo")}.IsAuthenticated()) - assert.True(t, AuthenticationSpec{JWTSecretName: util.NewString("")}.IsAuthenticated()) + assert.False(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}.IsAuthenticated()) + assert.True(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}.IsAuthenticated()) + assert.True(t, AuthenticationSpec{JWTSecretName: util.NewType[string]("")}.IsAuthenticated()) } func TestAuthenticationSpecSetDefaults(t *testing.T) { @@ -51,7 +51,7 @@ func TestAuthenticationSpecSetDefaults(t *testing.T) { } assert.Equal(t, "test-jwt", def(AuthenticationSpec{}).GetJWTSecretName()) - assert.Equal(t, "foo", def(AuthenticationSpec{JWTSecretName: util.NewString("foo")}).GetJWTSecretName()) + assert.Equal(t, "foo", def(AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}).GetJWTSecretName()) } func TestAuthenticationSpecResetImmutableFields(t *testing.T) { @@ -63,35 +63,35 @@ func TestAuthenticationSpecResetImmutableFields(t *testing.T) { }{ // Valid "changes" { - AuthenticationSpec{JWTSecretName: util.NewString("None")}, - AuthenticationSpec{JWTSecretName: util.NewString("None")}, - AuthenticationSpec{JWTSecretName: util.NewString("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, nil, }, { - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, nil, }, { - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo2")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo2")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo2")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo2")}, nil, }, // Invalid changes { - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, - AuthenticationSpec{JWTSecretName: util.NewString("None")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, []string{"test.jwtSecretName"}, }, { - AuthenticationSpec{JWTSecretName: util.NewString("None")}, - AuthenticationSpec{JWTSecretName: util.NewString("foo")}, - AuthenticationSpec{JWTSecretName: util.NewString("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}, + AuthenticationSpec{JWTSecretName: util.NewType[string]("None")}, []string{"test.jwtSecretName"}, }, } diff --git a/pkg/apis/deployment/v2alpha1/chaos_spec.go b/pkg/apis/deployment/v2alpha1/chaos_spec.go index 6c93c6ab2..be2ec057a 100644 --- a/pkg/apis/deployment/v2alpha1/chaos_spec.go +++ b/pkg/apis/deployment/v2alpha1/chaos_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -39,12 +39,12 @@ type ChaosSpec struct { // IsEnabled returns the value of enabled. func (s ChaosSpec) IsEnabled() bool { - return util.BoolOrDefault(s.Enabled) + return util.TypeOrDefault[bool](s.Enabled) } // GetInterval returns the value of interval. func (s ChaosSpec) GetInterval() time.Duration { - return util.DurationOrDefault(s.Interval) + return util.TypeOrDefault[time.Duration](s.Interval) } // GetKillPodProbability returns the value of kill-pod-probability. @@ -68,7 +68,7 @@ func (s ChaosSpec) Validate() error { // SetDefaults fills in missing defaults func (s *ChaosSpec) SetDefaults() { if s.GetInterval() == 0 { - s.Interval = util.NewDuration(time.Minute) + s.Interval = util.NewType[time.Duration](time.Minute) } if s.GetKillPodProbability() == 0 { s.KillPodProbability = NewPercent(50) @@ -78,10 +78,10 @@ func (s *ChaosSpec) SetDefaults() { // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *ChaosSpec) SetDefaultsFrom(source ChaosSpec) { if s.Enabled == nil { - s.Enabled = util.NewBoolOrNil(source.Enabled) + s.Enabled = util.NewTypeOrNil[bool](source.Enabled) } if s.Interval == nil { - s.Interval = util.NewDurationOrNil(source.Interval) + s.Interval = util.NewTypeOrNil[time.Duration](source.Interval) } if s.KillPodProbability == nil { s.KillPodProbability = NewPercentOrNil(source.KillPodProbability) diff --git a/pkg/apis/deployment/v2alpha1/deployment_metrics_spec.go b/pkg/apis/deployment/v2alpha1/deployment_metrics_spec.go index 3c5b4e83a..0ab98dc5f 100644 --- a/pkg/apis/deployment/v2alpha1/deployment_metrics_spec.go +++ b/pkg/apis/deployment/v2alpha1/deployment_metrics_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -106,7 +106,7 @@ func (s *MetricsSpec) GetPort() uint16 { // IsEnabled returns whether metrics are enabled or not func (s *MetricsSpec) IsEnabled() bool { - return util.BoolOrDefault(s.Enabled, false) + return util.TypeOrDefault[bool](s.Enabled, false) } // HasImage returns whether a image was specified or not @@ -118,22 +118,22 @@ func (s *MetricsSpec) HasImage() bool { // GetImage returns the Image or empty string // Deprecated func (s *MetricsSpec) GetImage() string { - return util.StringOrDefault(s.Image) + return util.TypeOrDefault[string](s.Image) } // SetDefaults sets default values func (s *MetricsSpec) SetDefaults(defaultTokenName string, isAuthenticated bool) { if s.Enabled == nil { - s.Enabled = util.NewBool(false) + s.Enabled = util.NewType[bool](false) } if s.GetJWTTokenSecretName() == "" { - s.Authentication.JWTTokenSecretName = util.NewString(defaultTokenName) + s.Authentication.JWTTokenSecretName = util.NewType[string](defaultTokenName) } } // GetJWTTokenSecretName returns the token secret name or empty string func (s *MetricsSpec) GetJWTTokenSecretName() string { - return util.StringOrDefault(s.Authentication.JWTTokenSecretName) + return util.TypeOrDefault[string](s.Authentication.JWTTokenSecretName) } // HasJWTTokenSecretName returns true if a secret name was specified @@ -144,13 +144,13 @@ func (s *MetricsSpec) HasJWTTokenSecretName() bool { // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *MetricsSpec) SetDefaultsFrom(source MetricsSpec) { if s.Enabled == nil { - s.Enabled = util.NewBoolOrNil(source.Enabled) + s.Enabled = util.NewTypeOrNil[bool](source.Enabled) } if s.Image == nil { - s.Image = util.NewStringOrNil(source.Image) + s.Image = util.NewTypeOrNil[string](source.Image) } if s.Authentication.JWTTokenSecretName == nil { - s.Authentication.JWTTokenSecretName = util.NewStringOrNil(source.Authentication.JWTTokenSecretName) + s.Authentication.JWTTokenSecretName = util.NewTypeOrNil[string](source.Authentication.JWTTokenSecretName) } setStorageDefaultsFromResourceList(&s.Resources.Limits, source.Resources.Limits) setStorageDefaultsFromResourceList(&s.Resources.Requests, source.Resources.Requests) diff --git a/pkg/apis/deployment/v2alpha1/deployment_spec.go b/pkg/apis/deployment/v2alpha1/deployment_spec.go index 3bece9cc5..beb88a5a8 100644 --- a/pkg/apis/deployment/v2alpha1/deployment_spec.go +++ b/pkg/apis/deployment/v2alpha1/deployment_spec.go @@ -217,7 +217,7 @@ func (s *DeploymentSpec) GetAllowMemberRecreation(group ServerGroup) bool { // GetRestoreFrom returns the restore from string or empty string if not set func (s *DeploymentSpec) GetRestoreFrom() string { - return util.StringOrDefault(s.RestoreFrom) + return util.TypeOrDefault[string](s.RestoreFrom) } // HasRestoreFrom returns true if RestoreFrom is set @@ -252,7 +252,7 @@ func (s DeploymentSpec) GetStorageEngine() StorageEngine { // GetImage returns the value of image. func (s DeploymentSpec) GetImage() string { - return util.StringOrDefault(s.Image) + return util.TypeOrDefault[string](s.Image) } // GetSyncImage returns, if set, Sync.Image or the default image. @@ -265,22 +265,22 @@ func (s DeploymentSpec) GetSyncImage() string { // GetImagePullPolicy returns the value of imagePullPolicy. func (s DeploymentSpec) GetImagePullPolicy() core.PullPolicy { - return util.PullPolicyOrDefault(s.ImagePullPolicy) + return util.TypeOrDefault[core.PullPolicy](s.ImagePullPolicy) } // IsDowntimeAllowed returns the value of downtimeAllowed. func (s DeploymentSpec) IsDowntimeAllowed() bool { - return util.BoolOrDefault(s.DowntimeAllowed) + return util.TypeOrDefault[bool](s.DowntimeAllowed) } // IsDisableIPv6 returns the value of disableIPv6. func (s DeploymentSpec) IsDisableIPv6() bool { - return util.BoolOrDefault(s.DisableIPv6) + return util.TypeOrDefault[bool](s.DisableIPv6) } // IsNetworkAttachedVolumes returns the value of networkAttachedVolumes, default false func (s DeploymentSpec) IsNetworkAttachedVolumes() bool { - return util.BoolOrDefault(s.NetworkAttachedVolumes, false) + return util.TypeOrDefault[bool](s.NetworkAttachedVolumes, false) } // GetListenAddr returns "[::]" or "0.0.0.0" depending on IsDisableIPv6 @@ -353,10 +353,10 @@ func (s *DeploymentSpec) SetDefaults(deploymentName string) { s.StorageEngine = NewStorageEngine(StorageEngineRocksDB) } if s.GetImage() == "" && s.IsDevelopment() { - s.Image = util.NewString(DefaultImage) + s.Image = util.NewType[string](DefaultImage) } if s.GetImagePullPolicy() == "" { - s.ImagePullPolicy = util.NewPullPolicy(core.PullIfNotPresent) + s.ImagePullPolicy = util.NewType[core.PullPolicy](core.PullIfNotPresent) } s.ExternalAccess.SetDefaults() s.RocksDB.SetDefaults() @@ -386,20 +386,20 @@ func (s *DeploymentSpec) SetDefaultsFrom(source DeploymentSpec) { s.StorageEngine = NewStorageEngineOrNil(source.StorageEngine) } if s.Image == nil { - s.Image = util.NewStringOrNil(source.Image) + s.Image = util.NewTypeOrNil[string](source.Image) } if s.ImagePullPolicy == nil { - s.ImagePullPolicy = util.NewPullPolicyOrNil(source.ImagePullPolicy) + s.ImagePullPolicy = util.NewTypeOrNil[core.PullPolicy](source.ImagePullPolicy) } if s.DowntimeAllowed == nil { - s.DowntimeAllowed = util.NewBoolOrNil(source.DowntimeAllowed) + s.DowntimeAllowed = util.NewTypeOrNil[bool](source.DowntimeAllowed) } if s.DisableIPv6 == nil { - s.DisableIPv6 = util.NewBoolOrNil(source.DisableIPv6) + s.DisableIPv6 = util.NewTypeOrNil[bool](source.DisableIPv6) } if s.AllowUnsafeUpgrade == nil { - s.AllowUnsafeUpgrade = util.NewBoolOrNil(source.AllowUnsafeUpgrade) + s.AllowUnsafeUpgrade = util.NewTypeOrNil[bool](source.AllowUnsafeUpgrade) } if s.Database == nil { s.Database = source.Database.DeepCopy() @@ -516,7 +516,7 @@ func (s DeploymentSpec) ResetImmutableFields(target *DeploymentSpec) []string { resetFields = append(resetFields, "storageEngine") } if s.IsDisableIPv6() != target.IsDisableIPv6() { - target.DisableIPv6 = util.NewBoolOrNil(s.DisableIPv6) + target.DisableIPv6 = util.NewTypeOrNil[bool](s.DisableIPv6) resetFields = append(resetFields, "disableIPv6") } if l := s.ExternalAccess.ResetImmutableFields("externalAccess", &target.ExternalAccess); l != nil { diff --git a/pkg/apis/deployment/v2alpha1/deployment_spec_test.go b/pkg/apis/deployment/v2alpha1/deployment_spec_test.go index e80b569ce..626af3075 100644 --- a/pkg/apis/deployment/v2alpha1/deployment_spec_test.go +++ b/pkg/apis/deployment/v2alpha1/deployment_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -53,30 +53,30 @@ func TestDeploymentSpecResetImmutableFields(t *testing.T) { }{ // Valid "changes" { - DeploymentSpec{Image: util.NewString("foo")}, - DeploymentSpec{Image: util.NewString("foo2")}, - DeploymentSpec{Image: util.NewString("foo2")}, + DeploymentSpec{Image: util.NewType[string]("foo")}, + DeploymentSpec{Image: util.NewType[string]("foo2")}, + DeploymentSpec{Image: util.NewType[string]("foo2")}, false, nil, }, { - DeploymentSpec{Image: util.NewString("foo")}, - DeploymentSpec{Image: util.NewString("foo2")}, - DeploymentSpec{Image: util.NewString("foo2")}, + DeploymentSpec{Image: util.NewType[string]("foo")}, + DeploymentSpec{Image: util.NewType[string]("foo2")}, + DeploymentSpec{Image: util.NewType[string]("foo2")}, true, nil, }, { - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullAlways)}, - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullNever)}, - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullNever)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullAlways)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullNever)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullNever)}, false, nil, }, { - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullAlways)}, - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullNever)}, - DeploymentSpec{ImagePullPolicy: util.NewPullPolicy(core.PullNever)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullAlways)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullNever)}, + DeploymentSpec{ImagePullPolicy: util.NewType[core.PullPolicy](core.PullNever)}, true, nil, }, @@ -97,9 +97,9 @@ func TestDeploymentSpecResetImmutableFields(t *testing.T) { []string{"mode", "agents.count"}, }, { - DeploymentSpec{DisableIPv6: util.NewBool(false)}, - DeploymentSpec{DisableIPv6: util.NewBool(true)}, - DeploymentSpec{DisableIPv6: util.NewBool(false)}, + DeploymentSpec{DisableIPv6: util.NewType[bool](false)}, + DeploymentSpec{DisableIPv6: util.NewType[bool](true)}, + DeploymentSpec{DisableIPv6: util.NewType[bool](false)}, false, []string{"disableIPv6"}, }, diff --git a/pkg/apis/deployment/v2alpha1/deployment_status.go b/pkg/apis/deployment/v2alpha1/deployment_status.go index 4aaf2c882..a765df6ba 100644 --- a/pkg/apis/deployment/v2alpha1/deployment_status.go +++ b/pkg/apis/deployment/v2alpha1/deployment_status.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -139,7 +139,7 @@ func (ds *DeploymentStatus) Equal(other DeploymentStatus) bool { // IsForceReload returns true if ForceStatusReload is set to true func (ds *DeploymentStatus) IsForceReload() bool { - return util.BoolOrDefault(ds.ForceStatusReload, false) + return util.TypeOrDefault[bool](ds.ForceStatusReload, false) } func (ds *DeploymentStatus) IsPlanEmpty() bool { diff --git a/pkg/apis/deployment/v2alpha1/external_access_spec.go b/pkg/apis/deployment/v2alpha1/external_access_spec.go index 7269ebead..c06e61f01 100644 --- a/pkg/apis/deployment/v2alpha1/external_access_spec.go +++ b/pkg/apis/deployment/v2alpha1/external_access_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -55,17 +55,17 @@ func (s ExternalAccessSpec) GetType() ExternalAccessType { // GetNodePort returns the value of nodePort. func (s ExternalAccessSpec) GetNodePort() int { - return util.IntOrDefault(s.NodePort) + return util.TypeOrDefault[int](s.NodePort) } // GetLoadBalancerIP returns the value of loadBalancerIP. func (s ExternalAccessSpec) GetLoadBalancerIP() string { - return util.StringOrDefault(s.LoadBalancerIP) + return util.TypeOrDefault[string](s.LoadBalancerIP) } // GetAdvertisedEndpoint returns the advertised endpoint or empty string if none was specified func (s ExternalAccessSpec) GetAdvertisedEndpoint() string { - return util.StringOrDefault(s.AdvertisedEndpoint) + return util.TypeOrDefault[string](s.AdvertisedEndpoint) } // GetManagedServiceNames returns a list of managed service names. @@ -107,10 +107,10 @@ func (s *ExternalAccessSpec) SetDefaultsFrom(source ExternalAccessSpec) { s.Type = NewExternalAccessTypeOrNil(source.Type) } if s.NodePort == nil { - s.NodePort = util.NewIntOrNil(source.NodePort) + s.NodePort = util.NewTypeOrNil[int](source.NodePort) } if s.LoadBalancerIP == nil { - s.LoadBalancerIP = util.NewStringOrNil(source.LoadBalancerIP) + s.LoadBalancerIP = util.NewTypeOrNil[string](source.LoadBalancerIP) } if s.LoadBalancerSourceRanges == nil && len(source.LoadBalancerSourceRanges) > 0 { s.LoadBalancerSourceRanges = append([]string{}, source.LoadBalancerSourceRanges...) diff --git a/pkg/apis/deployment/v2alpha1/license_spec.go b/pkg/apis/deployment/v2alpha1/license_spec.go index 951941553..02f1b8463 100644 --- a/pkg/apis/deployment/v2alpha1/license_spec.go +++ b/pkg/apis/deployment/v2alpha1/license_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ func (s LicenseSpec) HasSecretName() bool { // GetSecretName returns the license key if set. Empty string otherwise. func (s LicenseSpec) GetSecretName() string { - return util.StringOrDefault(s.SecretName) + return util.TypeOrDefault[string](s.SecretName) } // Validate validates the LicenseSpec @@ -54,6 +54,6 @@ func (s LicenseSpec) Validate() error { // SetDefaultsFrom fills all values not set in s with values from other func (s *LicenseSpec) SetDefaultsFrom(other LicenseSpec) { if !s.HasSecretName() { - s.SecretName = util.NewStringOrNil(other.SecretName) + s.SecretName = util.NewTypeOrNil[string](other.SecretName) } } diff --git a/pkg/apis/deployment/v2alpha1/license_spec_test.go b/pkg/apis/deployment/v2alpha1/license_spec_test.go index c3807cbd4..a77cbfddd 100644 --- a/pkg/apis/deployment/v2alpha1/license_spec_test.go +++ b/pkg/apis/deployment/v2alpha1/license_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import ( func TestLicenseSpecValidation(t *testing.T) { assert.Nil(t, LicenseSpec{SecretName: nil}.Validate()) - assert.Nil(t, LicenseSpec{SecretName: util.NewString("some-name")}.Validate()) + assert.Nil(t, LicenseSpec{SecretName: util.NewType[string]("some-name")}.Validate()) - assert.Error(t, LicenseSpec{SecretName: util.NewString("@@")}.Validate()) + assert.Error(t, LicenseSpec{SecretName: util.NewType[string]("@@")}.Validate()) } diff --git a/pkg/apis/deployment/v2alpha1/recovery_spec.go b/pkg/apis/deployment/v2alpha1/recovery_spec.go index 410b21350..73a685ab7 100644 --- a/pkg/apis/deployment/v2alpha1/recovery_spec.go +++ b/pkg/apis/deployment/v2alpha1/recovery_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,5 +35,5 @@ func (a *ArangoDeploymentRecoverySpec) Get() ArangoDeploymentRecoverySpec { } func (a ArangoDeploymentRecoverySpec) GetAutoRecover() bool { - return util.BoolOrDefault(a.AutoRecover, false) + return util.TypeOrDefault[bool](a.AutoRecover, false) } diff --git a/pkg/apis/deployment/v2alpha1/rocksdb_spec.go b/pkg/apis/deployment/v2alpha1/rocksdb_spec.go index 35221fe25..feae3c41e 100644 --- a/pkg/apis/deployment/v2alpha1/rocksdb_spec.go +++ b/pkg/apis/deployment/v2alpha1/rocksdb_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ type RocksDBEncryptionSpec struct { // GetKeySecretName returns the value of keySecretName. func (s RocksDBEncryptionSpec) GetKeySecretName() string { - return util.StringOrDefault(s.KeySecretName) + return util.TypeOrDefault[string](s.KeySecretName) } // IsEncrypted returns true when an encryption key secret name is provided, @@ -69,7 +69,7 @@ func (s *RocksDBSpec) SetDefaults() { // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *RocksDBSpec) SetDefaultsFrom(source RocksDBSpec) { if s.Encryption.KeySecretName == nil { - s.Encryption.KeySecretName = util.NewStringOrNil(source.Encryption.KeySecretName) + s.Encryption.KeySecretName = util.NewTypeOrNil[string](source.Encryption.KeySecretName) } } @@ -80,7 +80,7 @@ func (s RocksDBSpec) ResetImmutableFields(fieldPrefix string, target *RocksDBSpe var resetFields []string if s.IsEncrypted() != target.IsEncrypted() { // Note: You can change the name, but not from empty to non-empty (or reverse). - target.Encryption.KeySecretName = util.NewStringOrNil(s.Encryption.KeySecretName) + target.Encryption.KeySecretName = util.NewTypeOrNil[string](s.Encryption.KeySecretName) resetFields = append(resetFields, fieldPrefix+".encryption.keySecretName") } return resetFields diff --git a/pkg/apis/deployment/v2alpha1/rocksdb_spec_test.go b/pkg/apis/deployment/v2alpha1/rocksdb_spec_test.go index e8be1a3bf..8a0e15e0a 100644 --- a/pkg/apis/deployment/v2alpha1/rocksdb_spec_test.go +++ b/pkg/apis/deployment/v2alpha1/rocksdb_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -31,16 +31,16 @@ import ( func TestRocksDBSpecValidate(t *testing.T) { // Valid assert.Nil(t, RocksDBSpec{}.Validate()) - assert.Nil(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}.Validate()) + assert.Nil(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}.Validate()) // Not valid - assert.Error(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("Foo")}}.Validate()) + assert.Error(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("Foo")}}.Validate()) } func TestRocksDBSpecIsEncrypted(t *testing.T) { assert.False(t, RocksDBSpec{}.IsEncrypted()) - assert.False(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("")}}.IsEncrypted()) - assert.True(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}.IsEncrypted()) + assert.False(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("")}}.IsEncrypted()) + assert.True(t, RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}.IsEncrypted()) } func TestRocksDBSpecSetDefaults(t *testing.T) { @@ -67,23 +67,23 @@ func TestRocksDBSpecResetImmutableFields(t *testing.T) { nil, }, { - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, nil, }, { - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo2")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo2")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo2")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo2")}}, nil, }, // Invalid changes { - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("")}}, - RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewString("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("")}}, + RocksDBSpec{Encryption: RocksDBEncryptionSpec{KeySecretName: util.NewType[string]("foo")}}, []string{"test.encryption.keySecretName"}, }, } diff --git a/pkg/apis/deployment/v2alpha1/server_group_spec.go b/pkg/apis/deployment/v2alpha1/server_group_spec.go index 519dda4e8..9ada6c467 100644 --- a/pkg/apis/deployment/v2alpha1/server_group_spec.go +++ b/pkg/apis/deployment/v2alpha1/server_group_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -284,17 +284,17 @@ func (s ServerGroupSpec) GetVolumeClaimTemplate() *core.PersistentVolumeClaim { // GetCount returns the value of count. func (s ServerGroupSpec) GetCount() int { - return util.IntOrDefault(s.Count) + return util.TypeOrDefault[int](s.Count) } // GetMinCount returns MinCount or 1 if not set func (s ServerGroupSpec) GetMinCount() int { - return util.IntOrDefault(s.MinCount, 1) + return util.TypeOrDefault[int](s.MinCount, 1) } // GetMaxCount returns MaxCount or func (s ServerGroupSpec) GetMaxCount() int { - return util.IntOrDefault(s.MaxCount, math.MaxInt32) + return util.TypeOrDefault[int](s.MaxCount, math.MaxInt32) } // GetNodeSelector returns the selectors for nodes of this group @@ -315,9 +315,9 @@ func (s ServerGroupSpec) GetArgs() []string { // GetStorageClassName returns the value of storageClassName. func (s ServerGroupSpec) GetStorageClassName() string { if pvc := s.GetVolumeClaimTemplate(); pvc != nil { - return util.StringOrDefault(pvc.Spec.StorageClassName) + return util.TypeOrDefault[string](pvc.Spec.StorageClassName) } - return util.StringOrDefault(s.StorageClassName) + return util.TypeOrDefault[string](s.StorageClassName) } // GetTolerations returns the value of tolerations. @@ -327,7 +327,7 @@ func (s ServerGroupSpec) GetTolerations() []core.Toleration { // GetServiceAccountName returns the value of serviceAccountName. func (s ServerGroupSpec) GetServiceAccountName() string { - return util.StringOrDefault(s.ServiceAccountName) + return util.TypeOrDefault[string](s.ServiceAccountName) } // HasProbesSpec returns true if Probes is non nil @@ -522,12 +522,12 @@ func (s *ServerGroupSpec) SetDefaults(group ServerGroup, used bool, mode Deploym switch group { case ServerGroupSingle: if mode == DeploymentModeSingle { - s.Count = util.NewInt(1) // Single server + s.Count = util.NewType[int](1) // Single server } else { - s.Count = util.NewInt(2) // ActiveFailover + s.Count = util.NewType[int](2) // ActiveFailover } default: - s.Count = util.NewInt(3) + s.Count = util.NewType[int](3) } } else if s.GetCount() > 0 && !used { s.Count = nil @@ -574,25 +574,25 @@ func setStorageDefaultsFromResourceList(s *core.ResourceList, source core.Resour // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *ServerGroupSpec) SetDefaultsFrom(source ServerGroupSpec) { if s.Count == nil { - s.Count = util.NewIntOrNil(source.Count) + s.Count = util.NewTypeOrNil[int](source.Count) } if s.MinCount == nil { - s.MinCount = util.NewIntOrNil(source.MinCount) + s.MinCount = util.NewTypeOrNil[int](source.MinCount) } if s.MaxCount == nil { - s.MaxCount = util.NewIntOrNil(source.MaxCount) + s.MaxCount = util.NewTypeOrNil[int](source.MaxCount) } if s.Args == nil { s.Args = source.Args } if s.StorageClassName == nil { - s.StorageClassName = util.NewStringOrNil(source.StorageClassName) + s.StorageClassName = util.NewTypeOrNil[string](source.StorageClassName) } if s.Tolerations == nil { s.Tolerations = source.Tolerations } if s.ServiceAccountName == nil { - s.ServiceAccountName = util.NewStringOrNil(source.ServiceAccountName) + s.ServiceAccountName = util.NewTypeOrNil[string](source.ServiceAccountName) } if s.NodeSelector == nil { s.NodeSelector = source.NodeSelector @@ -610,7 +610,7 @@ func (s ServerGroupSpec) ResetImmutableFields(group ServerGroup, fieldPrefix str var resetFields []string if group == ServerGroupAgents { if s.GetCount() != target.GetCount() { - target.Count = util.NewIntOrNil(s.Count) + target.Count = util.NewTypeOrNil[int](s.Count) resetFields = append(resetFields, fieldPrefix+".count") } } diff --git a/pkg/apis/deployment/v2alpha1/server_group_spec_pod_modes.go b/pkg/apis/deployment/v2alpha1/server_group_spec_pod_modes.go index 4b3b75fe7..8e361af0c 100644 --- a/pkg/apis/deployment/v2alpha1/server_group_spec_pod_modes.go +++ b/pkg/apis/deployment/v2alpha1/server_group_spec_pod_modes.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -58,7 +58,7 @@ func (s *ServerGroupSpecPodMode) Apply(p *core.PodSpec) { // Default, no change case ServerGroupPIDModePod: // Enable Pod shared namespaces - p.ShareProcessNamespace = util.NewBool(true) + p.ShareProcessNamespace = util.NewType[bool](true) case ServerGroupPIDModeHost: // Enable Host shared namespaces p.HostPID = true diff --git a/pkg/apis/deployment/v2alpha1/server_group_spec_test.go b/pkg/apis/deployment/v2alpha1/server_group_spec_test.go index 253254803..ec13c560e 100644 --- a/pkg/apis/deployment/v2alpha1/server_group_spec_test.go +++ b/pkg/apis/deployment/v2alpha1/server_group_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,55 +30,55 @@ import ( func TestServerGroupSpecValidateCount(t *testing.T) { // Valid - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction)) - - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(2), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(6), MinCount: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(5), MinCount: util.NewInt(5), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](6)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](3)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction)) + + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2), MinCount: util.NewType[int](2), MaxCount: util.NewType[int](5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1), MaxCount: util.NewType[int](5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](6), MinCount: util.NewType[int](2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](5), MinCount: util.NewType[int](5), MaxCount: util.NewType[int](5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) // Invalid - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(0)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(-1)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction)) - - assert.Error(t, ServerGroupSpec{Count: util.NewInt(2), MinCount: util.NewInt(5), MaxCount: util.NewInt(1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(6), MaxCount: util.NewInt(5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), MinCount: util.NewInt(2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, false, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupSingle).Validate(ServerGroupSingle, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](0)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](-1)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](2)}.WithGroup(ServerGroupAgents).Validate(ServerGroupAgents, true, DeploymentModeActiveFailover, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupDBServers).Validate(ServerGroupDBServers, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupSyncMasters).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentProduction)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1)}.WithGroup(ServerGroupSyncWorkers).Validate(ServerGroupSyncWorkers, true, DeploymentModeCluster, EnvironmentProduction)) + + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](2), MinCount: util.NewType[int](5), MaxCount: util.NewType[int](1)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](6), MaxCount: util.NewType[int](5)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), MinCount: util.NewType[int](2)}.WithGroup(ServerGroupCoordinators).Validate(ServerGroupCoordinators, true, DeploymentModeCluster, EnvironmentDevelopment)) } @@ -120,13 +120,13 @@ func TestServerGroupSpecDefault(t *testing.T) { func TestServerGroupSpecValidateArgs(t *testing.T) { // Valid - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Nil(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--master.endpoint"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Nil(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) // Invalid - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--server.authentication", "true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--master.endpoint=http://something"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) - assert.Error(t, ServerGroupSpec{Count: util.NewInt(1), Args: []string{"--mq.type=strange"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--server.authentication=true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--server.authentication", "true"}}.WithDefaults(ServerGroupSingle, true, DeploymentModeSingle).Validate(ServerGroupSingle, true, DeploymentModeSingle, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--master.endpoint=http://something"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) + assert.Error(t, ServerGroupSpec{Count: util.NewType[int](1), Args: []string{"--mq.type=strange"}}.WithDefaults(ServerGroupSyncMasters, true, DeploymentModeCluster).Validate(ServerGroupSyncMasters, true, DeploymentModeCluster, EnvironmentDevelopment)) } diff --git a/pkg/apis/deployment/v2alpha1/sync_authentication_spec.go b/pkg/apis/deployment/v2alpha1/sync_authentication_spec.go index 44ffe7d87..5e783f984 100644 --- a/pkg/apis/deployment/v2alpha1/sync_authentication_spec.go +++ b/pkg/apis/deployment/v2alpha1/sync_authentication_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -34,12 +34,12 @@ type SyncAuthenticationSpec struct { // GetJWTSecretName returns the value of jwtSecretName. func (s SyncAuthenticationSpec) GetJWTSecretName() string { - return util.StringOrDefault(s.JWTSecretName) + return util.TypeOrDefault[string](s.JWTSecretName) } // GetClientCASecretName returns the value of clientCASecretName. func (s SyncAuthenticationSpec) GetClientCASecretName() string { - return util.StringOrDefault(s.ClientCASecretName) + return util.TypeOrDefault[string](s.ClientCASecretName) } // Validate the given spec @@ -58,22 +58,22 @@ func (s *SyncAuthenticationSpec) SetDefaults(defaultJWTSecretName, defaultClient if s.GetJWTSecretName() == "" { // Note that we don't check for nil here, since even a specified, but empty // string should result in the default value. - s.JWTSecretName = util.NewString(defaultJWTSecretName) + s.JWTSecretName = util.NewType[string](defaultJWTSecretName) } if s.GetClientCASecretName() == "" { // Note that we don't check for nil here, since even a specified, but empty // string should result in the default value. - s.ClientCASecretName = util.NewString(defaultClientCASecretName) + s.ClientCASecretName = util.NewType[string](defaultClientCASecretName) } } // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *SyncAuthenticationSpec) SetDefaultsFrom(source SyncAuthenticationSpec) { if s.JWTSecretName == nil { - s.JWTSecretName = util.NewStringOrNil(source.JWTSecretName) + s.JWTSecretName = util.NewTypeOrNil[string](source.JWTSecretName) } if s.ClientCASecretName == nil { - s.ClientCASecretName = util.NewStringOrNil(source.ClientCASecretName) + s.ClientCASecretName = util.NewTypeOrNil[string](source.ClientCASecretName) } } diff --git a/pkg/apis/deployment/v2alpha1/sync_monitoring_spec.go b/pkg/apis/deployment/v2alpha1/sync_monitoring_spec.go index 2cf73a968..a286fcbfd 100644 --- a/pkg/apis/deployment/v2alpha1/sync_monitoring_spec.go +++ b/pkg/apis/deployment/v2alpha1/sync_monitoring_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ type MonitoringSpec struct { // GetTokenSecretName returns the value of tokenSecretName. func (s MonitoringSpec) GetTokenSecretName() string { - return util.StringOrDefault(s.TokenSecretName) + return util.TypeOrDefault[string](s.TokenSecretName) } // Validate the given spec @@ -49,13 +49,13 @@ func (s *MonitoringSpec) SetDefaults(defaultTokenSecretName string) { if s.GetTokenSecretName() == "" { // Note that we don't check for nil here, since even a specified, but empty // string should result in the default value. - s.TokenSecretName = util.NewString(defaultTokenSecretName) + s.TokenSecretName = util.NewType[string](defaultTokenSecretName) } } // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *MonitoringSpec) SetDefaultsFrom(source MonitoringSpec) { if s.TokenSecretName == nil { - s.TokenSecretName = util.NewStringOrNil(source.TokenSecretName) + s.TokenSecretName = util.NewTypeOrNil[string](source.TokenSecretName) } } diff --git a/pkg/apis/deployment/v2alpha1/sync_monitoring_spec_test.go b/pkg/apis/deployment/v2alpha1/sync_monitoring_spec_test.go index 41ed94ac3..f49b61209 100644 --- a/pkg/apis/deployment/v2alpha1/sync_monitoring_spec_test.go +++ b/pkg/apis/deployment/v2alpha1/sync_monitoring_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -31,12 +31,12 @@ import ( func TestMonitoringSpecValidate(t *testing.T) { // Valid assert.Nil(t, MonitoringSpec{TokenSecretName: nil}.Validate()) - assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewString("")}.Validate()) - assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewString("foo")}.Validate()) - assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewString("foo")}.Validate()) + assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewType[string]("")}.Validate()) + assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewType[string]("foo")}.Validate()) + assert.Nil(t, MonitoringSpec{TokenSecretName: util.NewType[string]("foo")}.Validate()) // Not valid - assert.Error(t, MonitoringSpec{TokenSecretName: util.NewString("Foo")}.Validate()) + assert.Error(t, MonitoringSpec{TokenSecretName: util.NewType[string]("Foo")}.Validate()) } func TestMonitoringSpecSetDefaults(t *testing.T) { @@ -51,5 +51,5 @@ func TestMonitoringSpecSetDefaults(t *testing.T) { assert.Equal(t, "", def(MonitoringSpec{}).GetTokenSecretName()) assert.Equal(t, "def2", def2(MonitoringSpec{}).GetTokenSecretName()) - assert.Equal(t, "foo", def(MonitoringSpec{TokenSecretName: util.NewString("foo")}).GetTokenSecretName()) + assert.Equal(t, "foo", def(MonitoringSpec{TokenSecretName: util.NewType[string]("foo")}).GetTokenSecretName()) } diff --git a/pkg/apis/deployment/v2alpha1/sync_spec.go b/pkg/apis/deployment/v2alpha1/sync_spec.go index a7f33c324..b9de0cfe7 100644 --- a/pkg/apis/deployment/v2alpha1/sync_spec.go +++ b/pkg/apis/deployment/v2alpha1/sync_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,12 +38,12 @@ type SyncSpec struct { // IsEnabled returns the value of enabled. func (s SyncSpec) IsEnabled() bool { - return util.BoolOrDefault(s.Enabled) + return util.TypeOrDefault[bool](s.Enabled) } // GetSyncImage returns the syncer image or empty string func (s SyncSpec) GetSyncImage() string { - return util.StringOrDefault(s.Image) + return util.TypeOrDefault[string](s.Image) } // HasSyncImage returns whether a special sync image is set @@ -84,10 +84,10 @@ func (s *SyncSpec) SetDefaults(defaultJWTSecretName, defaultClientAuthCASecretNa // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *SyncSpec) SetDefaultsFrom(source SyncSpec) { if s.Enabled == nil { - s.Enabled = util.NewBoolOrNil(source.Enabled) + s.Enabled = util.NewTypeOrNil[bool](source.Enabled) } if s.Image == nil { - s.Image = util.NewStringOrNil(source.Image) + s.Image = util.NewTypeOrNil[string](source.Image) } s.ExternalAccess.SetDefaultsFrom(source.ExternalAccess) s.Authentication.SetDefaultsFrom(source.Authentication) diff --git a/pkg/apis/deployment/v2alpha1/sync_spec_test.go b/pkg/apis/deployment/v2alpha1/sync_spec_test.go index 4534bc58d..29ee57afd 100644 --- a/pkg/apis/deployment/v2alpha1/sync_spec_test.go +++ b/pkg/apis/deployment/v2alpha1/sync_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -30,16 +30,16 @@ import ( func TestSyncSpecValidate(t *testing.T) { // Valid - auth := SyncAuthenticationSpec{JWTSecretName: util.NewString("foo"), ClientCASecretName: util.NewString("foo-client")} - tls := TLSSpec{CASecretName: util.NewString("None")} + auth := SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo"), ClientCASecretName: util.NewType[string]("foo-client")} + tls := TLSSpec{CASecretName: util.NewType[string]("None")} assert.Nil(t, SyncSpec{Authentication: auth}.Validate(DeploymentModeSingle)) assert.Nil(t, SyncSpec{Authentication: auth}.Validate(DeploymentModeActiveFailover)) assert.Nil(t, SyncSpec{Authentication: auth}.Validate(DeploymentModeCluster)) - assert.Nil(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewBool(true)}.Validate(DeploymentModeCluster)) + assert.Nil(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewType[bool](true)}.Validate(DeploymentModeCluster)) // Not valid - assert.Error(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewBool(true)}.Validate(DeploymentModeSingle)) - assert.Error(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewBool(true)}.Validate(DeploymentModeActiveFailover)) + assert.Error(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewType[bool](true)}.Validate(DeploymentModeSingle)) + assert.Error(t, SyncSpec{Authentication: auth, TLS: tls, Enabled: util.NewType[bool](true)}.Validate(DeploymentModeActiveFailover)) } func TestSyncSpecSetDefaults(t *testing.T) { @@ -49,11 +49,11 @@ func TestSyncSpecSetDefaults(t *testing.T) { } assert.False(t, def(SyncSpec{}).IsEnabled()) - assert.False(t, def(SyncSpec{Enabled: util.NewBool(false)}).IsEnabled()) - assert.True(t, def(SyncSpec{Enabled: util.NewBool(true)}).IsEnabled()) + assert.False(t, def(SyncSpec{Enabled: util.NewType[bool](false)}).IsEnabled()) + assert.True(t, def(SyncSpec{Enabled: util.NewType[bool](true)}).IsEnabled()) assert.Equal(t, "test-jwt", def(SyncSpec{}).Authentication.GetJWTSecretName()) assert.Equal(t, "test-mon", def(SyncSpec{}).Monitoring.GetTokenSecretName()) - assert.Equal(t, "foo", def(SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo")}}).Authentication.GetJWTSecretName()) + assert.Equal(t, "foo", def(SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo")}}).Authentication.GetJWTSecretName()) } func TestSyncSpecResetImmutableFields(t *testing.T) { @@ -65,33 +65,33 @@ func TestSyncSpecResetImmutableFields(t *testing.T) { }{ // Valid "changes" { - SyncSpec{Enabled: util.NewBool(false)}, - SyncSpec{Enabled: util.NewBool(true)}, - SyncSpec{Enabled: util.NewBool(true)}, + SyncSpec{Enabled: util.NewType[bool](false)}, + SyncSpec{Enabled: util.NewType[bool](true)}, + SyncSpec{Enabled: util.NewType[bool](true)}, nil, }, { - SyncSpec{Enabled: util.NewBool(true)}, - SyncSpec{Enabled: util.NewBool(false)}, - SyncSpec{Enabled: util.NewBool(false)}, + SyncSpec{Enabled: util.NewType[bool](true)}, + SyncSpec{Enabled: util.NewType[bool](false)}, + SyncSpec{Enabled: util.NewType[bool](false)}, nil, }, { - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("None"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("None"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("None"), ClientCASecretName: util.NewString("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("None"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("None"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("None"), ClientCASecretName: util.NewType[string]("some")}}, nil, }, { - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo"), ClientCASecretName: util.NewString("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo"), ClientCASecretName: util.NewType[string]("some")}}, nil, }, { - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo2"), ClientCASecretName: util.NewString("some")}}, - SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewString("foo2"), ClientCASecretName: util.NewString("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo2"), ClientCASecretName: util.NewType[string]("some")}}, + SyncSpec{Authentication: SyncAuthenticationSpec{JWTSecretName: util.NewType[string]("foo2"), ClientCASecretName: util.NewType[string]("some")}}, nil, }, } diff --git a/pkg/apis/deployment/v2alpha1/tls_spec.go b/pkg/apis/deployment/v2alpha1/tls_spec.go index 3aa687459..11c3c386c 100644 --- a/pkg/apis/deployment/v2alpha1/tls_spec.go +++ b/pkg/apis/deployment/v2alpha1/tls_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -68,7 +68,7 @@ const ( // GetCASecretName returns the value of caSecretName. func (s TLSSpec) GetCASecretName() string { - return util.StringOrDefault(s.CASecretName) + return util.TypeOrDefault[string](s.CASecretName) } // GetAltNames returns the value of altNames. @@ -132,7 +132,7 @@ func (s *TLSSpec) SetDefaults(defaultCASecretName string) { if s.GetCASecretName() == "" { // Note that we don't check for nil here, since even a specified, but empty // string should result in the default value. - s.CASecretName = util.NewString(defaultCASecretName) + s.CASecretName = util.NewType[string](defaultCASecretName) } if s.GetTTL() == "" { // Note that we don't check for nil here, since even a specified, but zero @@ -144,7 +144,7 @@ func (s *TLSSpec) SetDefaults(defaultCASecretName string) { // SetDefaultsFrom fills unspecified fields with a value from given source spec. func (s *TLSSpec) SetDefaultsFrom(source TLSSpec) { if s.CASecretName == nil { - s.CASecretName = util.NewStringOrNil(source.CASecretName) + s.CASecretName = util.NewTypeOrNil[string](source.CASecretName) } if s.AltNames == nil { s.AltNames = source.AltNames diff --git a/pkg/apis/deployment/v2alpha1/tls_spec_test.go b/pkg/apis/deployment/v2alpha1/tls_spec_test.go index ed8528874..46e67c719 100644 --- a/pkg/apis/deployment/v2alpha1/tls_spec_test.go +++ b/pkg/apis/deployment/v2alpha1/tls_spec_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -31,23 +31,23 @@ import ( func TestTLSSpecValidate(t *testing.T) { // Valid - assert.Nil(t, TLSSpec{CASecretName: util.NewString("foo")}.Validate()) - assert.Nil(t, TLSSpec{CASecretName: util.NewString("None")}.Validate()) - assert.Nil(t, TLSSpec{CASecretName: util.NewString("None"), AltNames: []string{}}.Validate()) - assert.Nil(t, TLSSpec{CASecretName: util.NewString("None"), AltNames: []string{"foo"}}.Validate()) - assert.Nil(t, TLSSpec{CASecretName: util.NewString("None"), AltNames: []string{"email@example.com", "127.0.0.1"}}.Validate()) + assert.Nil(t, TLSSpec{CASecretName: util.NewType[string]("foo")}.Validate()) + assert.Nil(t, TLSSpec{CASecretName: util.NewType[string]("None")}.Validate()) + assert.Nil(t, TLSSpec{CASecretName: util.NewType[string]("None"), AltNames: []string{}}.Validate()) + assert.Nil(t, TLSSpec{CASecretName: util.NewType[string]("None"), AltNames: []string{"foo"}}.Validate()) + assert.Nil(t, TLSSpec{CASecretName: util.NewType[string]("None"), AltNames: []string{"email@example.com", "127.0.0.1"}}.Validate()) // Not valid assert.Error(t, TLSSpec{CASecretName: nil}.Validate()) - assert.Error(t, TLSSpec{CASecretName: util.NewString("")}.Validate()) - assert.Error(t, TLSSpec{CASecretName: util.NewString("Foo")}.Validate()) - assert.Error(t, TLSSpec{CASecretName: util.NewString("foo"), AltNames: []string{"@@"}}.Validate()) + assert.Error(t, TLSSpec{CASecretName: util.NewType[string]("")}.Validate()) + assert.Error(t, TLSSpec{CASecretName: util.NewType[string]("Foo")}.Validate()) + assert.Error(t, TLSSpec{CASecretName: util.NewType[string]("foo"), AltNames: []string{"@@"}}.Validate()) } func TestTLSSpecIsSecure(t *testing.T) { - assert.True(t, TLSSpec{CASecretName: util.NewString("")}.IsSecure()) - assert.True(t, TLSSpec{CASecretName: util.NewString("foo")}.IsSecure()) - assert.False(t, TLSSpec{CASecretName: util.NewString("None")}.IsSecure()) + assert.True(t, TLSSpec{CASecretName: util.NewType[string]("")}.IsSecure()) + assert.True(t, TLSSpec{CASecretName: util.NewType[string]("foo")}.IsSecure()) + assert.False(t, TLSSpec{CASecretName: util.NewType[string]("None")}.IsSecure()) } func TestTLSSpecSetDefaults(t *testing.T) { @@ -57,7 +57,7 @@ func TestTLSSpecSetDefaults(t *testing.T) { } assert.Equal(t, "", def(TLSSpec{}).GetCASecretName()) - assert.Equal(t, "foo", def(TLSSpec{CASecretName: util.NewString("foo")}).GetCASecretName()) + assert.Equal(t, "foo", def(TLSSpec{CASecretName: util.NewType[string]("foo")}).GetCASecretName()) assert.Len(t, def(TLSSpec{}).GetAltNames(), 0) assert.Len(t, def(TLSSpec{AltNames: []string{"foo.local"}}).GetAltNames(), 1) assert.Equal(t, defaultTLSTTL, def(TLSSpec{}).GetTTL()) diff --git a/pkg/apis/replication/v1/endpoint_authentication_spec.go b/pkg/apis/replication/v1/endpoint_authentication_spec.go index 096b82215..85bbbd4c7 100644 --- a/pkg/apis/replication/v1/endpoint_authentication_spec.go +++ b/pkg/apis/replication/v1/endpoint_authentication_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -41,12 +41,12 @@ type EndpointAuthenticationSpec struct { // GetKeyfileSecretName returns the value of keyfileSecretName. func (s EndpointAuthenticationSpec) GetKeyfileSecretName() string { - return util.StringOrDefault(s.KeyfileSecretName) + return util.TypeOrDefault[string](s.KeyfileSecretName) } // GetUserSecretName returns the value of userSecretName. func (s EndpointAuthenticationSpec) GetUserSecretName() string { - return util.StringOrDefault(s.UserSecretName) + return util.TypeOrDefault[string](s.UserSecretName) } // Validate the given spec, returning an error on validation @@ -71,10 +71,10 @@ func (s *EndpointAuthenticationSpec) SetDefaults() { // SetDefaultsFrom fills empty field with default values from the given source. func (s *EndpointAuthenticationSpec) SetDefaultsFrom(source EndpointAuthenticationSpec) { if s.KeyfileSecretName == nil { - s.KeyfileSecretName = util.NewStringOrNil(source.KeyfileSecretName) + s.KeyfileSecretName = util.NewTypeOrNil[string](source.KeyfileSecretName) } if s.UserSecretName == nil { - s.UserSecretName = util.NewStringOrNil(source.UserSecretName) + s.UserSecretName = util.NewTypeOrNil[string](source.UserSecretName) } } diff --git a/pkg/apis/replication/v1/endpoint_spec.go b/pkg/apis/replication/v1/endpoint_spec.go index ab10f45db..701b1a6ff 100644 --- a/pkg/apis/replication/v1/endpoint_spec.go +++ b/pkg/apis/replication/v1/endpoint_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ type EndpointSpec struct { // GetDeploymentName returns the value of deploymentName. func (s EndpointSpec) GetDeploymentName() string { - return util.StringOrDefault(s.DeploymentName) + return util.TypeOrDefault[string](s.DeploymentName) } // HasDeploymentName returns the true when a non-empty deployment name it set. @@ -85,7 +85,7 @@ func (s *EndpointSpec) SetDefaults() { // SetDefaultsFrom fills empty field with default values from the given source. func (s *EndpointSpec) SetDefaultsFrom(source EndpointSpec) { if s.DeploymentName == nil { - s.DeploymentName = util.NewStringOrNil(source.DeploymentName) + s.DeploymentName = util.NewTypeOrNil[string](source.DeploymentName) } s.Authentication.SetDefaultsFrom(source.Authentication) s.TLS.SetDefaultsFrom(source.TLS) diff --git a/pkg/apis/replication/v1/endpoint_tls_spec.go b/pkg/apis/replication/v1/endpoint_tls_spec.go index 7ed98518a..6b75f31c0 100644 --- a/pkg/apis/replication/v1/endpoint_tls_spec.go +++ b/pkg/apis/replication/v1/endpoint_tls_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ type EndpointTLSSpec struct { // GetCASecretName returns the value of caSecretName. func (s EndpointTLSSpec) GetCASecretName() string { - return util.StringOrDefault(s.CASecretName) + return util.TypeOrDefault[string](s.CASecretName) } // Validate the given spec, returning an error on validation @@ -57,7 +57,7 @@ func (s *EndpointTLSSpec) SetDefaults() { // SetDefaultsFrom fills empty field with default values from the given source. func (s *EndpointTLSSpec) SetDefaultsFrom(source EndpointTLSSpec) { if s.CASecretName == nil { - s.CASecretName = util.NewStringOrNil(source.CASecretName) + s.CASecretName = util.NewTypeOrNil[string](source.CASecretName) } } diff --git a/pkg/apis/replication/v2alpha1/endpoint_authentication_spec.go b/pkg/apis/replication/v2alpha1/endpoint_authentication_spec.go index c8a76563d..1146ee7c0 100644 --- a/pkg/apis/replication/v2alpha1/endpoint_authentication_spec.go +++ b/pkg/apis/replication/v2alpha1/endpoint_authentication_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -41,12 +41,12 @@ type EndpointAuthenticationSpec struct { // GetKeyfileSecretName returns the value of keyfileSecretName. func (s EndpointAuthenticationSpec) GetKeyfileSecretName() string { - return util.StringOrDefault(s.KeyfileSecretName) + return util.TypeOrDefault[string](s.KeyfileSecretName) } // GetUserSecretName returns the value of userSecretName. func (s EndpointAuthenticationSpec) GetUserSecretName() string { - return util.StringOrDefault(s.UserSecretName) + return util.TypeOrDefault[string](s.UserSecretName) } // Validate the given spec, returning an error on validation @@ -71,10 +71,10 @@ func (s *EndpointAuthenticationSpec) SetDefaults() { // SetDefaultsFrom fills empty field with default values from the given source. func (s *EndpointAuthenticationSpec) SetDefaultsFrom(source EndpointAuthenticationSpec) { if s.KeyfileSecretName == nil { - s.KeyfileSecretName = util.NewStringOrNil(source.KeyfileSecretName) + s.KeyfileSecretName = util.NewTypeOrNil[string](source.KeyfileSecretName) } if s.UserSecretName == nil { - s.UserSecretName = util.NewStringOrNil(source.UserSecretName) + s.UserSecretName = util.NewTypeOrNil[string](source.UserSecretName) } } diff --git a/pkg/apis/replication/v2alpha1/endpoint_spec.go b/pkg/apis/replication/v2alpha1/endpoint_spec.go index 95c049054..1f2bfb554 100644 --- a/pkg/apis/replication/v2alpha1/endpoint_spec.go +++ b/pkg/apis/replication/v2alpha1/endpoint_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ type EndpointSpec struct { // GetDeploymentName returns the value of deploymentName. func (s EndpointSpec) GetDeploymentName() string { - return util.StringOrDefault(s.DeploymentName) + return util.TypeOrDefault[string](s.DeploymentName) } // HasDeploymentName returns the true when a non-empty deployment name it set. @@ -85,7 +85,7 @@ func (s *EndpointSpec) SetDefaults() { // SetDefaultsFrom fills empty field with default values from the given source. func (s *EndpointSpec) SetDefaultsFrom(source EndpointSpec) { if s.DeploymentName == nil { - s.DeploymentName = util.NewStringOrNil(source.DeploymentName) + s.DeploymentName = util.NewTypeOrNil[string](source.DeploymentName) } s.Authentication.SetDefaultsFrom(source.Authentication) s.TLS.SetDefaultsFrom(source.TLS) diff --git a/pkg/apis/replication/v2alpha1/endpoint_tls_spec.go b/pkg/apis/replication/v2alpha1/endpoint_tls_spec.go index f22a327b7..af20a16e9 100644 --- a/pkg/apis/replication/v2alpha1/endpoint_tls_spec.go +++ b/pkg/apis/replication/v2alpha1/endpoint_tls_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ type EndpointTLSSpec struct { // GetCASecretName returns the value of caSecretName. func (s EndpointTLSSpec) GetCASecretName() string { - return util.StringOrDefault(s.CASecretName) + return util.TypeOrDefault[string](s.CASecretName) } // Validate the given spec, returning an error on validation @@ -57,7 +57,7 @@ func (s *EndpointTLSSpec) SetDefaults() { // SetDefaultsFrom fills empty field with default values from the given source. func (s *EndpointTLSSpec) SetDefaultsFrom(source EndpointTLSSpec) { if s.CASecretName == nil { - s.CASecretName = util.NewStringOrNil(source.CASecretName) + s.CASecretName = util.NewTypeOrNil[string](source.CASecretName) } } diff --git a/pkg/deployment/agency/generator_database_test.go b/pkg/deployment/agency/generator_database_test.go index 46752d498..36a165bf0 100644 --- a/pkg/deployment/agency/generator_database_test.go +++ b/pkg/deployment/agency/generator_database_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -95,7 +95,7 @@ func (d databaseGenerator) Add() StateGenerator { } planCol := StatePlanCollection{ - Name: util.NewString(col), + Name: util.NewType[string](col), Shards: planShards, WriteConcern: colDet.wc, ReplicationFactor: colDet.rf, diff --git a/pkg/deployment/cleanup.go b/pkg/deployment/cleanup.go index f035cdd1c..f0e359bd2 100644 --- a/pkg/deployment/cleanup.go +++ b/pkg/deployment/cleanup.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ func (d *Deployment) removePodFinalizers(ctx context.Context, cachedStatus inspe defer cancel() if err := d.PodsModInterface().Delete(ctxChild, pod.GetName(), meta.DeleteOptions{ - GracePeriodSeconds: util.NewInt64(0), + GracePeriodSeconds: util.NewType[int64](0), }); err != nil { if !kerrors.IsNotFound(err) { log.Err(err).Warn("Failed to remove pod") diff --git a/pkg/deployment/deployment_affinity_test.go b/pkg/deployment/deployment_affinity_test.go index b4b74d9d8..d30d29d6d 100644 --- a/pkg/deployment/deployment_affinity_test.go +++ b/pkg/deployment/deployment_affinity_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ func TestEnsurePod_ArangoDB_AntiAffinity(t *testing.T) { Name: "DBserver POD with antiAffinity required", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -118,7 +118,7 @@ func TestEnsurePod_ArangoDB_AntiAffinity(t *testing.T) { Name: "DBserver POD with antiAffinity prefered", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -180,7 +180,7 @@ func TestEnsurePod_ArangoDB_AntiAffinity(t *testing.T) { Name: "DBserver POD with antiAffinity both", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -246,7 +246,7 @@ func TestEnsurePod_ArangoDB_AntiAffinity(t *testing.T) { Name: "DBserver POD with antiAffinity mixed", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -332,7 +332,7 @@ func TestEnsurePod_ArangoDB_Affinity(t *testing.T) { Name: "DBserver POD with affinity required", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -397,7 +397,7 @@ func TestEnsurePod_ArangoDB_Affinity(t *testing.T) { Name: "DBserver POD with affinity prefered", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -462,7 +462,7 @@ func TestEnsurePod_ArangoDB_Affinity(t *testing.T) { Name: "DBserver POD with affinity both", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -531,7 +531,7 @@ func TestEnsurePod_ArangoDB_Affinity(t *testing.T) { Name: "DBserver POD with affinity mixed", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -611,7 +611,7 @@ func TestEnsurePod_ArangoDB_NodeAffinity(t *testing.T) { Name: "DBserver POD with nodeAffinity required", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ diff --git a/pkg/deployment/deployment_core_test.go b/pkg/deployment/deployment_core_test.go index 09a264e0d..75fb2913e 100644 --- a/pkg/deployment/deployment_core_test.go +++ b/pkg/deployment/deployment_core_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -41,10 +41,10 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Agent Pod with image pull policy", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, - ImagePullPolicy: util.NewPullPolicy(core.PullAlways), + ImagePullPolicy: util.NewType[core.PullPolicy](core.PullAlways), }, }, Helper: func(t *testing.T, deployment *Deployment, testCase *testCaseStruct) { @@ -92,10 +92,10 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Agent Pod with image pull policy", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, - ImagePullPolicy: util.NewPullPolicy(core.PullAlways), + ImagePullPolicy: util.NewType[core.PullPolicy](core.PullAlways), }, }, Helper: func(t *testing.T, deployment *Deployment, testCase *testCaseStruct) { @@ -143,7 +143,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Agent Pod with sidecar", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, Agents: api.ServerGroupSpec{ @@ -209,7 +209,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Agent Pod with image pull secrets", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, ImagePullSecrets: []string{"docker-registry", "other-registry"}, @@ -268,7 +268,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Agent Pod with alpine init container", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -325,7 +325,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "DBserver POD with resource requirements", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -382,7 +382,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "DBserver POD with resource requirements and memory override", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -439,7 +439,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "DBserver POD with resource requirements and persistent volume claim", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -499,7 +499,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Initialized DBserver POD with alpine init container", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -558,7 +558,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Agent Pod without TLS, authentication, persistent volume claim, metrics, rocksDB encryption, license", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -609,7 +609,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Agent Pod with persistent volume claim", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -666,7 +666,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Agent Pod with TLS", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: tlsSpec, }, @@ -719,7 +719,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Agent Pod with authentication and unsecured liveness", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, TLS: noTLS, Environment: api.NewEnvironment(api.EnvironmentProduction), @@ -777,10 +777,10 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Agent Pod with TLS and authentication and secured liveness probe", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, TLS: api.TLSSpec{ - CASecretName: util.NewString(testCASecretName), + CASecretName: util.NewType[string](testCASecretName), }, }, }, @@ -838,7 +838,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Agent Pod with encrypted rocksdb", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, RocksDB: rocksDBSpec, @@ -895,7 +895,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "DBserver Pod with internal metrics exporter", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, TLS: noTLS, Metrics: metricsSpec, @@ -956,14 +956,14 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "DBserver Pod with metrics exporter which contains resource requirements", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, TLS: noTLS, Metrics: api.MetricsSpec{ - Enabled: util.NewBool(true), - Image: util.NewString(testImage), + Enabled: util.NewType[bool](true), + Image: util.NewType[string](testImage), Authentication: api.MetricsAuthenticationSpec{ - JWTTokenSecretName: util.NewString(testExporterToken), + JWTTokenSecretName: util.NewType[string](testExporterToken), }, Resources: resourcesUnfiltered, }, @@ -1024,7 +1024,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "DBserver Pod with lifecycle init container which contains resource requirements", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, TLS: noTLS, Metrics: metricsSpec, @@ -1097,7 +1097,7 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "DBserver Pod with metrics exporter and lifecycle init container and alpine init container", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, TLS: noTLS, Metrics: metricsSpec, @@ -1167,11 +1167,11 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Coordinator Pod with TLS and authentication and readiness and liveness", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, Environment: api.NewEnvironment(api.EnvironmentProduction), TLS: api.TLSSpec{ - CASecretName: util.NewString(testCASecretName), + CASecretName: util.NewType[string](testCASecretName), }, }, }, @@ -1229,10 +1229,10 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Single Pod with TLS and authentication and readiness and readiness", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, TLS: api.TLSSpec{ - CASecretName: util.NewString(testCASecretName), + CASecretName: util.NewType[string](testCASecretName), }, }, }, @@ -1294,13 +1294,13 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { Name: "Single Pod with TLS and authentication and readiness and port override", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, TLS: api.TLSSpec{ - CASecretName: util.NewString(testCASecretName), + CASecretName: util.NewType[string](testCASecretName), }, Single: api.ServerGroupSpec{ - Port: util.NewUInt16(18529), + Port: util.NewType[uint16](18529), }, }, }, @@ -1365,14 +1365,14 @@ func TestEnsurePod_ArangoDB_Core(t *testing.T) { }, ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, Environment: api.NewEnvironment(api.EnvironmentProduction), TLS: api.TLSSpec{ - CASecretName: util.NewString(testCASecretName), + CASecretName: util.NewType[string](testCASecretName), }, Coordinators: api.ServerGroupSpec{ - Port: util.NewUInt16(18529), + Port: util.NewType[uint16](18529), }, }, }, diff --git a/pkg/deployment/deployment_definitions_test.go b/pkg/deployment/deployment_definitions_test.go index d9635521a..0eccc388d 100644 --- a/pkg/deployment/deployment_definitions_test.go +++ b/pkg/deployment/deployment_definitions_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -81,31 +81,31 @@ var ( } noAuthentication = api.AuthenticationSpec{ - JWTSecretName: util.NewString(api.JWTSecretNameDisabled), + JWTSecretName: util.NewType[string](api.JWTSecretNameDisabled), } noTLS = api.TLSSpec{ - CASecretName: util.NewString(api.CASecretNameDisabled), + CASecretName: util.NewType[string](api.CASecretNameDisabled), } authenticationSpec = api.AuthenticationSpec{ - JWTSecretName: util.NewString(testJWTSecretName), + JWTSecretName: util.NewType[string](testJWTSecretName), } tlsSpec = api.TLSSpec{ - CASecretName: util.NewString(testCASecretName), + CASecretName: util.NewType[string](testCASecretName), } rocksDBSpec = api.RocksDBSpec{ Encryption: api.RocksDBEncryptionSpec{ - KeySecretName: util.NewString(testRocksDBEncryptionKey), + KeySecretName: util.NewType[string](testRocksDBEncryptionKey), }, } metricsSpec = api.MetricsSpec{ - Enabled: util.NewBool(true), - Image: util.NewString(testImage), + Enabled: util.NewType[bool](true), + Image: util.NewType[string](testImage), Authentication: api.MetricsAuthenticationSpec{ - JWTTokenSecretName: util.NewString(testExporterToken), + JWTTokenSecretName: util.NewType[string](testExporterToken), }, } diff --git a/pkg/deployment/deployment_encryption_test.go b/pkg/deployment/deployment_encryption_test.go index 3c9439e20..135f4ff72 100644 --- a/pkg/deployment/deployment_encryption_test.go +++ b/pkg/deployment/deployment_encryption_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ func TestEnsurePod_ArangoDB_Encryption(t *testing.T) { Name: "Agent CE 3.7.0 Pod with encrypted rocksdb", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, RocksDB: rocksDBSpec, @@ -99,14 +99,14 @@ func TestEnsurePod_ArangoDB_Encryption(t *testing.T) { Name: "DBserver CE 3.7.0 Pod with metrics exporter, lifecycle, tls, authentication, license, rocksDB encryption, secured liveness", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, TLS: tlsSpec, Metrics: metricsSpec, RocksDB: rocksDBSpec, Environment: api.NewEnvironment(api.EnvironmentProduction), License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -186,7 +186,7 @@ func TestEnsurePod_ArangoDB_Encryption(t *testing.T) { Name: "Agent EE 3.7.0 Pod with encrypted rocksdb, disabled feature", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, RocksDB: rocksDBSpec, @@ -246,7 +246,7 @@ func TestEnsurePod_ArangoDB_Encryption(t *testing.T) { Name: "Agent EE 3.7.0 Pod with encrypted rocksdb, enabled feature", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, RocksDB: rocksDBSpec, diff --git a/pkg/deployment/deployment_features_test.go b/pkg/deployment/deployment_features_test.go index a816966d0..21b8fc815 100644 --- a/pkg/deployment/deployment_features_test.go +++ b/pkg/deployment/deployment_features_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { Name: "DBserver POD with disabled foxx services", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -96,7 +96,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { Name: "DBserver POD with enabled foxx services", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -113,7 +113,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { deployment.currentObjectStatus.Members.DBServers[0].IsInitialized = true deployment.currentObject.Spec.Features = &api.DeploymentFeatures{ - FoxxQueues: util.NewBool(false), + FoxxQueues: util.NewType[bool](false), } testCase.createTestPodData(deployment, api.ServerGroupDBServers, firstDBServerStatus) @@ -159,7 +159,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { Name: "Coordinator POD with undefined foxx services", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -218,7 +218,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { Name: "Coordinator POD with disabled foxx services", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -235,7 +235,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { deployment.currentObjectStatus.Members.Coordinators[0].IsInitialized = true deployment.currentObject.Spec.Features = &api.DeploymentFeatures{ - FoxxQueues: util.NewBool(false), + FoxxQueues: util.NewType[bool](false), } testCase.createTestPodData(deployment, api.ServerGroupCoordinators, firstCoordinatorStatus) @@ -281,7 +281,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { Name: "Coordinator POD with enabled foxx services", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -298,7 +298,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { deployment.currentObjectStatus.Members.Coordinators[0].IsInitialized = true deployment.currentObject.Spec.Features = &api.DeploymentFeatures{ - FoxxQueues: util.NewBool(true), + FoxxQueues: util.NewType[bool](true), } testCase.createTestPodData(deployment, api.ServerGroupCoordinators, firstCoordinatorStatus) @@ -344,7 +344,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { Name: "Single POD with undefined foxx services", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -405,7 +405,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { Name: "Single POD with disabled foxx services", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -422,7 +422,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { deployment.currentObjectStatus.Members.Single[0].IsInitialized = true deployment.currentObject.Spec.Features = &api.DeploymentFeatures{ - FoxxQueues: util.NewBool(false), + FoxxQueues: util.NewType[bool](false), } testCase.createTestPodData(deployment, api.ServerGroupSingle, singleStatus) @@ -470,7 +470,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { Name: "Single POD with enabled foxx services", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -487,7 +487,7 @@ func TestEnsurePod_ArangoDB_Features(t *testing.T) { deployment.currentObjectStatus.Members.Single[0].IsInitialized = true deployment.currentObject.Spec.Features = &api.DeploymentFeatures{ - FoxxQueues: util.NewBool(true), + FoxxQueues: util.NewType[bool](true), } testCase.createTestPodData(deployment, api.ServerGroupSingle, singleStatus) diff --git a/pkg/deployment/deployment_image_test.go b/pkg/deployment/deployment_image_test.go index 1e69f2231..d14f4053f 100644 --- a/pkg/deployment/deployment_image_test.go +++ b/pkg/deployment/deployment_image_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -56,10 +56,10 @@ func TestEnsurePod_ArangoDB_ImagePropagation(t *testing.T) { Name: "Agent Pod with defined image", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(image), + Image: util.NewType[string](image), Authentication: noAuthentication, TLS: noTLS, - ImagePullPolicy: util.NewPullPolicy(core.PullAlways), + ImagePullPolicy: util.NewType[core.PullPolicy](core.PullAlways), }, }, Helper: func(t *testing.T, deployment *Deployment, testCase *testCaseStruct) { @@ -107,11 +107,11 @@ func TestEnsurePod_ArangoDB_ImagePropagation(t *testing.T) { Name: "Agent Pod with defined image and defined kubelet mode", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(image), + Image: util.NewType[string](image), ImageDiscoveryMode: api.NewDeploymentImageDiscoveryModeSpec(api.DeploymentImageDiscoveryKubeletMode), Authentication: noAuthentication, TLS: noTLS, - ImagePullPolicy: util.NewPullPolicy(core.PullAlways), + ImagePullPolicy: util.NewType[core.PullPolicy](core.PullAlways), }, }, Helper: func(t *testing.T, deployment *Deployment, testCase *testCaseStruct) { @@ -159,11 +159,11 @@ func TestEnsurePod_ArangoDB_ImagePropagation(t *testing.T) { Name: "Agent Pod with defined image and defined direct mode", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(image), + Image: util.NewType[string](image), ImageDiscoveryMode: api.NewDeploymentImageDiscoveryModeSpec(api.DeploymentImageDiscoveryDirectMode), Authentication: noAuthentication, TLS: noTLS, - ImagePullPolicy: util.NewPullPolicy(core.PullAlways), + ImagePullPolicy: util.NewType[core.PullPolicy](core.PullAlways), }, }, Helper: func(t *testing.T, deployment *Deployment, testCase *testCaseStruct) { diff --git a/pkg/deployment/deployment_metrics_test.go b/pkg/deployment/deployment_metrics_test.go index 9aa38b5e7..b5147487b 100644 --- a/pkg/deployment/deployment_metrics_test.go +++ b/pkg/deployment/deployment_metrics_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -37,13 +37,13 @@ func TestEnsurePod_Metrics(t *testing.T) { Name: "DBserver Pod with metrics exporter and port override", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, Metrics: func() api.MetricsSpec { m := metricsSpec.DeepCopy() - m.Port = util.NewUInt16(9999) + m.Port = util.NewType[uint16](9999) return *m }(), @@ -97,7 +97,7 @@ func TestEnsurePod_Metrics(t *testing.T) { Name: "DBserver Pod with metrics exporter with mode", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, Metrics: func() api.MetricsSpec { @@ -157,7 +157,7 @@ func TestEnsurePod_Metrics(t *testing.T) { Name: "DBserver Pod with metrics exporter with internal mode", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, Metrics: func() api.MetricsSpec { @@ -225,7 +225,7 @@ func TestEnsurePod_Metrics(t *testing.T) { Name: "Agent Pod with metrics exporter with internal mode", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, Metrics: func() api.MetricsSpec { diff --git a/pkg/deployment/deployment_pod_probe_test.go b/pkg/deployment/deployment_pod_probe_test.go index e4e8bb814..38c0e2726 100644 --- a/pkg/deployment/deployment_pod_probe_test.go +++ b/pkg/deployment/deployment_pod_probe_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "Agent Pod default probes", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -95,13 +95,13 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "Agent Pod customized probes", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, Agents: api.ServerGroupSpec{ Probes: &api.ServerGroupProbesSpec{ LivenessProbeSpec: &api.ServerGroupProbeSpec{ - TimeoutSeconds: util.NewInt32(50), + TimeoutSeconds: util.NewType[int32](50), }, }, }, @@ -154,13 +154,13 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "Agent Pod enabled probes", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, Agents: api.ServerGroupSpec{ Probes: &api.ServerGroupProbesSpec{ - LivenessProbeDisabled: util.NewBool(false), - ReadinessProbeDisabled: util.NewBool(false), + LivenessProbeDisabled: util.NewType[bool](false), + ReadinessProbeDisabled: util.NewType[bool](false), }, }, }, @@ -211,7 +211,7 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "DBServer Pod default probes", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -261,13 +261,13 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "DBServer Pod enabled probes", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ Probes: &api.ServerGroupProbesSpec{ - LivenessProbeDisabled: util.NewBool(false), - ReadinessProbeDisabled: util.NewBool(false), + LivenessProbeDisabled: util.NewType[bool](false), + ReadinessProbeDisabled: util.NewType[bool](false), }, }, }, @@ -318,7 +318,7 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "Coordinator Pod default probes", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, }, @@ -368,13 +368,13 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "Coordinator Pod enabled probes", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, Coordinators: api.ServerGroupSpec{ Probes: &api.ServerGroupProbesSpec{ - LivenessProbeDisabled: util.NewBool(false), - ReadinessProbeDisabled: util.NewBool(false), + LivenessProbeDisabled: util.NewType[bool](false), + ReadinessProbeDisabled: util.NewType[bool](false), }, }, }, @@ -425,7 +425,7 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "DBServer with early connections", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(createTestImageForVersion("3.10.0")), + Image: util.NewType[string](createTestImageForVersion("3.10.0")), Authentication: noAuthentication, TLS: noTLS, }, @@ -482,7 +482,7 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "DBServer without early connections because version is lower than 3.10.0", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(createTestImageForVersion("3.9.2")), + Image: util.NewType[string](createTestImageForVersion("3.9.2")), Authentication: noAuthentication, TLS: noTLS, }, @@ -536,7 +536,7 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "DBServer without early connections because 3.10 feature is disabled", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(createTestImageForVersion("3.10.0")), + Image: util.NewType[string](createTestImageForVersion("3.10.0")), Authentication: noAuthentication, TLS: noTLS, }, @@ -590,7 +590,7 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "Coordinator should be without early connections", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(createTestImageForVersion("3.10.0")), + Image: util.NewType[string](createTestImageForVersion("3.10.0")), Authentication: noAuthentication, TLS: noTLS, }, @@ -644,7 +644,7 @@ func TestEnsurePod_ArangoDB_Probe(t *testing.T) { Name: "Agent should be without early connections", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(createTestImageForVersion("3.10.0")), + Image: util.NewType[string](createTestImageForVersion("3.10.0")), Authentication: noAuthentication, TLS: noTLS, }, diff --git a/pkg/deployment/deployment_pod_resources_test.go b/pkg/deployment/deployment_pod_resources_test.go index 73e7ecb74..7a6aa66f3 100644 --- a/pkg/deployment/deployment_pod_resources_test.go +++ b/pkg/deployment/deployment_pod_resources_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -98,7 +98,7 @@ func TestEnsurePod_ArangoDB_Resources(t *testing.T) { Name: "DBserver POD with resource requirements", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -155,12 +155,12 @@ func TestEnsurePod_ArangoDB_Resources(t *testing.T) { Name: "DBserver POD with resource requirements, with override flag", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ Resources: resourcesUnfiltered, - OverrideDetectedTotalMemory: util.NewBool(false), + OverrideDetectedTotalMemory: util.NewType[bool](false), }, }, }, @@ -213,11 +213,11 @@ func TestEnsurePod_ArangoDB_Resources(t *testing.T) { Name: "DBserver POD without resource requirements, with override flag", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ - OverrideDetectedTotalMemory: util.NewBool(true), + OverrideDetectedTotalMemory: util.NewType[bool](true), }, }, }, diff --git a/pkg/deployment/deployment_pod_sync_test.go b/pkg/deployment/deployment_pod_sync_test.go index e56b916f0..8621b922b 100644 --- a/pkg/deployment/deployment_pod_sync_test.go +++ b/pkg/deployment/deployment_pod_sync_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -42,7 +42,7 @@ func TestEnsurePod_Sync_Error(t *testing.T) { Name: "Sync Pod does not work for enterprise image", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), }, }, Helper: func(t *testing.T, deployment *Deployment, testCase *testCaseStruct) { @@ -61,7 +61,7 @@ func TestEnsurePod_Sync_Error(t *testing.T) { Name: "Sync Pod cannot get master JWT secret", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), }, }, Helper: func(t *testing.T, deployment *Deployment, testCase *testCaseStruct) { @@ -81,9 +81,9 @@ func TestEnsurePod_Sync_Error(t *testing.T) { Name: "Sync Pod cannot get monitoring token secret", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), }, }, }, @@ -115,9 +115,9 @@ func TestEnsurePod_Sync_Master(t *testing.T) { Name: "Sync Master Pod cannot create TLS keyfile secret", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), }, }, }, @@ -142,10 +142,10 @@ func TestEnsurePod_Sync_Master(t *testing.T) { Name: "Sync Master Pod cannot get cluster JWT secret", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), }, }, }, @@ -170,10 +170,10 @@ func TestEnsurePod_Sync_Master(t *testing.T) { Name: "Sync Master Pod cannot get authentication CA certificate", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), }, }, }, @@ -200,13 +200,13 @@ func TestEnsurePod_Sync_Master(t *testing.T) { "liveness probe, priority class name, resource requirements", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: authenticationSpec, Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), }, SyncMasters: api.ServerGroupSpec{ - ServiceAccountName: util.NewString(testServiceAccountName), + ServiceAccountName: util.NewType[string](testServiceAccountName), NodeSelector: nodeSelectorTest, PriorityClassName: testPriorityClassName, Resources: resourcesUnfiltered, @@ -292,14 +292,14 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, Environment: api.NewEnvironment(api.EnvironmentProduction), Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), }, License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -380,11 +380,11 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, Environment: api.NewEnvironment(api.EnvironmentProduction), Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), ExternalAccess: api.SyncExternalAccessSpec{ MasterEndpoint: []string{ "https://arangodb.xyz:8629", @@ -392,7 +392,7 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, }, License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -492,11 +492,11 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, Environment: api.NewEnvironment(api.EnvironmentProduction), Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), ExternalAccess: api.SyncExternalAccessSpec{ MasterEndpoint: []string{ "https://arangodb.xyz:8629", @@ -504,7 +504,7 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, }, License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -585,11 +585,11 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, Environment: api.NewEnvironment(api.EnvironmentProduction), Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), ExternalAccess: api.SyncExternalAccessSpec{ MasterEndpoint: []string{ "https://arangodb.xyz:8629", @@ -597,7 +597,7 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, }, License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -686,11 +686,11 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, Environment: api.NewEnvironment(api.EnvironmentProduction), Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), ExternalAccess: api.SyncExternalAccessSpec{ MasterEndpoint: []string{ "https://127.0.0.1:8629", @@ -698,7 +698,7 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, }, License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -790,14 +790,14 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, Environment: api.NewEnvironment(api.EnvironmentProduction), Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), }, License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -889,11 +889,11 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, Environment: api.NewEnvironment(api.EnvironmentProduction), Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), ExternalAccess: api.SyncExternalAccessSpec{ MasterEndpoint: []string{ "https://arangodb.xyz:8629", @@ -903,7 +903,7 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, }, License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -1005,11 +1005,11 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, Environment: api.NewEnvironment(api.EnvironmentProduction), Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), ExternalAccess: api.SyncExternalAccessSpec{ MasterEndpoint: []string{ "https://arangodb.xyz:8629", @@ -1019,7 +1019,7 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, }, License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -1119,11 +1119,11 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, Environment: api.NewEnvironment(api.EnvironmentProduction), Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), ExternalAccess: api.SyncExternalAccessSpec{ MasterEndpoint: []string{ "https://arangodb2.xyz:8629", @@ -1133,7 +1133,7 @@ func TestEnsurePod_Sync_Master(t *testing.T) { }, }, License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -1242,19 +1242,19 @@ func TestEnsurePod_Sync_Worker(t *testing.T) { }, ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, Sync: api.SyncSpec{ - Enabled: util.NewBool(true), + Enabled: util.NewType[bool](true), }, SyncWorkers: api.ServerGroupSpec{ - ServiceAccountName: util.NewString(testServiceAccountName), + ServiceAccountName: util.NewType[string](testServiceAccountName), NodeSelector: nodeSelectorTest, PriorityClassName: testPriorityClassName, Resources: resourcesUnfiltered, }, License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, diff --git a/pkg/deployment/deployment_pod_tls_sni_test.go b/pkg/deployment/deployment_pod_tls_sni_test.go index e24be7b11..3db61f969 100644 --- a/pkg/deployment/deployment_pod_tls_sni_test.go +++ b/pkg/deployment/deployment_pod_tls_sni_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -58,7 +58,7 @@ func TestEnsurePod_ArangoDB_TLS_SNI(t *testing.T) { Name: "Pod SNI Mounts", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: func() api.TLSSpec { s := tlsSpec.DeepCopy() @@ -134,7 +134,7 @@ func TestEnsurePod_ArangoDB_TLS_SNI(t *testing.T) { Name: "Pod SNI Mounts - Enterprise - 3.6.0", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(createTestImageForVersion("3.6.0")), + Image: util.NewType[string](createTestImageForVersion("3.6.0")), Authentication: noAuthentication, TLS: func() api.TLSSpec { s := tlsSpec.DeepCopy() @@ -209,7 +209,7 @@ func TestEnsurePod_ArangoDB_TLS_SNI(t *testing.T) { Name: "Pod SNI Mounts - 3.7.0", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: func() api.TLSSpec { s := tlsSpec.DeepCopy() @@ -284,7 +284,7 @@ func TestEnsurePod_ArangoDB_TLS_SNI(t *testing.T) { Name: "Pod SNI Mounts - Enterprise- 3.7.0", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: func() api.TLSSpec { s := tlsSpec.DeepCopy() @@ -392,7 +392,7 @@ func TestEnsurePod_ArangoDB_TLS_SNI(t *testing.T) { Name: "Pod SNI Mounts - Enterprise - 3.7.0 - DBServer", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: func() api.TLSSpec { s := tlsSpec.DeepCopy() diff --git a/pkg/deployment/deployment_pod_volumes_test.go b/pkg/deployment/deployment_pod_volumes_test.go index fd921ce6e..ead50b374 100644 --- a/pkg/deployment/deployment_pod_volumes_test.go +++ b/pkg/deployment/deployment_pod_volumes_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ func TestEnsurePod_ArangoDB_Volumes(t *testing.T) { Name: "DBserver POD with Volume", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -115,7 +115,7 @@ func TestEnsurePod_ArangoDB_Volumes(t *testing.T) { Name: "DBserver POD with Volumes", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ @@ -176,7 +176,7 @@ func TestEnsurePod_ArangoDB_Volumes(t *testing.T) { Name: "DBserver POD with Volume Mount", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), Authentication: noAuthentication, TLS: noTLS, DBServers: api.ServerGroupSpec{ diff --git a/pkg/deployment/deployment_run_test.go b/pkg/deployment/deployment_run_test.go index e5cbf8088..36e3464da 100644 --- a/pkg/deployment/deployment_run_test.go +++ b/pkg/deployment/deployment_run_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -223,7 +223,7 @@ func runTestCase(t *testing.T, testCase testCaseStruct) { pods, err := d.deps.Client.Kubernetes().CoreV1().Pods(testNamespace).List(context.Background(), meta.ListOptions{}) require.NoError(t, err) require.Len(t, pods.Items, 1) - if util.BoolOrDefault(testCase.CompareChecksum, true) { + if util.TypeOrDefault[bool](testCase.CompareChecksum, true) { compareSpec(t, testCase.ExpectedPod.Spec, pods.Items[0].Spec) } require.Equal(t, testCase.ExpectedPod.Spec, pods.Items[0].Spec) diff --git a/pkg/deployment/deployment_suite_test.go b/pkg/deployment/deployment_suite_test.go index c55efaf51..498677dd6 100644 --- a/pkg/deployment/deployment_suite_test.go +++ b/pkg/deployment/deployment_suite_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -923,7 +923,7 @@ func (testCase *testCaseStruct) createTestEnvVariables(deployment *Deployment, g LocalObjectReference: core.LocalObjectReference{ Name: features.ConfigMapName(), }, - Optional: util.NewBool(true), + Optional: util.NewType[bool](true), }, }, } diff --git a/pkg/deployment/features/metrics.go b/pkg/deployment/features/metrics.go index 032168142..1bc30bd6e 100644 --- a/pkg/deployment/features/metrics.go +++ b/pkg/deployment/features/metrics.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ var metricsExporter = &feature{ enterpriseRequired: false, enabledByDefault: true, deprecated: "It is always set to True", - constValue: util.NewBool(true), + constValue: util.NewType[bool](true), hidden: true, } diff --git a/pkg/deployment/images.go b/pkg/deployment/images.go index 0f42d7e2b..791db6833 100644 --- a/pkg/deployment/images.go +++ b/pkg/deployment/images.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -223,7 +223,7 @@ func (ib *imagesBuilder) fetchArangoDBImageIDAndVersion(ctx context.Context, cac if s := ib.Spec.License; s.HasSecretName() { if secret, ok := cachedStatus.Secret().V1().GetSimple(s.GetSecretName()); ok { if _, ok := secret.Data[constants.SecretKeyToken]; ok { - license = util.NewString(s.GetSecretName()) + license = util.NewType[string](s.GetSecretName()) } } } diff --git a/pkg/deployment/images_test.go b/pkg/deployment/images_test.go index 8a272713f..03d074085 100644 --- a/pkg/deployment/images_test.go +++ b/pkg/deployment/images_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -68,7 +68,7 @@ func TestEnsureImages(t *testing.T) { Name: "Image has not been changed", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testImage), + Image: util.NewType[string](testImage), }, }, }, @@ -76,7 +76,7 @@ func TestEnsureImages(t *testing.T) { Name: "Image has been changed", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testNewImage), + Image: util.NewType[string](testNewImage), }, }, RetrySoon: true, @@ -132,9 +132,9 @@ func TestEnsureImages(t *testing.T) { Name: "Image not been changed with license (proper one)", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testNewImage), + Image: util.NewType[string](testNewImage), License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -179,9 +179,9 @@ func TestEnsureImages(t *testing.T) { Name: "Image not been changed with license (missing one)", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testNewImage), + Image: util.NewType[string](testNewImage), License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -235,9 +235,9 @@ func TestEnsureImages(t *testing.T) { Name: "Image not been changed with license (missing key)", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testNewImage), + Image: util.NewType[string](testNewImage), License: api.LicenseSpec{ - SecretName: util.NewString(testLicense), + SecretName: util.NewType[string](testLicense), }, }, }, @@ -278,7 +278,7 @@ func TestEnsureImages(t *testing.T) { Name: "Image is being updated in failed phase", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testNewImage), + Image: util.NewType[string](testNewImage), }, }, Before: func(t *testing.T, deployment *Deployment) { @@ -305,7 +305,7 @@ func TestEnsureImages(t *testing.T) { Name: "Image is being updated too long in failed phase", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testNewImage), + Image: util.NewType[string](testNewImage), }, }, Before: func(t *testing.T, deployment *Deployment) { @@ -329,7 +329,7 @@ func TestEnsureImages(t *testing.T) { Name: "Image is being updated in not ready phase", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testNewImage), + Image: util.NewType[string](testNewImage), }, }, RetrySoon: true, @@ -358,7 +358,7 @@ func TestEnsureImages(t *testing.T) { Name: "Image is being updated in ready phase with empty statuses list", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testNewImage), + Image: util.NewType[string](testNewImage), }, }, RetrySoon: true, @@ -388,7 +388,7 @@ func TestEnsureImages(t *testing.T) { Name: "Can not get API version of arnagod", ArangoDeployment: &api.ArangoDeployment{ Spec: api.DeploymentSpec{ - Image: util.NewString(testNewImage), + Image: util.NewType[string](testNewImage), }, }, RetrySoon: true, diff --git a/pkg/deployment/member/phase_updates.go b/pkg/deployment/member/phase_updates.go index bc2d871bc..947c3c93f 100644 --- a/pkg/deployment/member/phase_updates.go +++ b/pkg/deployment/member/phase_updates.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go b/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go index 1dae0e129..9b89bfd4c 100644 --- a/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go +++ b/pkg/deployment/reconcile/action_arango_member_update_pod_spec.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -81,7 +81,7 @@ func (a *actionArangoMemberUpdatePodSpec) Start(ctx context.Context) (bool, erro if m.Endpoint == nil || *m.Endpoint != endpoint { // Update endpoint - m.Endpoint = util.NewString(endpoint) + m.Endpoint = util.NewType[string](endpoint) if err := status.Members.Update(m, a.action.Group); err != nil { a.log.Err(err).Error("Unable to update endpoint") return false, err diff --git a/pkg/deployment/reconcile/action_disable_scaling_cluster.go b/pkg/deployment/reconcile/action_disable_scaling_cluster.go index a543c9133..13ecc8a69 100644 --- a/pkg/deployment/reconcile/action_disable_scaling_cluster.go +++ b/pkg/deployment/reconcile/action_disable_scaling_cluster.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import ( func newDisableClusterScalingAction(action api.Action, actionCtx ActionContext) Action { a := &actionDisableClusterScaling{} - a.actionImpl = newActionImpl(action, actionCtx, util.NewString("")) + a.actionImpl = newActionImpl(action, actionCtx, util.NewType[string]("")) return a } diff --git a/pkg/deployment/reconcile/action_enable_scaling_cluster.go b/pkg/deployment/reconcile/action_enable_scaling_cluster.go index b9e65e1f0..9363959cc 100644 --- a/pkg/deployment/reconcile/action_enable_scaling_cluster.go +++ b/pkg/deployment/reconcile/action_enable_scaling_cluster.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import ( func newEnableClusterScalingAction(action api.Action, actionCtx ActionContext) Action { a := &actionEnableClusterScaling{} - a.actionImpl = newActionImpl(action, actionCtx, util.NewString("")) + a.actionImpl = newActionImpl(action, actionCtx, util.NewType[string]("")) return a } diff --git a/pkg/deployment/reconcile/action_tls_status_update.go b/pkg/deployment/reconcile/action_tls_status_update.go index 91f8c65ca..8ef84f668 100644 --- a/pkg/deployment/reconcile/action_tls_status_update.go +++ b/pkg/deployment/reconcile/action_tls_status_update.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ func (a *actionTLSKeyStatusUpdate) Start(ctx context.Context) (bool, error) { r := false if len(keyHashes) == 1 { if s.Hashes.TLS.CA == nil || *s.Hashes.TLS.CA != keyHashes[0] { - s.Hashes.TLS.CA = util.NewString(keyHashes[0]) + s.Hashes.TLS.CA = util.NewType[string](keyHashes[0]) r = true } } diff --git a/pkg/deployment/reconcile/action_wait_for_member_in_sync.go b/pkg/deployment/reconcile/action_wait_for_member_in_sync.go index ee3902314..a328059b1 100644 --- a/pkg/deployment/reconcile/action_wait_for_member_in_sync.go +++ b/pkg/deployment/reconcile/action_wait_for_member_in_sync.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -74,7 +74,7 @@ func (a *actionWaitForMemberInSync) check() (bool, error) { groupSpec := spec.GetServerGroupSpec(a.action.Group) - if !util.BoolOrDefault(groupSpec.ExtendedRotationCheck, false) { + if !util.TypeOrDefault[bool](groupSpec.ExtendedRotationCheck, false) { return true, nil } diff --git a/pkg/deployment/reconcile/condition_member_recreation.go b/pkg/deployment/reconcile/condition_member_recreation.go index 906a46a91..bb21db18e 100644 --- a/pkg/deployment/reconcile/condition_member_recreation.go +++ b/pkg/deployment/reconcile/condition_member_recreation.go @@ -125,7 +125,7 @@ func (r *Reconciler) isStorageClassChanged(_ context.Context, apiObject k8sutil. r.log.Str("role", group.AsRole()).Str("id", member.ID).Warn("Failed to get PVC") return false, "", fmt.Errorf("failed to get PVC %s", member.PersistentVolumeClaim.GetName()) } else { - pvcClassName := util.StringOrDefault(pvc.Spec.StorageClassName) + pvcClassName := util.TypeOrDefault[string](pvc.Spec.StorageClassName) if pvcClassName == storageClassName { // A storage class has not been changed. return false, "", nil diff --git a/pkg/deployment/reconcile/helper_shutdown.go b/pkg/deployment/reconcile/helper_shutdown.go index c17881458..8b240d212 100644 --- a/pkg/deployment/reconcile/helper_shutdown.go +++ b/pkg/deployment/reconcile/helper_shutdown.go @@ -317,7 +317,7 @@ func (s shutdownNow) CheckProgress(ctx context.Context) (bool, bool, error) { // Terminate pod. options := meta.DeleteOptions{ // Leave one second to clean a PVC. - GracePeriodSeconds: util.NewInt64(1), + GracePeriodSeconds: util.NewType[int64](1), } if err := cache.Client().Kubernetes().CoreV1().Pods(cache.Namespace()).Delete(ctx, podName, options); err != nil { if !kerrors.IsNotFound(err) { diff --git a/pkg/deployment/reconcile/plan_builder_rotate_upgrade_decision.go b/pkg/deployment/reconcile/plan_builder_rotate_upgrade_decision.go index 4481114a0..5a0dc7bd5 100644 --- a/pkg/deployment/reconcile/plan_builder_rotate_upgrade_decision.go +++ b/pkg/deployment/reconcile/plan_builder_rotate_upgrade_decision.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -84,7 +84,7 @@ func (r *Reconciler) createRotateOrUpgradeDecisionMember(spec api.DeploymentSpec } d.updateAllowed, d.updateMessage = groupReadyForRestart(context, status, element.Member, element.Group) - d.unsafeUpdateAllowed = util.BoolOrDefault(spec.AllowUnsafeUpgrade, false) + d.unsafeUpdateAllowed = util.TypeOrDefault[bool](spec.AllowUnsafeUpgrade, false) if rotation.CheckPossible(element.Member) { if element.Member.Conditions.IsTrue(api.ConditionTypeRestart) { diff --git a/pkg/deployment/reconcile/plan_builder_rotate_upgrade_test.go b/pkg/deployment/reconcile/plan_builder_rotate_upgrade_test.go index 22e8b4e63..d374ab70b 100644 --- a/pkg/deployment/reconcile/plan_builder_rotate_upgrade_test.go +++ b/pkg/deployment/reconcile/plan_builder_rotate_upgrade_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ func Test_RotateUpgrade_Condition(t *testing.T) { newSpec := func(image string, mode api.DeploymentImageDiscoveryModeSpec) api.DeploymentSpec { return api.DeploymentSpec{ - Image: util.NewString(image), + Image: util.NewType[string](image), ImageDiscoveryMode: api.NewDeploymentImageDiscoveryModeSpec(mode), } } diff --git a/pkg/deployment/reconcile/plan_builder_test.go b/pkg/deployment/reconcile/plan_builder_test.go index 6ea18ffbb..90ef51781 100644 --- a/pkg/deployment/reconcile/plan_builder_test.go +++ b/pkg/deployment/reconcile/plan_builder_test.go @@ -457,12 +457,12 @@ func TestCreatePlanSingleScale(t *testing.T) { assert.True(t, changed) assert.Len(t, newPlan, 0) // Single mode does not scale - spec.Single.Count = util.NewInt(2) + spec.Single.Count = util.NewType[int](2) newPlan, _, changed = r.createNormalPlan(ctx, depl, nil, spec, status, c) assert.True(t, changed) assert.Len(t, newPlan, 0) // Single mode does not scale - spec.Single.Count = util.NewInt(1) + spec.Single.Count = util.NewType[int](1) // Test with 2 single members (which should not happen) and try to scale down status.Members.Single = api.MemberStatusList{ api.MemberStatus{ @@ -494,7 +494,7 @@ func TestCreatePlanActiveFailoverScale(t *testing.T) { Mode: api.NewMode(api.DeploymentModeActiveFailover), } spec.SetDefaults("test") - spec.Single.Count = util.NewInt(2) + spec.Single.Count = util.NewType[int](2) depl := &api.ArangoDeployment{ ObjectMeta: meta.ObjectMeta{ Name: "test_depl", @@ -673,8 +673,8 @@ func TestCreatePlanClusterScale(t *testing.T) { }, }, } - spec.DBServers.Count = util.NewInt(1) - spec.Coordinators.Count = util.NewInt(1) + spec.DBServers.Count = util.NewType[int](1) + spec.Coordinators.Count = util.NewType[int](1) newPlan, _, changed = r.createNormalPlan(ctx, depl, nil, spec, status, c) assert.True(t, changed) require.Len(t, newPlan, 7) // Note: Downscaling is done 1 at a time @@ -774,7 +774,7 @@ func TestCreatePlan(t *testing.T) { Spec: api.DeploymentSpec{ Mode: api.NewMode(api.DeploymentModeCluster), TLS: api.TLSSpec{ - CASecretName: util.NewString(api.CASecretNameDisabled), + CASecretName: util.NewType[string](api.CASecretNameDisabled), }, }, Status: api.DeploymentStatus{ @@ -825,7 +825,7 @@ func TestCreatePlan(t *testing.T) { PVCS: map[string]*core.PersistentVolumeClaim{ pvcName: { Spec: core.PersistentVolumeClaimSpec{ - StorageClassName: util.NewString("oldStorage"), + StorageClassName: util.NewType[string]("oldStorage"), }, }, }, @@ -838,10 +838,10 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.DBServers = api.ServerGroupSpec{ - Count: util.NewInt(3), + Count: util.NewType[int](3), VolumeClaimTemplate: &core.PersistentVolumeClaim{ Spec: core.PersistentVolumeClaimSpec{ - StorageClassName: util.NewString("newStorage"), + StorageClassName: util.NewType[string]("newStorage"), }, }, } @@ -878,7 +878,7 @@ func TestCreatePlan(t *testing.T) { PVCS: map[string]*core.PersistentVolumeClaim{ pvcName: { Spec: core.PersistentVolumeClaimSpec{ - StorageClassName: util.NewString("oldStorage"), + StorageClassName: util.NewType[string]("oldStorage"), }, }, }, @@ -888,10 +888,10 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.DBServers = api.ServerGroupSpec{ - Count: util.NewInt(3), + Count: util.NewType[int](3), VolumeClaimTemplate: &core.PersistentVolumeClaim{ Spec: core.PersistentVolumeClaimSpec{ - StorageClassName: util.NewString("newStorage"), + StorageClassName: util.NewType[string]("newStorage"), }, }, } @@ -912,7 +912,7 @@ func TestCreatePlan(t *testing.T) { PVCS: map[string]*core.PersistentVolumeClaim{ pvcName: { Spec: core.PersistentVolumeClaimSpec{ - StorageClassName: util.NewString(""), + StorageClassName: util.NewType[string](""), }, }, }, @@ -922,8 +922,8 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.Agents = api.ServerGroupSpec{ - Count: util.NewInt(2), - StorageClassName: util.NewString("newStorage"), + Count: util.NewType[int](2), + StorageClassName: util.NewType[string]("newStorage"), } ad.Status.Members.Agents[0].Phase = api.MemberPhaseCreated ad.Status.Members.Agents[0].PersistentVolumeClaim = &api.MemberPersistentVolumeClaimStatus{ @@ -951,7 +951,7 @@ func TestCreatePlan(t *testing.T) { PVCS: map[string]*core.PersistentVolumeClaim{ pvcName: { Spec: core.PersistentVolumeClaimSpec{ - StorageClassName: util.NewString("oldStorage"), + StorageClassName: util.NewType[string]("oldStorage"), }, }, }, @@ -961,10 +961,10 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.Coordinators = api.ServerGroupSpec{ - Count: util.NewInt(3), + Count: util.NewType[int](3), VolumeClaimTemplate: &core.PersistentVolumeClaim{ Spec: core.PersistentVolumeClaimSpec{ - StorageClassName: util.NewString("newStorage"), + StorageClassName: util.NewType[string]("newStorage"), }, }, } @@ -994,7 +994,7 @@ func TestCreatePlan(t *testing.T) { PVCS: map[string]*core.PersistentVolumeClaim{ "pvc_test": { Spec: core.PersistentVolumeClaimSpec{ - StorageClassName: util.NewString("oldStorage"), + StorageClassName: util.NewType[string]("oldStorage"), }, Status: core.PersistentVolumeClaimStatus{ Conditions: []core.PersistentVolumeClaimCondition{ @@ -1055,10 +1055,10 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.Agents = api.ServerGroupSpec{ - Count: util.NewInt(2), + Count: util.NewType[int](2), VolumeClaimTemplate: &core.PersistentVolumeClaim{ Spec: core.PersistentVolumeClaimSpec{ - StorageClassName: util.NewString("oldStorage"), + StorageClassName: util.NewType[string]("oldStorage"), }, }, } @@ -1079,7 +1079,7 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.Agents = api.ServerGroupSpec{ - Count: util.NewInt(2), + Count: util.NewType[int](2), } ad.Status.Members.Agents[0].Phase = api.MemberPhaseFailed ad.Status.Members.Agents[0].ID = "id" @@ -1102,7 +1102,7 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.Coordinators = api.ServerGroupSpec{ - Count: util.NewInt(2), + Count: util.NewType[int](2), } ad.Status.Members.Coordinators[0].Phase = api.MemberPhaseFailed ad.Status.Members.Coordinators[0].ID = "id" @@ -1122,7 +1122,7 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.DBServers = api.ServerGroupSpec{ - Count: util.NewInt(3), + Count: util.NewType[int](3), } ad.Status.Members.DBServers[0].Phase = api.MemberPhaseFailed ad.Status.Members.DBServers[0].ID = "id" @@ -1142,7 +1142,7 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.DBServers = api.ServerGroupSpec{ - Count: util.NewInt(2), + Count: util.NewType[int](2), } ad.Status.Members.DBServers[2].Phase = api.MemberPhaseFailed ad.Status.Members.DBServers[2].ID = "id3" @@ -1162,7 +1162,7 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.DBServers = api.ServerGroupSpec{ - Count: util.NewInt(3), + Count: util.NewType[int](3), } ad.Status.Members.DBServers[0].Phase = api.MemberPhaseCreated ad.Status.Members.DBServers[0].Conditions = api.ConditionList{ @@ -1187,7 +1187,7 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.DBServers = api.ServerGroupSpec{ - Count: util.NewInt(2), + Count: util.NewType[int](2), } ad.Status.Members.DBServers[2].ID = "id3" ad.Status.Members.DBServers[2].Phase = api.MemberPhaseCreated @@ -1213,7 +1213,7 @@ func TestCreatePlan(t *testing.T) { }, Helper: func(ad *api.ArangoDeployment) { ad.Spec.DBServers = api.ServerGroupSpec{ - Count: util.NewInt(2), + Count: util.NewType[int](2), } ad.Status.Members.DBServers[0].Phase = api.MemberPhaseCreated }, diff --git a/pkg/deployment/resources/inspector/metrics_test.go b/pkg/deployment/resources/inspector/metrics_test.go index da22d7380..ce9c556fd 100644 --- a/pkg/deployment/resources/inspector/metrics_test.go +++ b/pkg/deployment/resources/inspector/metrics_test.go @@ -175,7 +175,7 @@ func testModClientMetrics[S meta.Object](t *testing.T, definition definitions.Co t.Run("ForceDelete", func(t *testing.T) { err := in.Delete(context.Background(), obj.GetName(), meta.DeleteOptions{ - GracePeriodSeconds: util.NewInt64(0), + GracePeriodSeconds: util.NewType[int64](0), }) require.NoError(t, err) @@ -186,7 +186,7 @@ func testModClientMetrics[S meta.Object](t *testing.T, definition definitions.Co t.Run("ForceDelete - missing", func(t *testing.T) { err := in.Delete(context.Background(), obj.GetName(), meta.DeleteOptions{ - GracePeriodSeconds: util.NewInt64(0), + GracePeriodSeconds: util.NewType[int64](0), }) require.Error(t, err) diff --git a/pkg/deployment/resources/pod_creator.go b/pkg/deployment/resources/pod_creator.go index 4bdbaddbe..c193f3900 100644 --- a/pkg/deployment/resources/pod_creator.go +++ b/pkg/deployment/resources/pod_creator.go @@ -109,7 +109,7 @@ func createArangodArgs(cachedStatus interfaces.Inspector, input pod.Input, addit if err != nil { return nil, err } - endpoint = util.StringOrDefault(input.Member.Endpoint, endpoint) + endpoint = util.TypeOrDefault[string](input.Member.Endpoint, endpoint) myTCPURL := scheme + "://" + net.JoinHostPort(endpoint, strconv.Itoa(shared.ArangoPort)) addAgentEndpoints := false @@ -128,7 +128,7 @@ func createArangodArgs(cachedStatus interfaces.Inspector, input pod.Input, addit if err != nil { return nil, err } - options.Addf("--agency.endpoint", "%s://%s", scheme, net.JoinHostPort(util.StringOrDefault(p.Endpoint, dnsName), strconv.Itoa(shared.ArangoPort))) + options.Addf("--agency.endpoint", "%s://%s", scheme, net.JoinHostPort(util.TypeOrDefault[string](p.Endpoint, dnsName), strconv.Itoa(shared.ArangoPort))) } } case api.ServerGroupDBServers: @@ -172,7 +172,7 @@ func createArangodArgs(cachedStatus interfaces.Inspector, input pod.Input, addit if err != nil { return nil, err } - options.Addf("--cluster.agency-endpoint", "%s://%s", scheme, net.JoinHostPort(util.StringOrDefault(p.Endpoint, dnsName), strconv.Itoa(shared.ArangoPort))) + options.Addf("--cluster.agency-endpoint", "%s://%s", scheme, net.JoinHostPort(util.TypeOrDefault[string](p.Endpoint, dnsName), strconv.Itoa(shared.ArangoPort))) } } diff --git a/pkg/deployment/resources/pod_creator_agent_args_test.go b/pkg/deployment/resources/pod_creator_agent_args_test.go index 20e334971..fcc303ca8 100644 --- a/pkg/deployment/resources/pod_creator_agent_args_test.go +++ b/pkg/deployment/resources/pod_creator_agent_args_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -202,7 +202,7 @@ func TestCreateArangodArgsAgent(t *testing.T) { Spec: api.DeploymentSpec{ Mode: api.NewMode(api.DeploymentModeCluster), TLS: api.TLSSpec{ - CASecretName: util.NewString("None"), + CASecretName: util.NewType[string]("None"), }, }, } @@ -266,7 +266,7 @@ func TestCreateArangodArgsAgent(t *testing.T) { }, } apiObject.Spec.SetDefaults("test") - apiObject.Spec.Authentication.JWTSecretName = util.NewString("None") + apiObject.Spec.Authentication.JWTSecretName = util.NewType[string]("None") apiObject.Spec.StorageEngine = api.NewStorageEngine(api.StorageEngineMMFiles) agents := api.MemberStatusList{ api.MemberStatus{ID: "a1"}, diff --git a/pkg/deployment/resources/pod_creator_arangod.go b/pkg/deployment/resources/pod_creator_arangod.go index 582c9f6aa..09e8fb2d2 100644 --- a/pkg/deployment/resources/pod_creator_arangod.go +++ b/pkg/deployment/resources/pod_creator_arangod.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -173,7 +173,7 @@ func (a *ArangoDContainer) GetImage() string { switch a.spec.ImageDiscoveryMode.Get() { case api.DeploymentImageDiscoveryDirectMode: // In case of direct mode ignore discovery - return util.StringOrDefault(a.spec.Image, a.imageInfo.ImageID) + return util.TypeOrDefault[string](a.spec.Image, a.imageInfo.ImageID) default: return a.imageInfo.ImageID } @@ -255,7 +255,7 @@ func (a *ArangoDContainer) GetEnvs() ([]core.EnvVar, []core.EnvFromSource) { Name: features.ConfigMapName(), }, // Optional in case if operator could not create it when process started. - Optional: util.NewBool(true), + Optional: util.NewType[bool](true), }, }, } diff --git a/pkg/deployment/resources/pod_creator_coordinator_args_test.go b/pkg/deployment/resources/pod_creator_coordinator_args_test.go index 73275a491..1155fad8f 100644 --- a/pkg/deployment/resources/pod_creator_coordinator_args_test.go +++ b/pkg/deployment/resources/pod_creator_coordinator_args_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -229,7 +229,7 @@ func TestCreateArangodArgsCoordinator(t *testing.T) { Spec: api.DeploymentSpec{ Mode: api.NewMode(api.DeploymentModeCluster), TLS: api.TLSSpec{ - CASecretName: util.NewString("None"), + CASecretName: util.NewType[string]("None"), }, }, } @@ -291,7 +291,7 @@ func TestCreateArangodArgsCoordinator(t *testing.T) { }, } apiObject.Spec.SetDefaults("test") - apiObject.Spec.Authentication.JWTSecretName = util.NewString("None") + apiObject.Spec.Authentication.JWTSecretName = util.NewType[string]("None") agents := api.MemberStatusList{ api.MemberStatus{ID: "a1"}, api.MemberStatus{ID: "a2"}, diff --git a/pkg/deployment/resources/pod_creator_dbserver_args_test.go b/pkg/deployment/resources/pod_creator_dbserver_args_test.go index 26de96aa9..1ee82d906 100644 --- a/pkg/deployment/resources/pod_creator_dbserver_args_test.go +++ b/pkg/deployment/resources/pod_creator_dbserver_args_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -168,7 +168,7 @@ func TestCreateArangodArgsDBServer(t *testing.T) { }, Spec: api.DeploymentSpec{ Mode: api.NewMode(api.DeploymentModeCluster), - ClusterDomain: util.NewString("cluster.local"), + ClusterDomain: util.NewType[string]("cluster.local"), }, } apiObject.Spec.SetDefaults("test") @@ -230,7 +230,7 @@ func TestCreateArangodArgsDBServer(t *testing.T) { Spec: api.DeploymentSpec{ Mode: api.NewMode(api.DeploymentModeCluster), TLS: api.TLSSpec{ - CASecretName: util.NewString("None"), + CASecretName: util.NewType[string]("None"), }, }, } @@ -292,7 +292,7 @@ func TestCreateArangodArgsDBServer(t *testing.T) { }, } apiObject.Spec.SetDefaults("test") - apiObject.Spec.Authentication.JWTSecretName = util.NewString("None") + apiObject.Spec.Authentication.JWTSecretName = util.NewType[string]("None") agents := api.MemberStatusList{ api.MemberStatus{ID: "a1"}, api.MemberStatus{ID: "a2"}, diff --git a/pkg/deployment/resources/pod_creator_probes.go b/pkg/deployment/resources/pod_creator_probes.go index 558bdd5e5..87b7ec30f 100644 --- a/pkg/deployment/resources/pod_creator_probes.go +++ b/pkg/deployment/resources/pod_creator_probes.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -350,8 +350,8 @@ func (r *Resources) probeBuilderReadinessSimpleCoreOperator(spec api.DeploymentS } p.SetSpec(&api.ServerGroupProbeSpec{ - InitialDelaySeconds: util.NewInt32(15), - PeriodSeconds: util.NewInt32(10), + InitialDelaySeconds: util.NewType[int32](15), + PeriodSeconds: util.NewType[int32](10), }) return p, nil @@ -369,8 +369,8 @@ func (r *Resources) probeBuilderReadinessSimpleCore(spec api.DeploymentSpec, gro } p.SetSpec(&api.ServerGroupProbeSpec{ - InitialDelaySeconds: util.NewInt32(15), - PeriodSeconds: util.NewInt32(10), + InitialDelaySeconds: util.NewType[int32](15), + PeriodSeconds: util.NewType[int32](10), }) return p, nil diff --git a/pkg/deployment/resources/pod_creator_single_args_test.go b/pkg/deployment/resources/pod_creator_single_args_test.go index ef9b15c58..44accaeea 100644 --- a/pkg/deployment/resources/pod_creator_single_args_test.go +++ b/pkg/deployment/resources/pod_creator_single_args_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -133,7 +133,7 @@ func TestCreateArangodArgsSingle(t *testing.T) { Spec: api.DeploymentSpec{ Mode: api.NewMode(api.DeploymentModeSingle), TLS: api.TLSSpec{ - CASecretName: util.NewString("None"), + CASecretName: util.NewType[string]("None"), }, }, } @@ -222,7 +222,7 @@ func TestCreateArangodArgsSingle(t *testing.T) { Mode: api.NewMode(api.DeploymentModeSingle), }, } - apiObject.Spec.Authentication.JWTSecretName = util.NewString("None") + apiObject.Spec.Authentication.JWTSecretName = util.NewType[string]("None") apiObject.Spec.SetDefaults("test") input := pod.Input{ ApiObject: apiObject, diff --git a/pkg/deployment/resources/pod_finalizers.go b/pkg/deployment/resources/pod_finalizers.go index ed6029fda..5e8a53bc8 100644 --- a/pkg/deployment/resources/pod_finalizers.go +++ b/pkg/deployment/resources/pod_finalizers.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -102,7 +102,7 @@ func (r *Resources) runPodFinalizers(ctx context.Context, p *core.Pod, memberSta groupSpec := r.context.GetSpec().GetServerGroupSpec(group) if t := p.ObjectMeta.DeletionTimestamp; t != nil { d := time.Duration(groupSpec.GetShutdownDelay(group)) * time.Second - gr := time.Duration(util.Int64OrDefault(p.ObjectMeta.GetDeletionGracePeriodSeconds(), 0)) * time.Second + gr := time.Duration(util.TypeOrDefault[int64](p.ObjectMeta.GetDeletionGracePeriodSeconds(), 0)) * time.Second e := t.Time.Add(-1 * gr).Sub(time.Now().Add(-1 * d)) log.Str("finalizer", f).Str("left", e.String()).Error("Delay finalizer status") if e < 0 || d == 0 { diff --git a/pkg/deployment/resources/pod_inspector.go b/pkg/deployment/resources/pod_inspector.go index f759e947f..ff9e756fc 100644 --- a/pkg/deployment/resources/pod_inspector.go +++ b/pkg/deployment/resources/pod_inspector.go @@ -437,7 +437,7 @@ func (r *Resources) InspectPods(ctx context.Context, cachedStatus inspectorInter defer c() if err := cachedStatus.PodsModInterface().V1().Delete(nctx, pod.GetName(), meta.DeleteOptions{ - GracePeriodSeconds: util.NewInt64(gps), + GracePeriodSeconds: util.NewType[int64](gps), Preconditions: meta.NewUIDPreconditions(string(pod.GetUID())), }); err != nil { if kerrors.IsNotFound(err) { diff --git a/pkg/deployment/rotation/arangod_test.go b/pkg/deployment/rotation/arangod_test.go index 38504dfb9..ce068cd03 100644 --- a/pkg/deployment/rotation/arangod_test.go +++ b/pkg/deployment/rotation/arangod_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -83,7 +83,7 @@ func Test_ArangoD_TerminationGracePeriodSeconds(t *testing.T) { pod.Spec.TerminationGracePeriodSeconds = nil }), status: buildPodSpec(func(pod *core.PodTemplateSpec) { - pod.Spec.TerminationGracePeriodSeconds = util.NewInt64(30) + pod.Spec.TerminationGracePeriodSeconds = util.NewType[int64](30) }), TestCaseOverride: TestCaseOverride{ @@ -93,7 +93,7 @@ func Test_ArangoD_TerminationGracePeriodSeconds(t *testing.T) { { name: "Remove", spec: buildPodSpec(func(pod *core.PodTemplateSpec) { - pod.Spec.TerminationGracePeriodSeconds = util.NewInt64(30) + pod.Spec.TerminationGracePeriodSeconds = util.NewType[int64](30) }), status: buildPodSpec(func(pod *core.PodTemplateSpec) { pod.Spec.TerminationGracePeriodSeconds = nil @@ -106,10 +106,10 @@ func Test_ArangoD_TerminationGracePeriodSeconds(t *testing.T) { { name: "Update", spec: buildPodSpec(func(pod *core.PodTemplateSpec) { - pod.Spec.TerminationGracePeriodSeconds = util.NewInt64(33) + pod.Spec.TerminationGracePeriodSeconds = util.NewType[int64](33) }), status: buildPodSpec(func(pod *core.PodTemplateSpec) { - pod.Spec.TerminationGracePeriodSeconds = util.NewInt64(30) + pod.Spec.TerminationGracePeriodSeconds = util.NewType[int64](30) }), TestCaseOverride: TestCaseOverride{ diff --git a/pkg/handlers/backup/handler.go b/pkg/handlers/backup/handler.go index 045337478..0124ed7cf 100644 --- a/pkg/handlers/backup/handler.go +++ b/pkg/handlers/backup/handler.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -180,7 +180,7 @@ func (h *handler) refreshDeploymentBackup(deployment *database.ArangoDeployment, status := updateStatus(backup, updateStatusState(backupApi.ArangoBackupStateReady, ""), updateStatusBackup(backupMeta), - updateStatusBackupImported(util.NewBool(true))) + updateStatusBackupImported(util.NewType[bool](true))) backup.Status = *status diff --git a/pkg/handlers/backup/state_create_test.go b/pkg/handlers/backup/state_create_test.go index b6d9eafd5..3db5918ea 100644 --- a/pkg/handlers/backup/state_create_test.go +++ b/pkg/handlers/backup/state_create_test.go @@ -70,7 +70,7 @@ func Test_State_Create_SuccessForced(t *testing.T) { obj, deployment := newObjectSet(backupApi.ArangoBackupStateCreate) obj.Spec.Options = &backupApi.ArangoBackupSpecOptions{ - AllowInconsistent: util.NewBool(true), + AllowInconsistent: util.NewType[bool](true), } // Act @@ -194,8 +194,8 @@ func Test_State_CreateError_Transfer_To_Failed(t *testing.T) { } obj.Spec.Backoff = &backupApi.ArangoBackupSpecBackOff{ - Iterations: util.NewInt(1), - MaxIterations: util.NewInt(2), + Iterations: util.NewType[int](1), + MaxIterations: util.NewType[int](2), } obj.Status.Time.Time = time.Now().Add(-2 * downloadDelay) diff --git a/pkg/handlers/backup/state_downloading.go b/pkg/handlers/backup/state_downloading.go index 4f9018ffc..4f14bea7e 100644 --- a/pkg/handlers/backup/state_downloading.go +++ b/pkg/handlers/backup/state_downloading.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -91,7 +91,7 @@ func stateDownloadingHandler(h *handler, backup *backupApi.ArangoBackup) (*backu updateStatusState(backupApi.ArangoBackupStateReady, ""), updateStatusAvailable(true), updateStatusBackup(backupMeta), - updateStatusBackupDownload(util.NewBool(true)), + updateStatusBackupDownload(util.NewType[bool](true)), cleanStatusJob(), ) } diff --git a/pkg/handlers/backup/state_ready_test.go b/pkg/handlers/backup/state_ready_test.go index 28e2be3c7..b817fadaf 100644 --- a/pkg/handlers/backup/state_ready_test.go +++ b/pkg/handlers/backup/state_ready_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -292,7 +292,7 @@ func Test_State_Ready_DownloadDoNothing(t *testing.T) { require.NoError(t, err) obj.Status.Backup = createBackupFromMeta(backupMeta, &backupApi.ArangoBackupDetails{ - Downloaded: util.NewBool(true), + Downloaded: util.NewType[bool](true), }) // Act @@ -325,8 +325,8 @@ func Test_State_Ready_DoUploadDownloadedBackup(t *testing.T) { require.NoError(t, err) obj.Status.Backup = createBackupFromMeta(backupMeta, &backupApi.ArangoBackupDetails{ - Downloaded: util.NewBool(true), - Uploaded: util.NewBool(false), + Downloaded: util.NewType[bool](true), + Uploaded: util.NewType[bool](false), }) // Act @@ -358,7 +358,7 @@ func Test_State_Ready_DoNotReUploadBackup(t *testing.T) { require.NoError(t, err) obj.Status.Backup = createBackupFromMeta(backupMeta, &backupApi.ArangoBackupDetails{ - Uploaded: util.NewBool(true), + Uploaded: util.NewType[bool](true), }) // Act @@ -388,7 +388,7 @@ func Test_State_Ready_RemoveUploadedFlag(t *testing.T) { require.NoError(t, err) obj.Status.Backup = createBackupFromMeta(backupMeta, &backupApi.ArangoBackupDetails{ - Uploaded: util.NewBool(true), + Uploaded: util.NewType[bool](true), }) // Act diff --git a/pkg/handlers/backup/state_uploaderror_test.go b/pkg/handlers/backup/state_uploaderror_test.go index 5c072aab6..2385dfb9a 100644 --- a/pkg/handlers/backup/state_uploaderror_test.go +++ b/pkg/handlers/backup/state_uploaderror_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -49,7 +49,7 @@ func Test_State_UploadError_Reschedule(t *testing.T) { ID: string(backupMeta.ID), Version: backupMeta.Version, CreationTimestamp: meta.Now(), - Uploaded: util.NewBool(true), + Uploaded: util.NewType[bool](true), } obj.Status.Time.Time = time.Now().Add(-2 * downloadDelay) @@ -86,7 +86,7 @@ func Test_State_UploadError_Wait(t *testing.T) { ID: string(backupMeta.ID), Version: backupMeta.Version, CreationTimestamp: meta.Now(), - Uploaded: util.NewBool(true), + Uploaded: util.NewType[bool](true), } obj.Status.Backoff = &backupApi.ArangoBackupStatusBackOff{ Next: meta.Time{Time: time.Now().Add(5 * time.Second)}, @@ -122,7 +122,7 @@ func Test_State_UploadError_BackToReady(t *testing.T) { ID: string(backupMeta.ID), Version: backupMeta.Version, CreationTimestamp: meta.Now(), - Uploaded: util.NewBool(true), + Uploaded: util.NewType[bool](true), } obj.Status.Time.Time = time.Now().Add(2 * downloadDelay) diff --git a/pkg/handlers/backup/state_uploading.go b/pkg/handlers/backup/state_uploading.go index e116cf311..34c6e0ff3 100644 --- a/pkg/handlers/backup/state_uploading.go +++ b/pkg/handlers/backup/state_uploading.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -75,7 +75,7 @@ func stateUploadingHandler(h *handler, backup *backupApi.ArangoBackup) (*backupA return wrapUpdateStatus(backup, updateStatusState(backupApi.ArangoBackupStateReady, ""), cleanStatusJob(), - updateStatusBackupUpload(util.NewBool(true)), + updateStatusBackupUpload(util.NewType[bool](true)), updateStatusAvailable(true), cleanBackOff(), ) @@ -88,7 +88,7 @@ func stateUploadingHandler(h *handler, backup *backupApi.ArangoBackup) (*backupA return wrapUpdateStatus(backup, updateStatusState(backupApi.ArangoBackupStateReady, ""), cleanStatusJob(), - updateStatusBackupUpload(util.NewBool(false)), + updateStatusBackupUpload(util.NewType[bool](false)), updateStatusAvailable(true), cleanBackOff(), ) diff --git a/pkg/handlers/backup/status.go b/pkg/handlers/backup/status.go index 75868a260..85e191967 100644 --- a/pkg/handlers/backup/status.go +++ b/pkg/handlers/backup/status.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -143,7 +143,7 @@ func createBackupFromMeta(backupMeta driver.BackupMeta, old *backupApi.ArangoBac } obj.Keys = keysToHashList(backupMeta.Keys) - obj.PotentiallyInconsistent = util.NewBool(backupMeta.PotentiallyInconsistent) + obj.PotentiallyInconsistent = util.NewType[bool](backupMeta.PotentiallyInconsistent) obj.SizeInBytes = backupMeta.SizeInBytes obj.CreationTimestamp = meta.Time{ Time: backupMeta.DateTime, diff --git a/pkg/replication/finalizers.go b/pkg/replication/finalizers.go index 0d850d6f2..4dc25ae25 100644 --- a/pkg/replication/finalizers.go +++ b/pkg/replication/finalizers.go @@ -178,7 +178,7 @@ func (dr *DeploymentReplication) inspectFinalizerDeplReplStopSync(ctx context.Co } // Check whether data consistency must be ensured. - if syncInfo.Status.IsActive() && util.BoolOrDefault(p.Spec.Cancellation.EnsureInSync, true) { + if syncInfo.Status.IsActive() && util.TypeOrDefault[bool](p.Spec.Cancellation.EnsureInSync, true) { if inSync, inSyncShards, totalShards, err := dr.ensureInSync(ctx, destClient); err != nil { return false, err } else if !inSync { @@ -195,7 +195,7 @@ func (dr *DeploymentReplication) inspectFinalizerDeplReplStopSync(ctx context.Co // From here on this code should be launched only once unless abort option is changed // or replication is not in cancelling state. sourceServerMode := driver.ServerModeDefault - if util.BoolOrDefault(p.Spec.Cancellation.SourceReadOnly) { + if util.TypeOrDefault[bool](p.Spec.Cancellation.SourceReadOnly) { sourceServerMode = driver.ServerModeReadOnly } req := client.CancelSynchronizationRequest{ diff --git a/pkg/storage/daemon_set.go b/pkg/storage/daemon_set.go index b4396307f..14360a0b0 100644 --- a/pkg/storage/daemon_set.go +++ b/pkg/storage/daemon_set.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -74,7 +74,7 @@ func (ls *LocalStorage) ensureDaemonSet(apiObject *api.ArangoLocalStorage) error if apiObject.Spec.GetPrivileged() { c.SecurityContext = &core.SecurityContext{ - Privileged: util.NewBool(true), + Privileged: util.NewType[bool](true), } } diff --git a/pkg/storage/utils/taints_test.go b/pkg/storage/utils/taints_test.go index d403475a8..9329e6e7a 100644 --- a/pkg/storage/utils/taints_test.go +++ b/pkg/storage/utils/taints_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -95,7 +95,7 @@ func Test_Taints(t *testing.T) { tolerations: []core.Toleration{ { Operator: core.TolerationOpExists, - TolerationSeconds: util.NewInt64(300), + TolerationSeconds: util.NewType[int64](300), }, }, @@ -114,7 +114,7 @@ func Test_Taints(t *testing.T) { tolerations: []core.Toleration{ { Operator: core.TolerationOpExists, - TolerationSeconds: util.NewInt64(300), + TolerationSeconds: util.NewType[int64](300), }, }, @@ -133,7 +133,7 @@ func Test_Taints(t *testing.T) { tolerations: []core.Toleration{ { Operator: core.TolerationOpExists, - TolerationSeconds: util.NewInt64(300), + TolerationSeconds: util.NewType[int64](300), }, }, diff --git a/pkg/util/k8sutil/dns_test.go b/pkg/util/k8sutil/dns_test.go index d21112a31..b0c211c34 100644 --- a/pkg/util/k8sutil/dns_test.go +++ b/pkg/util/k8sutil/dns_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -56,5 +56,5 @@ func TestCreatePodDNSNameWithDomain(t *testing.T) { } assert.Equal(t, "test-agent-id1.test-int.ns.svc", CreatePodDNSNameWithDomain(depl, nil, "agent", "id1")) - assert.Equal(t, "test-agent-id1.test-int.ns.svc.cluster.local", CreatePodDNSNameWithDomain(depl, util.NewString("cluster.local"), "agent", "id1")) + assert.Equal(t, "test-agent-id1.test-int.ns.svc.cluster.local", CreatePodDNSNameWithDomain(depl, util.NewType[string]("cluster.local"), "agent", "id1")) } diff --git a/pkg/util/k8sutil/images_test.go b/pkg/util/k8sutil/images_test.go index a5e369c8c..136d7be86 100644 --- a/pkg/util/k8sutil/images_test.go +++ b/pkg/util/k8sutil/images_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import ( "github.com/stretchr/testify/require" core "k8s.io/api/core/v1" + "github.com/arangodb/kube-arangodb/pkg/apis/shared" "github.com/arangodb/kube-arangodb/pkg/util/errors" ) @@ -62,15 +63,36 @@ func TestGetArangoDBImageIDFromPod(t *testing.T) { }, want: "test", }, - "image ID from two containers": { + "image ID from two containers - first one as server": { args: args{ pod: &core.Pod{ Status: core.PodStatus{ ContainerStatuses: []core.ContainerStatus{ { + Name: shared.ServerContainerName, ImageID: dockerPullableImageIDPrefix + "test_arango", }, { + Name: "other", + ImageID: dockerPullableImageIDPrefix + "test1_arango", + }, + }, + }, + }, + }, + want: "test_arango", + }, + "image ID from two containers - second one as server": { + args: args{ + pod: &core.Pod{ + Status: core.PodStatus{ + ContainerStatuses: []core.ContainerStatus{ + { + Name: "other", + ImageID: dockerPullableImageIDPrefix + "test_arango", + }, + { + Name: shared.ServerContainerName, ImageID: dockerPullableImageIDPrefix + "test1_arango", }, }, @@ -79,6 +101,25 @@ func TestGetArangoDBImageIDFromPod(t *testing.T) { }, want: "test1_arango", }, + "image ID from two containers - no server": { + args: args{ + pod: &core.Pod{ + Status: core.PodStatus{ + ContainerStatuses: []core.ContainerStatus{ + { + Name: "other2", + ImageID: dockerPullableImageIDPrefix + "test_arango", + }, + { + Name: "other", + ImageID: dockerPullableImageIDPrefix + "test1_arango", + }, + }, + }, + }, + }, + want: "test_arango", + }, } for testName, testCase := range tests { diff --git a/pkg/util/k8sutil/patcher/service_ports_test.go b/pkg/util/k8sutil/patcher/service_ports_test.go index 1db6d9174..5d5b215b0 100644 --- a/pkg/util/k8sutil/patcher/service_ports_test.go +++ b/pkg/util/k8sutil/patcher/service_ports_test.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -186,7 +186,7 @@ func Test_Service_OnlyPorts(t *testing.T) { { Name: "test", Protocol: core.ProtocolTCP, - AppProtocol: util.NewString("test"), + AppProtocol: util.NewType[string]("test"), Port: 8528, TargetPort: intstr.IntOrString{ StrVal: "TEST", diff --git a/pkg/util/metrics/description.go b/pkg/util/metrics/description.go index a6572c0d8..94b4a1842 100644 --- a/pkg/util/metrics/description.go +++ b/pkg/util/metrics/description.go @@ -1,7 +1,7 @@ // // DISCLAIMER // -// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany +// Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -62,8 +62,8 @@ func (d *description) Labels(labels ...string) []*dto.LabelPair { for k, v := range d.constLabels { var z dto.LabelPair - z.Name = util.NewString(k) - z.Value = util.NewString(v) + z.Name = util.NewType[string](k) + z.Value = util.NewType[string](v) l = append(l, &z) } @@ -74,8 +74,8 @@ func (d *description) Labels(labels ...string) []*dto.LabelPair { var z dto.LabelPair - z.Name = util.NewString(d.variableLabels[id]) - z.Value = util.NewString(labels[id]) + z.Name = util.NewType[string](d.variableLabels[id]) + z.Value = util.NewType[string](labels[id]) l = append(l, &z) } diff --git a/pkg/util/refs.go b/pkg/util/refs.go index 416d49dc3..9847147c9 100644 --- a/pkg/util/refs.go +++ b/pkg/util/refs.go @@ -20,128 +20,28 @@ package util -import ( - "time" - - core "k8s.io/api/core/v1" -) - -// NewString returns a reference to a string with given value. -func NewString(input string) *string { +// NewType returns a reference to a simple type with given value. +func NewType[T interface{}](input T) *T { return &input } -// NewStringOrNil returns nil if input is nil, otherwise returns a clone of the given value. -func NewStringOrNil(input *string) *string { +// NewTypeOrNil returns nil if input is nil, otherwise returns a clone of the given value. +func NewTypeOrNil[T interface{}](input *T) *T { if input == nil { return nil } - return NewString(*input) -} -// StringOrDefault returns the default value (or empty string) if input is nil, otherwise returns the referenced value. -func StringOrDefault(input *string, defaultValue ...string) string { - if input == nil { - if len(defaultValue) > 0 { - return defaultValue[0] - } - return "" - } - return *input -} - -// NewInt returns a reference to an int with given value. -func NewInt(input int) *int { - return &input + return NewType(*input) } -// NewIntOrNil returns nil if input is nil, otherwise returns a clone of the given value. -func NewIntOrNil(input *int) *int { - if input == nil { - return nil - } - return NewInt(*input) -} - -// IntOrDefault returns the default value (or 0) if input is nil, otherwise returns the referenced value. -func IntOrDefault(input *int, defaultValue ...int) int { +// TypeOrDefault returns the default value (or T default value) if input is nil, otherwise returns the referenced value. +func TypeOrDefault[T interface{}](input *T, defaultValue ...T) T { if input == nil { if len(defaultValue) > 0 { return defaultValue[0] } - return 0 - } - return *input -} - -// New32Int returns a reference to an int with given value. -func NewInt32(input int32) *int32 { - return &input -} - -// New32IntOrNil returns nil if input is nil, otherwise returns a clone of the given value. -func NewInt32OrNil(input *int32) *int32 { - if input == nil { - return nil - } - return NewInt32(*input) -} - -// Int32OrDefault returns the default value (or 0) if input is nil, otherwise returns the referenced value. -func Int32OrDefault(input *int32, defaultValue ...int32) int32 { - if input == nil { - if len(defaultValue) > 0 { - return defaultValue[0] - } - return 0 - } - return *input -} - -// NewInt64 returns a reference to an int64 with given value. -func NewInt64(input int64) *int64 { - return &input -} - -// NewInt64OrNil returns nil if input is nil, otherwise returns a clone of the given value. -func NewInt64OrNil(input *int64) *int64 { - if input == nil { - return nil - } - return NewInt64(*input) -} - -// Int64OrDefault returns the default value (or 0) if input is nil, otherwise returns the referenced value. -func Int64OrDefault(input *int64, defaultValue ...int64) int64 { - if input == nil { - if len(defaultValue) > 0 { - return defaultValue[0] - } - return 0 - } - return *input -} - -// NewUInt16 returns a reference to an uint16 with given value. -func NewUInt16(input uint16) *uint16 { - return &input -} - -// NewUInt16OrNil returns nil if input is nil, otherwise returns a clone of the given value. -func NewUInt16OrNil(input *uint16) *uint16 { - if input == nil { - return nil - } - return NewUInt16(*input) -} - -// UInt16OrDefault returns the default value (or 0) if input is nil, otherwise returns the referenced value. -func UInt16OrDefault(input *uint16, defaultValue ...uint16) uint16 { - if input == nil { - if len(defaultValue) > 0 { - return defaultValue[0] - } - return 0 + var def T + return def } return *input } @@ -154,75 +54,3 @@ func BoolSwitch[T interface{}](s bool, t, f T) T { return f } - -// NewBool returns a reference to a bool with given value. -func NewBool(input bool) *bool { - return &input -} - -// NewBoolOrNil returns nil if input is nil, otherwise returns a clone of the given value. -func NewBoolOrNil(input *bool) *bool { - if input == nil { - return nil - } - return NewBool(*input) -} - -// BoolOrDefault returns the default value (or false) if input is nil, otherwise returns the referenced value. -func BoolOrDefault(input *bool, defaultValue ...bool) bool { - if input == nil { - if len(defaultValue) > 0 { - return defaultValue[0] - } - return false - } - return *input -} - -// NewDuration returns a reference to a duration with given value. -func NewDuration(input time.Duration) *time.Duration { - return &input -} - -// NewDurationOrNil returns nil if input is nil, otherwise returns a clone of the given value. -func NewDurationOrNil(input *time.Duration) *time.Duration { - if input == nil { - return nil - } - return NewDuration(*input) -} - -// DurationOrDefault returns the default value (or 0) if input is nil, otherwise returns the referenced value. -func DurationOrDefault(input *time.Duration, defaultValue ...time.Duration) time.Duration { - if input == nil { - if len(defaultValue) > 0 { - return defaultValue[0] - } - return 0 - } - return *input -} - -// NewPullPolicy returns a reference to a pull policy with given value. -func NewPullPolicy(input core.PullPolicy) *core.PullPolicy { - return &input -} - -// NewPullPolicyOrNil returns nil if input is nil, otherwise returns a clone of the given value. -func NewPullPolicyOrNil(input *core.PullPolicy) *core.PullPolicy { - if input == nil { - return nil - } - return NewPullPolicy(*input) -} - -// PullPolicyOrDefault returns the default value (or 0) if input is nil, otherwise returns the referenced value. -func PullPolicyOrDefault(input *core.PullPolicy, defaultValue ...core.PullPolicy) core.PullPolicy { - if input == nil { - if len(defaultValue) > 0 { - return defaultValue[0] - } - return "" - } - return *input -} diff --git a/pkg/util/refs_test.go b/pkg/util/refs_test.go new file mode 100644 index 000000000..db3ce3687 --- /dev/null +++ b/pkg/util/refs_test.go @@ -0,0 +1,118 @@ +// +// DISCLAIMER +// +// Copyright 2023 ArangoDB GmbH, Cologne, Germany +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Copyright holder is ArangoDB GmbH, Cologne, Germany +// + +package util + +import ( + "reflect" + "testing" + "time" + + "github.com/stretchr/testify/require" + core "k8s.io/api/core/v1" +) + +func testRefs[T interface{}](t *testing.T, in, v1, def T) { + tp := reflect.TypeOf(in) + t.Run(tp.String(), func(t *testing.T) { + t.Run("New", func(t *testing.T) { + n := NewType[T](in) + + tn := reflect.ValueOf(n) + + require.Equal(t, reflect.Pointer, tn.Kind()) + require.Equal(t, tp.Kind(), tn.Elem().Kind()) + require.Equal(t, in, tn.Elem().Interface()) + }) + t.Run("NewOrNil", func(t *testing.T) { + t.Run("Nil", func(t *testing.T) { + n := NewTypeOrNil[T](nil) + + tn := reflect.ValueOf(n) + + require.Equal(t, reflect.Pointer, tn.Kind()) + require.True(t, tn.IsNil()) + }) + t.Run("Value", func(t *testing.T) { + n := NewTypeOrNil[T](&in) + + tn := reflect.ValueOf(n) + + require.Equal(t, reflect.Pointer, tn.Kind()) + require.False(t, tn.IsNil()) + require.Equal(t, tp.Kind(), tn.Elem().Kind()) + require.Equal(t, in, tn.Elem().Interface()) + }) + }) + t.Run("Default", func(t *testing.T) { + t.Run("Ensure default", func(t *testing.T) { + var val T + require.Equal(t, def, val) + }) + + t.Run("With Input", func(t *testing.T) { + n := TypeOrDefault[T](&in) + + tn := reflect.ValueOf(n) + + require.Equal(t, tp.Kind(), tn.Kind()) + require.Equal(t, in, tn.Interface()) + }) + + t.Run("With Input & Default", func(t *testing.T) { + n := TypeOrDefault[T](&in, v1) + + tn := reflect.ValueOf(n) + + require.Equal(t, tp.Kind(), tn.Kind()) + require.Equal(t, in, tn.Interface()) + }) + + t.Run("With Nil & Default", func(t *testing.T) { + n := TypeOrDefault[T](nil, v1) + + tn := reflect.ValueOf(n) + + require.Equal(t, tp.Kind(), tn.Kind()) + require.Equal(t, v1, tn.Interface()) + }) + + t.Run("With Nil", func(t *testing.T) { + n := TypeOrDefault[T](nil) + + tn := reflect.ValueOf(n) + + require.Equal(t, tp.Kind(), tn.Kind()) + require.Equal(t, def, tn.Interface()) + }) + }) + }) +} + +func Test_Refs(t *testing.T) { + testRefs[string](t, "test", "otherValue", "") + testRefs[int](t, 777, 555, 0) + testRefs[int32](t, 777, 555, 0) + testRefs[int64](t, 777, 555, 0) + testRefs[uint16](t, 777, 555, 0) + testRefs[bool](t, false, true, false) + testRefs[time.Duration](t, time.Duration(500), time.Duration(1500), time.Duration(0)) + testRefs[core.PullPolicy](t, core.PullAlways, core.PullNever, "") +}