dongjoon-hyun commented on code in PR #909:
URL:
https://github.com/apache/spark-kubernetes-operator/pull/909#discussion_r4648635760
##########
spark-operator/src/main/java/org/apache/spark/k8s/operator/utils/ConfigurableEventRecorder.java:
##########
@@ -259,7 +287,7 @@ private void sweep(long now, long minInterval) {
* @return The number of tracked events.
*/
int trackedEventCount() {
- return lastRecorded.size();
+ return lastRecorded.values().stream().mapToInt(Map::size).sum();
Review Comment:
nit: The Javadoc of `lastRecorded` (L84-85) says that each inner map is only
touched inside a `compute` of its uid, but this reads the sizes of the inner
`HashMap`s outside of it. It's harmless since only the tests call it, but how
about mentioning this exception in the Javadoc?
##########
spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/ClusterInitStep.java:
##########
@@ -275,6 +299,10 @@ private boolean isMasterRequested(SparkClusterContext
context) {
// read as absent, and getResourceStrictly does the same for a transient
failure, a 500 or a
// 429, since the create path it serves re-reads anyway. Either would
release the Kueue quota
// of a running master. Only a 404 may mean absent, which the client
reports as null.
- return
context.getClient().resource(context.getMasterStatefulSetSpec()).get() != null;
+ StatefulSet master =
context.getClient().resource(context.getMasterStatefulSetSpec()).get();
Review Comment:
This builds the whole `SparkClusterResourceSpec` through the submission
worker only to read the master `StatefulSet` by name, on every reconcile of a
held cluster. It is also why a master spec which cannot be built escapes the
suspend check, P5 of round 2. `ClusterSuspendStep` already uses
`getMasterStatefulSetName(name)`. How about
`client.apps().statefulSets().inNamespace(namespace).withName(getMasterStatefulSetName(name)).get()`,
which reports a 404 as `null` as well? This is not introduced by this PR, so
it can be a follow-up.
##########
spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/SuspendUtils.java:
##########
@@ -89,4 +94,39 @@ static ReconcileProgress holdForSuspend(final BaseContext<?>
context, final Stri
return completeAndRequeueAfter(
Duration.ofSeconds(SUSPEND_HOLD_REQUEUE_INTERVAL_SECONDS.getValue()));
}
+
+ /**
+ * Reports a failed check of whether the resources of a suspended resource
were requested, and
+ * returns the progress to retry it with. Whether they are live is unknown
then, so the resource
+ * is neither held, which would claim in an event that none was requested
and release the Kueue
+ * quota of a running driver or master, nor started. Like a failed Kueue
admission request, a
+ * transport level failure is not published, since writing an event would
only add load to an API
+ * server that is often the cause of it. A throttled read is not published
for the same reason,
+ * since the API server is overloaded then by definition. Anything else is,
since a suspended
+ * resource may have no persisted status to show it and would otherwise be
retried without any
+ * signal.
+ *
+ * @param context The context of the suspended resource.
+ * @param e The failure to report.
+ * @param requested The resources whose request could not be checked, as
named in the event and
+ * the log, e.g. {@code "driver"}.
+ * @return The progress to return, requeued after the steady-state interval.
+ */
+ static ReconcileProgress retryAfterCheckFailure(
+ final BaseContext<?> context, final KubernetesClientException e, final
String requested) {
+ String what =
+ "Failed to check whether the "
+ + requested
+ + " of the suspended "
+ + context.getResource().getKind()
+ + " was requested";
+ log.warn("{}, will retry.", what, e);
+ if (!ReconcilerUtils.isTransientError(e) && e.getCode() !=
HTTP_TOO_MANY_REQUESTS) {
Review Comment:
nit: P14 of round 2 is still open. This is one more copy of `log.warn`
followed by `EventUtils.warn` unless the failure is transient, now with an
extra `429` rule, which a shared helper would apply in one place. It's fine as
a follow-up.
##########
spark-operator/src/main/java/org/apache/spark/k8s/operator/utils/ConfigurableEventRecorder.java:
##########
@@ -54,6 +56,8 @@
* drops an event repeated on the same resource with the same reason and the
same message within
* {@link
*
org.apache.spark.k8s.operator.config.SparkOperatorConf#KUBERNETES_EVENTS_MIN_INTERVAL_SECONDS}.
+ * A {@code Warning} event published on a resource ends the interval of its
{@code Normal} events,
+ * so that the next one is published even if it repeats, see {@link
#withinMinInterval}.
Review Comment:
Since the latest commit, a published `Normal` event also drops the `Warning`
entries of its resource, but this paragraph describes the other direction only.
The Javadoc of `record` (L133-134) and the description of
`spark.kubernetes.operator.events.minIntervalSeconds` in `SparkOperatorConf`,
which generates `docs/config_properties.md`, still say that only the same
reason and the same message matter. Could we update them as
`docs/configuration.md` does?
##########
spark-operator-api/src/main/java/org/apache/spark/k8s/operator/utils/ModelUtils.java:
##########
@@ -145,6 +145,24 @@ public static OwnerReference
buildOwnerReferenceTo(HasMetadata owner) {
.build();
}
+ /**
+ * Checks whether the given resource has an owner reference to the given
owner. The uid rather
+ * than the name identifies the owner, since a name can be reused by a later
resource.
+ *
+ * @param resource The resource whose owner references are checked.
+ * @param owner The presumed owner.
+ * @return True if the owner has a uid and the resource has an owner
reference to it, false
+ * otherwise.
+ * @since 1.2.0
+ */
+ public static boolean isOwnedBy(HasMetadata resource, HasMetadata owner) {
Review Comment:
nit: Thank you for adding the shared helper.
`DriverResourceDecorator#decorate` still scans the owner references by itself
(kind, name and uid), so `ClusterInitStep` is the only caller, and a future fix
of the matching would still be needed in two places. Could it use `isOwnedBy`
as well? It can be a follow-up.
##########
spark-operator/src/test/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/ClusterInitStepTest.java:
##########
@@ -541,33 +542,45 @@ private static Pod pod(String name, String role) {
.build();
}
- @Test
- void resumedClusterSuspendedAgainGoesBackToSuspended() {
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void resumedOrRequeuedClusterSuspendedAgainGoesBackToSuspended(boolean
requeued) {
Review Comment:
This test covers `CLUSTER_RESUMED_MESSAGE` and `CLUSTER_REQUEUED_MESSAGE`,
while the other suspend tests start from the initial `Submitted` state only. No
test covers the fallback which the Javadoc of `isInitialSubmission` describes:
a persisted `Submitted` state with another message, i.e. with `lastKey() > 0`,
still looks the master up and is held if it is absent. Could we add a case for
it, so that a regression of that branch, e.g. back to a check of the history
key, fails a test?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]