Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions nullplatform/agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ resource "example_resource" "this" {
| <a name="input_image_pull_secrets"></a> [image\_pull\_secrets](#input\_image\_pull\_secrets) | Image pull secrets configuration | `string` | `""` | no |
| <a name="input_image_repository"></a> [image\_repository](#input\_image\_repository) | Container image repository for the agent. Defaults to the official nullplatform image. | `string` | `""` | no |
| <a name="input_image_tag"></a> [image\_tag](#input\_image\_tag) | Image tag for the agent container image | `string` | n/a | yes |
| <a name="input_init_containers"></a> [init\_containers](#input\_init\_containers) | Additional init containers to run before the main agent container (raw Kubernetes container spec, passed through to the Helm chart's initContainers value) | `list(any)` | `[]` | no |
| <a name="input_init_scripts"></a> [init\_scripts](#input\_init\_scripts) | List of initialization scripts to execute during agent startup | `list(string)` | `[]` | no |
| <a name="input_initial_ingress_path"></a> [initial\_ingress\_path](#input\_initial\_ingress\_path) | Defines the initial ingress path used when deploying the application for the first time. | `string` | `""` | no |
| <a name="input_namespace"></a> [namespace](#input\_namespace) | Kubernetes namespace where the nullplatform agent will run | `string` | `"nullplatform-tools"` | no |
Expand All @@ -170,6 +171,14 @@ resource "example_resource" "this" {
| <a name="input_service_template"></a> [service\_template](#input\_service\_template) | Specifies the name or reference of the scope service template to be used for deployment. | `string` | `""` | no |
| <a name="input_tags_selectors"></a> [tags\_selectors](#input\_tags\_selectors) | Map of tags used to select and filter channels and agents | `map(string)` | n/a | yes |
| <a name="input_use_account_slug"></a> [use\_account\_slug](#input\_use\_account\_slug) | Flag to determine whether to use account slug in resource naming | `string` | `""` | no |
| <a name="input_volume_mounts"></a> [volume\_mounts](#input\_volume\_mounts) | Additional volumeMounts to add to the main agent container (raw Kubernetes volumeMount spec, passed through to the Helm chart's volumeMounts value) | `list(any)` | `[]` | no |
| <a name="input_volumes"></a> [volumes](#input\_volumes) | Additional volumes to add to the agent pod (raw Kubernetes volume spec, passed through to the Helm chart's volumes value) | `list(any)` | `[]` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_rendered_values"></a> [rendered\_values](#output\_rendered\_values) | The rendered Helm values passed to the agent chart. |
<!-- END_TF_DOCS -->

<!-- BEGIN_AI_METADATA
Expand Down
3 changes: 3 additions & 0 deletions nullplatform/agent/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,8 @@ locals {
aws_iam_role_arn = var.cloud_provider == "aws" ? var.aws_iam_role_arn : ""
init_scripts = var.init_scripts
service_account_name = var.service_account_name
init_containers = var.init_containers
volumes = var.volumes
volume_mounts = var.volume_mounts
})
}
9 changes: 9 additions & 0 deletions nullplatform/agent/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
############################################
# Rendered Helm Values (used in tests)
############################################

output "rendered_values" {
description = "The rendered Helm values passed to the agent chart."
value = local.nullplatform_agent_values
sensitive = true
}
15 changes: 15 additions & 0 deletions nullplatform/agent/templates/nullplatform_agent_values.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,18 @@ initScripts:
%{ endfor }
%{ endif }

%{ if length(init_containers) > 0 }
initContainers:
${yamlencode(init_containers)}
%{ endif }

%{ if length(volumes) > 0 }
volumes:
${yamlencode(volumes)}
%{ endif }

%{ if length(volume_mounts) > 0 }
volumeMounts:
${yamlencode(volume_mounts)}
%{ endif }

97 changes: 97 additions & 0 deletions nullplatform/agent/tests/agent_values.tftest.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
mock_provider "helm" {}

variables {
api_key = "test-api-key"
cluster_name = "test-cluster"
nrn = "organization=1:account=2:namespace=3"
tags_selectors = { environment = "test" }
image_tag = "latest"
cloud_provider = "gcp"
private_gateway_name = ""
private_domain = ""
}

############################################
# initContainers
############################################

run "init_containers_omitted_by_default" {
command = plan

assert {
condition = !strcontains(output.rendered_values, "initContainers:")
error_message = "initContainers block should be omitted when init_containers is empty"
}
}

run "init_containers_rendered" {
command = plan

variables {
init_containers = [
{
name = "kubelogin-install"
image = "busybox:1.36"
volumeMounts = [
{ name = "kubelogin-bin", mountPath = "/shared" }
]
}
]
}

assert {
condition = strcontains(output.rendered_values, "initContainers:")
error_message = "initContainers block should be present when init_containers is non-empty"
}

assert {
condition = strcontains(output.rendered_values, "\"name\": \"kubelogin-install\"")
error_message = "init container name should be rendered"
}
}

############################################
# volumes / volumeMounts
############################################

run "volumes_and_volume_mounts_omitted_by_default" {
command = plan

assert {
condition = !strcontains(output.rendered_values, "\nvolumes:")
error_message = "volumes block should be omitted when volumes is empty"
}

assert {
condition = !strcontains(output.rendered_values, "volumeMounts:")
error_message = "volumeMounts block should be omitted when volume_mounts is empty"
}
}

run "volumes_and_volume_mounts_rendered" {
command = plan

variables {
volumes = [
{ name = "kubelogin-bin", emptyDir = {} }
]
volume_mounts = [
{ name = "kubelogin-bin", mountPath = "/usr/local/bin/kubelogin", subPath = "kubelogin" }
]
}

assert {
condition = strcontains(output.rendered_values, "\nvolumes:")
error_message = "volumes block should be present when volumes is non-empty"
}

assert {
condition = strcontains(output.rendered_values, "volumeMounts:")
error_message = "volumeMounts block should be present when volume_mounts is non-empty"
}

assert {
condition = strcontains(output.rendered_values, "\"mountPath\": \"/usr/local/bin/kubelogin\"")
error_message = "volume mount path should be rendered"
}
}
21 changes: 21 additions & 0 deletions nullplatform/agent/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,24 @@ variable "extra_envs" {
type = map(string)
default = {}
}

# Additional init containers to run before the main agent container (raw container spec, passed through to the chart's initContainers value)
variable "init_containers" {
description = "Additional init containers to run before the main agent container (raw Kubernetes container spec, passed through to the Helm chart's initContainers value)"
type = list(any)
default = []
}

# Additional volumes to add to the agent pod (raw volume spec, passed through to the chart's volumes value)
variable "volumes" {
description = "Additional volumes to add to the agent pod (raw Kubernetes volume spec, passed through to the Helm chart's volumes value)"
type = list(any)
default = []
}

# Additional volumeMounts to add to the main agent container (raw volumeMount spec, passed through to the chart's volumeMounts value)
variable "volume_mounts" {
description = "Additional volumeMounts to add to the main agent container (raw Kubernetes volumeMount spec, passed through to the Helm chart's volumeMounts value)"
type = list(any)
default = []
}