Skip to content

Commit

Permalink
feat(shulker-crds): add redis provided spec to cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylvln committed Oct 27, 2023
1 parent 048bb66 commit 490db51
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@shulker/docs",
"name": "@shulkermc/docs",
"private": true,
"engines": {
"node": "^20"
Expand Down
23 changes: 23 additions & 0 deletions kube/resources/crd/bases/shulkermc.io_minecraftclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,34 @@ spec:
spec:
properties:
redis:
description: Redis configuration to use as a synchronization backend for the different Shulker components
nullable: true
properties:
provided:
description: Configuration needed to connect to a provided Redis instance. If type is not `Provide`d, this field is ignored
nullable: true
properties:
credentialsSecretName:
description: Kubernetes Secret containing the credentials to use. It must contains a `username` and `password` keys
nullable: true
type: string
host:
description: Host of the Redis instance
type: string
port:
default: 6379
description: Port of the Redis instance
format: uint16
minimum: 0.0
type: integer
required:
- host
type: object
type:
description: Type of Redis deployment to use. Shulker can provided a single-node managed Redis to use for development purposes. Production workload should use a dedicated Redis cluster. Defaults to ManagedSingleNode
enum:
- ManagedSingleNode
- Provided
type: string
required:
- type
Expand Down
33 changes: 33 additions & 0 deletions packages/shulker-crds/src/v1alpha1/minecraft_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ use strum::{Display, IntoStaticStr};
)]
#[serde(rename_all = "camelCase")]
pub struct MinecraftClusterSpec {
/// Redis configuration to use as a synchronization backend
/// for the different Shulker components
#[serde(skip_serializing_if = "Option::is_none")]
pub redis: Option<MinecraftClusterRedisSpec>,
}

#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct MinecraftClusterRedisSpec {
/// Type of Redis deployment to use. Shulker can provided a single-node
/// managed Redis to use for development purposes. Production workload
/// should use a dedicated Redis cluster. Defaults to ManagedSingleNode
pub type_: MinecraftClusterRedisDeploymentType,

/// Configuration needed to connect to a provided Redis instance.
/// If type is not `Provide`d, this field is ignored
#[serde(default, skip_serializing_if = "Option::is_none")]
pub provided: Option<MinecraftClusterRedisProvidedSpec>,
}

#[derive(
Expand All @@ -33,6 +43,29 @@ pub enum MinecraftClusterRedisDeploymentType {
Provided,
}

#[derive(Deserialize, Serialize, Clone, Debug, Default, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct MinecraftClusterRedisProvidedSpec {
/// Host of the Redis instance
pub host: String,

/// Port of the Redis instance
#[schemars(default = "MinecraftClusterRedisProvidedSpec::default_port")]
pub port: u16,

/// Kubernetes Secret containing the credentials to use. It must
/// contains a `username` and `password` keys
#[serde(default, skip_serializing_if = "Option::is_none")]
pub credentials_secret_name: Option<String>,
}

#[cfg(not(tarpaulin_include))]
impl MinecraftClusterRedisProvidedSpec {
fn default_port() -> u16 {
6379
}
}

/// The status object of `MinecraftCluster`
#[derive(Deserialize, Serialize, Clone, Debug, JsonSchema)]
#[serde(rename_all = "camelCase")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ mod tests {
let mut cluster = TEST_CLUSTER.clone();
cluster.spec.redis = Some(MinecraftClusterRedisSpec {
type_: MinecraftClusterRedisDeploymentType::ManagedSingleNode,
..MinecraftClusterRedisSpec::default()
});

// W
Expand All @@ -140,6 +141,7 @@ mod tests {
let mut cluster = TEST_CLUSTER.clone();
cluster.spec.redis = Some(MinecraftClusterRedisSpec {
type_: MinecraftClusterRedisDeploymentType::Provided,
..MinecraftClusterRedisSpec::default()
});

// W
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ mod tests {
let mut cluster = TEST_CLUSTER.clone();
cluster.spec.redis = Some(MinecraftClusterRedisSpec {
type_: MinecraftClusterRedisDeploymentType::ManagedSingleNode,
..MinecraftClusterRedisSpec::default()
});

// W
Expand All @@ -233,6 +234,7 @@ mod tests {
let mut cluster = TEST_CLUSTER.clone();
cluster.spec.redis = Some(MinecraftClusterRedisSpec {
type_: MinecraftClusterRedisDeploymentType::Provided,
..MinecraftClusterRedisSpec::default()
});

// W
Expand Down

0 comments on commit 490db51

Please sign in to comment.