Skip to content

Commit

Permalink
.gtpl
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieu-benoit committed Nov 20, 2024
1 parent dfaf33a commit 7891a04
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 60 deletions.
18 changes: 3 additions & 15 deletions modules/htc_res_defs/k8s_service_account.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@ resource "humanitec_resource_definition" "k8s_service_account" {
driver_inputs = {
values_string = jsonencode({
templates = {
init = <<EOL
name: {{ index (splitList "." "$${context.res.id}") 1 }}
EOL
manifests = <<EOL
service-account.yaml:
location: namespace
data:
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .init.name }}
EOL
outputs = <<EOL
name: {{ .init.name }}
EOL
init = file("${path.module}/manifests/k8s-service-account/init.gtpl")
manifests = file("${path.module}/manifests/k8s-service-account/manifests.gtpl")
outputs = file("${path.module}/manifests/k8s-service-account/outputs.gtpl")
}
})
}
Expand Down
1 change: 1 addition & 0 deletions modules/htc_res_defs/manifests/k8s-namespace/init.gtpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: ${context.app.id}-${context.env.id}
12 changes: 12 additions & 0 deletions modules/htc_res_defs/manifests/k8s-namespace/manifests.gtpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace.yaml:
location: cluster
data:
apiVersion: v1
kind: Namespace
metadata:
labels:
humanitec.io/app: ${context.app.id}
humanitec.io/env: ${context.env.id}
pod-security.kubernetes.io/enforce: restricted
istio-injection: enabled
name: {{ .init.name }}
1 change: 1 addition & 0 deletions modules/htc_res_defs/manifests/k8s-namespace/outputs.gtpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
namespace: {{ .init.name }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: {{ index (splitList "." "${context.res.id}") 1 }}
11 changes: 11 additions & 0 deletions modules/htc_res_defs/manifests/k8s-service-account/manifests.gtpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
service-account.yaml:
location: namespace
data:
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
humanitec.io/workload: {{ .init.name }}
humanitec.io/app: ${context.app.id}
humanitec.io/env: ${context.env.id}
name: {{ .init.name }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: {{ .init.name }}
27 changes: 27 additions & 0 deletions modules/htc_res_defs/manifests/workload/outputs.gtpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
update:
- op: add
path: /spec/serviceAccountName
value: $${resources.k8s-service-account.outputs.name}
- op: add
path: /spec/automountServiceAccountToken
value: false
- op: add
path: /spec/securityContext
value:
fsGroup: 1000
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
seccompProfile:
type: RuntimeDefault
{{- range $containerId, $value := .resource.spec.containers }}
- op: add
path: /spec/containers/{{ $containerId }}/securityContext
value:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
readOnlyRootFilesystem: true
{{- end }}
17 changes: 3 additions & 14 deletions modules/htc_res_defs/namespace.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,9 @@ resource "humanitec_resource_definition" "k8s_namespace" {
driver_inputs = {
values_string = jsonencode({
templates = {
init = "name: $${context.app.id}-$${context.env.id}"
manifests = <<EOL
namespace.yaml:
location: cluster
data:
apiVersion: v1
kind: Namespace
metadata:
labels:
pod-security.kubernetes.io/enforce: restricted
istio-injection: enabled
name: {{ .init.name }}
EOL
outputs = "namespace: {{ .init.name }}"
init = file("${path.module}/manifests/k8s-namespace/init.gtpl")
manifests = file("${path.module}/manifests/k8s-namespace/manifests.gtpl")
outputs = file("${path.module}/manifests/k8s-namespace/outputs.gtpl")
}
})
}
Expand Down
32 changes: 1 addition & 31 deletions modules/htc_res_defs/workload.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,7 @@ resource "humanitec_resource_definition" "workload" {
driver_inputs = {
values_string = jsonencode({
templates = {
init = ""
manifests = ""
outputs = <<EOL
update:
- op: add
path: /spec/serviceAccountName
value: $${resources.k8s-service-account.outputs.name}
- op: add
path: /spec/automountServiceAccountToken
value: false
- op: add
path: /spec/securityContext
value:
fsGroup: 1000
runAsGroup: 1000
runAsNonRoot: true
runAsUser: 1000
seccompProfile:
type: RuntimeDefault
{{- range $containerId, $value := .resource.spec.containers }}
- op: add
path: /spec/containers/{{ $containerId }}/securityContext
value:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
readOnlyRootFilesystem: true
{{- end }}
EOL
outputs = file("${path.module}/manifests/workload/outputs.gtpl")
}
})
}
Expand Down

0 comments on commit 7891a04

Please sign in to comment.