Skip to content

Commit

Permalink
osbuild-worker: add CHANNEL to worker logs
Browse files Browse the repository at this point in the history
aka "the deployment channel" like "staging" or "production"
  • Loading branch information
schuellerf committed Aug 26, 2024
1 parent f9d1b51 commit 09e53fc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/osbuild-worker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -112,6 +114,7 @@ func parseConfig(file string) (*workerConfig, error) {
OSBuildExecutor: &executorConfig{
Type: "host",
},
DeploymentChannel: "local",
}

_, err := toml.DecodeFile(file, &config)
Expand Down
13 changes: 13 additions & 0 deletions cmd/osbuild-worker/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ cloudwatch_group = "osbuild-worker"
Credentials: "/etc/osbuild-worker/pulp-creds",
ServerURL: "https://example.com/pulp",
},
DeploymentChannel: "local",
},
},
{
Expand All @@ -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",
},
},
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/osbuild-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"flag"
"fmt"
slogger "github.com/osbuild/osbuild-composer/pkg/splunk_logger"
"net/url"
"os"
"path"
Expand Down Expand Up @@ -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=?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 09e53fc

Please sign in to comment.