dongjoon-hyun commented on code in PR #909:
URL:
https://github.com/apache/spark-kubernetes-operator/pull/909#discussion_r4659028034
##########
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) {
+ String uid = owner.getMetadata().getUid();
+ List<OwnerReference> ownerReferences =
resource.getMetadata().getOwnerReferences();
+ return uid != null
+ && ownerReferences != null
+ && ownerReferences.stream().anyMatch(reference ->
uid.equals(reference.getUid()));
Review Comment:
**[P2]** No test covers these conditions except for an owner reference with
another uid, which `suspendedClusterWithLeftoverMasterOfDeletedClusterIsHeld`
and `leftoverMasterOfDeletedClusterDoesNotBypassKueueAdmission` use. I tried
the following mutation locally, so that a resource without owner references, or
an owner without a uid, counts as owned, and all 773 tests of
`:spark-operator-api:test` and `:spark-operator:test` still pass.
```java
return uid == null
|| ownerReferences == null
|| ownerReferences.isEmpty()
|| ownerReferences.stream().anyMatch(reference ->
uid.equals(reference.getUid()));
```
A resource without owner references is not only theoretical. For example,
after `kubectl delete sparkcluster --cascade=orphan`, the master `StatefulSet`
is kept and the garbage collector removes its owner reference, so a recreated
`SparkCluster` of the same name must not count it as requested. Since this is a
public method of `spark-operator-api` (`@since 1.2.0`) and `ModelUtilsTest` is
next to it, how about a unit test there, which covers a matching uid among
other owner references, another uid, no owner references and an owner without a
uid?
##########
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:
**[P3]** nit. P14 of round 2 is still open, as my last review mentioned.
Apart from the reason, this is `KueueWorkloadUtils.retryAfterRequestFailure`
with the `429` rule and without its 5-second retry of a transport-level
failure. Since it is fine as a follow-up, could you file a JIRA issue for it
and link it here, so that it is not lost once this PR is merged?
##########
docs/architecture.md:
##########
@@ -327,7 +327,7 @@ stateDiagram-v2
RunningHealthy --> Suspended : spec.suspend=true or Kueue eviction
Suspended --> Submitted : spec.suspend=false or after Kueue eviction
- Submitted --> Suspended : spec.suspend=true after resume
+ Submitted --> Suspended : spec.suspend=true, unless a first attempt has no
master yet or cannot check it
Review Comment:
**[P1]** This label covers the new transition of a first attempt whose
master exists, but the Kueue section of this document still describes the
previous one, which now holds for a `SparkApplication` only, as the Javadoc of
`SuspendUtils.holdForSuspend` says since round 3. These lines are not in the
diff, so I'm leaving this here.
- L115: `suspend -->|unset, or requested already| queued{...}`. A suspended
`SparkCluster` whose master was requested already goes to `Suspended` at
`ClusterInitStep` L91-101 instead, so it reaches neither the queue check nor
`request`.
- L143-146: `... is not held and requests no admission, since it has to
complete the initialization rather than run unobserved. Its resources are
applied again in that reconciliation, ...` Such a cluster neither completes its
initialization nor applies its resources again, as
`suspendAfterMasterRequestedGoesToSuspended` asserts.
- L132-133: `A cluster resumed from Suspended moves back to Suspended
instead of being held.` A first attempt whose master exists does so as well now.
How about the following, for example?
```
suspend -->|unset, or a driver requested already| queued{Queue label and
Kueue enabled?}
```
```
* A driver or master which was requested already, e.g. when the status
update after the request
failed, is not held and requests no admission. A driver, or the master of
a cluster which is not
suspended, has to complete the initialization rather than run unobserved.
Its resources are
applied again in that reconciliation, so the flavors of the earlier
admission are applied again
as well, rather than dropped from them. A suspended cluster goes to
`Suspended` instead.
```
And for L132-133, `A cluster resumed from Suspended, or one whose master was
requested already, moves to Suspended instead of being held.`
--
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]