Skip to content

Commit

Permalink
fix: only set job meta if unset
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra authored and moshloop committed Jan 30, 2024
1 parent 59134bd commit 9f5aef7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (k Context) StartSpan(name string) (Context, trace.Span) {
func getObjectMeta(ctx commons.Context) metav1.ObjectMeta {
o := ctx.Value("object")
if o == nil {
return metav1.ObjectMeta{Annotations: map[string]string{}, Labels: map[string]string{}}
return metav1.ObjectMeta{Annotations: make(map[string]string), Labels: make(map[string]string)}
}
return o.(metav1.ObjectMeta)
}
Expand Down
19 changes: 11 additions & 8 deletions job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/samber/lo"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
Expand Down Expand Up @@ -324,13 +323,17 @@ func (j *Job) init() {
j.Context = j.Context.WithoutName().WithName(j.Name)
}

j.Context = j.Context.WithObject(v1.ObjectMeta{
Name: j.Name,
Annotations: map[string]string{
"debug": lo.Ternary(j.Debug, "true", "false"),
"trace": lo.Ternary(j.Trace, "true", "false"),
},
})
obj := j.Context.GetObjectMeta()
if obj.Name == "" {
obj.Name = j.Name
}
if obj.Annotations == nil {
obj.Annotations = make(map[string]string)
}
obj.Annotations["debug"] = lo.Ternary(j.Debug, "true", "false")
obj.Annotations["trace"] = lo.Ternary(j.Trace, "true", "false")

j.Context = j.Context.WithObject(obj)

if dbLevel, ok := getProperty(j, properties, "db-log-level"); ok {
j.Context = j.Context.WithDBLogLevel(dbLevel)
Expand Down

0 comments on commit 9f5aef7

Please sign in to comment.