Skip to content

Commit

Permalink
[FLINK-15647][k8s] Return an empty Map instead of null when annotatio…
Browse files Browse the repository at this point in the history
…ns is not set

This closes apache#10973.
  • Loading branch information
zhengcanbin authored and tillrohrmann committed Mar 24, 2020
1 parent 3df0eb7 commit f6312b8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
import org.apache.flink.kubernetes.utils.Constants;
import org.apache.flink.kubernetes.utils.KubernetesUtils;

import javax.annotation.Nullable;

import java.util.Collections;
import java.util.Map;

import static org.apache.flink.util.Preconditions.checkArgument;
Expand Down Expand Up @@ -65,10 +64,9 @@ public Map<String, String> getEnvironments() {
return getPrefixedEnvironments(ResourceManagerOptions.CONTAINERIZED_MASTER_ENV_PREFIX);
}

@Nullable
@Override
public Map<String, String> getAnnotations() {
return flinkConfig.get(KubernetesConfigOptions.JOB_MANAGER_ANNOTATIONS);
return flinkConfig.getOptional(KubernetesConfigOptions.JOB_MANAGER_ANNOTATIONS).orElse(Collections.emptyMap());
}

public String getJobManagerMainContainerName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ public interface KubernetesParameters {

/**
* A map of user-specified annotations that are set to the JobManager and TaskManager pods.
*
* @return a map of annotations or null if not set.
*/
Map<String, String> getAnnotations();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import org.apache.flink.kubernetes.utils.KubernetesUtils;
import org.apache.flink.runtime.clusterframework.ContaineredTaskManagerParameters;

import javax.annotation.Nullable;

import java.util.Collections;
import java.util.Map;

import static org.apache.flink.util.Preconditions.checkArgument;
Expand Down Expand Up @@ -70,10 +69,9 @@ public Map<String, String> getEnvironments() {
return this.containeredTaskManagerParameters.taskManagerEnv();
}

@Nullable
@Override
public Map<String, String> getAnnotations() {
return flinkConfig.get(KubernetesConfigOptions.TASK_MANAGER_ANNOTATIONS);
return flinkConfig.getOptional(KubernetesConfigOptions.TASK_MANAGER_ANNOTATIONS).orElse(Collections.emptyMap());
}

public String getTaskManagerMainContainerName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
Expand Down Expand Up @@ -75,8 +75,8 @@ public void testGetEnvironments() {
}

@Test
public void testGetNullAnnotations() {
assertNull(kubernetesJobManagerParameters.getAnnotations());
public void testGetEmptyAnnotations() {
assertTrue(kubernetesJobManagerParameters.getAnnotations().isEmpty());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

/**
* General tests for the {@link KubernetesTaskManagerParameters}.
Expand Down Expand Up @@ -89,8 +89,8 @@ public void testGetEnvironments() {
}

@Test
public void testGetNullAnnotations() {
assertNull(kubernetesTaskManagerParameters.getAnnotations());
public void testGetEmptyAnnotations() {
assertTrue(kubernetesTaskManagerParameters.getAnnotations().isEmpty());
}

@Test
Expand Down

0 comments on commit f6312b8

Please sign in to comment.