Skip to content

Commit

Permalink
♻️ Mount benchmark-operator-config to vald-benchmark-job Pod
Browse files Browse the repository at this point in the history
Signed-off-by: vankichi <[email protected]>
  • Loading branch information
vankichi committed Apr 8, 2024
1 parent 63b53ea commit 9bf4b6c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
51 changes: 50 additions & 1 deletion internal/k8s/vald/benchmark/job/job_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const (
)

const (
svcAccount = "vald-benchmark-operator"
volumeName = "vald-benchmark-job-config"
configMapName = "vald-benchmark-operator-config"
svcAccount = "vald-benchmark-operator"
)

type BenchmarkJobTpl interface {
Expand Down Expand Up @@ -138,6 +140,53 @@ func (b *benchmarkJobTpl) CreateJobTpl(opts ...BenchmarkJobOption) (k8s.Job, err
},
},
},
{
Name: "MY_NODE_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "spec.nodeName",
},
},
},
{
Name: "MY_POD_NAMESPACE",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.namespace",
},
},
},
{
Name: "MY_POD_NAME",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "metadata.name",
},
},
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: volumeName,
MountPath: "/etc/server",
},
},
},
}
// mount benchmark operator config map.
// It is used for bind only observability config for each benchmark job
mode := int32(420)
b.jobTpl.Spec.Template.Spec.Volumes = []corev1.Volume{
{
Name: volumeName,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
// FIXME: get benchmark operator configmap name
Name: configMapName,
},
DefaultMode: &mode,
},
},
},
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/tools/benchmark/job/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var (
NAME = os.Getenv("CRD_NAME")
JOBNAME_ANNOTATION = "before-job-name"
JOBNAMESPACE_ANNOTATION = "before-job-namespace"
SERVICE_NAME = "vald-benchmark-job"
)

// NewConfig represents the set config from the given setting file path.
Expand All @@ -74,6 +75,7 @@ func NewConfig(ctx context.Context, path string) (cfg *Config, err error) {

if cfg.Observability != nil {
cfg.Observability = cfg.Observability.Bind()
cfg.Observability.OTLP.Attribute.ServiceName = SERVICE_NAME

Check warning on line 78 in pkg/tools/benchmark/job/config/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/tools/benchmark/job/config/config.go#L78

Added line #L78 was not covered by tests
} else {
cfg.Observability = new(config.Observability)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/tools/benchmark/job/usecase/benchmarkd.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func (r *run) Start(ctx context.Context) (<-chan error, error) {
if r.observability != nil {
oech = r.observability.Start(ctx)
}

dech, err = r.job.Start(ctx)
if err != nil {
ech <- err
Expand Down

0 comments on commit 9bf4b6c

Please sign in to comment.