Skip to content

Commit 6712304

Browse files
authored
[Feature] Add ArangoTask API (#935)
1 parent a117bdb commit 6712304

Some content is hidden

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

46 files changed

+2284
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- (Feature) (ACS) Add ACS handler
1010
- (Feature) Allow to restart DBServers in cases when WriteConcern will be satisfied
1111
- (Feature) Allow to configure action timeouts
12+
- (Feature) (AT) Add ArangoTask API
1213

1314
## [1.2.8](https://github.com/arangodb/kube-arangodb/tree/1.2.8) (2022-02-24)
1415
- Do not check License V2 on Community images

chart/kube-arangodb/templates/crd/cluster-role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rules:
1818
verbs: ["get", "list", "watch", "update", "delete"]
1919
resourceNames:
2020
- "arangoclustersynchronizations.database.arangodb.com"
21+
- "arangotasks.database.arangodb.com"
2122

2223
{{- end }}
2324
{{- end }}

chart/kube-arangodb/templates/deployment-operator/role.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ metadata:
1414
release: {{ .Release.Name }}
1515
rules:
1616
- apiGroups: ["database.arangodb.com"]
17-
resources: ["arangodeployments", "arangodeployments/status","arangomembers", "arangomembers/status", "arangoclustersynchronizations", "arangoclustersynchronizations/status"]
17+
resources: ["arangodeployments", "arangodeployments/status","arangomembers", "arangomembers/status", "arangoclustersynchronizations", "arangoclustersynchronizations/status", "arangotasks", "arangotasks/status"]
1818
verbs: ["*"]
1919
- apiGroups: [""]
2020
resources: ["pods", "services", "endpoints", "persistentvolumeclaims", "events", "secrets", "serviceaccounts"]

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
github.com/arangodb/go-driver v1.2.1
2929
github.com/arangodb/go-driver/v2 v2.0.0-20211021031401-d92dcd5a4c83
3030
github.com/arangodb/go-upgrade-rules v0.0.0-20180809110947-031b4774ff21
31+
github.com/arangodb/rebalancer v0.1.1
3132
github.com/cenkalti/backoff v2.2.1+incompatible
3233
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9
3334
github.com/ghodss/yaml v1.0.0
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
)
26+
27+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
28+
29+
// ArangoTaskList is a list of ArangoDB tasks.
30+
type ArangoTaskList struct {
31+
meta.TypeMeta `json:",inline"`
32+
// Standard list metadata
33+
// More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
34+
meta.ListMeta `json:"metadata,omitempty"`
35+
Items []ArangoTask `json:"items"`
36+
}
37+
38+
// +genclient
39+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
40+
41+
// ArangoTask contains task definition info.
42+
type ArangoTask struct {
43+
meta.TypeMeta `json:",inline"`
44+
meta.ObjectMeta `json:"metadata,omitempty"`
45+
Spec ArangoTaskSpec `json:"spec,omitempty"`
46+
Status ArangoTaskStatus `json:"status,omitempty"`
47+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 "encoding/json"
24+
25+
type ArangoTaskType string
26+
27+
type ArangoTaskDetails []byte
28+
29+
func (a ArangoTaskDetails) MarshalJSON() ([]byte, error) {
30+
d := make([]byte, len(a))
31+
32+
copy(d, a)
33+
34+
return d, nil
35+
}
36+
37+
func (a *ArangoTaskDetails) UnmarshalJSON(bytes []byte) error {
38+
var i interface{}
39+
40+
if err := json.Unmarshal(bytes, &i); err != nil {
41+
return err
42+
}
43+
44+
d := make([]byte, len(bytes))
45+
46+
copy(d, bytes)
47+
48+
*a = d
49+
50+
return nil
51+
}
52+
53+
func (a ArangoTaskDetails) Get(i interface{}) error {
54+
return json.Unmarshal(a, &i)
55+
}
56+
57+
func (a *ArangoTaskDetails) Set(i interface{}) error {
58+
if d, err := json.Marshal(i); err != nil {
59+
return err
60+
} else {
61+
*a = d
62+
}
63+
64+
return nil
65+
}
66+
67+
var _ json.Unmarshaler = &ArangoTaskDetails{}
68+
var _ json.Marshaler = ArangoTaskDetails{}
69+
70+
type ArangoTaskSpec struct {
71+
Type ArangoTaskType `json:"type,omitempty"`
72+
73+
Details ArangoTaskDetails `json:"details,omitempty"`
74+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
type ArangoTaskState string
24+
25+
const (
26+
ArangoTaskUnknownState ArangoTaskState = ""
27+
ArangoTaskPendingState ArangoTaskState = "Pending"
28+
ArangoTaskRunningState ArangoTaskState = "Running"
29+
ArangoTaskSuccessState ArangoTaskState = "Success"
30+
ArangoTaskFailedState ArangoTaskState = "Failed"
31+
)
32+
33+
type ArangoTaskStatus struct {
34+
AcceptedSpec *ArangoTaskSpec `json:"acceptedSpec,omitempty"`
35+
36+
State ArangoTaskState `json:"state,omitempty"`
37+
Details ArangoTaskDetails `json:"details,omitempty"`
38+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
"encoding/json"
25+
"reflect"
26+
"testing"
27+
28+
"github.com/stretchr/testify/require"
29+
)
30+
31+
func Test_ArangoTask_Details(t *testing.T) {
32+
arangoTaskDetails(t, int(5))
33+
arangoTaskDetails(t, "test")
34+
arangoTaskDetails(t, []interface{}{"data", "two"})
35+
arangoTaskDetails(t, map[string]interface{}{
36+
"data": "exp",
37+
})
38+
}
39+
40+
func arangoTaskDetails(t *testing.T, obj interface{}) {
41+
arangoTaskDetailsExp(t, obj, obj)
42+
}
43+
44+
func arangoTaskDetailsExp(t *testing.T, obj, exp interface{}) {
45+
t.Run(reflect.TypeOf(obj).String(), func(t *testing.T) {
46+
var d ArangoTaskDetails
47+
48+
require.NoError(t, d.Set(obj))
49+
50+
b, err := json.Marshal(d)
51+
require.NoError(t, err)
52+
53+
var n ArangoTaskDetails
54+
require.NoError(t, json.Unmarshal(b, &n))
55+
56+
require.NoError(t, n.Get(&exp))
57+
58+
require.EqualValues(t, obj, exp)
59+
})
60+
}

pkg/apis/deployment/v1/register.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func addKnownTypes(s *runtime.Scheme) error {
5252
&ArangoMemberList{},
5353
&ArangoClusterSynchronization{},
5454
&ArangoClusterSynchronizationList{},
55+
&ArangoTask{},
56+
&ArangoTaskList{},
5557
)
5658
metav1.AddToGroupVersion(s, SchemeGroupVersion)
5759
return nil

0 commit comments

Comments
 (0)