Skip to content

Commit dc33ab6

Browse files
committed
add deprecation of old restart mechanic
1 parent 8a9200c commit dc33ab6

3 files changed

Lines changed: 58 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ All notable changes to this project will be documented in this file.
1818
restart. The default `resource-version` keeps the previous behavior. Switching from
1919
`resource-version` to `data-hash` does not restart the Pods by itself ([#449]).
2020

21+
### Deprecated
22+
23+
- The restarter change tracking mechanism `resource-version`. The next release uses `data-hash` for
24+
every StatefulSet and ignores the annotation `restarter.stackable.tech/change-tracking-mechanism`.
25+
Writes to a referenced ConfigMap or Secret that leave its content as it is will then no longer
26+
restart the Pods ([#449]).
27+
2128
### Changed
2229

2330
- Bump stackable-operator to 0.116.0 ([#439], [#443], [#444]).

‎docs/modules/commons-operator/pages/restarter.adoc‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ Annotation:: `restarter.stackable.tech/change-tracking-mechanism`
6565

6666
This annotation selects what counts as a change of a referenced ConfigMap or Secret:
6767

68-
`resource-version` (default):: Every write to the object counts as a change, including writes that only touch its metadata (labels, annotations, managed fields) or that write identical content.
68+
`resource-version` (default, deprecated):: Every write to the object counts as a change, including writes that only touch its metadata (labels, annotations, managed fields) or that write identical content.
69+
This mechanism is deprecated and will be removed in the next release, see <<change-tracking-deprecation>>.
6970
`data-hash`:: Only a change of the content (`data` and `binaryData` of a ConfigMap, `data` of a Secret) counts as a change.
7071
Writes by third parties that leave the content as it is do not restart the Pods.
7172
To hash the content, the operator reads a referenced object whenever its resource version changes.
@@ -93,6 +94,18 @@ metadata:
9394
...
9495
----
9596

97+
[#change-tracking-deprecation]
98+
==== Deprecation of `resource-version`
99+
100+
The next release removes the `resource-version` mechanism and uses `data-hash` for every StatefulSet.
101+
It ignores the value of the annotation `restarter.stackable.tech/change-tracking-mechanism`, and logs a warning if it is `resource-version`.
102+
The operator already logs this warning in this release, once per StatefulSet after each operator start.
103+
104+
The switch works as described above and does not restart any Pods by itself.
105+
To try `data-hash` before that, set the annotation on individual StatefulSets.
106+
107+
If you rely on writes to a ConfigMap or Secret restarting the Pods, for example by changing a label or annotation of it, use `kubectl rollout restart statefulset \{name\}` instead.
108+
96109
==== Pod template annotations
97110

98111
To detect changes, the operator adds an annotation for every referenced ConfigMap and Secret to the Pod template of the StatefulSet.

‎rust/operator-binary/src/restart_controller/statefulset.rs‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::{
2-
collections::{BTreeMap, BTreeSet},
2+
collections::{BTreeMap, BTreeSet, HashSet},
33
fmt::Debug,
44
future::Future,
5-
sync::Arc,
5+
sync::{Arc, Mutex, PoisonError},
66
time::Duration,
77
};
88

@@ -94,6 +94,10 @@ pub struct Ctx {
9494
cm_digests: DigestCache<ConfigMap>,
9595
secret_digests: DigestCache<Secret>,
9696
digest_key: DigestKeyStore,
97+
98+
/// Namespace and name of the StatefulSets already warned about the deprecation of
99+
/// [`ChangeTrackingMechanism::ResourceVersion`], see [`warn_deprecated_mechanism`].
100+
deprecation_warned: Mutex<HashSet<(String, String)>>,
97101
}
98102

99103
#[derive(Snafu, Debug, EnumDiscriminants)]
@@ -178,6 +182,7 @@ pub fn create_context(
178182
cm_digests: DigestCache::default(),
179183
secret_digests: DigestCache::default(),
180184
digest_key: DigestKeyStore::new(client, operator_namespace),
185+
deprecation_warned: Mutex::default(),
181186
});
182187

183188
(ctx, cm_store_tx, secret_store_tx)
@@ -413,6 +418,29 @@ where
413418
}
414419
}
415420

421+
/// Logs the deprecation of [`ChangeTrackingMechanism::ResourceVersion`] for the StatefulSet
422+
/// `name` in `namespace`, once per StatefulSet and operator run.
423+
///
424+
/// Every write to a watched ConfigMap or Secret reconciles every StatefulSet (see [`trigger_all`]),
425+
/// so warning on every call would repeat the warning for each such write. Keyed by name instead of
426+
/// uid, because the webhook sees StatefulSets on creation before they have a uid.
427+
fn warn_deprecated_mechanism(ctx: &Ctx, namespace: &str, name: String) {
428+
let first_warning = ctx
429+
.deprecation_warned
430+
.lock()
431+
.unwrap_or_else(PoisonError::into_inner)
432+
.insert((namespace.to_owned(), name.clone()));
433+
if first_warning {
434+
tracing::warn!(
435+
k8s.object.namespace = namespace,
436+
k8s.object.name = name,
437+
"The change tracking mechanism \"resource-version\" is deprecated and will be removed \
438+
in the next release, which will use \"data-hash\" for every StatefulSet and ignore \
439+
the value of the annotation {CHANGE_TRACKING_MECHANISM_ANNOTATION:?}"
440+
);
441+
}
442+
}
443+
416444
pub async fn get_updated_restarter_annotations(
417445
sts: &StatefulSet,
418446
ctx: Arc<Ctx>,
@@ -421,6 +449,13 @@ pub async fn get_updated_restarter_annotations(
421449
"A StatefulSet observed by a reflector (so send by Kubernetes) always has a namespace set",
422450
);
423451
let mechanism = ChangeTrackingMechanism::from_statefulset(sts)?;
452+
if mechanism == ChangeTrackingMechanism::ResourceVersion
453+
&& sts
454+
.annotations()
455+
.contains_key(CHANGE_TRACKING_MECHANISM_ANNOTATION)
456+
{
457+
warn_deprecated_mechanism(&ctx, ns, sts.name_any());
458+
}
424459
let previous_annotations = sts
425460
.spec
426461
.as_ref()

0 commit comments

Comments
 (0)