otterc commented on code in PR #925:
URL: 
https://github.com/apache/spark-kubernetes-operator/pull/925#discussion_r4166649684


##########
spark-operator/src/main/java/org/apache/spark/k8s/operator/decorators/DriverResourceDecorator.java:
##########
@@ -73,6 +73,10 @@ public <T extends HasMetadata> T decorate(T resource) {
           new ObjectMetaBuilder(resource.getMetadata())
               .addToOwnerReferences(buildOwnerReferenceTo(driverPod))
               .addToLabels(driverPod.getMetadata().getLabels())
+              // Re-apply the resource's own labels last so a label set 
explicitly on

Review Comment:
    Could you add a line to the decorate() javadoc stating the precedence, 
something like "Driver pod labels are copied onto the resource; labels already 
set on the resource take precedence on key collision."? That way the contract 
is visible without reading the implementation.



##########
spark-operator/src/test/java/org/apache/spark/k8s/operator/decorators/DriverResourceDecoratorTest.java:
##########
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.spark.k8s.operator.decorators;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Map;
+
+import io.fabric8.kubernetes.api.model.OwnerReference;
+import io.fabric8.kubernetes.api.model.Pod;
+import io.fabric8.kubernetes.api.model.PodBuilder;
+import io.fabric8.kubernetes.api.model.Service;
+import io.fabric8.kubernetes.api.model.ServiceBuilder;
+import org.junit.jupiter.api.Test;
+
+class DriverResourceDecoratorTest {
+
+  private static Pod driverPod() {
+    return new PodBuilder()
+        .withKind("Pod")
+        .withApiVersion("v1")
+        .withNewMetadata()
+        .withName("spark-driver")
+        .withUid("driver-uid")
+        .addToLabels("spark-app-name", "app1")
+        .addToLabels("istio.io/use-waypoint", "none")
+        .endMetadata()
+        .build();
+  }
+
+  /**
+   * Regression: a label set explicitly on the resource (e.g. a per-service 
waypoint label) must win
+   * over a driver-pod label of the same key, not be overwritten by it.
+   */
+  @Test
+  void perServiceLabelWinsOverDriverPodLabel() {
+    Service service =
+        new ServiceBuilder()
+            .withNewMetadata()
+            .withName("app1-connect-svc")
+            .addToLabels("istio.io/use-waypoint", "waypoint-ns1")
+            .endMetadata()
+            .withNewSpec()
+            .endSpec()
+            .build();
+
+    new DriverResourceDecorator(driverPod()).decorate(service);
+
+    assertEquals(
+        "waypoint-ns1", 
service.getMetadata().getLabels().get("istio.io/use-waypoint"));
+  }
+
+  /** Driver-pod labels whose key is absent on the resource are still 
propagated (GC identity). */
+  @Test
+  void driverPodOnlyLabelsArePropagated() {

Review Comment:
   `perServiceLabelWinsOverDriverPodLabel` and 
`driverPodOnlyLabelsArePropagated` have identical setup, and the second already 
asserts everything the first does, so the first can be dropped. The 
`.withNewSpec().endSpec()` calls can also go, since the decorator only reads 
metadata. A small `service(Map<String,String> labels)` helper would cover all 
four remaining cases.



-- 
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]

Reply via email to