Skip to content

Commit d157752

Browse files
authored
One RSS per namespace. Add role/binding for secrets (#375)
Change the ApplicationSet module so that each RunnerScaleSet is executed in its own namespace. Add a role to get read access to secrets and a rolebinding in each namespace. Also update the RSS name to reflect the OS/version of the runner container image, rather than the containing VM. Signed-off-by: Andrea Frittoli <andrea.frittoli@uk.ibm.com>
1 parent c51523b commit d157752

4 files changed

Lines changed: 86 additions & 23 deletions

File tree

arc/aws/391835788720/us-east-1/03_argocd/runner-set-lf-aws.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module "argocd-runner-scale-set" {
77
token = local.argocd_ready ? local.argocd_terraform_sa_token : null
88
organization = "lf"
99
cluster = "in-cluster"
10-
namespace = "lf-aws"
1110
provider_path = "argocd/aws/391835788720/us-east-1"
1211
git_revision = var.git_revision
1312
}

arc/modules/argocd-runner-scale-set/arc_runner_scale_set.tf

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,53 @@ locals {
2424
arc_private_key = data.aws_secretsmanager_secret_version.arc_secrets_private_key.secret_string
2525
}
2626

27+
# ClusterRole with secret read permissions
28+
# This is never used cluster-wide, only in specific namespaces
29+
resource "kubernetes_cluster_role" "secret_reader" {
30+
metadata {
31+
name = "secret-reader"
32+
}
33+
34+
rule {
35+
api_groups = [""]
36+
resources = ["secrets"]
37+
verbs = ["get", "list", "watch"]
38+
}
39+
}
40+
41+
/*
42+
* A few resources need to be provisioned for each RunnerScaleSet
43+
* i.e. for each folder under ${var.provider_path}/${var.cluster}
44+
*
45+
* - A namespace
46+
* - The GitHub secret
47+
* - A RoleBinding the allows access to the secret
48+
*/
49+
50+
// Find folders directly under argocd/${var.provider_path}/${var.cluster}
51+
// and create a JSON map of results for next resources to loop on
52+
data "external" "runner_scale_sets" {
53+
program = ["bash", "-c", <<-EOT
54+
REPO_ROOT=$(git rev-parse --show-toplevel)
55+
find "$REPO_ROOT/${var.provider_path}/${var.cluster}" -mindepth 1 -maxdepth 1 -type d -type d -exec basename {} \; | jq -R -s -c 'split("\n")[:-1] | map({key: ., value: .}) | from_entries'
56+
EOT
57+
]
58+
}
59+
2760
resource "kubernetes_namespace" "arc_runners" {
61+
for_each = data.external.runner_scale_sets.result
62+
2863
metadata {
29-
name = var.namespace
64+
name = "${var.organization}-${each.value}"
3065
}
3166
}
3267

3368
resource "kubernetes_secret" "github_app" {
69+
for_each = data.external.runner_scale_sets.result
70+
3471
metadata {
3572
name = "github-config"
36-
namespace = var.namespace
73+
namespace = "${var.organization}-${each.value}"
3774
}
3875

3976
data = {
@@ -45,6 +82,27 @@ resource "kubernetes_secret" "github_app" {
4582
type = "Opaque"
4683
}
4784

85+
resource "kubernetes_role_binding" "secret_access" {
86+
for_each = data.external.runner_scale_sets.result
87+
88+
metadata {
89+
name = "secret-reader-binding"
90+
namespace = "${var.organization}-${each.value}"
91+
}
92+
93+
role_ref {
94+
api_group = "rbac.authorization.k8s.io"
95+
kind = "ClusterRole"
96+
name = kubernetes_cluster_role.secret_reader.metadata[0].name
97+
}
98+
99+
subject {
100+
kind = "ServiceAccount"
101+
name = var.arc_controller_sa
102+
namespace = var.arc_controller_sa_namespace
103+
}
104+
}
105+
48106
// This secret is required by ArgoCD to enable using an OCI repo
49107
// for helm charts. It's deployed once in the argocd namespace.
50108
resource "kubernetes_secret" "arc_runner_scale_set_oci_repo" {
@@ -123,18 +181,17 @@ resource "argocd_project" "arc_rss_project" {
123181
* - the helm chart
124182
* - the value files
125183
*
126-
* Value files can be found under argocd/cloud/tenant/region/cluster/namespace/<runner-scale-set-name>.
127-
* Each cloud/tenant/region/cluster/namespace combination has its ApplicationSet.
128-
* Various RunnerSets in the same namespace belong to the same ApplicationSet, with one application each.
184+
* Value files can be found under argocd/cloud/tenant/region/cluster/<runner-scale-set-name>.
185+
* Each cloud/tenant/region/cluster combination has its ApplicationSet.
186+
* Each RunnerSets runs in its own namespace belong to the ApplicationSet, with one application each.
129187
*
130188
* The cluster folder is used to select the cluster name in ArgoCD
131-
* The namespace folder is used to define the target namespace in ArgoCD
132189
* Each resource in the folder is applied as a dedicated Application
133190
*/
134191
resource "argocd_application_set" "arc_runner_scale_set" {
135192

136193
metadata {
137-
name = "arc-rss-${var.cluster}-${var.namespace}"
194+
name = "arc-rss-${var.organization}-${var.cluster}"
138195
namespace = "argocd"
139196
}
140197

@@ -147,7 +204,7 @@ resource "argocd_application_set" "arc_runner_scale_set" {
147204
repo_url = "https://github.com/pytorch/ci-infra"
148205
revision = var.git_revision
149206
directory {
150-
path = "${var.provider_path}/${var.cluster}/${var.namespace}/*"
207+
path = "${var.provider_path}/${var.cluster}/*"
151208
}
152209
}
153210
}
@@ -170,6 +227,11 @@ resource "argocd_application_set" "arc_runner_scale_set" {
170227
value_files = [
171228
"$values/{{.path.path}}/values.yaml"
172229
]
230+
values = <<-EOT
231+
controllerServiceAccount:
232+
name: ${var.arc_controller_sa}
233+
namespace: ${var.arc_controller_sa_namespace}
234+
EOT
173235
}
174236
}
175237
source {
@@ -180,7 +242,7 @@ resource "argocd_application_set" "arc_runner_scale_set" {
180242

181243
destination {
182244
name = "{{index .path.segments 4}}"
183-
namespace = "{{index .path.segments 5}}"
245+
namespace = "${var.organization}-{{index .path.segments 5}}"
184246
}
185247

186248
sync_policy {

arc/modules/argocd-runner-scale-set/variables.tf

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ variable "organization" {
1414
default = "lf"
1515
}
1616

17-
variable "namespace" {
18-
description = "The namespace for in the format <org>-<cloud>"
19-
type = string
20-
default = "lf-aws"
21-
}
22-
2317
variable "cluster" {
2418
description = "The name of the cluster as defined in ArgoCD"
2519
type = string
@@ -50,3 +44,15 @@ variable "aws_secret_key_name" {
5044
type = string
5145
default = "pytorch-arc-github-app-private-key"
5246
}
47+
48+
variable "arc_controller_sa" {
49+
description = "Service account used by the ARC controller"
50+
type = string
51+
default = "arc-gha-rs-controller"
52+
}
53+
54+
variable "arc_controller_sa_namespace" {
55+
description = "Namespace where the service account used by the ARC controller is defined"
56+
type = string
57+
default = "arc-system"
58+
}

argocd/aws/391835788720/us-east-1/in-cluster/lf-aws/linux-20250911-amd64-2c-4g/values.yaml renamed to argocd/aws/391835788720/us-east-1/in-cluster/ubuntu-22-amd64-2c-4g/values.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@ maxRunners: 2
1111
## calculated as a sum of minRunners and the number of jobs assigned to the scale set.
1212
minRunners: 0
1313

14-
runnerGroup: "linux-amd64-2c-4g"
14+
# Using the default runner group for now
15+
# runnerGroup: "ubuntu-amd64-2c-4g"
1516

16-
runnerScaleSetName: "lf-aws-linux-20250911-amd64-2c-4g"
17+
runnerScaleSetName: "lf-aws-ubuntu-22-amd64-2c-4g"
1718

1819
template:
1920
spec:
2021
containers:
2122
- name: runner
2223
image: ghcr.io/actions/actions-runner:latest
2324
command: ["/home/runner/run.sh"]
24-
25-
# Service account of the controller
26-
controllerServiceAccount:
27-
name: "arc-gha-rs-controller"
28-
namespace: "arc-systems"

0 commit comments

Comments
 (0)