Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Coredns config configurable #74

Merged
merged 10 commits into from
Dec 16, 2023
Merged
111 changes: 69 additions & 42 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ The following parameters are available in the `k8s` class:
* [`uid`](#-k8s--uid)
* [`gid`](#-k8s--gid)
* [`etcd_cluster_name`](#-k8s--etcd_cluster_name)
* [`cluster_domain`](#-k8s--cluster_domain)
* [`native_packaging`](#-k8s--native_packaging)
* [`version`](#-k8s--version)
* [`etcd_version`](#-k8s--etcd_version)
Expand Down Expand Up @@ -127,7 +128,6 @@ The following parameters are available in the `k8s` class:
* [`cluster_cidr`](#-k8s--cluster_cidr)
* [`api_service_address`](#-k8s--api_service_address)
* [`dns_service_address`](#-k8s--dns_service_address)
* [`cluster_domain`](#-k8s--cluster_domain)
* [`role`](#-k8s--role)
* [`firewall_type`](#-k8s--firewall_type)

Expand Down Expand Up @@ -212,6 +212,14 @@ name of the etcd cluster for searching its nodes in the puppetdb

Default value: `'default'`

##### <a name="-k8s--cluster_domain"></a>`cluster_domain`

Data type: `Stdlib::Fqdn`

domain name for the cluster

Default value: `'cluster.local'`

##### <a name="-k8s--native_packaging"></a>`native_packaging`

Data type: `K8s::Native_packaging`
Expand Down Expand Up @@ -468,14 +476,6 @@ Data type: `K8s::IP_addresses`

Default value: `k8s::ip_in_cidr($service_cluster_cidr, 'second')`

##### <a name="-k8s--cluster_domain"></a>`cluster_domain`

Data type: `Stdlib::Fqdn`



Default value: `'cluster.local'`

##### <a name="-k8s--role"></a>`role`

Data type: `Enum['node','server','none']`
Expand Down Expand Up @@ -2700,56 +2700,59 @@ Generates and deploys the default CoreDNS DNS provider for Kubernetes

The following parameters are available in the `k8s::server::resources::coredns` class:

* [`dns_service_address`](#-k8s--server--resources--coredns--dns_service_address)
* [`registry`](#-k8s--server--resources--coredns--registry)
* [`image`](#-k8s--server--resources--coredns--image)
* [`image_tag`](#-k8s--server--resources--coredns--image_tag)
* [`cluster_domain`](#-k8s--server--resources--coredns--cluster_domain)
* [`corefile_content`](#-k8s--server--resources--coredns--corefile_content)
* [`deployment_config`](#-k8s--server--resources--coredns--deployment_config)
* [`dns_service_address`](#-k8s--server--resources--coredns--dns_service_address)
* [`ensure`](#-k8s--server--resources--coredns--ensure)
* [`hosts`](#-k8s--server--resources--coredns--hosts)
* [`image`](#-k8s--server--resources--coredns--image)
* [`image_pull_secrets`](#-k8s--server--resources--coredns--image_pull_secrets)
* [`ensure`](#-k8s--server--resources--coredns--ensure)
* [`image_tag`](#-k8s--server--resources--coredns--image_tag)
* [`kubeconfig`](#-k8s--server--resources--coredns--kubeconfig)
* [`cluster_domain`](#-k8s--server--resources--coredns--cluster_domain)
* [`registry`](#-k8s--server--resources--coredns--registry)
* [`template_path`](#-k8s--server--resources--coredns--template_path)
* [`template_variables`](#-k8s--server--resources--coredns--template_variables)

##### <a name="-k8s--server--resources--coredns--dns_service_address"></a>`dns_service_address`
##### <a name="-k8s--server--resources--coredns--cluster_domain"></a>`cluster_domain`

Data type: `K8s::IP_addresses`
Data type: `Stdlib::Fqdn`

The address for the DNS service
The cluster domain to use for the CoreDNS ConfigMap

Default value: `$k8s::server::resources::dns_service_address`
Default value: `$k8s::server::resources::cluster_domain`

##### <a name="-k8s--server--resources--coredns--registry"></a>`registry`
##### <a name="-k8s--server--resources--coredns--corefile_content"></a>`corefile_content`

Data type: `String[1]`
Data type: `Optional[String[1]]`

The CoreDNS image registry to use
The content to use for the CoreDNS ConfigMap

Default value: `$k8s::server::resources::coredns_registry`
Default value: `undef`

##### <a name="-k8s--server--resources--coredns--image"></a>`image`
##### <a name="-k8s--server--resources--coredns--deployment_config"></a>`deployment_config`

Data type: `String[1]`
Data type: `Hash[String,Data]`

The CoreDNS image name to use
Additional configuration to merge into the Kubernetes Deployment object

Default value: `$k8s::server::resources::coredns_image`
Default value: `$k8s::server::resources::coredns_deployment_config`

##### <a name="-k8s--server--resources--coredns--image_tag"></a>`image_tag`
##### <a name="-k8s--server--resources--coredns--dns_service_address"></a>`dns_service_address`

Data type: `String[1]`
Data type: `K8s::IP_addresses`

The CoreDNS image tag to use
The address for the DNS service

Default value: `$k8s::server::resources::coredns_tag`
Default value: `$k8s::server::resources::dns_service_address`

##### <a name="-k8s--server--resources--coredns--deployment_config"></a>`deployment_config`
##### <a name="-k8s--server--resources--coredns--ensure"></a>`ensure`

Data type: `Hash[String,Data]`
Data type: `K8s::Ensure`

Additional configuration to merge into the Kubernetes Deployment object
Whether the resource should be present or absent on the target system

Default value: `$k8s::server::resources::coredns_deployment_config`
Default value: `$k8s::ensure`

##### <a name="-k8s--server--resources--coredns--hosts"></a>`hosts`

Expand All @@ -2759,6 +2762,14 @@ Additional host-style entries for the CoreDNS deployment to serve

Default value: `[]`

##### <a name="-k8s--server--resources--coredns--image"></a>`image`

Data type: `String[1]`

The CoreDNS image name to use

Default value: `$k8s::server::resources::coredns_image`

##### <a name="-k8s--server--resources--coredns--image_pull_secrets"></a>`image_pull_secrets`

Data type: `Optional[Array]`
Expand All @@ -2767,29 +2778,45 @@ the secrets to pull from private registries

Default value: `$k8s::server::resources::image_pull_secrets`

##### <a name="-k8s--server--resources--coredns--ensure"></a>`ensure`

Data type: `K8s::Ensure`
##### <a name="-k8s--server--resources--coredns--image_tag"></a>`image_tag`

Data type: `String[1]`

The CoreDNS image tag to use

Default value: `$k8s::ensure`
Default value: `$k8s::server::resources::coredns_tag`

##### <a name="-k8s--server--resources--coredns--kubeconfig"></a>`kubeconfig`

Data type: `Stdlib::Unixpath`


The path to the kubeconfig to use for kubectl commands

Default value: `$k8s::server::resources::kubeconfig`

##### <a name="-k8s--server--resources--coredns--cluster_domain"></a>`cluster_domain`
##### <a name="-k8s--server--resources--coredns--registry"></a>`registry`

Data type: `String[1]`

The CoreDNS image registry to use

Default value: `$k8s::server::resources::coredns_registry`

Default value: `$k8s::server::resources::cluster_domain`
##### <a name="-k8s--server--resources--coredns--template_path"></a>`template_path`

Data type: `String[1]`

The path to the template to use for the CoreDNS ConfigMap

Default value: `'k8s/server/resources/coredns_corefile.epp'`

##### <a name="-k8s--server--resources--coredns--template_variables"></a>`template_variables`

Data type: `Hash[String, Any]`

The variables to use for the CoreDNS ConfigMap template

Default value: `{ cluster_domain => $cluster_domain }`

### <a name="k8s--server--resources--flannel"></a>`k8s::server::resources::flannel`

Expand Down
2 changes: 1 addition & 1 deletion data/common.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
---
--- {}
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# @param uid user id for kubernetes files and services
# @param gid group id for kubernetes files and services
# @param etcd_cluster_name name of the etcd cluster for searching its nodes in the puppetdb
# @param cluster_domain domain name for the cluster
#
class k8s (
K8s::Ensure $ensure = 'present',
Expand Down
51 changes: 21 additions & 30 deletions manifests/server/resources/coredns.pp
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
# @summary Generates and deploys the default CoreDNS DNS provider for Kubernetes
#
# @param dns_service_address The address for the DNS service
# @param registry The CoreDNS image registry to use
# @param image The CoreDNS image name to use
# @param image_tag The CoreDNS image tag to use
# @param cluster_domain The cluster domain to use for the CoreDNS ConfigMap
# @param corefile_content The content to use for the CoreDNS ConfigMap
# @param deployment_config Additional configuration to merge into the Kubernetes Deployment object
# @param dns_service_address The address for the DNS service
# @param ensure Whether the resource should be present or absent on the target system
# @param hosts Additional host-style entries for the CoreDNS deployment to serve
# @param image The CoreDNS image name to use
# @param image_pull_secrets the secrets to pull from private registries
# @param image_tag The CoreDNS image tag to use
# @param kubeconfig The path to the kubeconfig to use for kubectl commands
# @param registry The CoreDNS image registry to use
# @param template_path The path to the template to use for the CoreDNS ConfigMap
# @param template_variables The variables to use for the CoreDNS ConfigMap template
#
class k8s::server::resources::coredns (
K8s::Ensure $ensure = $k8s::ensure,
Stdlib::Fqdn $cluster_domain = $k8s::server::resources::cluster_domain,
Stdlib::Unixpath $kubeconfig = $k8s::server::resources::kubeconfig,
K8s::IP_addresses $dns_service_address = $k8s::server::resources::dns_service_address,
String[1] $cluster_domain = $k8s::server::resources::cluster_domain,
String[1] $registry = $k8s::server::resources::coredns_registry,
String[1] $image = $k8s::server::resources::coredns_image,
String[1] $image_tag = $k8s::server::resources::coredns_tag,
Optional[Array] $image_pull_secrets = $k8s::server::resources::image_pull_secrets,
Hash[String,Data] $deployment_config = $k8s::server::resources::coredns_deployment_config,
Array[String[1]] $hosts = [],
String[1] $template_path = 'k8s/server/resources/coredns_corefile.epp',
Optional[String[1]] $corefile_content = undef,
Hash[String, Any] $template_variables = { cluster_domain => $cluster_domain },
) {
assert_private()

Expand All @@ -35,6 +44,12 @@

$_hosts = $hosts.join("\n")

if $corefile_content {
$_corefile_content = $corefile_content
} else {
$_corefile_content = epp($template_path, $template_variables)
}

kubectl_apply {
default:
ensure => $ensure,
Expand Down Expand Up @@ -117,31 +132,7 @@
},
},
data => {
'Corefile' => [
'.:53 {',
' errors',
' health {',
' lameduck 5s',
' }',
' ready',
" kubernetes ${cluster_domain} in-addr.arpa ip6.arpa {",
' fallthrough in-addr.arpa ip6.arpa',
' }',
' prometheus :9153',
' hosts /etc/coredns/PuppetHosts {',
' ttl 60',
' reload 15s',
' fallthrough',
' }',
' forward . /etc/resolv.conf {',
' max_concurrent 1000',
' }',
' cache 30',
' loop',
' reload',
' loadbalance',
'}',
].join("\n"),
'Corefile' => $_corefile_content,
'PuppetHosts' => $_hosts,
},
};
Expand Down
26 changes: 26 additions & 0 deletions templates/server/resources/coredns_corefile.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<%- |
Stdlib::Fqdn $cluster_domain,
| -%>
.:53 {
errors
health {
lameduck 5s
}
ready
kubernetes <%= $cluster_domain %> in-addr.arpa ip6.arpa {
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
hosts /etc/coredns/PuppetHosts {
ttl 60
reload 15s
fallthrough
}
forward . /etc/resolv.conf {
max_concurrent 1000
}
cache 30
loop
reload
loadbalance
}