-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor jobUUIDAndLogger helper function
- Loading branch information
1 parent
4de7d6d
commit ee90a66
Showing
2 changed files
with
36 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package scheduler | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/buildkite/agent-stack-k8s/v2/internal/controller/config" | ||
"github.com/google/uuid" | ||
"go.uber.org/zap" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// loggerForObject curries a logger with namespace, name, and job UUID taken | ||
// from the object labels. | ||
func loggerForObject(baseLog *zap.Logger, obj metav1.Object) *zap.Logger { | ||
return baseLog.With( | ||
zap.String("namespace", obj.GetNamespace()), | ||
zap.String("name", obj.GetName()), | ||
zap.String("jobUUID", obj.GetLabels()[config.UUIDLabel]), | ||
) | ||
} | ||
|
||
// jobUUIDForObject parses the Buildkite job UUID from the object labels. | ||
func jobUUIDForObject(obj metav1.Object) (uuid.UUID, error) { | ||
rawJobUUID := obj.GetLabels()[config.UUIDLabel] | ||
if rawJobUUID == "" { | ||
return uuid.UUID{}, errors.New("no job UUID label") | ||
} | ||
|
||
return uuid.Parse(rawJobUUID) | ||
} |