Skip to content

Commit d59dde5

Browse files
committed
ingress labels and default label selector
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 08ce9cb commit d59dde5

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/EventSourceUtils.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
/** Utility class to locate secondary resources. */
5252
public class EventSourceUtils {
5353

54+
public static final String LABEL_COMPONENT_INGRESS = "ingress";
55+
5456
private static final String FLINK_DEPLOYMENT_IDX = FlinkDeploymentController.class.getName();
5557
private static final String FLINK_SESSIONJOB_IDX = FlinkSessionJobController.class.getName();
5658
private static final String FLINK_STATE_SNAPSHOT_IDX = FlinkStateSnapshot.class.getName();
@@ -107,13 +109,10 @@ public static InformerEventSource<Deployment, FlinkDeployment> getDeploymentInfo
107109

108110
public static InformerEventSource<?, FlinkDeployment> getIngressInformerEventSource(
109111
EventSourceContext<FlinkDeployment> context) {
110-
// final String labelSelector =
111-
// Map.of(Constants.LABEL_COMPONENT_KEY,
112-
// Constants.LABEL_COMPONENT_JOB_MANAGER)
113-
// .entrySet()
114-
// .stream()
115-
// .map(Object::toString)
116-
// .collect(Collectors.joining(","));
112+
final String labelSelector =
113+
Map.of(Constants.LABEL_COMPONENT_KEY, LABEL_COMPONENT_INGRESS).entrySet().stream()
114+
.map(Object::toString)
115+
.collect(Collectors.joining(","));
117116

118117
var ingressClass =
119118
ingressInNetworkingV1(context.getClient())
@@ -122,7 +121,7 @@ public static InformerEventSource<?, FlinkDeployment> getIngressInformerEventSou
122121

123122
var configuration =
124123
InformerEventSourceConfiguration.from(ingressClass, FlinkDeployment.class)
125-
// .withLabelSelector(labelSelector)
124+
.withLabelSelector(labelSelector)
126125
.withNamespacesInheritedFromController()
127126
.withFollowControllerNamespacesChanges(true)
128127
.build();

flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/utils/IngressUtils.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.apache.flink.kubernetes.operator.api.spec.FlinkDeploymentSpec;
2323
import org.apache.flink.kubernetes.operator.controller.FlinkResourceContext;
2424
import org.apache.flink.kubernetes.operator.exception.ReconciliationException;
25+
import org.apache.flink.kubernetes.utils.Constants;
2526
import org.apache.flink.util.Preconditions;
2627

2728
import io.fabric8.kubernetes.api.model.HasMetadata;
@@ -45,11 +46,14 @@
4546
import java.net.MalformedURLException;
4647
import java.net.URL;
4748
import java.util.Collections;
49+
import java.util.HashMap;
4850
import java.util.List;
4951
import java.util.Optional;
5052
import java.util.regex.Pattern;
5153
import java.util.stream.Collectors;
5254

55+
import static org.apache.flink.kubernetes.operator.utils.EventSourceUtils.LABEL_COMPONENT_INGRESS;
56+
5357
/** Ingress utilities. */
5458
public class IngressUtils {
5559

@@ -98,10 +102,12 @@ private static HasMetadata getIngress(
98102
FlinkDeploymentSpec spec,
99103
Configuration effectiveConfig,
100104
KubernetesClient client) {
105+
var labels = new HashMap<>(spec.getIngress().getLabels());
106+
labels.put(Constants.LABEL_COMPONENT_KEY, LABEL_COMPONENT_INGRESS);
101107
if (ingressInNetworkingV1(client)) {
102108
return new IngressBuilder()
103109
.withNewMetadata()
104-
.withLabels(spec.getIngress().getLabels())
110+
.withLabels(labels)
105111
.withAnnotations(spec.getIngress().getAnnotations())
106112
.withName(objectMeta.getName())
107113
.withNamespace(objectMeta.getNamespace())
@@ -133,7 +139,7 @@ private static HasMetadata getIngress(
133139
return new io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder()
134140
.withNewMetadata()
135141
.withAnnotations(spec.getIngress().getAnnotations())
136-
.withLabels(spec.getIngress().getLabels())
142+
.withLabels(labels)
137143
.withName(objectMeta.getName())
138144
.withNamespace(objectMeta.getNamespace())
139145
.endMetadata()

0 commit comments

Comments
 (0)