-
Notifications
You must be signed in to change notification settings - Fork 1k
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
IngressController code optimization #2913
Conversation
/** get new KubernetesClient */ | ||
@throws(classOf[KubernetesClientException]) | ||
def newK8sClient(): KubernetesClient = { | ||
new DefaultKubernetesClient() | ||
def getK8sClient(): KubernetesClient = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are better ways to implement the singleton pattern in scala:
private lazy val kubernetesClient: KubernetesClient = new DefaultKubernetesClient()
def getK8sClient(): KubernetesClient = kubernetesClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for reviewing the code
@@ -107,7 +116,7 @@ object KubernetesRetriever extends Logger { | |||
* deployment namespace | |||
*/ | |||
def isDeploymentExists(name: String, namespace: String): Boolean = { | |||
using(KubernetesRetriever.newK8sClient()) { | |||
using(KubernetesRetriever.getK8sClient()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The KubernetesRetriever.getK8sClient() method will return a singleton KubernetesClient. However, the using method closes the KubernetesClient after used, which can lead to bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for reviewing the code
IngressController code optimization