Skip to content

Commit d2045e0

Browse files
authored
[Feature] Extract Scheduler API (#1599)
1 parent 5eb65d3 commit d2045e0

Some content is hidden

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

63 files changed

+2498
-1523
lines changed

.golangci.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ linters-settings:
4141
alias: policy
4242
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/shared/v1
4343
alias: sharedApi
44+
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1
45+
alias: schedulerApi
46+
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container
47+
alias: schedulerContainerApi
48+
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources
49+
alias: schedulerContainerResourcesApi
50+
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod
51+
alias: schedulerPodApi
52+
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod/resources
53+
alias: schedulerPodResourcesApi
4454
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/shared
4555
alias: shared
4656
- pkg: github.com/arangodb/kube-arangodb/pkg/handlers/enterprise/ml/shared

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
4+
- (Feature) Extract Scheduler API
45

56
## [1.2.38](https://github.com/arangodb/kube-arangodb/tree/1.2.38) (2024-02-22)
67
- (Feature) Extract GRPC Server

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,14 @@ update-generated:
431431
"client lister informer deepcopy" \
432432
"github.com/arangodb/kube-arangodb/pkg/generated" \
433433
"github.com/arangodb/kube-arangodb/pkg/apis" \
434-
"deployment:v1 replication:v1 storage:v1alpha backup:v1 deployment:v2alpha1 replication:v2alpha1 apps:v1 ml:v1alpha1" \
434+
"deployment:v1 replication:v1 storage:v1alpha backup:v1 deployment:v2alpha1 replication:v2alpha1 apps:v1 ml:v1alpha1 scheduler:v1alpha1" \
435435
--go-header-file "./tools/codegen/boilerplate.go.txt" \
436436
$(VERIFYARGS)
437437
GOPATH=$(GOBUILDDIR) $(VENDORDIR)/k8s.io/code-generator/generate-groups.sh \
438438
"deepcopy" \
439439
"github.com/arangodb/kube-arangodb/pkg/generated" \
440440
"github.com/arangodb/kube-arangodb/pkg/apis" \
441-
"shared:v1" \
441+
"shared:v1 scheduler:v1alpha1/container scheduler:v1alpha1/container/resources scheduler:v1alpha1/pod scheduler:v1alpha1/pod/resources" \
442442
--go-header-file "./tools/codegen/boilerplate.go.txt" \
443443
$(VERIFYARGS)
444444

docs/api/ArangoMLExtension.V1Alpha1.md

+286-286
Large diffs are not rendered by default.

docs/api/ArangoMLStorage.V1Alpha1.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Default Value: `9202`
116116

117117
### .spec.mode.sidecar.env
118118

119-
Type: `core.EnvVar` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/envs.go#L33)</sup>
119+
Type: `core.EnvVar` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/environments.go#L33)</sup>
120120

121121
Env keeps the information about environment variables provided to the container
122122

@@ -127,7 +127,7 @@ Links:
127127

128128
### .spec.mode.sidecar.envFrom
129129

130-
Type: `core.EnvFromSource` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/envs.go#L38)</sup>
130+
Type: `core.EnvFromSource` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/environments.go#L38)</sup>
131131

132132
EnvFrom keeps the information about environment variable sources provided to the container
133133

@@ -138,43 +138,43 @@ Links:
138138

139139
### .spec.mode.sidecar.image
140140

141-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/image.go#L31)</sup>
141+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/image.go#L34)</sup>
142142

143143
Image define image details
144144

145145
***
146146

147-
### .spec.mode.sidecar.listenPort
147+
### .spec.mode.sidecar.imagePullPolicy
148148

149-
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/ml/v1alpha1/storage_spec_mode_sidecar.go#L32)</sup>
149+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/image.go#L38)</sup>
150150

151-
ListenPort defines on which port the sidecar container will be listening for connections
151+
ImagePullPolicy define Image pull policy
152152

153-
Default Value: `9201`
153+
Default Value: `IfNotPresent`
154154

155155
***
156156

157-
### .spec.mode.sidecar.pullPolicy
158-
159-
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/image.go#L35)</sup>
157+
### .spec.mode.sidecar.imagePullSecrets
160158

161-
PullPolicy define Image pull policy
159+
Type: `array` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/image.go#L41)</sup>
162160

163-
Default Value: `IfNotPresent`
161+
ImagePullSecrets define Secrets used to pull Image from registry
164162

165163
***
166164

167-
### .spec.mode.sidecar.pullSecrets
165+
### .spec.mode.sidecar.listenPort
166+
167+
Type: `integer` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/ml/v1alpha1/storage_spec_mode_sidecar.go#L32)</sup>
168168

169-
Type: `array` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/image.go#L38)</sup>
169+
ListenPort defines on which port the sidecar container will be listening for connections
170170

171-
PullSecrets define Secrets used to pull Image from registry
171+
Default Value: `9201`
172172

173173
***
174174

175175
### .spec.mode.sidecar.resources
176176

177-
Type: `core.ResourceRequirements` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/resources.go#L34)</sup>
177+
Type: `core.ResourceRequirements` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/resources.go#L34)</sup>
178178

179179
Resources holds resource requests & limits for container
180180

@@ -185,7 +185,7 @@ Links:
185185

186186
### .spec.mode.sidecar.securityContext
187187

188-
Type: `core.SecurityContext` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/security_container.go#L29)</sup>
188+
Type: `core.SecurityContext` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/security.go#L31)</sup>
189189

190190
PodSecurityContext holds pod-level security attributes and common container settings.
191191

internal/docs_test.go

+94-48
Original file line numberDiff line numberDiff line change
@@ -137,72 +137,118 @@ func Test_GenerateAPIDocs(t *testing.T) {
137137

138138
fset := token.NewFileSet()
139139

140-
sharedFields := parseSourceFiles(t, root, fset, fmt.Sprintf("%s/pkg/apis/shared/v1", root))
140+
type inputPackageTypes map[string]map[string]any
141+
142+
type inputPackage struct {
143+
Types inputPackageTypes
144+
145+
Shared []string
146+
}
147+
148+
type inputPackages map[string]map[string]inputPackage
141149

142150
// package path -> result doc file name -> name of the top-level field to be described -> field instance for reflection
143-
input := map[string]map[string]map[string]interface{}{
144-
fmt.Sprintf("%s/pkg/apis/deployment/v1", root): {
145-
"ArangoDeployment.V1": {
146-
"Spec": deploymentApi.ArangoDeployment{}.Spec,
147-
},
148-
"ArangoMember.V1": {
149-
"Spec": deploymentApi.ArangoMember{}.Spec,
151+
input := inputPackages{
152+
"deployment": map[string]inputPackage{
153+
"v1": {
154+
Types: inputPackageTypes{
155+
"ArangoDeployment.V1": {
156+
"Spec": deploymentApi.ArangoDeployment{}.Spec,
157+
},
158+
"ArangoMember.V1": {
159+
"Spec": deploymentApi.ArangoMember{}.Spec,
160+
},
161+
},
150162
},
151163
},
152-
fmt.Sprintf("%s/pkg/apis/apps/v1", root): {
153-
"ArangoJob.V1": {
154-
"Spec": appsApi.ArangoJob{}.Spec,
164+
"apps": map[string]inputPackage{
165+
"v1": {
166+
Types: inputPackageTypes{
167+
"ArangoJob.V1": {
168+
"Spec": appsApi.ArangoJob{}.Spec,
169+
},
170+
},
155171
},
156172
},
157-
fmt.Sprintf("%s/pkg/apis/backup/v1", root): {
158-
"ArangoBackup.V1": {
159-
"Spec": backupApi.ArangoBackup{}.Spec,
160-
"Status": backupApi.ArangoBackup{}.Status,
161-
},
162-
"ArangoBackupPolicy.V1": {
163-
"Spec": backupApi.ArangoBackupPolicy{}.Spec,
164-
"Status": backupApi.ArangoBackupPolicy{}.Status,
173+
"backup": map[string]inputPackage{
174+
"v1": {
175+
Types: inputPackageTypes{
176+
"ArangoBackup.V1": {
177+
"Spec": backupApi.ArangoBackup{}.Spec,
178+
"Status": backupApi.ArangoBackup{}.Status,
179+
},
180+
"ArangoBackupPolicy.V1": {
181+
"Spec": backupApi.ArangoBackupPolicy{}.Spec,
182+
"Status": backupApi.ArangoBackupPolicy{}.Status,
183+
},
184+
},
165185
},
166186
},
167-
fmt.Sprintf("%s/pkg/apis/ml/v1alpha1", root): {
168-
"ArangoMLExtension.V1Alpha1": {
169-
"Spec": mlApi.ArangoMLExtension{}.Spec,
170-
"Status": mlApi.ArangoMLExtension{}.Status,
171-
},
172-
"ArangoMLStorage.V1Alpha1": {
173-
"Spec": mlApi.ArangoMLStorage{}.Spec,
174-
"Status": mlApi.ArangoMLStorage{}.Status,
175-
},
176-
"ArangoMLCronJob.V1Alpha1": {
177-
"Spec": mlApi.ArangoMLCronJob{}.Spec,
178-
"Status": mlApi.ArangoMLCronJob{}.Status,
179-
},
180-
"ArangoMLBatchJob.V1Alpha1": {
181-
"Spec": mlApi.ArangoMLBatchJob{}.Spec,
182-
"Status": mlApi.ArangoMLBatchJob{}.Status,
187+
"ml": map[string]inputPackage{
188+
"v1alpha1": {
189+
Types: inputPackageTypes{
190+
"ArangoMLExtension.V1Alpha1": {
191+
"Spec": mlApi.ArangoMLExtension{}.Spec,
192+
"Status": mlApi.ArangoMLExtension{}.Status,
193+
},
194+
"ArangoMLStorage.V1Alpha1": {
195+
"Spec": mlApi.ArangoMLStorage{}.Spec,
196+
"Status": mlApi.ArangoMLStorage{}.Status,
197+
},
198+
"ArangoMLCronJob.V1Alpha1": {
199+
"Spec": mlApi.ArangoMLCronJob{}.Spec,
200+
"Status": mlApi.ArangoMLCronJob{}.Status,
201+
},
202+
"ArangoMLBatchJob.V1Alpha1": {
203+
"Spec": mlApi.ArangoMLBatchJob{}.Spec,
204+
"Status": mlApi.ArangoMLBatchJob{}.Status,
205+
},
206+
},
207+
Shared: []string{
208+
"shared/v1",
209+
"scheduler/v1alpha1",
210+
"scheduler/v1alpha1/container",
211+
"scheduler/v1alpha1/container/resources",
212+
"scheduler/v1alpha1/pod",
213+
"scheduler/v1alpha1/pod/resources",
214+
},
183215
},
184216
},
185-
fmt.Sprintf("%s/pkg/apis/replication/v1", root): {
186-
"ArangoDeploymentReplication.V1": {
187-
"Spec": replicationApi.ArangoDeploymentReplication{}.Spec,
217+
"replication": map[string]inputPackage{
218+
"v1": {
219+
Types: inputPackageTypes{
220+
"ArangoDeploymentReplication.V1": {
221+
"Spec": replicationApi.ArangoDeploymentReplication{}.Spec,
222+
},
223+
},
188224
},
189225
},
190-
fmt.Sprintf("%s/pkg/apis/storage/v1alpha", root): {
191-
"ArangoLocalStorage.V1Alpha": {
192-
"Spec": storageApi.ArangoLocalStorage{}.Spec,
226+
"storage": map[string]inputPackage{
227+
"v1alpha": {
228+
Types: inputPackageTypes{
229+
"ArangoLocalStorage.V1Alpha": {
230+
"Spec": storageApi.ArangoLocalStorage{}.Spec,
231+
},
232+
},
193233
},
194234
},
195235
}
196236

197-
for apiDir, docs := range input {
198-
fields := parseSourceFiles(t, root, fset, apiDir)
237+
for name, versions := range input {
238+
for version, docs := range versions {
239+
fields := parseSourceFiles(t, root, fset, path.Join(root, "pkg/apis", name, version))
199240

200-
for n, f := range sharedFields {
201-
require.NotContains(t, fields, n)
202-
fields[n] = f
203-
}
241+
for _, p := range docs.Shared {
242+
sharedFields := parseSourceFiles(t, root, fset, path.Join(root, "pkg/apis", p))
204243

205-
generateDocs(t, docs, fields, fset)
244+
for n, f := range sharedFields {
245+
require.NotContains(t, fields, n)
246+
fields[n] = f
247+
}
248+
}
249+
250+
generateDocs(t, docs.Types, fields, fset)
251+
}
206252
}
207253
}
208254

pkg/apis/ml/v1alpha1/extension_spec.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// DISCLAIMER
33
//
4-
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
4+
// Copyright 2023-2024 ArangoDB GmbH, Cologne, Germany
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
77
// you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
package v1alpha1
2222

2323
import (
24+
schedulerContainerResourcesApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources"
2425
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
2526
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
2627
)
@@ -34,7 +35,7 @@ type ArangoMLExtensionSpec struct {
3435
Storage *sharedApi.Object `json:"storage,omitempty"`
3536

3637
// Image defines default image used for the extension
37-
*sharedApi.Image `json:",inline"`
38+
*schedulerContainerResourcesApi.Image `json:",inline"`
3839

3940
// ArangoMLExtensionTemplate define Init job specification
4041
Init *ArangoMLExtensionTemplate `json:"init,omitempty"`
@@ -54,7 +55,7 @@ func (a *ArangoMLExtensionSpec) GetMetadataService() *ArangoMLExtensionSpecMetad
5455
return a.MetadataService
5556
}
5657

57-
func (a *ArangoMLExtensionSpec) GetImage() *sharedApi.Image {
58+
func (a *ArangoMLExtensionSpec) GetImage() *schedulerContainerResourcesApi.Image {
5859
if a == nil || a.Image == nil {
5960
return nil
6061
}
@@ -102,7 +103,7 @@ func (a *ArangoMLExtensionSpec) Validate() error {
102103
shared.PrefixResourceErrors("storage", shared.ValidateRequired(a.GetStorage(), func(obj sharedApi.Object) error { return obj.Validate() })),
103104
a.GetImage().Validate(),
104105
shared.PrefixResourceErrors("init", a.GetInit().Validate()),
105-
shared.ValidateAnyNotNil(".image or .init.image needs to be specified", a.GetImage(), a.GetInit().GetContainerTemplate().GetImage()),
106+
shared.ValidateAnyNotNil(".image or .init.image needs to be specified", a.GetImage(), a.GetInit().GetContainer().GetImage()),
106107
shared.PrefixResourceErrors("deployment", a.GetDeployment().Validate()),
107108
shared.PrefixResourceErrors("jobsTemplates", a.GetJobsTemplates().Validate()),
108109
))

pkg/apis/ml/v1alpha1/extension_spec_deployment.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
package v1alpha1
2222

2323
import (
24+
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod"
2425
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
25-
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
2626
"github.com/arangodb/kube-arangodb/pkg/util"
2727
"github.com/arangodb/kube-arangodb/pkg/util/errors"
2828
)
@@ -58,8 +58,8 @@ type ArangoMLExtensionSpecDeployment struct {
5858
// Service defines how components will be exposed
5959
Service *ArangoMLExtensionSpecDeploymentService `json:"service,omitempty"`
6060

61-
// PodTemplate defines base template for pods
62-
*sharedApi.PodTemplate
61+
// Pod defines base template for pods
62+
*schedulerPodApi.Pod
6363

6464
// Prediction defines how Prediction workload will be deployed
6565
Prediction *ArangoMLExtensionSpecDeploymentComponent `json:"prediction,omitempty"`
@@ -76,12 +76,12 @@ func (s *ArangoMLExtensionSpecDeployment) GetReplicas() int32 {
7676
return *s.Replicas
7777
}
7878

79-
func (s *ArangoMLExtensionSpecDeployment) GetPodTemplate() *sharedApi.PodTemplate {
80-
if s == nil || s.PodTemplate == nil {
79+
func (s *ArangoMLExtensionSpecDeployment) GetPodTemplate() *schedulerPodApi.Pod {
80+
if s == nil || s.Pod == nil {
8181
return nil
8282
}
8383

84-
return s.PodTemplate
84+
return s.Pod
8585
}
8686

8787
func (s *ArangoMLExtensionSpecDeployment) GetPrediction() *ArangoMLExtensionSpecDeploymentComponent {

0 commit comments

Comments
 (0)