Skip to content

Commit 1b66d2e

Browse files
authored
ArangoJob model (#833)
* ArangoJob model * Update Makefile
1 parent efb5d3f commit 1b66d2e

26 files changed

+1290
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ update-generated:
219219
"all" \
220220
"github.com/arangodb/kube-arangodb/pkg/generated" \
221221
"github.com/arangodb/kube-arangodb/pkg/apis" \
222-
"deployment:v1 replication:v1 storage:v1alpha backup:v1 deployment:v2alpha1 replication:v2alpha1" \
222+
"deployment:v1 replication:v1 storage:v1alpha backup:v1 deployment:v2alpha1 replication:v2alpha1 apps:v1" \
223223
--go-header-file "./tools/codegen/boilerplate.go.txt" \
224224
$(VERIFYARGS)
225225
GOPATH=$(GOBUILDDIR) $(VENDORDIR)/k8s.io/code-generator/generate-groups.sh \

pkg/apis/apps/definitions.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2021 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+
// Author Jakub Wierzbowski
21+
//
22+
23+
package apps
24+
25+
const (
26+
ArangoJobCRDName = ArangoJobResourcePlural + "." + ArangoAppsGroupName
27+
ArangoJobResourceKind = "ArangoJob"
28+
ArangoJobResourcePlural = "arangojobs"
29+
30+
ArangoAppsGroupName = "apps.arangodb.com"
31+
)
32+
33+
var (
34+
ArangoJobShortNames = []string{"arangojob"}
35+
)

pkg/apis/apps/v1/doc.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2021 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+
// Author Jakub Wierzbowski
21+
//
22+
23+
// +k8s:deepcopy-gen=package
24+
// +groupName=apps.arangodb.com
25+
package v1

pkg/apis/apps/v1/job.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2021 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+
// Author Jakub Wierzbowski
21+
//
22+
23+
package v1
24+
25+
import (
26+
"github.com/arangodb/kube-arangodb/pkg/apis/apps"
27+
28+
batchv1 "k8s.io/api/batch/v1"
29+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
)
31+
32+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
33+
34+
// ArangoJobList is a list of ArangoDB jobs.
35+
type ArangoJobList struct {
36+
metav1.TypeMeta `json:",inline"`
37+
metav1.ListMeta `json:"metadata,omitempty"`
38+
39+
Items []ArangoJob `json:"items"`
40+
}
41+
42+
// +genclient
43+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
44+
45+
// ArangoJob contains definition and status of the ArangoDB type Job.
46+
type ArangoJob struct {
47+
metav1.TypeMeta `json:",inline"`
48+
metav1.ObjectMeta `json:"metadata,omitempty"`
49+
Spec ArangoJobSpec `json:"spec,omitempty"`
50+
Status batchv1.JobStatus `json:"status,omitempty"`
51+
}
52+
53+
// AsOwner creates an OwnerReference for the given job
54+
func (a *ArangoJob) AsOwner() metav1.OwnerReference {
55+
trueVar := true
56+
return metav1.OwnerReference{
57+
APIVersion: SchemeGroupVersion.String(),
58+
Kind: apps.ArangoJobResourceKind,
59+
Name: a.Name,
60+
UID: a.UID,
61+
Controller: &trueVar,
62+
}
63+
}

pkg/apis/apps/v1/job_spec.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2021 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+
// Author Jakub Wierzbowski
21+
//
22+
23+
package v1
24+
25+
import batchv1 "k8s.io/api/batch/v1"
26+
27+
type ArangoJobSpec struct {
28+
ArangoDeploymentName string `json:"arangoDeploymentName"`
29+
JobTemplate *batchv1.JobSpec `json:"jobTemplate,omitempty"`
30+
}

pkg/apis/apps/v1/job_validate.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2021 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+
// Author Jakub Wierzbowski
21+
//
22+
23+
package v1
24+
25+
import "github.com/arangodb/kube-arangodb/pkg/util/errors"
26+
27+
func (a *ArangoJob) Validate() error {
28+
if err := a.Spec.Validate(); err != nil {
29+
return err
30+
}
31+
32+
return nil
33+
}
34+
35+
func (a *ArangoJobSpec) Validate() error {
36+
if a.ArangoDeploymentName == "" {
37+
return errors.Newf("deployment name can not be empty")
38+
}
39+
40+
if a.JobTemplate == nil {
41+
return errors.Newf("jobTemplate name can not be empty")
42+
}
43+
44+
return nil
45+
}

pkg/apis/apps/v1/register.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2021 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+
// Author Jakub Wierzbowski
21+
//
22+
23+
package v1
24+
25+
import (
26+
"github.com/arangodb/kube-arangodb/pkg/apis/apps"
27+
28+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/runtime"
30+
"k8s.io/apimachinery/pkg/runtime/schema"
31+
)
32+
33+
const (
34+
ArangoAppsVersion = "v1"
35+
)
36+
37+
var (
38+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
39+
AddToScheme = SchemeBuilder.AddToScheme
40+
41+
SchemeGroupVersion = schema.GroupVersion{Group: apps.ArangoAppsGroupName, Version: ArangoAppsVersion}
42+
)
43+
44+
// Resource gets an ArangoCluster GroupResource for a specified resource
45+
func Resource(resource string) schema.GroupResource {
46+
return SchemeGroupVersion.WithResource(resource).GroupResource()
47+
}
48+
49+
// addKnownTypes adds the set of types defined in this package to the supplied scheme.
50+
func addKnownTypes(s *runtime.Scheme) error {
51+
s.AddKnownTypes(SchemeGroupVersion,
52+
&ArangoJob{},
53+
&ArangoJobList{},
54+
)
55+
metav1.AddToGroupVersion(s, SchemeGroupVersion)
56+
return nil
57+
}

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

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

0 commit comments

Comments
 (0)