Skip to content

Commit

Permalink
feat: bench job support inherit kubebench toleration (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengluodb authored Aug 13, 2024
1 parent bc82721 commit b31cdb4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 4 additions & 0 deletions deploy/helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ spec:
value: "{{ .Values.kubebenchImages.exporter }}"
- name: KUBEBENCH_TOOLS_IMAGE
value: "{{ .Values.kubebenchImages.tools }}"
{{- with .Values.tolerations }}
- name: CM_TOLERATIONS
value: {{ toJson . | quote }}
{{- end }}
command:
- /manager
securityContext:
Expand Down
14 changes: 12 additions & 2 deletions internal/utils/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@ package utils

import (
"context"
"encoding/json"
"fmt"
"github.com/apecloud/kubebench/api/v1alpha1"
"github.com/apecloud/kubebench/pkg/constants"
"strings"

"github.com/spf13/viper"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/apecloud/kubebench/api/v1alpha1"
"github.com/apecloud/kubebench/pkg/constants"
)

func IsJobExisted(cli client.Client, reqCtx context.Context, jobName string, namespace string) (bool, error) {
Expand Down Expand Up @@ -200,6 +204,12 @@ func JobTemplate(name, namespace string) *batchv1.Job {

func AddTolerationToJobs(jobs []*batchv1.Job, tolerations []corev1.Toleration) {
for _, job := range jobs {
if cmTolerations := viper.GetString(constants.CfgKeyCtrlrMgrTolerations); cmTolerations != "" {
if err := json.Unmarshal([]byte(cmTolerations), &job.Spec.Template.Spec.Tolerations); err != nil {
klog.Errorf("Failed to marshal CfgKeyCtrlrMgrTolerations for job, tolerations is %s ", cmTolerations)
}
}

job.Spec.Template.Spec.Tolerations = append(job.Spec.Template.Spec.Tolerations, tolerations...)
}
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/constants/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const (
KubebenchTools = "KUBEBENCH_TOOLS_IMAGE"
)

const (
CfgKeyCtrlrMgrTolerations = "CM_TOLERATIONS"
)

func init() {
viper.SetDefault(KubebenchEnvPgbench, "registry.cn-hangzhou.aliyuncs.com/apecloud/spilo:14.8.0")
viper.SetDefault(KubebenchEnvSysbench, "registry.cn-hangzhou.aliyuncs.com/apecloud/customsuites:latest")
Expand All @@ -30,6 +34,7 @@ func init() {
viper.SetDefault(KubebenchEnvRedisBench, "registry.cn-hangzhou.aliyuncs.com/apecloud/redis:7.0.5")
viper.SetDefault(KubebenchExporter, "apecloud-registry.cn-zhangjiakou.cr.aliyuncs.com/apecloud/kubebench:0.0.10")
viper.SetDefault(KubebenchTools, "apecloud-registry.cn-zhangjiakou.cr.aliyuncs.com/apecloud/kubebench:0.0.10")
viper.SetDefault(CfgKeyCtrlrMgrTolerations, os.Getenv(CfgKeyCtrlrMgrTolerations))
}

// GetBenchmarkImage get benchmark image
Expand Down

0 comments on commit b31cdb4

Please sign in to comment.