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

copy explicitly named labels from vault-crd to secret #53

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
copy explicitly named labels from vault-crd to secret
akloss-cibo committed Sep 16, 2020
commit f975163011a9520cf440ec33c5081755eb6adb1d
1 change: 1 addition & 0 deletions src/main/java/de/koudingspawn/vault/Constants.java
Original file line number Diff line number Diff line change
@@ -4,4 +4,5 @@ public class Constants {
public static String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm'Z'";
public static String COMPARE_ANNOTATION = "/compare";
public static String LAST_UPDATE_ANNOTATION = "/lastUpdated";
public static String COPY_LABELS_ANNOTATION = "/copyLabels";
}
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@

import static de.koudingspawn.vault.Constants.COMPARE_ANNOTATION;
import static de.koudingspawn.vault.Constants.LAST_UPDATE_ANNOTATION;
import static de.koudingspawn.vault.Constants.COPY_LABELS_ANNOTATION;

@Component
public class KubernetesService {
@@ -87,13 +88,21 @@ private ObjectMeta metaData(ObjectMeta resource, String compare) {
ObjectMeta meta = new ObjectMeta();
meta.setNamespace(resource.getNamespace());
meta.setName(resource.getName());
if (resource.getLabels() != null) {
meta.setLabels(resource.getLabels());
}

HashMap<String, String> annotations = new HashMap<>();
if (resource.getAnnotations() != null) {
annotations.putAll(resource.getAnnotations());
Map<String, String> labels = resource.getLabels();
if (labels != null) {
String[] labelNames = annotations.getOrDefault(crdName + COPY_LABELS_ANNOTATION, "").split(",");
HashMap<String, String> secretLabels = new HashMap<>();
for (String labelName : labelNames) {
String value = labels.get(labelName);
if (value != null) {
secretLabels.put(labelName, value);
}
}
meta.setLabels(secretLabels);
}
}
annotations.put(crdName + LAST_UPDATE_ANNOTATION, LocalDateTime.now().toString());
annotations.put(crdName + COMPARE_ANNOTATION, compare);