Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

ChengJie1053
Copy link
Member

IngressController code optimization

/** get new KubernetesClient */
@throws(classOf[KubernetesClientException])
def newK8sClient(): KubernetesClient = {
new DefaultKubernetesClient()
def getK8sClient(): KubernetesClient = {
Copy link
Member

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

Copy link
Member Author

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()) {
Copy link
Member

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.

Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants