From 09e53fc558fb696bbd00a8eb0f8d068c180fdb2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Sch=C3=BCller?= Date: Wed, 21 Aug 2024 10:24:21 +0200 Subject: [PATCH] osbuild-worker: add CHANNEL to worker logs aka "the deployment channel" like "staging" or "production" --- cmd/osbuild-worker/config.go | 3 +++ cmd/osbuild-worker/config_test.go | 13 +++++++++++++ cmd/osbuild-worker/main.go | 5 +++++ .../client_credentials.sh | 1 + 4 files changed, 22 insertions(+) diff --git a/cmd/osbuild-worker/config.go b/cmd/osbuild-worker/config.go index f28cf0effc..ac3dae5926 100644 --- a/cmd/osbuild-worker/config.go +++ b/cmd/osbuild-worker/config.go @@ -103,6 +103,8 @@ type workerConfig struct { // default value: &{ Type: host } OSBuildExecutor *executorConfig `toml:"osbuild_executor"` RepositoryMTLSConfig *repositoryMTLSConfig `toml:"repository_mtls"` + // something like "production" or "staging" to be added to logging + DeploymentChannel string `toml:"deployment_channel"` } func parseConfig(file string) (*workerConfig, error) { @@ -112,6 +114,7 @@ func parseConfig(file string) (*workerConfig, error) { OSBuildExecutor: &executorConfig{ Type: "host", }, + DeploymentChannel: "local", } _, err := toml.DecodeFile(file, &config) diff --git a/cmd/osbuild-worker/config_test.go b/cmd/osbuild-worker/config_test.go index 46aa7f8999..540570d2fd 100644 --- a/cmd/osbuild-worker/config_test.go +++ b/cmd/osbuild-worker/config_test.go @@ -136,6 +136,7 @@ cloudwatch_group = "osbuild-worker" Credentials: "/etc/osbuild-worker/pulp-creds", ServerURL: "https://example.com/pulp", }, + DeploymentChannel: "local", }, }, { @@ -146,6 +147,18 @@ cloudwatch_group = "osbuild-worker" OSBuildExecutor: &executorConfig{ Type: "host", }, + DeploymentChannel: "local", + }, + }, + { + name: "set_channel", + config: `deployment_channel = "staging"`, + want: &workerConfig{ + BasePath: "/api/worker/v1", + OSBuildExecutor: &executorConfig{ + Type: "host", + }, + DeploymentChannel: "staging", }, }, } diff --git a/cmd/osbuild-worker/main.go b/cmd/osbuild-worker/main.go index d7fe8b0735..d81c754600 100644 --- a/cmd/osbuild-worker/main.go +++ b/cmd/osbuild-worker/main.go @@ -7,6 +7,7 @@ import ( "errors" "flag" "fmt" + slogger "github.com/osbuild/osbuild-composer/pkg/splunk_logger" "net/url" "os" "path" @@ -193,6 +194,10 @@ func main() { logrus.Fatalf("Could not print config: %v", err) } + if config.DeploymentChannel != "" { + logrus.AddHook(&slogger.EnvironmentHook{Channel: config.DeploymentChannel}) + } + cacheDirectory, ok := os.LookupEnv("CACHE_DIRECTORY") if !ok { logrus.Fatal("CACHE_DIRECTORY is not set. Is the service file missing CacheDirectory=?") diff --git a/templates/packer/ansible/roles/common/files/worker-initialization-scripts/client_credentials.sh b/templates/packer/ansible/roles/common/files/worker-initialization-scripts/client_credentials.sh index a8497c1214..7c983c169d 100755 --- a/templates/packer/ansible/roles/common/files/worker-initialization-scripts/client_credentials.sh +++ b/templates/packer/ansible/roles/common/files/worker-initialization-scripts/client_credentials.sh @@ -20,6 +20,7 @@ jq -r ".client_secret" /tmp/client-credentials.json > /etc/osbuild-worker/client rm -f /tmp/client-credentials.json sudo tee -a /etc/osbuild-worker/osbuild-worker.toml > /dev/null << EOF +deployment_channel = "${CHANNEL:-local}" [authentication] oauth_url = "${TOKEN_URL:-https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token}" client_id = "${CLIENT_ID}"