-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ impl status handle of continuous benchmark crds (#1955)
Signed-off-by: vankichi <[email protected]>
- Loading branch information
Showing
19 changed files
with
1,036 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// | ||
// Copyright (C) 2019-2022 vdaas.org vald team <[email protected]> | ||
// | ||
// 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 | ||
// | ||
// https://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. | ||
// | ||
|
||
// Package job manages the main logic of benchmark job. | ||
package job | ||
|
||
import ( | ||
batchv1 "k8s.io/api/batch/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
type benchmarkJobTemplate = batchv1.Job | ||
|
||
const ( | ||
SvcAccountName = "vald-benchmark-operator" | ||
ContainerName = "vald-benchmark-job" | ||
ContainerImage = "local-registry:5000/vdaas/vald-benchmark-job:latest" | ||
|
||
RestartPolicyAlways corev1.RestartPolicy = "Always" | ||
RestartPolicyOnFailure corev1.RestartPolicy = "OnFailure" | ||
RestartPolicyNever corev1.RestartPolicy = "Never" | ||
) | ||
|
||
// NewBenchmarkJobTemplate creates the job template for crating k8s job resource. | ||
func NewBenchmarkJobTemplate(opts ...BenchmarkJobOption) (benchmarkJobTemplate, error) { | ||
jobTmpl := new(benchmarkJobTemplate) | ||
for _, opt := range append(defaultBenchmarkJobOpts, opts...) { | ||
err := opt(jobTmpl) | ||
if err != nil { | ||
return *jobTmpl, err | ||
} | ||
} | ||
jobTmpl.Spec.Template.Spec.Containers = []corev1.Container{ | ||
{ | ||
Name: ContainerName, | ||
Image: ContainerImage, | ||
ImagePullPolicy: corev1.PullAlways, | ||
LivenessProbe: &corev1.Probe{ | ||
InitialDelaySeconds: int32(60), | ||
PeriodSeconds: int32(10), | ||
TimeoutSeconds: int32(300), | ||
ProbeHandler: corev1.ProbeHandler{ | ||
Exec: &corev1.ExecAction{ | ||
Command: []string{ | ||
"/go/bin/job", | ||
"-v", | ||
}, | ||
}, | ||
}, | ||
}, | ||
StartupProbe: &corev1.Probe{ | ||
FailureThreshold: int32(30), | ||
PeriodSeconds: int32(10), | ||
TimeoutSeconds: int32(300), | ||
ProbeHandler: corev1.ProbeHandler{ | ||
Exec: &corev1.ExecAction{ | ||
Command: []string{ | ||
"/go/bin/job", | ||
"-v", | ||
}, | ||
}, | ||
}, | ||
}, | ||
Ports: []corev1.ContainerPort{ | ||
{ | ||
Name: "liveness", | ||
Protocol: corev1.ProtocolTCP, | ||
ContainerPort: int32(3000), | ||
}, | ||
{ | ||
Name: "readiness", | ||
Protocol: corev1.ProtocolTCP, | ||
ContainerPort: int32(3001), | ||
}, | ||
}, | ||
Env: []corev1.EnvVar{ | ||
{ | ||
Name: "CRD_NAMESPACE", | ||
ValueFrom: &corev1.EnvVarSource{ | ||
FieldRef: &corev1.ObjectFieldSelector{ | ||
FieldPath: "metadata.namespace", | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "CRD_NAME", | ||
ValueFrom: &corev1.EnvVarSource{ | ||
FieldRef: &corev1.ObjectFieldSelector{ | ||
FieldPath: "metadata.labels['job-name']", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
return *jobTmpl, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// Copyright (C) 2019-2022 vdaas.org vald team <[email protected]> | ||
// | ||
// 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 | ||
// | ||
// https://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. | ||
// | ||
|
||
package job | ||
|
||
import ( | ||
"github.com/vdaas/vald/internal/k8s" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
// BenchmarkJobOption represents the option for create benchmark job template. | ||
type BenchmarkJobOption func(b *benchmarkJobTemplate) error | ||
|
||
var defaultBenchmarkJobOpts = []BenchmarkJobOption{ | ||
WithSvcAccountName(SvcAccountName), | ||
WithRestartPolicy(RestartPolicyNever), | ||
} | ||
|
||
// WithSvcAccountName sets the service account name for benchmark job. | ||
func WithSvcAccountName(name string) BenchmarkJobOption { | ||
return func(b *benchmarkJobTemplate) error { | ||
if len(name) > 0 { | ||
b.Spec.Template.Spec.ServiceAccountName = name | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// WithRestartPolicy sets the job restart policy for benchmark job. | ||
func WithRestartPolicy(rp corev1.RestartPolicy) BenchmarkJobOption { | ||
return func(b *benchmarkJobTemplate) error { | ||
if len(rp) > 0 { | ||
b.Spec.Template.Spec.RestartPolicy = rp | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// WithBackoffLimit sets the job backoff limit for benchmark job. | ||
func WithBackoffLimit(bo int32) BenchmarkJobOption { | ||
return func(b *benchmarkJobTemplate) error { | ||
b.Spec.BackoffLimit = &bo | ||
return nil | ||
} | ||
} | ||
|
||
// WithName sets the job name of benchmark job. | ||
func WithName(name string) BenchmarkJobOption { | ||
return func(b *benchmarkJobTemplate) error { | ||
b.Name = name | ||
return nil | ||
} | ||
} | ||
|
||
// WithNamespace specify namespace where job will execute. | ||
func WithNamespace(ns string) BenchmarkJobOption { | ||
return func(b *benchmarkJobTemplate) error { | ||
b.Namespace = ns | ||
return nil | ||
} | ||
} | ||
|
||
// WithOwnerRef sets the OwnerReference to the job resource. | ||
func WithOwnerRef(refs []k8s.OwnerReference) BenchmarkJobOption { | ||
return func(b *benchmarkJobTemplate) error { | ||
if len(refs) > 0 { | ||
b.OwnerReferences = refs | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// WithCompletions sets the job completion. | ||
func WithCompletions(com int32) BenchmarkJobOption { | ||
return func(b *benchmarkJobTemplate) error { | ||
if com > 1 { | ||
b.Spec.Completions = &com | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// WithParallelism sets the job parallelism. | ||
func WithParallelism(parallelism int32) BenchmarkJobOption { | ||
return func(b *benchmarkJobTemplate) error { | ||
if parallelism > 1 { | ||
b.Spec.Parallelism = ¶llelism | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// WithLabel sets the label to the job resource. | ||
func WithLabel(label map[string]string) BenchmarkJobOption { | ||
return func(b *benchmarkJobTemplate) error { | ||
if len(label) > 0 { | ||
b.Labels = label | ||
} | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.