8000 [Feature] [ACS] Add resource plan (#986) · sharekey/kube-arangodb@d56e3f9 · GitHub
[go: up one dir, main page]

8000 Skip to content

Commit d56e3f9

Browse files
authored
[Feature] [ACS] Add resource plan (arangodb#986)
1 parent 4229258 commit d56e3f9

15 files changed

+263
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- (Bugfix) Fix arangosync members state inspection
55
- (Feature) (ACS) Improve Reconciliation Loop
66
- (Bugfix) Allow missing Monitoring CRD
7+
- (Feature) (ACS) Add Resource plan
78

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

pkg/apis/deployment/v1/deployment_status.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ type DeploymentStatus struct {
6464
// HighPriorityPlan to update this deployment. Executed before plan
6565
HighPriorityPlan Plan `json:"highPriorityPlan,omitempty"`
6666

67+
// ResourcesPlan to update this deployment. Executed before plan, after highPlan
68+
ResourcesPlan Plan `json:"resourcesPlan,omitempty"`
69+
6770
// AcceptedSpec contains the last specification that was accepted by the operator.
6871
AcceptedSpec *DeploymentSpec `json:"accepted-spec,omitempty"`
6972

@@ -103,6 +106,8 @@ func (ds *DeploymentStatus) Equal(other DeploymentStatus) bool {
103106
ds.Members.Equal(other.Members) &&
104107
ds.Conditions.Equal(other.Conditions) &&
105108
ds.Plan.Equal(other.Plan) &&
109+
ds.HighPriorityPlan.Equal(other.HighPriorityPlan) &&
110+
ds.ResourcesPlan.Equal(other.ResourcesPlan) &&
106111
ds.AcceptedSpec.Equal(other.AcceptedSpec) &&
107112
ds.SecretHashes.Equal(other.SecretHashes) &&
108113
ds.Agency.Equal(other.Agency) &&

pkg/apis/deployment/v1/plan.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ const (
192192
// Rebalancer
193193
ActionTypeRebalancerGenerate ActionType = "RebalancerGenerate"
194194
ActionTypeRebalancerCheck ActionType = "RebalancerCheck"
195+
196+
// Resources
197+
ActionTypeResourceSync ActionType = "ResourceSync"
195198
)
196199

197200
const (

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

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

pkg/apis/deployment/v2alpha1/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 v2alpha1
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 v2alpha1
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/v2alpha1/cluster_synchronization_status.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ package v2alpha1
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/v2alpha1/deployment_status.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ type DeploymentStatus struct {
6464
// HighPriorityPlan to update this deployment. Executed before plan
6565
HighPriorityPlan Plan `json:"highPriorityPlan,omitempty"`
6666

67+
// ResourcesPlan to update this deployment. Executed before plan, after highPlan
68+
ResourcesPlan Plan `json:"resourcesPlan,omitempty"`
69+
6770
// AcceptedSpec contains the last specification that was accepted by the operator.
6871
AcceptedSpec *DeploymentSpec `json:"accepted-spec,omitempty"`
6972

@@ -103,6 +106,8 @@ func (ds *DeploymentStatus) Equal(other DeploymentStatus) bool {
103106
ds.Members.Equal(other.Members) &&
104107
ds.Conditions.Equal(other.Conditions) &&
105108
ds.Plan.Equal(other.Plan) &&
109+
ds.HighPriorityPlan.Equal(other.HighPriorityPlan) &&
110+
ds.ResourcesPlan.Equal(other.ResourcesPlan) &&
106111
ds.AcceptedSpec.Equal(other.AcceptedSpec) &&
107112
ds.SecretHashes.Equal(other.SecretHashes) &&
108113
ds.Agency.Equal(other.Agency) &&

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

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

pkg/deployment/acs/acs.community.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,39 @@ import (
2828
"github.com/arangodb/kube-arangodb/pkg/deployment/acs/sutil"
2929
inspectorInterface "github.com/arangodb/kube-arangodb/pkg/util/k8sutil/inspector"
3030
"github.com/arangodb/kube-arangodb/pkg/util/kclient"
31+
"k8s.io/apimachinery/pkg/types"
3132
)
3233

33-
func NewACS() sutil.ACS {
34-
return acs{}
34+
func NewACS(main types.UID, cache inspectorInterface.Inspector) sutil.ACS {
35+
return acs{
36+
main: main,
37+
cache: cache,
38+
}
3539
}
3640

3741
type acs struct {
42+
main types.UID
43+
cache inspectorInterface.Inspector
44+
}
45+
46+
func (a acs) UID() types.UID {
47+
return a.main
48+
}
49+
50+
func (a acs) Cache() inspectorInterface.Inspector {
51+
return a.cache
52+
}
53+
54+
func (a acs) Cluster(uid types.UID) (sutil.ACSItem, bool) {
55+
if a.main == uid || uid == "" {
56+
return a, true
57+
}
58+
59+
return nil, false
60+
}
61+
62+
func (a acs) RemoteClusters() []types.UID {
63+
return nil
3864
}
3965

4066
func (a acs) Inspect(ctx context.Context, deployment *api.ArangoDeployment, client kclient.Client, cachedStatus inspectorInterface.Inspector) error {

0 commit comments

Comments
 (0)
0