Skip to content

Commit

Permalink
[Feature] Extract Scheduler API
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow committed Feb 22, 2024
1 parent 5eb65d3 commit 058cf24
Show file tree
Hide file tree
Showing 63 changed files with 2,498 additions and 1,523 deletions.
10 changes: 10 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ linters-settings:
alias: policy
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/shared/v1
alias: sharedApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1
alias: schedulerApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container
alias: schedulerContainerApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/container/resources
alias: schedulerContainerResourcesApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod
alias: schedulerPodApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod/resources
alias: schedulerPodResourcesApi
- pkg: github.com/arangodb/kube-arangodb/pkg/apis/shared
alias: shared
- pkg: github.com/arangodb/kube-arangodb/pkg/handlers/enterprise/ml/shared
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

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

## [1.2.38](https://github.com/arangodb/kube-arangodb/tree/1.2.38) (2024-02-22)
- (Feature) Extract GRPC Server
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,14 @@ update-generated:
"client lister informer deepcopy" \
"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 apps:v1 ml:v1alpha1" \
"deployment:v1 replication:v1 storage:v1alpha backup:v1 deployment:v2alpha1 replication:v2alpha1 apps:v1 ml:v1alpha1 scheduler:v1alpha1" \
--go-header-file "./tools/codegen/boilerplate.go.txt" \
$(VERIFYARGS)
GOPATH=$(GOBUILDDIR) $(VENDORDIR)/k8s.io/code-generator/generate-groups.sh \
"deepcopy" \
"github.com/arangodb/kube-arangodb/pkg/generated" \
"github.com/arangodb/kube-arangodb/pkg/apis" \
"shared:v1" \
"shared:v1 scheduler:v1alpha1/container scheduler:v1alpha1/container/resources scheduler:v1alpha1/pod scheduler:v1alpha1/pod/resources" \
--go-header-file "./tools/codegen/boilerplate.go.txt" \
$(VERIFYARGS)

Expand Down
572 changes: 286 additions & 286 deletions docs/api/ArangoMLExtension.V1Alpha1.md

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions docs/api/ArangoMLStorage.V1Alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Default Value: `9202`

### .spec.mode.sidecar.env

Type: `core.EnvVar` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/envs.go#L33)</sup>
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>

Env keeps the information about environment variables provided to the container

Expand All @@ -127,7 +127,7 @@ Links:

### .spec.mode.sidecar.envFrom

Type: `core.EnvFromSource` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/envs.go#L38)</sup>
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>

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

Expand All @@ -138,43 +138,43 @@ Links:

### .spec.mode.sidecar.image

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

Image define image details

***

### .spec.mode.sidecar.listenPort
### .spec.mode.sidecar.imagePullPolicy

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>
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/scheduler/v1alpha1/container/resources/image.go#L38)</sup>

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

Default Value: `9201`
Default Value: `IfNotPresent`

***

### .spec.mode.sidecar.pullPolicy

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

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

Default Value: `IfNotPresent`
ImagePullSecrets define Secrets used to pull Image from registry

***

### .spec.mode.sidecar.pullSecrets
### .spec.mode.sidecar.listenPort

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>

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

PullSecrets define Secrets used to pull Image from registry
Default Value: `9201`

***

### .spec.mode.sidecar.resources

Type: `core.ResourceRequirements` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/resources.go#L34)</sup>
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>

Resources holds resource requests & limits for container

Expand All @@ -185,7 +185,7 @@ Links:

### .spec.mode.sidecar.securityContext

Type: `core.SecurityContext` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.38/pkg/apis/shared/v1/security_container.go#L29)</sup>
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>

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

Expand Down
142 changes: 94 additions & 48 deletions internal/docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,72 +137,118 @@ func Test_GenerateAPIDocs(t *testing.T) {

fset := token.NewFileSet()

sharedFields := parseSourceFiles(t, root, fset, fmt.Sprintf("%s/pkg/apis/shared/v1", root))
type inputPackageTypes map[string]map[string]any

type inputPackage struct {
Types inputPackageTypes

Shared []string
}

type inputPackages map[string]map[string]inputPackage

// package path -> result doc file name -> name of the top-level field to be described -> field instance for reflection
input := map[string]map[string]map[string]interface{}{
fmt.Sprintf("%s/pkg/apis/deployment/v1", root): {
"ArangoDeployment.V1": {
"Spec": deploymentApi.ArangoDeployment{}.Spec,
},
"ArangoMember.V1": {
"Spec": deploymentApi.ArangoMember{}.Spec,
input := inputPackages{
"deployment": map[string]inputPackage{
"v1": {
Types: inputPackageTypes{
"ArangoDeployment.V1": {
"Spec": deploymentApi.ArangoDeployment{}.Spec,
},
"ArangoMember.V1": {
"Spec": deploymentApi.ArangoMember{}.Spec,
},
},
},
},
fmt.Sprintf("%s/pkg/apis/apps/v1", root): {
"ArangoJob.V1": {
"Spec": appsApi.ArangoJob{}.Spec,
"apps": map[string]inputPackage{
"v1": {
Types: inputPackageTypes{
"ArangoJob.V1": {
"Spec": appsApi.ArangoJob{}.Spec,
},
},
},
},
fmt.Sprintf("%s/pkg/apis/backup/v1", root): {
"ArangoBackup.V1": {
"Spec": backupApi.ArangoBackup{}.Spec,
"Status": backupApi.ArangoBackup{}.Status,
},
"ArangoBackupPolicy.V1": {
"Spec": backupApi.ArangoBackupPolicy{}.Spec,
"Status": backupApi.ArangoBackupPolicy{}.Status,
"backup": map[string]inputPackage{
"v1": {
Types: inputPackageTypes{
"ArangoBackup.V1": {
"Spec": backupApi.ArangoBackup{}.Spec,
"Status": backupApi.ArangoBackup{}.Status,
},
"ArangoBackupPolicy.V1": {
"Spec": backupApi.ArangoBackupPolicy{}.Spec,
"Status": backupApi.ArangoBackupPolicy{}.Status,
},
},
},
},
fmt.Sprintf("%s/pkg/apis/ml/v1alpha1", root): {
"ArangoMLExtension.V1Alpha1": {
"Spec": mlApi.ArangoMLExtension{}.Spec,
"Status": mlApi.ArangoMLExtension{}.Status,
},
"ArangoMLStorage.V1Alpha1": {
"Spec": mlApi.ArangoMLStorage{}.Spec,
"Status": mlApi.ArangoMLStorage{}.Status,
},
"ArangoMLCronJob.V1Alpha1": {
"Spec": mlApi.ArangoMLCronJob{}.Spec,
"Status": mlApi.ArangoMLCronJob{}.Status,
},
"ArangoMLBatchJob.V1Alpha1": {
"Spec": mlApi.ArangoMLBatchJob{}.Spec,
"Status": mlApi.ArangoMLBatchJob{}.Status,
"ml": map[string]inputPackage{
"v1alpha1": {
Types: inputPackageTypes{
"ArangoMLExtension.V1Alpha1": {
"Spec": mlApi.ArangoMLExtension{}.Spec,
"Status": mlApi.ArangoMLExtension{}.Status,
},
"ArangoMLStorage.V1Alpha1": {
"Spec": mlApi.ArangoMLStorage{}.Spec,
"Status": mlApi.ArangoMLStorage{}.Status,
},
"ArangoMLCronJob.V1Alpha1": {
"Spec": mlApi.ArangoMLCronJob{}.Spec,
"Status": mlApi.ArangoMLCronJob{}.Status,
},
"ArangoMLBatchJob.V1Alpha1": {
"Spec": mlApi.ArangoMLBatchJob{}.Spec,
"Status": mlApi.ArangoMLBatchJob{}.Status,
},
},
Shared: []string{
"shared/v1",
"scheduler/v1alpha1",
"scheduler/v1alpha1/container",
"scheduler/v1alpha1/container/resources",
"scheduler/v1alpha1/pod",
"scheduler/v1alpha1/pod/resources",
},
},
},
fmt.Sprintf("%s/pkg/apis/replication/v1", root): {
"ArangoDeploymentReplication.V1": {
"Spec": replicationApi.ArangoDeploymentReplication{}.Spec,
"replication": map[string]inputPackage{
"v1": {
Types: inputPackageTypes{
"ArangoDeploymentReplication.V1": {
"Spec": replicationApi.ArangoDeploymentReplication{}.Spec,
},
},
},
},
fmt.Sprintf("%s/pkg/apis/storage/v1alpha", root): {
"ArangoLocalStorage.V1Alpha": {
"Spec": storageApi.ArangoLocalStorage{}.Spec,
"storage": map[string]inputPackage{
"v1alpha": {
Types: inputPackageTypes{
"ArangoLocalStorage.V1Alpha": {
"Spec": storageApi.ArangoLocalStorage{}.Spec,
},
},
},
},
}

for apiDir, docs := range input {
fields := parseSourceFiles(t, root, fset, apiDir)
for name, versions := range input {
for version, docs := range versions {
fields := parseSourceFiles(t, root, fset, path.Join(root, "pkg/apis", name, version))

for n, f := range sharedFields {
require.NotContains(t, fields, n)
fields[n] = f
}
for _, p := range docs.Shared {
sharedFields := parseSourceFiles(t, root, fset, path.Join(root, "pkg/apis", p))

generateDocs(t, docs, fields, fset)
for n, f := range sharedFields {
require.NotContains(t, fields, n)
fields[n] = f
}
}

generateDocs(t, docs.Types, fields, fset)
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/apis/ml/v1alpha1/extension_spec.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
// Copyright 2023-2024 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.
Expand All @@ -21,6 +21,7 @@
package v1alpha1

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

// Image defines default image used for the extension
*sharedApi.Image `json:",inline"`
*schedulerContainerResourcesApi.Image `json:",inline"`

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

func (a *ArangoMLExtensionSpec) GetImage() *sharedApi.Image {
func (a *ArangoMLExtensionSpec) GetImage() *schedulerContainerResourcesApi.Image {
if a == nil || a.Image == nil {
return nil
}
Expand Down Expand Up @@ -102,7 +103,7 @@ func (a *ArangoMLExtensionSpec) Validate() error {
shared.PrefixResourceErrors("storage", shared.ValidateRequired(a.GetStorage(), func(obj sharedApi.Object) error { return obj.Validate() })),
a.GetImage().Validate(),
shared.PrefixResourceErrors("init", a.GetInit().Validate()),
shared.ValidateAnyNotNil(".image or .init.image needs to be specified", a.GetImage(), a.GetInit().GetContainerTemplate().GetImage()),
shared.ValidateAnyNotNil(".image or .init.image needs to be specified", a.GetImage(), a.GetInit().GetContainer().GetImage()),
shared.PrefixResourceErrors("deployment", a.GetDeployment().Validate()),
shared.PrefixResourceErrors("jobsTemplates", a.GetJobsTemplates().Validate()),
))
Expand Down
12 changes: 6 additions & 6 deletions pkg/apis/ml/v1alpha1/extension_spec_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
package v1alpha1

import (
schedulerPodApi "github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/pod"
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
sharedApi "github.com/arangodb/kube-arangodb/pkg/apis/shared/v1"
"github.com/arangodb/kube-arangodb/pkg/util"
"github.com/arangodb/kube-arangodb/pkg/util/errors"
)
Expand Down Expand Up @@ -58,8 +58,8 @@ type ArangoMLExtensionSpecDeployment struct {
// Service defines how components will be exposed
Service *ArangoMLExtensionSpecDeploymentService `json:"service,omitempty"`

// PodTemplate defines base template for pods
*sharedApi.PodTemplate
// Pod defines base template for pods
*schedulerPodApi.Pod

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

func (s *ArangoMLExtensionSpecDeployment) GetPodTemplate() *sharedApi.PodTemplate {
if s == nil || s.PodTemplate == nil {
func (s *ArangoMLExtensionSpecDeployment) GetPodTemplate() *schedulerPodApi.Pod {
if s == nil || s.Pod == nil {
return nil
}

return s.PodTemplate
return s.Pod
}

func (s *ArangoMLExtensionSpecDeployment) GetPrediction() *ArangoMLExtensionSpecDeploymentComponent {
Expand Down
Loading

0 comments on commit 058cf24

Please sign in to comment.