Skip to content

Commit 5f283cd

Browse files
authored
[Feature] [ACS] Improve Reconciliation loop (#983)
1 parent 9d9d5e2 commit 5f283cd

File tree

13 files changed

+234
-23
lines changed

13 files changed

+234
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Bugfix) Fix arangosync members state inspection
5+
- (Feature) (ACS) Improve Reconciliation Loop
56

67
## [1.2.12](https://github.com/arangodb/kube-arangodb/tree/1.2.12) (2022-05-10)
78
- (Feature) Add CoreV1 Endpoints Inspector

pkg/apis/deployment/v1/cluster_synchronization_spec.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
package v1
2222

23+
import (
24+
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
25+
"github.com/pkg/errors"
26+
)
27+
2328
type ArangoClusterSynchronizationSpec struct {
2429
DeploymentName string `json:"deploymentName,omitempty"`
2530
KubeConfig *ArangoClusterSynchronizationKubeConfigSpec `json:"kubeconfig,omitempty"`
@@ -30,3 +35,15 @@ type ArangoClusterSynchronizationKubeConfigSpec struct {
3035
SecretKey string `json:"secretKey"`
3136
Namespace string `json:"namespace"`
3237
}
38+
39+
func (a *ArangoClusterSynchronizationKubeConfigSpec) Validate() error {
40+
if a == nil {
41+
return errors.Errorf("KubeConfig Spec cannot be nil")
42+
}
43+
44+
return shared.WithErrors(
45+
shared.PrefixResourceError("secretName", shared.ValidateResourceName(a.SecretName)),
46+
shared.PrefixResourceError("secretKey", shared.ValidateResourceName(a.SecretKey)),
47+
shared.PrefixResourceError("namespace", shared.ValidateResourceName(a.Namespace)),
48+
)
49+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package v1
22+
23+
import (
24+
"testing"
25+
26+
"github.com/pkg/errors"
27+
"github.com/stretchr/testify/require"
28+
)
29+
30+
func Test_ACS_KubeConfigSpec(t *testing.T) {
31+
test := func(t *testing.T, spec *ArangoClusterSynchronizationKubeConfigSpec, error error) {
32+
err := spec.Validate()
33+
34+
if error != nil {
35+
require.EqualError(t, err, error.Error())
36+
} else {
37+
require.NoError(t, err)
38+
}
39+
}
40+
41+
type testCase struct {
42+
spec *ArangoClusterSynchronizationKubeConfigSpec
43+
error string
44+
}
45+
46+
testCases := map[string]testCase{
47+
"Nil": {
48+
error: "KubeConfig Spec cannot be nil",
49+
},
50+
"Empty": {
51+
spec: &ArangoClusterSynchronizationKubeConfigSpec{},
52+
error: "Received 3 errors: secretName: Name '' is not a valid resource name, secretKey: Name '' is not a valid resource name, namespace: Name '' is not a valid resource name",
53+
},
54+
"Missing key & NS": {
55+
spec: &ArangoClusterSynchronizationKubeConfigSpec{
56+
SecretName: "secret",
57+
},
58+
error: "Received 2 errors: secretKey: Name '' is not a valid resource name, namespace: Name '' is not a valid resource name",
59+
},
60+
"Missing NS": {
61+
spec: &ArangoClusterSynchronizationKubeConfigSpec{
62+
SecretName: "secret",
63+
SecretKey: "key",
64+
},
65+
error: "Received 1 errors: namespace: Name '' is not a valid resource name",
66+
},
67+
"Valid": {
68+
spec: &ArangoClusterSynchronizationKubeConfigSpec{
69+
SecretName: "secret",
70+
SecretKey: "key",
71+
Namespace: "ns",
72+
},
73+
},
74+
"Invalid": {
75+
spec: &ArangoClusterSynchronizationKubeConfigSpec{
76+
SecretName: "secret_n",
77+
SecretKey: "key",
78+
Namespace: "ns",
79+
},
80+
error: "Received 1 errors: secretName: Name 'secret_n' is not a valid resource name",
81+
},
82+
}
83+
84+
for n, tc := range testCases {
85+
t.Run(n, func(t *testing.T) {
86+
var err error
87+
if tc.error != "" {
88+
err = errors.Errorf(tc.error)
89+
}
90+
test(t, tc.spec, err)
91+
})
92+
}
93+
}

pkg/apis/deployment/v1/cluster_synchronization_status.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ package v1
2323
import "k8s.io/apimachinery/pkg/types"
2424

2525
type ArangoClusterSynchronizationStatus struct {
26-
Deployment *ArangoClusterSynchronizationDeploymentStatus `json:"deployment,omitempty"`
27-
Conditions ConditionList `json:"conditions,omitempty"`
26+
Deployment *ArangoClusterSynchronizationDeploymentStatus `json:"deployment,omitempty"`
27+
RemoteDeployment *ArangoClusterSynchronizationDeploymentStatus `json:"remoteDeployment,omitempty"`
28+
29+
Conditions ConditionList `json:"conditions,omitempty"`
2830
}
2931

3032
type ArangoClusterSynchronizationDeploymentStatus struct {

pkg/apis/deployment/v1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/shared/names_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package shared
22+
23+
import (
24+
"testing"
25+
26+
"github.com/stretchr/testify/require"
27+
)
28+
29+
func Test_Names(t *testing.T) {
30+
t.Run("Empty", func(t *testing.T) {
31+
require.EqualError(t, ValidateResourceName(""), "Name '' is not a valid resource name")
32+
})
33+
}

pkg/deployment/acs/sutil/conditions.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ package sutil
2323
import api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
2424

2525
const (
26-
DeploymentReadyCondition api.ConditionType = "DeploymentReady"
27-
KubernetesConnectedCondition api.ConditionType = "KubernetesConnected"
26+
DeploymentReadyCondition api.ConditionType = "DeploymentReady"
27+
KubernetesConnectedCondition api.ConditionType = "KubernetesConnected"
28+
RemoteDeploymentReadyCondition api.ConditionType = "RemoteDeploymentReadyCondition"
29+
RemoteCacheReadyCondition api.ConditionType = "RemoteCacheReady"
30+
ConnectionReadyCondition api.ConditionType = "ConnectionReady"
2831
)

pkg/deployment/deployment.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ import (
6363
"github.com/arangodb/kube-arangodb/pkg/deployment/resources"
6464
"github.com/arangodb/kube-arangodb/pkg/util"
6565
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil"
66-
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle"
6766
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
6867
"github.com/arangodb/kube-arangodb/pkg/util/trigger"
6968
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -217,22 +216,6 @@ func (d *Deployment) SetAgencyMaintenanceMode(ctx context.Context, enabled bool)
217216
return nil
218217
}
219218

220-
func newDeploymentThrottle() throttle.Components {
221-
return throttle.NewThrottleComponents(
222-
30*time.Second, // ArangoDeploymentSynchronization
223-
30*time.Second, // ArangoMember
224-
30*time.Second, // ArangoTask
225-
30*time.Second, // Node
226-
15*time.Second, // PVC
227-
time.Second, // Pod
228-
30*time.Second, // PDB
229-
10*time.Second, // Secret
230-
10*time.Second, // Service
231-
30*time.Second, // SA
232-
30*time.Second, // ServiceMonitor
233-
15*time.Second) // Endpoints
234-
}
235-
236219
// New creates a new Deployment from the given API object.
237220
func New(config Config, deps Dependencies, apiObject *api.ArangoDeployment) (*Deployment, error) {
238221
if err := apiObject.Spec.Validate(); err != nil {
@@ -248,7 +231,7 @@ func New(config Config, deps Dependencies, apiObject *api.ArangoDeployment) (*De
248231
eventCh: make(chan *deploymentEvent, deploymentEventQueueSize),
249232
stopCh: make(chan struct{}),
250233
agencyCache: agency.NewCache(apiObject.Spec.Mode),
251-
currentState: inspector.NewInspector(newDeploymentThrottle(), deps.Client, apiObject.GetNamespace(), apiObject.GetName()),
234+
currentState: inspector.NewInspector(inspector.NewDefaultThrottle(), deps.Client, apiObject.GetNamespace(), apiObject.GetName()),
252235
acs: acs.NewACS(),
253236
}
254237

pkg/deployment/resources/inspector/inspector.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ func (i *inspectorState) Client() kclient.Client {
245245
return i.client
246246
}
247247

248+
func (i *inspectorState) SetClient(k kclient.Client) {
249+
i.lock.Lock()
250+
defer i.lock.Unlock()
251+
252+
i.client = k
253+
}
254+
248255
func (i *inspectorState) Namespace() string {
249256
return i.namespace
250257
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package inspector
22+
23+
import (
24+
"time"
25+
26+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector/throttle"
27+
)
28+
29+
func NewDefaultThrottle() throttle.Components {
30+
return throttle.NewThrottleComponents(
31+
30*time.Second, // ArangoDeploymentSynchronization
32+
30*time.Second, // ArangoMember
33+
30*time.Second, // ArangoTask
34+
30*time.Second, // Node
35+
15*time.Second, // PVC
36+
time.Second, // Pod
37+
30*time.Second, // PDB
38+
10*time.Second, // Secret
39+
10*time.Second, // Service
40+
30*time.Second, // SA
41+
30*time.Second, // ServiceMonitor
42+
15*time.Second) // Endpoints
43+
}

0 commit comments

Comments
 (0)