osbuild-worker: add CHANNEL to worker logs

aka "the deployment channel" like "staging" or "production"
This commit is contained in:
Florian Schüller 2024-08-21 10:24:21 +02:00 committed by Florian Schüller
parent 2519e55ccd
commit 8d24dcfbde
4 changed files with 22 additions and 0 deletions

View file

@ -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)

View file

@ -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",
},
},
}

View file

@ -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=?")

View file

@ -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}"