Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions internal/readme.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/apis/backup/v1/backup_spec_backoff_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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))
Expand All @@ -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())
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/backup/v1/backup_status_backoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/deployment/v1/authentication_spec.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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)
}
}

Expand All @@ -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
Expand Down
48 changes: 24 additions & 24 deletions pkg/apis/deployment/v1/authentication_spec_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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"},
},
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/deployment/v1/chaos_spec.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions pkg/apis/deployment/v1/deployment_metrics_spec.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
Loading