This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLATFORMINFRA-193: rework byoh-agent flags
- Loading branch information
1 parent
5f72e50
commit 48323ce
Showing
5 changed files
with
69 additions
and
0 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,44 @@ | ||
#!/bin/python3 | ||
import json | ||
import os | ||
|
||
METADATA_FILE_PATH = '/etc/infra-k8s/host-metadata.json' | ||
FLAGS_FILE_DIR = '/etc/byoh-agent' | ||
FLAGS_FILE_PATH = f'{FLAGS_FILE_DIR}/byoh-agent-flags.env' | ||
|
||
def load_metadata(): | ||
with open(METADATA_FILE_PATH) as f: | ||
return json.load(f) | ||
|
||
def create_config_dir(): | ||
os.makedirs(FLAGS_FILE_DIR, exist_ok=True) | ||
|
||
def construct_labels(metadata): | ||
common_labels = [ | ||
"--label", f"byoh.infrastructure.cluster.x-k8s.io/type={metadata.get('node_role')}", | ||
"--label", f"byoh.infrastructure.cluster.x-k8s.io/cluster={metadata.get('cluster_name')}", | ||
"--label", f"byoh.infrastructure.cluster.x-k8s.io/hostname={os.getenv('HOSTNAME')}", | ||
] | ||
|
||
extra_labels = [] | ||
for k, v in metadata.get('extra_labels', {}).items(): | ||
extra_labels += ["--label", f"{k}={v}"] | ||
|
||
return common_labels + extra_labels | ||
|
||
def construct_args(metadata): | ||
return construct_labels(metadata) + [ | ||
"--bootstrap-kubeconfig", "/etc/infra-k8s/kubeconfig", | ||
"--skip-installation", | ||
"--namespace", metadata.get('cluster_name'), | ||
"--metricsbindaddress", ":8081", | ||
] | ||
|
||
def write_env_file(metadata): | ||
# Writing structured form of flags as string into '/etc/byoh-agent/byoh-agent-flags.env' | ||
with open(FLAGS_FILE_PATH, 'w') as f: | ||
f.write(f"BYOH_AGENT_FLAGS=\"{' '.join(construct_args(metadata))}\"") | ||
|
||
metadata = load_metadata() | ||
create_config_dir() | ||
write_env_file(metadata) |
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,5 @@ | ||
[Path] | ||
Unit=byoh-agent-flag.service | ||
PathModified=/etc/infra-k8s/host-metadata.json | ||
[Install] | ||
WantedBy=multi-user.target |
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,16 @@ | ||
[Unit] | ||
Description=Prepares env with flags for byoh-agent service | ||
After=network.target | ||
StartLimitIntervalSec=60 | ||
StartLimitBurst=5 | ||
PartOf=byoh-agent.service | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
ExecStart=/opt/byoh-agent/byoh-agent-flags.py | ||
Restart=on-failure | ||
RestartSec=5 | ||
|
||
[Install] | ||
WantedBy=byoh-agent.service |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[Path] | ||
Unit=byoh-agent-watcher.service | ||
PathModified=/root/.byoh/config | ||
PathModified=/etc/byoh-agent/byoh-agent-flags.env | ||
[Install] | ||
WantedBy=multi-user.target |