Skip to content

Commit 48e38d0

Browse files
committed
fix : check if metadata.annotations is null
1 parent cc09486 commit 48e38d0

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlRollout.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ private void deploymentViewHistory(V1Deployment deployment, AppsV1Api api) throw
148148
List<Long> revisions = new ArrayList<>(historyInfo.keySet());
149149
revisions.sort(Long::compareTo);
150150
for (Long revision : revisions) {
151-
String changeCause =
152-
historyInfo.get(revision).getMetadata().getAnnotations().get(CHANGE_CAUSE_ANNOTATION);
151+
String changeCause = getChangeCause(historyInfo.get(revision).getMetadata());
153152
if (changeCause == null || changeCause.isEmpty()) {
154153
changeCause = "<none>";
155154
}
@@ -214,8 +213,7 @@ private void parseHistory(List<V1ControllerRevision> historyList, PodTemplatePar
214213
List<Long> revisions = new ArrayList<>(historyInfo.keySet());
215214
revisions.sort(Long::compareTo);
216215
for (Long revision : revisions) {
217-
String changeCause =
218-
historyInfo.get(revision).getMetadata().getAnnotations().get(CHANGE_CAUSE_ANNOTATION);
216+
String changeCause = getChangeCause(historyInfo.get(revision).getMetadata());
219217
if (changeCause == null || changeCause.isEmpty()) {
220218
changeCause = "<none>";
221219
}
@@ -250,6 +248,9 @@ private boolean isControlledBy(KubernetesObject obj, KubernetesObject owner) {
250248

251249
// getChangeCause returns the change-cause annotation of the input object
252250
private String getChangeCause(V1ObjectMeta meta) {
251+
if (meta.getAnnotations() == null) {
252+
return null;
253+
}
253254
return meta.getAnnotations().get(CHANGE_CAUSE_ANNOTATION);
254255
}
255256

extended/src/main/java/io/kubernetes/client/extended/kubectl/util/deployment/DeploymentHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public static V1ReplicaSet getAllReplicaSets(
6464
* @return the revision number
6565
*/
6666
public static Long revision(V1ObjectMeta meta) {
67+
if (meta.getAnnotations() == null) return 0L;
6768
String v = meta.getAnnotations().get(REVISION_ANNOTATION);
6869
return v == null ? 0L : Long.parseLong(v);
6970
}

0 commit comments

Comments
 (0)