Skip to content

Commit

Permalink
Use ephemeral storage if not persistence.enabled
Browse files Browse the repository at this point in the history
Signed-off-by: Xudong Sun <[email protected]>
  • Loading branch information
marshtompsxd committed Sep 16, 2023
1 parent ecbeac3 commit c94863f
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 65 deletions.
105 changes: 60 additions & 45 deletions src/controller_examples/zookeeper_controller/exec/reconciler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,56 +1213,63 @@ fn make_stateful_set(zk: &ZookeeperCluster, rv: &String) -> (stateful_set: State
});
// Set the templates used for creating the persistent volume claims attached to each pod
stateful_set_spec.set_volume_claim_templates({
let mut volume_claim_templates = Vec::new();
volume_claim_templates.push({
let mut pvc = PersistentVolumeClaim::default();
pvc.set_metadata({
let mut metadata = ObjectMeta::default();
metadata.set_name(new_strlit("data").to_string());
metadata.set_labels(make_labels(zk));
metadata.set_annotations(zk.spec().annotations());
metadata
});
pvc.set_spec({
let mut pvc_spec = PersistentVolumeClaimSpec::default();
pvc_spec.set_access_modes({
let mut access_modes = Vec::new();
access_modes.push(new_strlit("ReadWriteOnce").to_string());

proof {
assert_seqs_equal!(
[email protected]_values(|mode: String| mode@),
zk_spec::make_stateful_set(zk@, rv@)
.spec.get_Some_0().volume_claim_templates.get_Some_0()[0]
.spec.get_Some_0().access_modes.get_Some_0()
);
}

access_modes
if zk.spec().persistence().enabled() {
let mut volume_claim_templates = Vec::new();
volume_claim_templates.push({
let mut pvc = PersistentVolumeClaim::default();
pvc.set_metadata({
let mut metadata = ObjectMeta::default();
metadata.set_name(new_strlit("data").to_string());
metadata.set_labels(make_labels(zk));
metadata.set_annotations(zk.spec().annotations());
metadata
});
pvc_spec.set_resources({
let mut resources = ResourceRequirements::default();
resources.set_requests({
let mut requests = StringMap::empty();
requests.insert(new_strlit("storage").to_string(), zk.spec().persistence().storage_size());
requests
pvc.set_spec({
let mut pvc_spec = PersistentVolumeClaimSpec::default();
pvc_spec.set_access_modes({
let mut access_modes = Vec::new();
access_modes.push(new_strlit("ReadWriteOnce").to_string());
proof {
assert_seqs_equal!(
[email protected]_values(|mode: String| mode@),
zk_spec::make_stateful_set(zk@, rv@)
.spec.get_Some_0().volume_claim_templates.get_Some_0()[0]
.spec.get_Some_0().access_modes.get_Some_0()
);
}
access_modes
});
resources
pvc_spec.set_resources({
let mut resources = ResourceRequirements::default();
resources.set_requests({
let mut requests = StringMap::empty();
requests.insert(new_strlit("storage").to_string(), zk.spec().persistence().storage_size());
requests
});
resources
});
pvc_spec.overwrite_storage_class_name(zk.spec().persistence().storage_class_name());
pvc_spec
});
pvc_spec.overwrite_storage_class_name(zk.spec().persistence().storage_class_name());
pvc_spec
pvc
});
pvc
});

proof {
assert_seqs_equal!(
[email protected]_values(|pvc: PersistentVolumeClaim| pvc@),
zk_spec::make_stateful_set(zk@, rv@).spec.get_Some_0().volume_claim_templates.get_Some_0()
);
proof {
assert_seqs_equal!(
[email protected]_values(|pvc: PersistentVolumeClaim| pvc@),
zk_spec::make_stateful_set(zk@, rv@).spec.get_Some_0().volume_claim_templates.get_Some_0()
);
}
volume_claim_templates
} else {
let empty_templates = Vec::<PersistentVolumeClaim>::new();
proof {
assert_seqs_equal!(
[email protected]_values(|pvc: PersistentVolumeClaim| pvc@),
zk_spec::make_stateful_set(zk@, rv@).spec.get_Some_0().volume_claim_templates.get_Some_0()
);
}
empty_templates
}

volume_claim_templates
});
stateful_set_spec
});
Expand Down Expand Up @@ -1433,6 +1440,14 @@ fn make_zk_pod_spec(zk: &ZookeeperCluster) -> (pod_spec: PodSpec)
});
volume
});
if !zk.spec().persistence().enabled() {
volumes.push({
let mut volume = Volume::default();
volume.set_name(new_strlit("data").to_string());
volume.set_empty_dir();
volume
});
}

proof {
assert_seqs_equal!(
Expand Down
53 changes: 33 additions & 20 deletions src/controller_examples/zookeeper_controller/spec/reconciler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,23 +1053,29 @@ pub open spec fn make_stateful_set(zk: ZookeeperClusterView, rv: StringView) ->
.set_when_deleted(new_strlit("Delete")@)
.set_when_scaled(new_strlit("Delete")@)
)
.set_volume_claim_templates(seq![
PersistentVolumeClaimView::default()
.set_metadata(ObjectMetaView::default()
.set_name(new_strlit("data")@)
.set_labels(make_labels(zk))
.set_annotations(zk.spec.annotations)
)
.set_spec(PersistentVolumeClaimSpecView::default()
.set_access_modes(seq![new_strlit("ReadWriteOnce")@])
.set_resources(ResourceRequirementsView::default()
.set_requests(Map::empty()
.insert(new_strlit("storage")@, zk.spec.persistence.storage_size)
.set_volume_claim_templates({
if zk.spec.persistence.enabled {
seq![
PersistentVolumeClaimView::default()
.set_metadata(ObjectMetaView::default()
.set_name(new_strlit("data")@)
.set_labels(make_labels(zk))
.set_annotations(zk.spec.annotations)
)
.set_spec(PersistentVolumeClaimSpecView::default()
.set_access_modes(seq![new_strlit("ReadWriteOnce")@])
.set_resources(ResourceRequirementsView::default()
.set_requests(Map::empty()
.insert(new_strlit("storage")@, zk.spec.persistence.storage_size)
)
)
.overwrite_storage_class_name(zk.spec.persistence.storage_class_name)
)
.overwrite_storage_class_name(zk.spec.persistence.storage_class_name)
)
]);
]
} else {
seq![]
}
});

StatefulSetView::default().set_metadata(metadata).set_spec(spec)
}
Expand Down Expand Up @@ -1133,11 +1139,18 @@ pub open spec fn make_zk_pod_spec(zk: ZookeeperClusterView) -> PodSpecView
..ContainerView::default()
}
],
volumes: Some(seq![
VolumeView::default().set_name(new_strlit("conf")@).set_config_map(
ConfigMapVolumeSourceView::default().set_name(zk.metadata.name.get_Some_0() + new_strlit("-configmap")@)
)
]),
volumes: Some({
let volumes = seq![
VolumeView::default().set_name(new_strlit("conf")@).set_config_map(
ConfigMapVolumeSourceView::default().set_name(zk.metadata.name.get_Some_0() + new_strlit("-configmap")@)
)
];
if zk.spec.persistence.enabled {
volumes
} else {
volumes.push(VolumeView::default().set_name(new_strlit("data")@))
}
}),
tolerations: zk.spec.tolerations,
..PodSpecView::default()
}
Expand Down

0 comments on commit c94863f

Please sign in to comment.