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

feat: Support PodDisruptionBudgets #394

Merged
merged 32 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
13b4e6a
feat: Support PDBs
sbernauer Sep 19, 2023
ecdcdae
Read out spec.role.pdb field
sbernauer Sep 19, 2023
e4adc16
fix rbac permissions
sbernauer Sep 19, 2023
5c45fec
Pull in new operator-rs
sbernauer Sep 21, 2023
6f2cafc
changelog
sbernauer Sep 21, 2023
7e47719
Merge branch 'main' into feat/support-pdb
sbernauer Sep 21, 2023
34d919f
fix: Datanode maxUnavailable calculation
sbernauer Sep 21, 2023
f50edae
move docs
sbernauer Sep 21, 2023
a9a6524
first round of docs
sbernauer Sep 21, 2023
1ee267a
linter
sbernauer Sep 21, 2023
a4ba0a2
wording
sbernauer Sep 21, 2023
58d6d42
wording
sbernauer Sep 21, 2023
60b1ee2
Apply suggestions from code review
sbernauer Sep 22, 2023
ab848b7
max -> most
sbernauer Sep 22, 2023
2d963a9
new operator-rs
sbernauer Sep 22, 2023
47fe088
Use operator-rs 0.51.0
sbernauer Sep 25, 2023
cd3cf11
Rename docs page to "Allowed Pod disruptions" to match concepts page …
sbernauer Sep 25, 2023
413ff4d
wording
sbernauer Sep 25, 2023
f535a9d
wording
sbernauer Sep 25, 2023
0c4fde8
remove newlines
sbernauer Sep 25, 2023
3a941ef
rename doc files
sbernauer Sep 26, 2023
e9c9445
docs
sbernauer Sep 26, 2023
837637f
docs wording
sbernauer Sep 26, 2023
79e21b9
Update rust/crd/src/lib.rs
sbernauer Sep 26, 2023
741580b
Update docs/modules/hdfs/pages/usage-guide/operations/pod-disruptions…
sbernauer Sep 26, 2023
a0f0b4c
changelog
sbernauer Sep 26, 2023
65ebcef
Update docs/modules/hdfs/pages/usage-guide/operations/pod-disruptions…
sbernauer Sep 26, 2023
35fcdd9
typo
sbernauer Sep 26, 2023
7147491
use PascalCase for DataNodes
sbernauer Sep 26, 2023
339fffd
use op-rs 0.51.1
sbernauer Sep 26, 2023
d786405
Add pdb assert to smoke test
sbernauer Sep 26, 2023
bcaebc6
fix error message
sbernauer Sep 26, 2023
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
744 changes: 344 additions & 400 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9"
snafu = "0.7"
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.46.0" }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", tag = "0.50.0" }
strum = { version = "0.25", features = ["derive"] }
tokio = { version = "1.29", features = ["full"] }
tracing = "0.1"
tracing-futures = { version = "0.2", features = ["futures-03"] }

# [patch."https://github.com/stackabletech/operator-rs.git"]
# stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch = "main" }
[patch."https://github.com/stackabletech/operator-rs.git"]
stackable-operator = { git = "https://github.com/stackabletech//operator-rs.git", branch = "feat/support-pdb" }
# stackable-operator = { path = "/home/sbernauer/stackabletech/operator-rs" }
sbernauer marked this conversation as resolved.
Show resolved Hide resolved
86 changes: 85 additions & 1 deletion deploy/helm/hdfs-operator/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ spec:
nullable: true
type: boolean
dfsReplication:
default: 3
format: uint8
minimum: 0.0
nullable: true
type: integer
listenerClass:
default: cluster-internal
Expand Down Expand Up @@ -755,6 +755,22 @@ spec:
type: string
default: {}
type: object
pdb:
default:
enabled: true
maxUnavailable: null
properties:
enabled:
default: true
description: Wether a PodDisruptionBudget should be written out for this role. Disabling this enables you to specify you own - custom - one. Defaults to true.
type: boolean
maxUnavailable:
description: The number of Pods that are allowed to be down because of voluntary disruptions. If you don't explicitly set this, the operator will use a sane default based upon knowledge about the individual product.
format: uint16
minimum: 0.0
nullable: true
type: integer
type: object
podOverrides:
default: {}
description: See PodTemplateSpec (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#podtemplatespec-v1-core) for more details
Expand Down Expand Up @@ -1480,6 +1496,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -2007,6 +2025,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -2540,6 +2560,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -4934,6 +4956,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -5461,6 +5485,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -5994,6 +6020,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -7737,6 +7765,22 @@ spec:
type: string
default: {}
type: object
pdb:
default:
enabled: true
maxUnavailable: null
properties:
enabled:
default: true
description: Wether a PodDisruptionBudget should be written out for this role. Disabling this enables you to specify you own - custom - one. Defaults to true.
type: boolean
maxUnavailable:
description: The number of Pods that are allowed to be down because of voluntary disruptions. If you don't explicitly set this, the operator will use a sane default based upon knowledge about the individual product.
format: uint16
minimum: 0.0
nullable: true
type: integer
type: object
podOverrides:
default: {}
description: See PodTemplateSpec (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#podtemplatespec-v1-core) for more details
Expand Down Expand Up @@ -8462,6 +8506,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -8989,6 +9035,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -9522,6 +9570,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -11907,6 +11957,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -12434,6 +12486,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -12967,6 +13021,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -14668,6 +14724,22 @@ spec:
type: string
default: {}
type: object
pdb:
default:
enabled: true
maxUnavailable: null
properties:
enabled:
default: true
description: Wether a PodDisruptionBudget should be written out for this role. Disabling this enables you to specify you own - custom - one. Defaults to true.
type: boolean
maxUnavailable:
description: The number of Pods that are allowed to be down because of voluntary disruptions. If you don't explicitly set this, the operator will use a sane default based upon knowledge about the individual product.
format: uint16
minimum: 0.0
nullable: true
type: integer
type: object
podOverrides:
default: {}
description: See PodTemplateSpec (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/#podtemplatespec-v1-core) for more details
Expand Down Expand Up @@ -15393,6 +15465,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -15920,6 +15994,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -16453,6 +16529,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -18838,6 +18916,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -19365,6 +19445,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down Expand Up @@ -19898,6 +19980,8 @@ spec:
type: string
type: object
type: object
restartPolicy:
type: string
securityContext:
properties:
allowPrivilegeEscalation:
Expand Down
11 changes: 11 additions & 0 deletions deploy/helm/hdfs-operator/templates/roles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ rules:
- patch
- update
- watch
- apiGroups:
- policy
resources:
- poddisruptionbudgets
verbs:
- create
- get
- list
- patch
- update
- watch
- apiGroups:
- apiextensions.k8s.io
resources:
Expand Down
58 changes: 51 additions & 7 deletions rust/crd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ pub struct HdfsClusterSpec {
#[derive(Clone, Debug, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct HdfsClusterConfig {
// FIXME: This attribute does not seem to be read anywhere.
maltesander marked this conversation as resolved.
Show resolved Hide resolved
pub auto_format_fs: Option<bool>,
pub dfs_replication: Option<u8>,
#[serde(default = "default_dfs_replication_factor")]
pub dfs_replication: u8,
/// Name of the Vector aggregator discovery ConfigMap.
/// It must contain the key `ADDRESS` with the address of the Vector aggregator.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -113,6 +115,10 @@ pub struct HdfsClusterConfig {
pub authentication: Option<AuthenticationConfig>,
}

fn default_dfs_replication_factor() -> u8 {
DEFAULT_DFS_REPLICATION_FACTOR
}

// TODO: Temporary solution until listener-operator is finished
#[derive(
Clone, Debug, Default, Display, Deserialize, Eq, Hash, JsonSchema, PartialEq, Serialize,
Expand Down Expand Up @@ -684,6 +690,15 @@ impl HdfsCluster {
.map(|k| k.tls_secret_class.as_str())
}

pub fn num_datanodes(&self) -> u16 {
self.spec
.data_nodes
.iter()
.flat_map(|dn| dn.role_groups.values())
.map(|rg| rg.replicas.unwrap_or(1))
.sum()
}

/// Returns required port name and port number tuples depending on the role.
pub fn ports(&self, role: &HdfsRole) -> Vec<(String, u16)> {
match role {
Expand Down Expand Up @@ -930,9 +945,10 @@ impl Configuration for NameNodeConfigFragment {
) -> Result<BTreeMap<String, Option<String>>, ConfigError> {
let mut config = BTreeMap::new();
if file == HDFS_SITE_XML {
if let Some(replication) = &resource.spec.cluster_config.dfs_replication {
config.insert(DFS_REPLICATION.to_string(), Some(replication.to_string()));
}
config.insert(
DFS_REPLICATION.to_string(),
Some(resource.spec.cluster_config.dfs_replication.to_string()),
);
}

Ok(config)
Expand Down Expand Up @@ -1082,9 +1098,10 @@ impl Configuration for DataNodeConfigFragment {
) -> Result<BTreeMap<String, Option<String>>, ConfigError> {
let mut config = BTreeMap::new();
if file == HDFS_SITE_XML {
if let Some(replication) = &resource.spec.cluster_config.dfs_replication {
config.insert(DFS_REPLICATION.to_string(), Some(replication.to_string()));
}
config.insert(
DFS_REPLICATION.to_string(),
Some(resource.spec.cluster_config.dfs_replication.to_string()),
);
}

Ok(config)
Expand Down Expand Up @@ -1525,4 +1542,31 @@ spec:
};
assert_eq!(expected, rr);
}

#[test]
pub fn test_num_datanodes() {
let cr = "
---
apiVersion: hdfs.stackable.tech/v1alpha1
kind: HdfsCluster
metadata:
name: hdfs
spec:
image:
productVersion: 3.3.4
clusterConfig:
zookeeperConfigMapName: hdfs-zk
dataNodes:
roleGroups:
default: {}
second:
replicas: 2
third:
replicas: 42
";

let hdfs: HdfsCluster = serde_yaml::from_str(cr).unwrap();

assert_eq!(hdfs.num_datanodes(), 45);
}
}
3 changes: 3 additions & 0 deletions rust/operator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ strum.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-futures.workspace = true

[dev-dependencies]
rstest.workspace = true
Loading