difin commented on code in PR #6507:
URL: https://github.com/apache/hive/pull/6507#discussion_r3430338703
##########
packaging/src/kubernetes/src/java/org/apache/hive/kubernetes/operator/dependent/HiveDependentResource.java:
##########
@@ -125,6 +134,209 @@ public Matcher.Result<R> match(R actualResource, R
desired,
return super.match(actualResource, desired, primary, context);
}
+ @Override
+ protected R handleCreate(R desired, P primary, Context<P> context) {
+ try {
+ return super.handleCreate(desired, primary, context);
+ } catch (KubernetesClientException e) {
+ if (e.getCode() == 409) {
+ LOG.info("Resource {} already exists (informer lag), "
+ + "will reconcile on next event",
+ desired.getMetadata().getName());
+ return desired;
+ }
+ throw e;
+ }
+ }
+
+ /**
+ * Resolves the replica count to set in the desired workload spec.
+ * <p>
+ * Always returns an explicit value — never null. Returning null would cause
+ * JOSDK/SSA to omit spec.replicas, and Kubernetes would default it to 1.
+ * <p>
+ * When autoscaling is enabled:
+ * - On CREATE: returns initialReplicas (minReplicas for the component)
+ * - On UPDATE: returns the autoscaler's managed value, or falls back to
+ * the current actual replicas from the informer cache.
+ * <p>
+ * When autoscaling is disabled: returns staticReplicas (the spec value).
+ */
+ protected Integer resolveReplicaCount(P primary, Context<P> context,
+ AutoscalingSpec autoscaling, int staticReplicas, int initialReplicas) {
+ // Suspended cluster → 0 replicas (dependent resources natively respect
suspend).
+ // Exception: HMS stays running if includeMetastore=false in autoSuspend
config.
+ if (primary instanceof HiveCluster hc && hc.getSpec().suspend()) {
+ boolean isMetastore =
ConfigUtils.COMPONENT_METASTORE.equals(getComponentName());
+ if (!isMetastore || hc.getSpec().autoSuspend().includeMetastore()) {
+ return 0;
+ }
+ }
+ if (autoscaling == null || !autoscaling.isEnabled()) {
+ return staticReplicas;
+ }
+ Optional<R> existing = getSecondaryResource(primary, context);
+ if (existing.isPresent()) {
+ // Check if the autoscaler has made a decision during this operator's
lifecycle
+ Integer managed = HiveClusterAutoscaler.getManagedReplicas(
+ primary.getMetadata().getNamespace(),
+ primary.getMetadata().getName(),
+ getComponentName());
+ if (managed != null) {
+ return managed;
+ }
+ // Fallback: operator restarted and MANAGED_REPLICAS is empty — read
current value
+ R resource = existing.get();
+ if (resource instanceof io.fabric8.kubernetes.api.model.apps.Deployment
d) {
+ return d.getSpec() != null && d.getSpec().getReplicas() != null
+ ? d.getSpec().getReplicas() : initialReplicas;
+ }
+ if (resource instanceof io.fabric8.kubernetes.api.model.apps.StatefulSet
s) {
+ return s.getSpec() != null && s.getSpec().getReplicas() != null
+ ? s.getSpec().getReplicas() : initialReplicas;
+ }
+ return initialReplicas;
+ }
+ // First creation: start at minReplicas.
+ return initialReplicas;
+ }
+
+
+ /**
+ * Returns the component name for this dependent (used for autoscaler
replica lookup).
+ * Subclasses should override if they manage a workload with autoscaling.
+ */
+ protected String getComponentName() {
+ return null;
+ }
Review Comment:
Should it be defined as abstract?
--
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]