eclipse-jkube / jkube

Build and Deploy java applications on Kubernetes
https://www.eclipse.dev/jkube/
Eclipse Public License 2.0
755 stars 496 forks source link

GitEnricher : Return empty map instead of returning `null` #2710

Closed rohanKanojia closed 7 months ago

rohanKanojia commented 7 months ago

Component

JKube Kit

Task description

Description

GitEnricher has this getAnnotations method that returns a map of annotations containing Git related information of the project:

https://github.com/eclipse/jkube/blob/fddd604457c98a197bd8b2f3cbb3167dde2a9b3d/jkube-kit/enricher/generic/src/main/java/org/eclipse/jkube/enricher/generic/GitEnricher.java#L53-L67

It's initializing org.eclipse.jgit.lib.Repository object in try with resources block and catching the exception thrown in catch block. However, it returns a null value when the exception is caught.

https://github.com/eclipse/jkube/blob/fddd604457c98a197bd8b2f3cbb3167dde2a9b3d/jkube-kit/enricher/generic/src/main/java/org/eclipse/jkube/enricher/generic/GitEnricher.java#L66

We should be returning an empty map instead of null. We should remove this line as we're already returning Map annotations created in the beginning of the function at the end of method.

Expected Behavior

return null` line is removed from the method

Acceptance Criteria

How to manually test my changes

Kubernetes

If you don't have a real Kubernetes cluster available (most probably), you can use Minikube or Kind to test with a local cluster.

OpenShift

If you don't have a real OpenShift cluster available (most probably), you can use Red Hat's developer Sandbox for Red Hat OpenShift. The only requirement is to have a Red Hat account.

Once you have your Sandbox environment, you'll need to download the oc tool from the cluster console. (Press the ? icon and from the context menu select Command line tools, you'll be redirected to https://$subdomain.openshiftapps.com/command-lines-tools where you'll be able to download the CLI for your platform)

ajayl83 commented 7 months ago

@rohanKanojia can i pick it up? already returning Map annotations created in the beginning of the function at the end of metho-> Collections.emptyMap() is better option rather here!