Skip to content

Commit

Permalink
Extend components variable with flannel, calico, and cilium
Browse files Browse the repository at this point in the history
* By default the `networking` CNI provider is pre-installed,
but the component variable provides an extensible mechanism
to skip installing these components
* Validate that networking can only be set to one of flannel,
calico, or cilium
  • Loading branch information
dghubble committed May 18, 2024
1 parent 452bcf3 commit a54fe54
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
6 changes: 3 additions & 3 deletions conditional.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ locals {
daemonset_tolerations = var.daemonset_tolerations
}
)
if var.networking == "flannel"
if var.components.enable && var.components.flannel.enable && var.networking == "flannel"
}

# calico manifests map
Expand All @@ -37,7 +37,7 @@ locals {
daemonset_tolerations = var.daemonset_tolerations
}
)
if var.networking == "calico"
if var.components.enable && var.components.calico.enable && var.networking == "calico"
}

# cilium manifests map
Expand All @@ -53,7 +53,7 @@ locals {
daemonset_tolerations = var.daemonset_tolerations
}
)
if var.networking == "cilium"
if var.components.enable && var.components.cilium.enable && var.networking == "cilium"
}
}

35 changes: 34 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ variable "etcd_servers" {

variable "networking" {
type = string
description = "Choice of networking provider (flannel or calico or cilium or none)"
description = "Choice of networking provider (flannel or calico or cilium)"
default = "flannel"
validation {
condition = contains(["flannel", "calico", "cilium"], var.networking)
error_message = "networking can be flannel, calico, or cilium."
}
}

variable "network_mtu" {
Expand Down Expand Up @@ -124,11 +128,40 @@ variable "components" {
enable = true
}
)
# CNI providers are enabled for pre-install by default, but only the
# provider matching var.networking is actually installed.
flannel = optional(
object({
enable = optional(bool, true)
}),
{
enable = true
}
)
calico = optional(
object({
enable = optional(bool, true)
}),
{
enable = true
}
)
cilium = optional(
object({
enable = optional(bool, true)
}),
{
enable = true
}
)
})
default = {
enable = true
coredns = null
kube_proxy = null
flannel = null
calico = null
cilium = null
}
# Set the variable value to the default value when the caller
# sets it to null.
Expand Down

0 comments on commit a54fe54

Please sign in to comment.