Skip to content

Commit 3529bb6

Browse files
committed
Merge branch 'master' into feature/test-individual-pod-deletion
2 parents 884ed34 + e274839 commit 3529bb6

File tree

91 files changed

+4377
-1097
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4377
-1097
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ run-unit-tests: $(GOBUILDDIR) $(SOURCES)
217217
go test $(TESTVERBOSEOPTIONS) \
218218
$(REPOPATH)/pkg/apis/deployment/v1alpha \
219219
$(REPOPATH)/pkg/deployment \
220+
$(REPOPATH)/pkg/deployment/reconcile \
220221
$(REPOPATH)/pkg/util/k8sutil \
221222
$(REPOPATH)/pkg/util/k8sutil/test
222223

deps/github.com/arangodb/go-driver/http/connection.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ type ConnectionConfig struct {
6767
// directly after use, resulting in a large number of connections in `TIME_WAIT` state.
6868
// When this value is not set, the driver will set it to 64 automatically.
6969
Transport http.RoundTripper
70+
// DontFollowRedirect; if set, redirect will not be followed, response from the initial request will be returned without an error
71+
// DontFollowRedirect takes precendance over FailOnRedirect.
72+
DontFollowRedirect bool
7073
// FailOnRedirect; if set, redirect will not be followed, instead the status code is returned as error
7174
FailOnRedirect bool
7275
// Cluster configuration settings
@@ -137,7 +140,11 @@ func newHTTPConnection(endpoint string, config ConnectionConfig) (driver.Connect
137140
httpClient := &http.Client{
138141
Transport: config.Transport,
139142
}
140-
if config.FailOnRedirect {
143+
if config.DontFollowRedirect {
144+
httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
145+
return http.ErrUseLastResponse // Do not wrap, standard library will not understand
146+
}
147+
} else if config.FailOnRedirect {
141148
httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error {
142149
return driver.ArangoError{
143150
HasError: true,

examples/nodeport-cluster.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ spec:
77
app: arangodb
88
role: coordinator
99
type: NodePort
10+
publishNotReadyAddresses: true
1011
ports:
1112
- protocol: TCP
1213
port: 8529

examples/simple-cluster.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ metadata:
44
name: "example-simple-cluster"
55
spec:
66
mode: cluster
7+
image: arangodb/arangodb:3.3.4
8+
tls:
9+
altNames: ["kube-01", "kube-02", "kube-03"]
10+
coordinators:
11+
args:
12+
- --log.level=true

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func newOperatorConfigAndDeps(id, namespace, name string) (operator.Config, oper
186186
CreateCRD: operatorOptions.createCRD,
187187
}
188188
deps := operator.Dependencies{
189-
Log: logService.MustGetLogger("operator"),
189+
LogService: logService,
190190
KubeCli: kubecli,
191191
KubeExtCli: kubeExtCli,
192192
CRCli: crCli,

pkg/apis/deployment/v1alpha/authentication_spec.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,29 @@ package v1alpha
2525
import (
2626
"github.com/pkg/errors"
2727

28+
"github.com/arangodb/kube-arangodb/pkg/util"
2829
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
2930
)
3031

3132
// AuthenticationSpec holds authentication specific configuration settings
3233
type AuthenticationSpec struct {
33-
JWTSecretName string `json:"jwtSecretName,omitempty"`
34+
JWTSecretName *string `json:"jwtSecretName,omitempty"`
3435
}
3536

3637
const (
3738
// JWTSecretNameDisabled is the value of JWTSecretName to use for disabling authentication.
3839
JWTSecretNameDisabled = "None"
3940
)
4041

42+
// GetJWTSecretName returns the value of jwtSecretName.
43+
func (s AuthenticationSpec) GetJWTSecretName() string {
44+
return util.StringOrDefault(s.JWTSecretName)
45+
}
46+
4147
// IsAuthenticated returns true if authentication is enabled.
4248
// Returns false other (when JWTSecretName == "None").
4349
func (s AuthenticationSpec) IsAuthenticated() bool {
44-
return s.JWTSecretName != JWTSecretNameDisabled
50+
return s.GetJWTSecretName() != JWTSecretNameDisabled
4551
}
4652

4753
// Validate the given spec
@@ -50,7 +56,7 @@ func (s AuthenticationSpec) Validate(required bool) error {
5056
return maskAny(errors.Wrap(ValidationError, "JWT secret is required"))
5157
}
5258
if s.IsAuthenticated() {
53-
if err := k8sutil.ValidateResourceName(s.JWTSecretName); err != nil {
59+
if err := k8sutil.ValidateResourceName(s.GetJWTSecretName()); err != nil {
5460
return maskAny(err)
5561
}
5662
}
@@ -59,8 +65,17 @@ func (s AuthenticationSpec) Validate(required bool) error {
5965

6066
// SetDefaults fills in missing defaults
6167
func (s *AuthenticationSpec) SetDefaults(defaultJWTSecretName string) {
62-
if s.JWTSecretName == "" {
63-
s.JWTSecretName = defaultJWTSecretName
68+
if s.GetJWTSecretName() == "" {
69+
// Note that we don't check for nil here, since even a specified, but empty
70+
// string should result in the default value.
71+
s.JWTSecretName = util.NewString(defaultJWTSecretName)
72+
}
73+
}
74+
75+
// SetDefaultsFrom fills unspecified fields with a value from given source spec.
76+
func (s *AuthenticationSpec) SetDefaultsFrom(source AuthenticationSpec) {
77+
if s.JWTSecretName == nil {
78+
s.JWTSecretName = util.NewStringOrNil(source.JWTSecretName)
6479
}
6580
}
6681

@@ -71,7 +86,7 @@ func (s AuthenticationSpec) ResetImmutableFields(fieldPrefix string, target *Aut
7186
var resetFields []string
7287
if s.IsAuthenticated() != target.IsAuthenticated() {
7388
// Note: You can change the name, but not from empty to non-empty (or reverse).
74-
target.JWTSecretName = s.JWTSecretName
89+
target.JWTSecretName = util.NewStringOrNil(s.JWTSecretName)
7590
resetFields = append(resetFields, fieldPrefix+".jwtSecretName")
7691
}
7792
return resetFields

pkg/apis/deployment/v1alpha/authentication_spec_test.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,24 @@ package v1alpha
2525
import (
2626
"testing"
2727

28+
"github.com/arangodb/kube-arangodb/pkg/util"
2829
"github.com/stretchr/testify/assert"
2930
)
3031

3132
func TestAuthenticationSpecValidate(t *testing.T) {
3233
// Valid
33-
assert.Nil(t, AuthenticationSpec{JWTSecretName: "None"}.Validate(false))
34-
assert.Nil(t, AuthenticationSpec{JWTSecretName: "foo"}.Validate(false))
35-
assert.Nil(t, AuthenticationSpec{JWTSecretName: "foo"}.Validate(true))
34+
assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewString("None")}.Validate(false))
35+
assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewString("foo")}.Validate(false))
36+
assert.Nil(t, AuthenticationSpec{JWTSecretName: util.NewString("foo")}.Validate(true))
3637

3738
// Not valid
38-
assert.Error(t, AuthenticationSpec{JWTSecretName: "Foo"}.Validate(false))
39+
assert.Error(t, AuthenticationSpec{JWTSecretName: util.NewString("Foo")}.Validate(false))
3940
}
4041

4142
func TestAuthenticationSpecIsAuthenticated(t *testing.T) {
42-
assert.False(t, AuthenticationSpec{JWTSecretName: "None"}.IsAuthenticated())
43-
assert.True(t, AuthenticationSpec{JWTSecretName: "foo"}.IsAuthenticated())
44-
assert.True(t, AuthenticationSpec{JWTSecretName: ""}.IsAuthenticated())
43+
assert.False(t, AuthenticationSpec{JWTSecretName: util.NewString("None")}.IsAuthenticated())
44+
assert.True(t, AuthenticationSpec{JWTSecretName: util.NewString("foo")}.IsAuthenticated())
45+
assert.True(t, AuthenticationSpec{JWTSecretName: util.NewString("")}.IsAuthenticated())
4546
}
4647

4748
func TestAuthenticationSpecSetDefaults(t *testing.T) {
@@ -50,8 +51,8 @@ func TestAuthenticationSpecSetDefaults(t *testing.T) {
5051
return spec
5152
}
5253

53-
assert.Equal(t, "test-jwt", def(AuthenticationSpec{}).JWTSecretName)
54-
assert.Equal(t, "foo", def(AuthenticationSpec{JWTSecretName: "foo"}).JWTSecretName)
54+
assert.Equal(t, "test-jwt", def(AuthenticationSpec{}).GetJWTSecretName())
55+
assert.Equal(t, "foo", def(AuthenticationSpec{JWTSecretName: util.NewString("foo")}).GetJWTSecretName())
5556
}
5657

5758
func TestAuthenticationSpecResetImmutableFields(t *testing.T) {
@@ -63,35 +64,35 @@ func TestAuthenticationSpecResetImmutableFields(t *testing.T) {
6364
}{
6465
// Valid "changes"
6566
{
66-
AuthenticationSpec{JWTSecretName: "None"},
67-
AuthenticationSpec{JWTSecretName: "None"},
68-
AuthenticationSpec{JWTSecretName: "None"},
67+
AuthenticationSpec{JWTSecretName: util.NewString("None")},
68+
AuthenticationSpec{JWTSecretName: util.NewString("None")},
69+
AuthenticationSpec{JWTSecretName: util.NewString("None")},
6970
nil,
7071
},
7172
{
72-
AuthenticationSpec{JWTSecretName: "foo"},
73-
AuthenticationSpec{JWTSecretName: "foo"},
74-
AuthenticationSpec{JWTSecretName: "foo"},
73+
AuthenticationSpec{JWTSecretName: util.NewString("foo")},
74+
AuthenticationSpec{JWTSecretName: util.NewString("foo")},
75+
AuthenticationSpec{JWTSecretName: util.NewString("foo")},
7576
nil,
7677
},
7778
{
78-
AuthenticationSpec{JWTSecretName: "foo"},
79-
AuthenticationSpec{JWTSecretName: "foo2"},
80-
AuthenticationSpec{JWTSecretName: "foo2"},
79+
AuthenticationSpec{JWTSecretName: util.NewString("foo")},
80+
AuthenticationSpec{JWTSecretName: util.NewString("foo2")},
81+
AuthenticationSpec{JWTSecretName: util.NewString("foo2")},
8182
nil,
8283
},
8384

8485
// Invalid changes
8586
{
86-
AuthenticationSpec{JWTSecretName: "foo"},
87-
AuthenticationSpec{JWTSecretName: "None"},
88-
AuthenticationSpec{JWTSecretName: "foo"},
87+
AuthenticationSpec{JWTSecretName: util.NewString("foo")},
88+
AuthenticationSpec{JWTSecretName: util.NewString("None")},
89+
AuthenticationSpec{JWTSecretName: util.NewString("foo")},
8990
[]string{"test.jwtSecretName"},
9091
},
9192
{
92-
AuthenticationSpec{JWTSecretName: "None"},
93-
AuthenticationSpec{JWTSecretName: "foo"},
94-
AuthenticationSpec{JWTSecretName: "None"},
93+
AuthenticationSpec{JWTSecretName: util.NewString("None")},
94+
AuthenticationSpec{JWTSecretName: util.NewString("foo")},
95+
AuthenticationSpec{JWTSecretName: util.NewString("None")},
9596
[]string{"test.jwtSecretName"},
9697
},
9798
}

pkg/apis/deployment/v1alpha/conditions.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const (
3535
ConditionTypeReady ConditionType = "Ready"
3636
// ConditionTypeTerminated indicates that the member has terminated and will not restart.
3737
ConditionTypeTerminated ConditionType = "Terminated"
38+
// ConditionTypeAutoUpgrade indicates that the member has to be started with `--database.auto-upgrade` once.
39+
ConditionTypeAutoUpgrade ConditionType = "AutoUpgrade"
3840
)
3941

4042
// Condition represents one current condition of a deployment or deployment member.

pkg/apis/deployment/v1alpha/deployment_mode.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,27 @@ func (m DeploymentMode) HasCoordinators() bool {
7373
func (m DeploymentMode) SupportsSync() bool {
7474
return m == DeploymentModeCluster
7575
}
76+
77+
// NewMode returns a reference to a string with given value.
78+
func NewMode(input DeploymentMode) *DeploymentMode {
79+
return &input
80+
}
81+
82+
// NewModeOrNil returns nil if input is nil, otherwise returns a clone of the given value.
83+
func NewModeOrNil(input *DeploymentMode) *DeploymentMode {
84+
if input == nil {
85+
return nil
86+
}
87+
return NewMode(*input)
88+
}
89+
90+
// ModeOrDefault returns the default value (or empty string) if input is nil, otherwise returns the referenced value.
91+
func ModeOrDefault(input *DeploymentMode, defaultValue ...DeploymentMode) DeploymentMode {
92+
if input == nil {
93+
if len(defaultValue) > 0 {
94+
return defaultValue[0]
95+
}
96+
return ""
97+
}
98+
return *input
99+
}

0 commit comments

Comments
 (0)