Skip to content

Commit 8b8c104

Browse files
committed
add snapshot tests and make them succeed
1 parent aec271a commit 8b8c104

9 files changed

Lines changed: 358 additions & 31 deletions

File tree

extra/crds.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ spec:
242242
nullable: true
243243
type: string
244244
hbaseRootdir:
245+
description: Root directory for Hbase on the filesystem (usually a path in HDFS). Default is `/hbase`.
245246
nullable: true
246247
type: string
247248
listenerClass:
@@ -687,6 +688,7 @@ spec:
687688
nullable: true
688689
type: string
689690
hbaseRootdir:
691+
description: Root directory for Hbase on the filesystem (usually a path in HDFS). Default is `/hbase`.
690692
nullable: true
691693
type: string
692694
listenerClass:
@@ -2054,6 +2056,7 @@ spec:
20542056
nullable: true
20552057
type: string
20562058
hbaseRootdir:
2059+
description: Root directory for Hbase on the filesystem (usually a path in HDFS). Default is `/hbase`.
20572060
nullable: true
20582061
type: string
20592062
listenerClass:
@@ -2499,6 +2502,7 @@ spec:
24992502
nullable: true
25002503
type: string
25012504
hbaseRootdir:
2505+
description: Root directory for Hbase on the filesystem (usually a path in HDFS). Default is `/hbase`.
25022506
nullable: true
25032507
type: string
25042508
listenerClass:

rust/operator-binary/src/controller/build/properties/hbase_site.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ pub fn build(
3030

3131
// Defaults previously injected by product-config's `compute_files`.
3232
config.insert(HBASE_CLUSTER_DISTRIBUTED.to_string(), "true".to_string());
33-
if let Some(rootdir) = merged_config.hbase_rootdir() {
34-
config.insert(HBASE_ROOTDIR.to_string(), rootdir);
35-
}
33+
config.insert(HBASE_ROOTDIR.to_string(), merged_config.hbase_rootdir());
3634

3735
config.extend(zookeeper_config);
3836
config.extend(kerberos_config);

rust/operator-binary/src/controller/build/properties/ssl_client.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ use stackable_operator::v2::config_overrides::KeyValueConfigOverrides;
55

66
use crate::{config::writer::to_hadoop_xml, controller::build::properties::resolved_overrides};
77

8-
/// Renders `ssl-client.xml`. Returns "" (HBase rejects empty XML files) when empty.
8+
/// Renders `ssl-client.xml`.
99
pub fn build(settings: BTreeMap<String, String>, overrides: KeyValueConfigOverrides) -> String {
1010
let mut config: BTreeMap<String, Option<String>> = BTreeMap::new();
1111
config.extend(settings.into_iter().map(|(k, v)| (k, Some(v))));
1212
config.extend(resolved_overrides(overrides).map(|(k, v)| (k, Some(v))));
13-
if config.is_empty() {
14-
return String::new();
15-
}
1613
to_hadoop_xml(config.iter())
1714
}
1815

@@ -21,11 +18,6 @@ mod tests {
2118
use super::*;
2219
use crate::controller::build::properties::test_support::config_overrides;
2320

24-
#[test]
25-
fn empty_settings_without_overrides_renders_empty_string() {
26-
assert_eq!(build(BTreeMap::new(), config_overrides(&[])), "");
27-
}
28-
2921
#[test]
3022
fn settings_appear_in_xml() {
3123
let xml = build(

rust/operator-binary/src/controller/build/properties/ssl_server.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ use stackable_operator::v2::config_overrides::KeyValueConfigOverrides;
55

66
use crate::{config::writer::to_hadoop_xml, controller::build::properties::resolved_overrides};
77

8-
/// Renders `ssl-server.xml`. Returns "" (HBase rejects empty XML files) when empty.
8+
/// Renders `ssl-server.xml`.
99
pub fn build(settings: BTreeMap<String, String>, overrides: KeyValueConfigOverrides) -> String {
1010
let mut config: BTreeMap<String, Option<String>> = BTreeMap::new();
1111
config.extend(settings.into_iter().map(|(k, v)| (k, Some(v))));
1212
config.extend(resolved_overrides(overrides).map(|(k, v)| (k, Some(v))));
13-
if config.is_empty() {
14-
return String::new();
15-
}
1613
to_hadoop_xml(config.iter())
1714
}
1815

@@ -21,11 +18,6 @@ mod tests {
2118
use super::*;
2219
use crate::controller::build::properties::test_support::config_overrides;
2320

24-
#[test]
25-
fn empty_settings_without_overrides_renders_empty_string() {
26-
assert_eq!(build(BTreeMap::new(), config_overrides(&[])), "");
27-
}
28-
2921
#[test]
3022
fn settings_appear_in_xml() {
3123
let xml = build(

rust/operator-binary/src/crd/mod.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub const JVM_SECURITY_PROPERTIES_FILE: &str = "security.properties";
6060

6161
pub const HBASE_CLUSTER_DISTRIBUTED: &str = "hbase.cluster.distributed";
6262
pub const HBASE_ROOTDIR: &str = "hbase.rootdir";
63+
const DEFAULT_HBASE_ROOTDIR: &str = "/hbase";
6364

6465
const HBASE_UI_PORT_NAME_HTTP: &str = "ui-http";
6566
const HBASE_UI_PORT_NAME_HTTPS: &str = "ui-https";
@@ -87,6 +88,10 @@ const DEFAULT_REGION_MOVER_DELTA_TO_SHUTDOWN: Duration = Duration::from_minutes_
8788

8889
const DEFAULT_LISTENER_CLASS: &str = "cluster-internal";
8990

91+
fn default_hbase_rootdir() -> String {
92+
DEFAULT_HBASE_ROOTDIR.to_string()
93+
}
94+
9095
pub type MasterRoleType =
9196
Role<HbaseConfigFragment, v1alpha1::HbaseConfigOverrides, GenericRoleConfig, JavaCommonConfig>;
9297

@@ -593,7 +598,7 @@ impl HbaseRole {
593598
};
594599

595600
HbaseConfigFragment {
596-
hbase_rootdir: None,
601+
hbase_rootdir: Some(default_hbase_rootdir()),
597602
resources,
598603
logging: product_logging::spec::default_logging(),
599604
affinity: get_affinity(cluster_name, self, hdfs_discovery_cm_name),
@@ -796,7 +801,7 @@ impl AnyConfigFragment {
796801
match role {
797802
HbaseRole::RegionServer => {
798803
AnyConfigFragment::RegionServer(RegionServerConfigFragment {
799-
hbase_rootdir: None,
804+
hbase_rootdir: Some(default_hbase_rootdir()),
800805
resources: default_resources(role),
801806
logging: product_logging::spec::default_logging(),
802807
affinity: get_affinity(cluster_name, role, hdfs_discovery_cm_name),
@@ -814,7 +819,7 @@ impl AnyConfigFragment {
814819
})
815820
}
816821
HbaseRole::RestServer => AnyConfigFragment::RestServer(HbaseConfigFragment {
817-
hbase_rootdir: None,
822+
hbase_rootdir: Some(default_hbase_rootdir()),
818823
resources: default_resources(role),
819824
logging: product_logging::spec::default_logging(),
820825
affinity: get_affinity(cluster_name, role, hdfs_discovery_cm_name),
@@ -825,7 +830,7 @@ impl AnyConfigFragment {
825830
listener_class: Some(DEFAULT_LISTENER_CLASS.to_string()),
826831
}),
827832
HbaseRole::Master => AnyConfigFragment::Master(HbaseConfigFragment {
828-
hbase_rootdir: None,
833+
hbase_rootdir: Some(default_hbase_rootdir()),
829834
resources: default_resources(role),
830835
logging: product_logging::spec::default_logging(),
831836
affinity: get_affinity(cluster_name, role, hdfs_discovery_cm_name),
@@ -891,8 +896,9 @@ pub enum Container {
891896
serde(rename_all = "camelCase")
892897
)]
893898
pub struct HbaseConfig {
894-
#[serde(default, skip_serializing_if = "Option::is_none")]
895-
pub hbase_rootdir: Option<String>,
899+
/// Root directory for Hbase on the filesystem (usually a path in HDFS). Default is `/hbase`.
900+
#[serde(default = "default_hbase_rootdir")]
901+
pub hbase_rootdir: String,
896902

897903
#[fragment_attrs(serde(default))]
898904
pub resources: Resources<HbaseStorageConfig, NoRuntimeLimits>,
@@ -971,8 +977,8 @@ impl Atomic for RegionMoverExtraCliOpts {}
971977
serde(rename_all = "camelCase")
972978
)]
973979
pub struct RegionServerConfig {
974-
#[serde(default, skip_serializing_if = "Option::is_none")]
975-
pub hbase_rootdir: Option<String>,
980+
#[serde(default = "default_hbase_rootdir")]
981+
pub hbase_rootdir: String,
976982
#[fragment_attrs(serde(default))]
977983
pub resources: Resources<HbaseStorageConfig, NoRuntimeLimits>,
978984
#[fragment_attrs(serde(default))]
@@ -1064,9 +1070,9 @@ impl AnyServiceConfig {
10641070
}
10651071
}
10661072

1067-
/// The configured `hbase.rootdir`, if any. Previously injected into
1073+
/// The configured `hbase.rootdir`. Previously injected into
10681074
/// `hbase-site.xml` via product-config's `compute_files`.
1069-
pub fn hbase_rootdir(&self) -> Option<String> {
1075+
pub fn hbase_rootdir(&self) -> String {
10701076
match self {
10711077
AnyServiceConfig::Master(config) => config.hbase_rootdir.clone(),
10721078
AnyServiceConfig::RegionServer(config) => config.hbase_rootdir.clone(),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
timeout: 60
5+
commands:
6+
#
7+
# ConfigMap data snapshot: test-hbase-master-default
8+
#
9+
- script: |
10+
export ZNODE_PATH=$(kubectl -n $NAMESPACE get zookeeperznode test-znode -o jsonpath='{.status.znodePath}')
11+
envsubst '$NAMESPACE $ZNODE_PATH' < 32_cm-test-hbase-master-default.yaml > /tmp/$NAMESPACE-expected.yaml
12+
kubectl -n $NAMESPACE get cm test-hbase-master-default -o yaml | yq '.data' > /tmp/$NAMESPACE-actual.yaml
13+
if ! diff /tmp/$NAMESPACE-expected.yaml /tmp/$NAMESPACE-actual.yaml; then
14+
echo "ERROR: ConfigMap test-hbase-master-default data drifted from snapshot."
15+
exit 1
16+
fi
17+
18+
#
19+
# ConfigMap data snapshot: test-hbase-regionserver-default
20+
#
21+
- script: |
22+
export ZNODE_PATH=$(kubectl -n $NAMESPACE get zookeeperznode test-znode -o jsonpath='{.status.znodePath}')
23+
envsubst '$NAMESPACE $ZNODE_PATH' < 32_cm-test-hbase-regionserver-default.yaml > /tmp/$NAMESPACE-expected.yaml
24+
kubectl -n $NAMESPACE get cm test-hbase-regionserver-default -o yaml | yq '.data' > /tmp/$NAMESPACE-actual.yaml
25+
if ! diff /tmp/$NAMESPACE-expected.yaml /tmp/$NAMESPACE-actual.yaml; then
26+
echo "ERROR: ConfigMap test-hbase-regionserver-default data drifted from snapshot."
27+
exit 1
28+
fi
29+
30+
#
31+
# ConfigMap data snapshot: test-hbase-restserver-default
32+
#
33+
- script: |
34+
export ZNODE_PATH=$(kubectl -n $NAMESPACE get zookeeperznode test-znode -o jsonpath='{.status.znodePath}')
35+
envsubst '$NAMESPACE $ZNODE_PATH' < 32_cm-test-hbase-restserver-default.yaml > /tmp/$NAMESPACE-expected.yaml
36+
kubectl -n $NAMESPACE get cm test-hbase-restserver-default -o yaml | yq '.data' > /tmp/$NAMESPACE-actual.yaml
37+
if ! diff /tmp/$NAMESPACE-expected.yaml /tmp/$NAMESPACE-actual.yaml; then
38+
echo "ERROR: ConfigMap test-hbase-restserver-default data drifted from snapshot."
39+
exit 1
40+
fi
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
hbase-env.sh: |
2+
export HBASE_HEAPSIZE="819m"
3+
export HBASE_MANAGES_ZK="false"
4+
export HBASE_MASTER_OPTS="-Djava.security.properties=/stackable/conf/security.properties"
5+
export HBASE_OPTS=""
6+
hbase-site.xml: |-
7+
<?xml version="1.0"?>
8+
<configuration>
9+
<property>
10+
<name>hbase.client.rpc.bind.address</name>
11+
<value>false</value>
12+
</property>
13+
<property>
14+
<name>hbase.cluster.distributed</name>
15+
<value>true</value>
16+
</property>
17+
<property>
18+
<name>hbase.master.bound.info.port</name>
19+
<value>16010</value>
20+
</property>
21+
<property>
22+
<name>hbase.master.hostname</name>
23+
<value>${env:HBASE_SERVICE_HOST}</value>
24+
</property>
25+
<property>
26+
<name>hbase.master.info.port</name>
27+
<value>${env:HBASE_INFO_PORT}</value>
28+
</property>
29+
<property>
30+
<name>hbase.master.ipc.address</name>
31+
<value>0.0.0.0</value>
32+
</property>
33+
<property>
34+
<name>hbase.master.ipc.port</name>
35+
<value>16000</value>
36+
</property>
37+
<property>
38+
<name>hbase.master.port</name>
39+
<value>${env:HBASE_SERVICE_PORT}</value>
40+
</property>
41+
<property>
42+
<name>hbase.regionserver.wal.codec</name>
43+
<value>org.apache.hadoop.hbase.regionserver.wal.IndexedWALEditCodec</value>
44+
</property>
45+
<property>
46+
<name>hbase.rootdir</name>
47+
<value>/hbase</value>
48+
</property>
49+
<property>
50+
<name>hbase.zookeeper.property.clientPort</name>
51+
<value>2282</value>
52+
</property>
53+
<property>
54+
<name>hbase.zookeeper.quorum</name>
55+
<value>test-zk-server.$NAMESPACE.svc.cluster.local:2282</value>
56+
</property>
57+
<property>
58+
<name>phoenix.log.saltBuckets</name>
59+
<value>2</value>
60+
</property>
61+
<property>
62+
<name>zookeeper.znode.parent</name>
63+
<value>$ZNODE_PATH/hbase</value>
64+
</property>
65+
</configuration>
66+
log4j2.properties: |-
67+
appenders = FILE, CONSOLE
68+
69+
appender.CONSOLE.type = Console
70+
appender.CONSOLE.name = CONSOLE
71+
appender.CONSOLE.target = SYSTEM_ERR
72+
appender.CONSOLE.layout.type = PatternLayout
73+
appender.CONSOLE.layout.pattern = %d{ISO8601} %-5p [%t] %c{2}: %.1000m%n
74+
appender.CONSOLE.filter.threshold.type = ThresholdFilter
75+
appender.CONSOLE.filter.threshold.level = INFO
76+
77+
appender.FILE.type = RollingFile
78+
appender.FILE.name = FILE
79+
appender.FILE.fileName = /stackable/log/hbase/hbase.log4j2.xml
80+
appender.FILE.filePattern = /stackable/log/hbase/hbase.log4j2.xml.%i
81+
appender.FILE.layout.type = XMLLayout
82+
appender.FILE.policies.type = Policies
83+
appender.FILE.policies.size.type = SizeBasedTriggeringPolicy
84+
appender.FILE.policies.size.size = 5MB
85+
appender.FILE.strategy.type = DefaultRolloverStrategy
86+
appender.FILE.strategy.max = 1
87+
appender.FILE.filter.threshold.type = ThresholdFilter
88+
appender.FILE.filter.threshold.level = INFO
89+
90+
91+
rootLogger.level=INFO
92+
rootLogger.appenderRefs = CONSOLE, FILE
93+
rootLogger.appenderRef.CONSOLE.ref = CONSOLE
94+
rootLogger.appenderRef.FILE.ref = FILE
95+
security.properties: |
96+
networkaddress.cache.negative.ttl=0
97+
networkaddress.cache.ttl=5
98+
ssl-client.xml: |-
99+
<?xml version="1.0"?>
100+
<configuration>
101+
</configuration>
102+
ssl-server.xml: |-
103+
<?xml version="1.0"?>
104+
<configuration>
105+
</configuration>

0 commit comments

Comments
 (0)