-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,15 +47,24 @@ object KubernetesRetriever extends Logger { | |
// see org.apache.flink.configuration.RestOptions.RETRY_MAX_ATTEMPTS | ||
val FLINK_REST_RETRY_MAX_ATTEMPTS = 2 | ||
|
||
private var kubernetesClient: KubernetesClient = _ | ||
|
||
/** get new KubernetesClient */ | ||
@throws(classOf[KubernetesClientException]) | ||
def newK8sClient(): KubernetesClient = { | ||
new DefaultKubernetesClient() | ||
def getK8sClient(): KubernetesClient = { | ||
if (kubernetesClient == null) { | ||
synchronized { | ||
if (kubernetesClient == null) { | ||
kubernetesClient = new DefaultKubernetesClient() | ||
} | ||
} | ||
} | ||
kubernetesClient | ||
} | ||
|
||
/** check connection of kubernetes cluster */ | ||
def checkK8sConnection(): Boolean = { | ||
Try(newK8sClient().getVersion != null).getOrElse(false) | ||
Try(getK8sClient().getVersion != null).getOrElse(false) | ||
} | ||
|
||
private val clusterClientServiceLoader = new DefaultClusterClientServiceLoader() | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks for reviewing the code |
||
client => | ||
client | ||
.apps() | ||
|
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:
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