Skip to content

Allow changing configuration options #71

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

Merged
merged 68 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
becd50a
WIP
lfrancke Feb 17, 2021
d18d6be
Fix compilation
lfrancke Feb 19, 2021
312a713
WIP (this might not compile, just to show what I'm working on)
lfrancke Feb 25, 2021
6e3afee
WIP (doesn't compile)
lfrancke Mar 1, 2021
ab3881c
fixed compile errors, removed clippy warnings
maltesander Mar 2, 2021
211e171
WIP
lfrancke Mar 9, 2021
beb968e
Merge branch 'main' into upgrades
lfrancke Mar 11, 2021
30a4803
Fix build and one message
lfrancke Mar 16, 2021
f830bc9
Merge branch 'main' into upgrades
lfrancke Mar 16, 2021
0ad5fd2
Fix test & clippy
lfrancke Mar 17, 2021
caf0cbd
Add some docs for upgrade errors
lfrancke Mar 17, 2021
6cc8b1f
WIP
lfrancke Feb 10, 2021
a713e5e
WIP
lfrancke Mar 18, 2021
db6b60d
Merge branch 'main' into config
lfrancke Mar 18, 2021
cd14201
Merge branch 'upgrades' into config
lfrancke Mar 19, 2021
a3b088f
WIP
lfrancke Mar 19, 2021
b736490
WIP
lfrancke Mar 22, 2021
9c3bf3c
Merge branch 'main' into config
lfrancke Apr 1, 2021
d2f9bb5
product_config changes
lfrancke Apr 1, 2021
1ced532
WIP
lfrancke Apr 29, 2021
a30513f
Merge branch 'main' into config
lfrancke May 3, 2021
ab68291
Merge main
lfrancke May 3, 2021
ddfda15
Fix build
lfrancke May 3, 2021
94b5739
WIP
lfrancke May 5, 2021
45a715a
WIP
lfrancke May 17, 2021
8eb123a
Merge branch 'main' into config
lfrancke May 17, 2021
82dd110
Fix some (not all) compilation errors
lfrancke May 17, 2021
4ebfd47
WIP
lfrancke May 18, 2021
787148a
Merge branch 'main' into config
lfrancke May 20, 2021
8d56780
WIP
lfrancke May 20, 2021
3c28f56
Use proper product_config branch
lfrancke May 20, 2021
41d6fda
Use proper product_config branch
lfrancke May 20, 2021
8890b97
Fix config json
lfrancke May 20, 2021
8330334
Fix config json
lfrancke May 20, 2021
5f018f6
Fix config parsing
lfrancke May 20, 2021
b89a89d
Implement config stuff from operator-rs & product-config
lfrancke Jun 2, 2021
bbcfc4e
Merge branch 'main' into config
lfrancke Jun 2, 2021
2dff420
Fix build
lfrancke Jun 2, 2021
7ff73e5
WIP
lfrancke Jun 8, 2021
0241d09
Merge remote-tracking branch 'origin/main' into config
maltesander Jun 10, 2021
6136ecd
Merged main.
maltesander Jun 10, 2021
9aae8a7
Merge remote-tracking branch 'origin/config' into config
maltesander Jun 10, 2021
de479ef
Merged main.
maltesander Jun 10, 2021
e129b16
First working version of product config integration.
maltesander Jun 10, 2021
88d2aac
WIP
maltesander Jun 10, 2021
532793c
WIP
maltesander Jun 10, 2021
04c381d
WIP
maltesander Jun 11, 2021
4e2fda7
First "working" version with product config and operator-rs changes.
maltesander Jun 23, 2021
5916ae9
WIP
maltesander Jun 23, 2021
c60ed3e
Merge remote-tracking branch 'origin/main' into config
maltesander Jun 23, 2021
942325d
Adapted to changes in operator-rs (https://github.com/stackabletech/o…
maltesander Jun 23, 2021
5456654
Adapted to operator-rs Configuration trait changes.
maltesander Jun 24, 2021
d7af60a
Removed foo / fake product config test.
maltesander Jun 24, 2021
23ce30b
Adapted to operator-rs changes.
maltesander Jun 24, 2021
9b0e181
Working with adapted product-config and operator-rs.
maltesander Jun 30, 2021
5e60563
Using validate_role_and_group_config from operator-rs framework.
maltesander Jun 30, 2021
e9e5601
Adapted to latest product-config and operator-rs
maltesander Jul 1, 2021
89725a0
Adapted to operator-rs into_dyn changes.
maltesander Jul 2, 2021
a68d499
Adapted to operator-rs changes.
maltesander Jul 4, 2021
c54cc6a
Adapted to operator-rs changes (list_owned).
maltesander Jul 6, 2021
f499f05
Added create config maps and adapted managed_by label.
maltesander Jul 7, 2021
a570d9f
Adapted to operator-rs changes.
maltesander Jul 8, 2021
4a9b354
Merge remote-tracking branch 'origin/main' into config
maltesander Jul 8, 2021
0829b4a
Merged Main
maltesander Jul 8, 2021
b38dcd5
Adapted to PR review.
maltesander Jul 13, 2021
12be307
Merge remote-tracking branch 'origin/main' into config
maltesander Jul 19, 2021
90c6ea7
Adapted to PR review.
maltesander Jul 19, 2021
acf7eb1
Adapted to operator-rs get_pod_name.
maltesander Jul 19, 2021
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
313 changes: 142 additions & 171 deletions Cargo.lock

Large diffs are not rendered by default.

106 changes: 106 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
version: 0.1.0
spec:
units:
- unit: &unitDirectory
name: "directory"
regex: "^/|(/[\\w-]+)+$"
examples:
- "/tmp/xyz"
- unit: &unitPort
name: "port"
regex: "^([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$"
properties:
- property: &tickTime
propertyNames:
- name: "tickTime"
kind:
type: "file"
file: "zoo.cfg"
datatype:
type: "integer"
min: "1"
recommendedValues:
- fromVersion: "0.0.0"
value: "3000"
roles:
- name: "server"
required: true
asOfVersion: "0.0.0"
comment: "ZK only checks whether the value is 0, all other values (including negative ones) are considered valid, we disallow negative values here, see QuorumPeerConfig.java"
description: "The basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime."

- property: &clientPort
propertyNames:
- name: "clientPort"
kind:
type: "file"
file: "zoo.cfg"
datatype:
type: "string"
unit: *unitPort
defaultValues:
- value: "2181"
recommendedValues:
- value: "2181"
roles:
- name: "server"
required: true
asOfVersion: "0.0.0"
comment: "See QuorumPeerConfig.java, I'm unsure what happens when this is set to 0, it might work, it might not"
description: "The port to listen for client connections; that is, the port that clients attempt to connect to."

- property: &dataDir
propertyNames:
- name: "dataDir"
kind:
type: "file"
file: "zoo.cfg"
datatype:
type: "string"
unit: *unitDirectory
recommendedValues:
- value: "/tmp/zookeeper"
roles:
- name: "server"
required: true
asOfVersion: "0.0.0"
comment: "See QuorumPeerConfig.java"
description: "The location where ZooKeeper will store the in-memory database snapshots and, unless specified otherwise, the transaction log of updates to the database. Note: Be careful where you put the transaction log. A dedicated transaction log device is key to consistent good performance. Putting the log on a busy device will adversely affect performance."

# Role required "true" is only correct if more than one zookeeper instances is used.
- property: &initLimit
propertyNames:
- name: "initLimit"
kind:
type: "file"
file: "zoo.cfg"
datatype:
type: "integer"
min: "1"
recommendedValues:
- value: "5"
roles:
- name: "server"
required: true
asOfVersion: "0.0.0"
comment: "ZK only checks whether the value is 0, all other values (including negative ones) are considered valid, we disallow negative values here, see QuorumPeerConfig.java"
description: "Amount of time, in ticks (see `tickTime`), to allow followers to connect and sync to a leader. Increased this value as needed, if the amount of data managed by ZooKeeper is large."

# Role required "true" is only correct if more than one zookeeper instances is used.
- property: &syncLimit
propertyNames:
- name: "syncLimit"
kind:
type: "file"
file: "zoo.cfg"
datatype:
type: "integer"
min: "1"
recommendedValues:
- value: "2"
roles:
- name: "server"
required: true
asOfVersion: "0.0.0"
comment: "ZK only checks whether the value is 0, all other values (including negative ones) are considered valid, we disallow negative values here, see QuorumPeerConfig.java"
description: "Amount of time, in ticks (see `tickTime`), to allow followers to sync with ZooKeeper. If followers fall too far behind a leader, they will be dropped. In other words: The number of ticks that can pass between sending a request and getting an acknowledgment before a follower is dropped."
8 changes: 4 additions & 4 deletions crd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ name = "stackable-zookeeper-crd"
version = "0.1.0-nightly"

[dependencies]
product-config = { git = "https://github.com/stackabletech/product-config.git", branch = "main" }
stackable-operator = { git = "https://github.com/stackabletech/operator-rs.git", branch = "main" }

k8s-openapi = { version = "0.11", default-features = false }
kube = { version = "0.56", default-features = false, features = ["derive", "jsonpatch"] }
k8s-openapi = { version = "0.12", default-features = false, features = ["v1_20"] }
kube = { version = "0.57", default-features = false, features = ["derive", "jsonpatch"] }
schemars = "0.8"
semver = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.8"
strum = "0.21"
strum_macros = "0.21"
thiserror = "1.0"
tracing = "0.1"

[dev-dependencies]
indoc = "1.0"
k8s-openapi = { version = "0.11", default-features = false, features = ["v1_20"] }
k8s-openapi = { version = "0.12", default-features = false, features = ["v1_20"] }
rstest = "0.10"
serde_yaml = "0.8"

Expand Down
15 changes: 5 additions & 10 deletions crd/src/bin/generate_crd.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use stackable_operator::crd::CustomResourceExt;
use stackable_zookeeper_crd::ZookeeperCluster;
use std::fs;

fn main() {
let target_file = "./crd/zookeepercluster.crd.yaml";
let schema = ZookeeperCluster::crd();
let string_schema = match serde_yaml::to_string(&schema) {
Ok(schema) => schema,
Err(err) => panic!("Failed to retrieve CRD: [{}]", err),
};
match fs::write(target_file, string_schema) {
Ok(()) => println!("Successfully wrote CRD to file."),
Err(err) => println!("Failed to write file: [{}]", err),
let target_file = "deploy/crd/zookeepercluster.crd.yaml";
match ZookeeperCluster::write_yaml_schema(target_file) {
Ok(_) => println!("Wrote CRD to [{}]", target_file),
Err(err) => println!("Could not write CRD to [{}]: {:?}", target_file, err),
}
}
76 changes: 50 additions & 26 deletions crd/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,82 @@
pub mod error;
pub mod util;

use k8s_openapi::apimachinery::pkg::apis::meta::v1::{Condition, LabelSelector};
use k8s_openapi::apimachinery::pkg::apis::meta::v1::Condition;
use kube::CustomResource;
use schemars::JsonSchema;
use semver::{Error as SemVerError, Version};
use serde::{Deserialize, Serialize};
use stackable_operator::label_selector;
use stackable_operator::product_config_utils::{ConfigError, Configuration};
use stackable_operator::role_utils::Role;
use stackable_operator::status::Conditions;
use stackable_operator::Crd;
use std::collections::HashMap;
use std::collections::BTreeMap;

pub const APP_NAME: &str = "zookeeper";
pub const MANAGED_BY: &str = "stackable-zookeeper";
pub const MANAGED_BY: &str = "zookeeper-operator";

// TODO: We need to validate the name of the cluster because it is used in pod and configmap names, it can't bee too long
// This probably also means we shouldn't use the node_names in the pod_name...
#[derive(Clone, CustomResource, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
#[kube(
group = "zookeeper.stackable.tech",
version = "v1",
version = "v1alpha1",
kind = "ZookeeperCluster",
plural = "zookeeperclusters",
shortname = "zk",
namespaced
)]
#[kube(status = "ZookeeperClusterStatus")]
pub struct ZookeeperClusterSpec {
pub version: ZookeeperVersion,
pub servers: RoleGroups<ZookeeperConfig>,
pub servers: Role<ZookeeperConfig>,
}

#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
// TODO: These all should be "Property" Enums that can be either simple or complex where complex allows forcing/ignoring errors and/or warnings
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RoleGroups<T> {
pub selectors: HashMap<String, SelectorAndConfig<T>>,
pub struct ZookeeperConfig {
pub client_port: Option<u16>, // int in Java
pub data_dir: Option<String>, // String in Java
pub init_limit: Option<u32>, // int in Java
pub sync_limit: Option<u32>, // int in Java
pub tick_time: Option<u32>, // int in Java
}

#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SelectorAndConfig<T> {
pub instances: u16,
pub instances_per_node: u8,
pub config: Option<T>,
#[schemars(schema_with = "label_selector::schema")]
pub selector: Option<LabelSelector>,
}
impl Configuration for ZookeeperConfig {
type Configurable = ZookeeperCluster;

#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
pub struct ZookeeperConfig {}
fn compute_env(
&self,
_resource: &Self::Configurable,
_role_name: &str,
) -> Result<BTreeMap<String, Option<String>>, ConfigError> {
Ok(BTreeMap::new())
}

fn compute_cli(
&self,
_resource: &Self::Configurable,
_role_name: &str,
) -> Result<BTreeMap<String, Option<String>>, ConfigError> {
Ok(BTreeMap::new())
}

fn compute_files(
&self,
_resource: &Self::Configurable,
_role_name: &str,
_file: &str,
) -> Result<BTreeMap<String, Option<String>>, ConfigError> {
let temp = product_config::ser::to_hash_map(self).map_err(|err| {
ConfigError::InvalidConfiguration {
reason: format!("Could not deserialize config: {}", err.to_string()),
}
})?;
let result: BTreeMap<String, Option<String>> =
temp.into_iter().map(|(k, v)| (k, Some(v))).collect();
Ok(result)
}
}

impl Conditions for ZookeeperCluster {
fn conditions(&self) -> Option<&[Condition]> {
Expand All @@ -66,11 +95,6 @@ impl Conditions for ZookeeperCluster {
}
}

impl Crd for ZookeeperCluster {
const RESOURCE_NAME: &'static str = "zookeeperclusters.zookeeper.stackable.tech";
const CRD_DEFINITION: &'static str = include_str!("../../deploy/crd/zookeepercluster.crd.yaml");
}

#[allow(non_camel_case_types)]
#[derive(
Clone,
Expand Down
Loading