Skip to content

Commit

Permalink
feat(k8s): run adhoc jobs in dedicated namespace (#1065)
Browse files Browse the repository at this point in the history
* feat(k8s): run adhoc jobs in dedicated namespace

* feat: add ttl for all jobs
  • Loading branch information
m90 authored Aug 14, 2023
1 parent e038ba8 commit 7c2995d
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 9 deletions.
2 changes: 2 additions & 0 deletions k8s/jobs/changeReplicationPasswordOnSecondary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ apiVersion: batch/v1
kind: Job
metadata:
generateName: change-replication-password-on-secondary-
namespace: adhoc-jobs
spec:
template:
ttlSecondsAfterFinished: 604800
spec:
ttlSecondsAfterFinished: 604800
containers:
Expand Down
2 changes: 2 additions & 0 deletions k8s/jobs/elasticSearchImportJob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ apiVersion: batch/v1
kind: Job
metadata:
generateName: load-elasticsearch-data-
namespace: adhoc-jobs
spec:
template:
ttlSecondsAfterFinished: 604800
metadata:
name: load-elasticsearch-data
spec:
Expand Down
2 changes: 2 additions & 0 deletions k8s/jobs/forceSearchIndexFrom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ apiVersion: batch/v1
kind: Job
metadata:
generateName: force-search-index-from-
namespace: adhoc-jobs
spec:
template:
ttlSecondsAfterFinished: 604800
metadata:
name: force-search-index-from
spec:
Expand Down
2 changes: 2 additions & 0 deletions k8s/jobs/rebuildQuantityUnitsJob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ apiVersion: batch/v1
kind: Job
metadata:
generateName: rebuild-quantity-units-
namespace: adhoc-jobs
spec:
template:
ttlSecondsAfterFinished: 604800
metadata:
name: rebuild-quantity-units
spec:
Expand Down
2 changes: 2 additions & 0 deletions k8s/jobs/resetOtherSqlSecretsJob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ apiVersion: batch/v1
kind: Job
metadata:
generateName: reset-other-sql-secrets-job-
namespace: adhoc-jobs
spec:
template:
ttlSecondsAfterFinished: 604800
spec:
ttlSecondsAfterFinished: 604800
containers:
Expand Down
2 changes: 2 additions & 0 deletions k8s/jobs/resetRootSqlSecretJob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ apiVersion: batch/v1
kind: Job
metadata:
generateName: reset-root-sql-secret-job-
namespace: adhoc-jobs
spec:
template:
ttlSecondsAfterFinished: 604800
spec:
ttlSecondsAfterFinished: 604800
containers:
Expand Down
2 changes: 2 additions & 0 deletions k8s/jobs/runAllMWJobsJob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ apiVersion: batch/v1
kind: Job
metadata:
generateName: run-all-mw-jobs-
namespace: adhoc-jobs
spec:
template:
ttlSecondsAfterFinished: 604800
metadata:
name: run-all-mw-jobs
spec:
Expand Down
20 changes: 20 additions & 0 deletions tf/env/local/namespaces.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,23 @@ resource "kubernetes_resource_quota" "api-jobs-podquota" {
scopes = ["BestEffort"]
}
}


resource "kubernetes_namespace" "adhoc-job-namespace" {
metadata {
name = "adhoc-jobs"
}
}

resource "kubernetes_resource_quota" "adhoc-jobs-podquota" {
metadata {
name = "api-jobs-podquota"
namespace = kubernetes_namespace.api-job-namespace.metadata[0].name
}
spec {
hard = {
pods = 1
}
scopes = ["BestEffort"]
}
}
2 changes: 1 addition & 1 deletion tf/env/local/secrets-api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ resource "random_password" "api-app-jwt-secret" {
}

resource "kubernetes_secret" "api-app-secrets" {
for_each = toset(["default", "api-jobs"])
for_each = toset(["default", "api-jobs", "adhoc-jobs"])
metadata {
name = "api-app-secrets"
namespace = each.value
Expand Down
4 changes: 2 additions & 2 deletions tf/env/local/secrets-recapcha.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "kubernetes_secret" "recaptcha-v3-dev-secrets" {
for_each = toset(["default", "api-jobs"])
for_each = toset(["default", "api-jobs", "adhoc-jobs"])
metadata {
name = "recaptcha-v3-dev-secrets"
# default as staging
Expand All @@ -18,7 +18,7 @@ moved {
}

resource "kubernetes_secret" "recaptcha-v2-dev-secrets" {
for_each = toset(["default", "api-jobs"])
for_each = toset(["default", "api-jobs", "adhoc-jobs"])
metadata {
name = "recaptcha-v2-dev-secrets"
# default as staging
Expand Down
2 changes: 1 addition & 1 deletion tf/env/local/secrets-redis.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "random_password" "redis-password" {

# Used by the sql service for initial setup
resource "kubernetes_secret" "redis-password" {
for_each = toset(["default", "api-jobs"])
for_each = toset(["default", "api-jobs", "adhoc-jobs"])
metadata {
name = "redis-password"
namespace = each.value
Expand Down
4 changes: 2 additions & 2 deletions tf/env/local/secrets-sql.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resource "random_password" "sql-passwords" {

# Used by the sql service for initial setup
resource "kubernetes_secret" "sql-secrets-passwords" {
for_each = toset(["default", "api-jobs"])
for_each = toset(["default", "api-jobs", "adhoc-jobs"])
metadata {
name = "sql-secrets-passwords"
namespace = each.value
Expand All @@ -27,7 +27,7 @@ moved {

# Used by the init script on sql services for user and permissions setup
resource "kubernetes_secret" "sql-secrets-init-passwords" {
for_each = toset(["default", "api-jobs"])
for_each = toset(["default", "api-jobs", "adhoc-jobs"])
metadata {
name = "sql-secrets-init-passwords"
namespace = each.value
Expand Down
6 changes: 5 additions & 1 deletion tf/env/production/kubernetes-secrets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ module "wbaas-k8s-secrets" {
api_passport_private_key = tls_private_key.api-passport.private_key_pem
api_app_key = random_password.api-app-key.result
api_app_jwt_secret = random_password.api-app-jwt-secret.result
mediawiki_secret_namespaces = ["default", kubernetes_namespace.api-job-namespace.metadata[0].name]
mediawiki_secret_namespaces = [
"default",
kubernetes_namespace.api-job-namespace.metadata[0].name,
kubernetes_namespace.adhoc-job-namespace.metadata[0].name
]
logical_backup_openssl_secret = random_password.logical_backup_random_password.result
}

24 changes: 24 additions & 0 deletions tf/env/production/namespaces.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,27 @@ resource "kubernetes_resource_quota" "api-jobs-podquota" {
scopes = ["BestEffort"]
}
}


resource "kubernetes_namespace" "adhoc-job-namespace" {
provider = kubernetes.wbaas-2

metadata {
name = "adhoc-jobs"
}
}

resource "kubernetes_resource_quota" "adhoc-jobs-podquota" {
provider = kubernetes.wbaas-2

metadata {
name = "api-jobs-podquota"
namespace = kubernetes_namespace.api-job-namespace.metadata[0].name
}
spec {
hard = {
pods = 8
}
scopes = ["BestEffort"]
}
}
8 changes: 6 additions & 2 deletions tf/env/staging/kubernetes-secrets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module "wbaas2-k8s-secrets" {
api_passport_private_key = tls_private_key.api-passport.private_key_pem
api_app_key = random_password.api-app-key.result
api_app_jwt_secret = random_password.api-app-jwt-secret.result
mediawiki_secret_namespaces = ["default", kubernetes_namespace.api-job-namespace.metadata[0].name]
logical_backup_openssl_secret = random_password.logical_backup_random_password.result
mediawiki_secret_namespaces = [
"default",
kubernetes_namespace.api-job-namespace.metadata[0].name,
kubernetes_namespace.adhoc-job-namespace.metadata[0].name
]
logical_backup_openssl_secret = random_password.logical_backup_random_password.result
}
23 changes: 23 additions & 0 deletions tf/env/staging/namespaces.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,26 @@ resource "kubernetes_resource_quota" "api-jobs-podquota" {
scopes = ["BestEffort"]
}
}

resource "kubernetes_namespace" "adhoc-job-namespace" {
provider = kubernetes.wbaas-2

metadata {
name = "adhoc-jobs"
}
}

resource "kubernetes_resource_quota" "adhoc-jobs-podquota" {
provider = kubernetes.wbaas-2

metadata {
name = "api-jobs-podquota"
namespace = kubernetes_namespace.api-job-namespace.metadata[0].name
}
spec {
hard = {
pods = 4
}
scopes = ["BestEffort"]
}
}

0 comments on commit 7c2995d

Please sign in to comment.