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

Configurable cluster domain #988

Merged
merged 4 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ The following settings can be optionally set to customize the node labels and ta
The following settings are set for you automatically by [pluto](sources/api/) based on runtime instance information, but you can override them if you know what you're doing!
* `settings.kubernetes.max-pods`: The maximum number of pods that can be scheduled on this node (limited by number of available IPv4 addresses)
* `settings.kubernetes.cluster-dns-ip`: The CIDR block of the primary network interface.
* `settings.kubernetes.cluster-domain`: The cluster domain is set to `cluster.local` by default.
* `settings.kubernetes.node-ip`: The IPv4 address of this node.
* `settings.kubernetes.pod-infra-container-image`: The URI of the "pause" container.

Expand Down
2 changes: 1 addition & 1 deletion packages/kubernetes-1.15/kubelet-config
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ authorization:
webhook:
cacheAuthorizedTTL: 5m0s
cacheUnauthorizedTTL: 30s
clusterDomain: cluster.local
clusterDomain: {{settings.kubernetes.cluster-domain}}
clusterDNS:
- {{settings.kubernetes.cluster-dns-ip}}
resolvConf: "/etc/resolv.conf"
Expand Down
2 changes: 1 addition & 1 deletion packages/kubernetes-1.16/kubelet-config
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ authorization:
webhook:
cacheAuthorizedTTL: 5m0s
cacheUnauthorizedTTL: 30s
clusterDomain: cluster.local
clusterDomain: {{settings.kubernetes.cluster-domain}}
clusterDNS:
- {{settings.kubernetes.cluster-dns-ip}}
resolvConf: "/etc/resolv.conf"
Expand Down
2 changes: 1 addition & 1 deletion packages/kubernetes-1.17/kubelet-config
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ authorization:
webhook:
cacheAuthorizedTTL: 5m0s
cacheUnauthorizedTTL: 30s
clusterDomain: cluster.local
clusterDomain: {{settings.kubernetes.cluster-domain}}
clusterDNS:
- {{settings.kubernetes.cluster-dns-ip}}
resolvConf: "/etc/resolv.conf"
Expand Down
5 changes: 5 additions & 0 deletions sources/models/defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,8 @@ template-path = "/usr/share/templates/chrony-conf"

[metadata.settings.ntp]
affected-services = ["chronyd"]

# Kubernetes

[settings.kubernetes]
cluster-domain = "cluster.local"
3 changes: 2 additions & 1 deletion sources/models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ use std::collections::HashMap;
use std::net::Ipv4Addr;

use crate::modeled_types::{
FriendlyVersion, KubernetesClusterName, KubernetesLabelKey, KubernetesLabelValue,
DNSDomain, FriendlyVersion, KubernetesClusterName, KubernetesLabelKey, KubernetesLabelValue,
KubernetesTaintValue, SingleLineString, Url, ValidBase64,
};

Expand All @@ -94,6 +94,7 @@ struct KubernetesSettings {
// Dynamic settings.
max_pods: u32,
cluster_dns_ip: Ipv4Addr,
cluster_domain: DNSDomain,
node_ip: Ipv4Addr,
pod_infra_container_image: SingleLineString,
}
Expand Down
3 changes: 3 additions & 0 deletions sources/models/src/modeled_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ pub mod error {

#[snafu(display("Given invalid cluster name '{}': {}", name, msg))]
InvalidClusterName { name: String, msg: String },

#[snafu(display("Invalid domain name '{}'", input))]
InvalidDomainName { input: String },
}
}

Expand Down
74 changes: 74 additions & 0 deletions sources/models/src/modeled_types/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,77 @@ mod test_version {
}
}
}

// =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=

/// DNSDomain represents a string that is a valid DNS domain. It stores the
/// original string and makes it accessible through standard traits. Its purpose
/// is input validation, for example validating the kubelet's "clusterDomain"
/// config value.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct DNSDomain {
inner: String,
}

impl TryFrom<&str> for DNSDomain {
type Error = error::Error;

fn try_from(input: &str) -> Result<Self, Self::Error> {
ensure!(input.len() <= 253, error::InvalidDomainName { input });

let labels = input.split(".");
for (i, label) in labels.enumerate() {
ensure!(i < 127, error::InvalidDomainName { input });
ensure!(label.len() <= 63, error::InvalidDomainName { input });
let last = label.len() - 1;
for (j, c) in label.chars().enumerate() {
ensure!(
(j != 0 && j != last && (c.is_alphanumeric() || c == '-'))
|| c.is_alphanumeric(),
error::InvalidDomainName { input }
);
}
}

Ok(Self {
inner: input.to_string(),
})
}
}

string_impls_for!(DNSDomain, "DNSDomain");

#[cfg(test)]
mod test_dns_domain {
use super::DNSDomain;
use std::convert::TryFrom;

#[test]
fn valid_dns_domain() {
for ok in &[
"cluster.local",
"dev.eks",
"stage.eks",
"prod.eks",
"1-good.local",
&"a".repeat(63),
&format!("a{}", ".a".repeat(126)),
] {
assert!(DNSDomain::try_from(*ok).is_ok());
}
}

#[test]
fn invalid_dns_domain() {
for err in &[
"-bad.com",
"bad-.com",
"-bad-.com",
"b_ad.com",
&"a".repeat(64),
&format!("a{}", ".a".repeat(127)),
] {
assert!(DNSDomain::try_from(*err).is_err());
}
}
}