Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-37478] Adding service labels to flink config #26301

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
adding service labels to flink config
  • Loading branch information
jklaw90 committed Mar 15, 2025
commit 946eb87c3b8441d977912415755764a1b7a5720b
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ public class KubernetesConfigOptions {
"The user-specified annotations that are set to the rest Service. The value should be "
+ "in the form of a1:v1,a2:v2");

public static final ConfigOption<Map<String, String>> REST_SERVICE_LABELS =
key("kubernetes.rest-service.labels")
.mapType()
.noDefaultValue()
.withDescription(
"The user-specified labels that are set to the rest Service. The value should be "
+ "in the form of a1:v1,a2:v2");

public static final ConfigOption<Map<String, String>> INTERNAL_SERVICE_ANNOTATIONS =
key("kubernetes.internal-service.annotations")
.mapType()
Expand All @@ -385,6 +393,14 @@ public class KubernetesConfigOptions {
"The user-specified annotations that are set to the internal Service. The value should be "
+ "in the form of a1:v1,a2:v2");

public static final ConfigOption<Map<String, String>> INTERNAL_SERVICE_LABELS =
key("kubernetes.internal-service.labels")
.mapType()
.noDefaultValue()
.withDescription(
"The user-specified labels that are set to the internal Service. The value should be "
+ "in the form of a1:v1,a2:v2");

/**
* Defines the configuration key of that external resource in Kubernetes. This is used as a
* suffix in an actual config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,24 @@ public Map<String, String> getRestServiceAnnotations() {
.orElse(Collections.emptyMap());
}

public Map<String, String> getRestServiceLabels() {
return flinkConfig
.getOptional(KubernetesConfigOptions.REST_SERVICE_LABELS)
.orElse(Collections.emptyMap());
}

public Map<String, String> getInternalServiceAnnotations() {
return flinkConfig
.getOptional(KubernetesConfigOptions.INTERNAL_SERVICE_ANNOTATIONS)
.orElse(Collections.emptyMap());
}

public Map<String, String> getInternalServiceLabels() {
return flinkConfig
.getOptional(KubernetesConfigOptions.INTERNAL_SERVICE_LABELS)
.orElse(Collections.emptyMap());
}

public int getJobManagerMemoryMB() {
return clusterSpecification.getMasterMemoryMB();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public Service buildUpInternalService(
.withNewMetadata()
.withName(serviceName)
.withLabels(kubernetesJobManagerParameters.getCommonLabels())
.addToLabels(kubernetesJobManagerParameters.getInternalServiceLabels())
.withAnnotations(kubernetesJobManagerParameters.getInternalServiceAnnotations())
.endMetadata()
.withNewSpec()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public Service buildUpExternalRestService(
.withNewMetadata()
.withName(serviceName)
.withLabels(kubernetesJobManagerParameters.getCommonLabels())
.addToLabels(kubernetesJobManagerParameters.getRestServiceLabels())
.withAnnotations(kubernetesJobManagerParameters.getRestServiceAnnotations())
.endMetadata()
.withNewSpec()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected void setupFlinkConfig() {
this.flinkConfig.set(KubernetesConfigOptions.JOB_MANAGER_LABELS, userLabels);
this.flinkConfig.set(KubernetesConfigOptions.JOB_MANAGER_ANNOTATIONS, userAnnotations);
this.flinkConfig.set(KubernetesConfigOptions.INTERNAL_SERVICE_ANNOTATIONS, userAnnotations);
this.flinkConfig.set(KubernetesConfigOptions.INTERNAL_SERVICE_LABELS, userLabels);
this.flinkConfig.set(KubernetesConfigOptions.JOB_MANAGER_NODE_SELECTOR, nodeSelector);
this.flinkConfig.set(
JobManagerOptions.TOTAL_PROCESS_MEMORY, MemorySize.ofMebiBytes(JOB_MANAGER_MEMORY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@ class ExternalServiceDecoratorTest extends KubernetesJobManagerTestBase {
}
};

private Map<String, String> customizedLabels =
new HashMap<String, String>() {
{
put("label1", "label-value1");
put("label2", "label-value2");
}
};

@Override
protected void onSetup() throws Exception {
super.onSetup();

this.flinkConfig.set(
KubernetesConfigOptions.REST_SERVICE_ANNOTATIONS, customizedAnnotations);
this.flinkConfig.set(KubernetesConfigOptions.REST_SERVICE_LABELS, customizedLabels);
this.externalServiceDecorator =
new ExternalServiceDecorator(this.kubernetesJobManagerParameters);
}
Expand All @@ -74,6 +83,7 @@ void testBuildAccompanyingKubernetesResources() throws IOException {
.isEqualTo(ExternalServiceDecorator.getExternalServiceName(CLUSTER_ID));

final Map<String, String> expectedLabels = getCommonLabels();
expectedLabels.putAll(customizedLabels);
assertThat(restService.getMetadata().getLabels()).isEqualTo(expectedLabels);

assertThat(restService.getSpec().getType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ void testBuildAccompanyingKubernetesResources() throws IOException {
.isEqualTo(InternalServiceDecorator.getInternalServiceName(CLUSTER_ID));

final Map<String, String> expectedLabels = getCommonLabels();
expectedLabels.putAll(userLabels);
assertThat(internalService.getMetadata().getLabels()).isEqualTo(expectedLabels);

assertThat(internalService.getMetadata().getAnnotations()).isEqualTo(userAnnotations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ void testGetRestServiceAnnotations() {
assertThat(resultAnnotations).isEqualTo(expectedAnnotations);
}

@Test
void testGetRestServiceLabels() {
final Map<String, String> expectedLabels = new HashMap<>();
expectedLabels.put("a1", "v1");
expectedLabels.put("a2", "v2");

flinkConfig.set(KubernetesConfigOptions.REST_SERVICE_LABELS, expectedLabels);

final Map<String, String> resultLabels =
kubernetesJobManagerParameters.getRestServiceLabels();

assertThat(resultLabels).isEqualTo(expectedLabels);
}

@Test
void testGetInternalServiceAnnotations() {
final Map<String, String> expectedAnnotations = new HashMap<>();
Expand All @@ -123,6 +137,20 @@ void testGetInternalServiceAnnotations() {
assertThat(resultAnnotations).isEqualTo(expectedAnnotations);
}

@Test
void testGetInternalServiceLabels() {
final Map<String, String> expectedLabels = new HashMap<>();
expectedLabels.put("a1", "v1");
expectedLabels.put("a2", "v2");

flinkConfig.set(KubernetesConfigOptions.INTERNAL_SERVICE_LABELS, expectedLabels);

final Map<String, String> resultLabels =
kubernetesJobManagerParameters.getInternalServiceLabels();

assertThat(resultLabels).isEqualTo(expectedLabels);
}

@Test
void testGetJobManagerMemoryMB() {
assertThat(kubernetesJobManagerParameters.getJobManagerMemoryMB())
Expand Down