Skip to content

ArangoJob model #833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ update-generated:
"all" \
"github.com/arangodb/kube-arangodb/pkg/generated" \
"github.com/arangodb/kube-arangodb/pkg/apis" \
"deployment:v1 replication:v1 storage:v1alpha backup:v1 deployment:v2alpha1 replication:v2alpha1" \
"deployment:v1 replication:v1 storage:v1alpha backup:v1 deployment:v2alpha1 replication:v2alpha1 apps:v1" \
--go-header-file "./tools/codegen/boilerplate.go.txt" \
$(VERIFYARGS)
GOPATH=$(GOBUILDDIR) $(VENDORDIR)/k8s.io/code-generator/generate-groups.sh \
Expand Down
35 changes: 35 additions & 0 deletions pkg/apis/apps/definitions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// DISCLAIMER
//
// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Jakub Wierzbowski
//

package apps

const (
ArangoJobCRDName = ArangoJobResourcePlural + "." + ArangoAppsGroupName
ArangoJobResourceKind = "ArangoJob"
ArangoJobResourcePlural = "arangojobs"

ArangoAppsGroupName = "apps.arangodb.com"
)

var (
ArangoJobShortNames = []string{"arangojob"}
)
25 changes: 25 additions & 0 deletions pkg/apis/apps/v1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// DISCLAIMER
//
// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Jakub Wierzbowski
//

// +k8s:deepcopy-gen=package
// +groupName=apps.arangodb.com
package v1
63 changes: 63 additions & 0 deletions pkg/apis/apps/v1/job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// DISCLAIMER
//
// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Jakub Wierzbowski
//

package v1

import (
"github.com/arangodb/kube-arangodb/pkg/apis/apps"

batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ArangoJobList is a list of ArangoDB jobs.
type ArangoJobList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []ArangoJob `json:"items"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ArangoJob contains definition and status of the ArangoDB type Job.
type ArangoJob struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ArangoJobSpec `json:"spec,omitempty"`
Status batchv1.JobStatus `json:"status,omitempty"`
}

// AsOwner creates an OwnerReference for the given job
func (a *ArangoJob) AsOwner() metav1.OwnerReference {
trueVar := true
return metav1.OwnerReference{
APIVersion: SchemeGroupVersion.String(),
Kind: apps.ArangoJobResourceKind,
Name: a.Name,
UID: a.UID,
Controller: &trueVar,
}
}
30 changes: 30 additions & 0 deletions pkg/apis/apps/v1/job_spec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// DISCLAIMER
//
// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Jakub Wierzbowski
//

package v1

import batchv1 "k8s.io/api/batch/v1"

type ArangoJobSpec struct {
ArangoDeploymentName string `json:"arangoDeploymentName"`
JobTemplate *batchv1.JobSpec `json:"jobTemplate,omitempty"`
}
45 changes: 45 additions & 0 deletions pkg/apis/apps/v1/job_validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// DISCLAIMER
//
// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Jakub Wierzbowski
//

package v1

import "github.com/arangodb/kube-arangodb/pkg/util/errors"

func (a *ArangoJob) Validate() error {
if err := a.Spec.Validate(); err != nil {
return err
}

return nil
}

func (a *ArangoJobSpec) Validate() error {
if a.ArangoDeploymentName == "" {
return errors.Newf("deployment name can not be empty")
}

if a.JobTemplate == nil {
return errors.Newf("jobTemplate name can not be empty")
}

return nil
}
57 changes: 57 additions & 0 deletions pkg/apis/apps/v1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// DISCLAIMER
//
// Copyright 2016-2021 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Jakub Wierzbowski
//

package v1

import (
"github.com/arangodb/kube-arangodb/pkg/apis/apps"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

const (
ArangoAppsVersion = "v1"
)

var (
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
AddToScheme = SchemeBuilder.AddToScheme

SchemeGroupVersion = schema.GroupVersion{Group: apps.ArangoAppsGroupName, Version: ArangoAppsVersion}
)

// Resource gets an ArangoCluster GroupResource for a specified resource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

// addKnownTypes adds the set of types defined in this package to the supplied scheme.
func addKnownTypes(s *runtime.Scheme) error {
s.AddKnownTypes(SchemeGroupVersion,
&ArangoJob{},
&ArangoJobList{},
)
metav1.AddToGroupVersion(s, SchemeGroupVersion)
return nil
}
112 changes: 112 additions & 0 deletions pkg/apis/apps/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading