Skip to content

Commit 0ab2c57

Browse files
committed
remove duplicate code
1 parent e9e6be0 commit 0ab2c57

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

operator/src/main/java/oracle/kubernetes/operator/helpers/AnnotationHelper.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,28 @@ private static V1Service addHash(V1Service service) {
6060
return service;
6161
}
6262

63+
static String getHash(V1Pod pod) {
64+
return getAnnotation(pod.getMetadata(), AnnotationHelper::getSha256Annotation);
65+
}
66+
67+
static String getHash(V1Service service) {
68+
return getAnnotation(service.getMetadata(), AnnotationHelper::getSha256Annotation);
69+
}
70+
6371
static String getDebugString(V1Pod pod) {
64-
return pod.getMetadata().getAnnotations().get(HASHED_STRING);
72+
return getAnnotation(pod.getMetadata(), AnnotationHelper::getDebugHashAnnotation);
6573
}
6674

67-
static String getHash(V1Pod pod) {
68-
return Optional.ofNullable(pod.getMetadata())
75+
private static String getAnnotation(
76+
V1ObjectMeta metadata, Function<Map<String, String>, String> annotationGetter) {
77+
return Optional.ofNullable(metadata)
6978
.map(V1ObjectMeta::getAnnotations)
70-
.map(AnnotationHelper::getSha256Annotation)
79+
.map(annotationGetter)
7180
.orElse("");
7281
}
7382

74-
static String getHash(V1Service service) {
75-
return Optional.ofNullable(service.getMetadata())
76-
.map(V1ObjectMeta::getAnnotations)
77-
.map(AnnotationHelper::getSha256Annotation)
78-
.orElse("");
83+
private static String getDebugHashAnnotation(Map<String, String> annotations) {
84+
return annotations.get(HASHED_STRING);
7985
}
8086

8187
private static String getSha256Annotation(Map<String, String> annotations) {

0 commit comments

Comments
 (0)