|
4 | 4 | import java.util.Collection; |
5 | 5 | import java.util.HashMap; |
6 | 6 | import java.util.Map; |
| 7 | +import java.util.Optional; |
7 | 8 |
|
8 | 9 | import org.slf4j.Logger; |
9 | 10 | import org.slf4j.LoggerFactory; |
@@ -58,7 +59,15 @@ public void create(DynamicKubernetesObject obj) throws SQLException { |
58 | 59 | public void createWithAnnotationsAndLabels(String yaml, Map<String, String> annotations, |
59 | 60 | Map<String, String> labels) throws SQLException { |
60 | 61 | DynamicKubernetesObject obj = objFromYaml(yaml); |
61 | | - createWithAnnotationsAndLabels(obj, annotations, labels); |
| 62 | + // Merge annotations and labels from existing yaml to the provided maps. |
| 63 | + Map<String, String> mergedAnnotations = new HashMap<>(); |
| 64 | + Optional.ofNullable(obj.getMetadata().getAnnotations()).ifPresent(mergedAnnotations::putAll); |
| 65 | + Optional.ofNullable(annotations).ifPresent(mergedAnnotations::putAll); |
| 66 | + |
| 67 | + Map<String, String> mergedLabels = new HashMap<>(); |
| 68 | + Optional.ofNullable(obj.getMetadata().getLabels()).ifPresent(mergedLabels::putAll); |
| 69 | + Optional.ofNullable(labels).ifPresent(mergedLabels::putAll); |
| 70 | + createWithAnnotationsAndLabels(obj, mergedAnnotations, mergedLabels); |
62 | 71 | } |
63 | 72 |
|
64 | 73 | public void createWithAnnotationsAndLabels(DynamicKubernetesObject obj, Map<String, String> annotations, |
|
0 commit comments