ssirowa14 commented on code in PR #925: URL: https://github.com/apache/spark-kubernetes-operator/pull/925#discussion_r4205855002
########## spark-operator/src/test/java/org/apache/spark/k8s/operator/decorators/DriverResourceDecoratorTest.java: ########## @@ -0,0 +1,180 @@ +/* + * 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.apache.spark.k8s.operator.Constants.LABEL_SPARK_APPLICATION_NAME; +import static org.apache.spark.k8s.operator.Constants.LABEL_SPARK_OPERATOR_NAME; +import static org.apache.spark.k8s.operator.Constants.LABEL_SPARK_ROLE_NAME; +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(LABEL_SPARK_OPERATOR_NAME, "spark-operator") + .addToLabels(LABEL_SPARK_APPLICATION_NAME, "app1") + // Prefix-matched managed label that is not one of the exact-match keys. + .addToLabels("spark.operator/submission-id", "sub-1") + .addToLabels(LABEL_SPARK_ROLE_NAME, "driver") + .addToLabels("spark-app-selector", "spark-app-selector-1") + .addToLabels("overlapping-label", "driver-value") Review Comment: Addressed in the latest commit. The fixture now: - Adds `spark-version` and `spark-app-name` to the driver pod and sets rogue values for both on the resource in `managedLabelsAreNotOverriddenByResource`, so all four exact-match keys (`spark-role`, `spark-app-selector`, `spark-version`, `spark-app-name`) are exercised. - Adds `driver-only-label`, a neutral label only on the driver pod, covering the propagation in `driverLabelsPropagatedAndResourceLabelWinsOnCollision`. - Adds `resource-only-label`, a neutral label only on the resource, covering its preservation. ########## spark-operator/src/main/java/org/apache/spark/k8s/operator/decorators/DriverResourceDecorator.java: ########## @@ -45,10 +55,33 @@ public class DriverResourceDecorator implements ResourceDecorator { private final Pod driverPod; + /** + * Operator- and Spark-managed identity labels whose driver-pod value must always propagate to + * secondary resources unchanged. A resource's own label of the same key + * must never override them. Any label key under the {@value #MANAGED_LABEL_PREFIX} prefix is + * protected the same way (which already covers the operator-namespaced keys listed here). + */ + private static final Set<String> MANAGED_LABEL_KEYS = + Set.of( + LABEL_SPARK_OPERATOR_NAME, + LABEL_SPARK_APPLICATION_NAME, Review Comment: Cleaned up redundant keys. ########## spark-operator/src/main/java/org/apache/spark/k8s/operator/decorators/DriverResourceDecorator.java: ########## @@ -73,9 +106,38 @@ public <T extends HasMetadata> T decorate(T resource) { new ObjectMetaBuilder(resource.getMetadata()) .addToOwnerReferences(buildOwnerReferenceTo(driverPod)) .addToLabels(driverPod.getMetadata().getLabels()) + .addToLabels(overridableLabels(resource.getMetadata().getLabels())) Review Comment: Yeah, makes sense. Refactored as per suggestion. -- 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]
