Skip to content

fix : check if metadata.annotations is null #1856

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

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ private void deploymentViewHistory(V1Deployment deployment, AppsV1Api api) throw
List<Long> revisions = new ArrayList<>(historyInfo.keySet());
revisions.sort(Long::compareTo);
for (Long revision : revisions) {
String changeCause =
historyInfo.get(revision).getMetadata().getAnnotations().get(CHANGE_CAUSE_ANNOTATION);
String changeCause = getChangeCause(historyInfo.get(revision).getMetadata());
if (changeCause == null || changeCause.isEmpty()) {
changeCause = "<none>";
}
Expand Down Expand Up @@ -214,8 +213,7 @@ private void parseHistory(List<V1ControllerRevision> historyList, PodTemplatePar
List<Long> revisions = new ArrayList<>(historyInfo.keySet());
revisions.sort(Long::compareTo);
for (Long revision : revisions) {
String changeCause =
historyInfo.get(revision).getMetadata().getAnnotations().get(CHANGE_CAUSE_ANNOTATION);
String changeCause = getChangeCause(historyInfo.get(revision).getMetadata());
if (changeCause == null || changeCause.isEmpty()) {
changeCause = "<none>";
}
Expand Down Expand Up @@ -250,6 +248,9 @@ private boolean isControlledBy(KubernetesObject obj, KubernetesObject owner) {

// getChangeCause returns the change-cause annotation of the input object
private String getChangeCause(V1ObjectMeta meta) {
if (meta.getAnnotations() == null) {
return null;
}
return meta.getAnnotations().get(CHANGE_CAUSE_ANNOTATION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static V1ReplicaSet getAllReplicaSets(
* @return the revision number
*/
public static Long revision(V1ObjectMeta meta) {
if (meta.getAnnotations() == null) return 0L;
String v = meta.getAnnotations().get(REVISION_ANNOTATION);
return v == null ? 0L : Long.parseLong(v);
}
Expand Down