Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangpeng
dinky
Commits
be747e50
Unverified
Commit
be747e50
authored
Apr 10, 2024
by
gaoyan
Committed by
GitHub
Apr 10, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize k8s delete cluster (#3368)
Co-authored-by:
gaoyan1998
<
gaoyan1998@users.noreply.github.com
>
parent
ea4599d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
6 deletions
+40
-6
KubernetesGateway.java
.../java/org/dinky/gateway/kubernetes/KubernetesGateway.java
+19
-6
K8sClientHelper.java
...a/org/dinky/gateway/kubernetes/utils/K8sClientHelper.java
+21
-0
No files found.
dinky-gateway/src/main/java/org/dinky/gateway/kubernetes/KubernetesGateway.java
View file @
be747e50
...
@@ -212,12 +212,25 @@ public abstract class KubernetesGateway extends AbstractGateway {
...
@@ -212,12 +212,25 @@ public abstract class KubernetesGateway extends AbstractGateway {
throw
new
GatewayException
(
throw
new
GatewayException
(
"No cluster id was specified. Please specify a cluster to which you would like"
+
" to connect."
);
"No cluster id was specified. Please specify a cluster to which you would like"
+
" to connect."
);
}
}
if
(
k8sClientHelper
.
getClusterIsPresent
(
clusterId
))
{
try
(
KubernetesClusterDescriptor
clusterDescriptor
=
try
(
KubernetesClusterDescriptor
clusterDescriptor
=
clusterClientFactory
.
createClusterDescriptor
(
configuration
))
{
clusterClientFactory
.
createClusterDescriptor
(
configuration
))
{
clusterDescriptor
.
killCluster
(
clusterId
);
clusterDescriptor
.
killCluster
(
clusterId
);
}
catch
(
Exception
e
)
{
int
retryCount
=
0
;
logger
.
error
(
e
.
getMessage
(),
e
);
while
(
k8sClientHelper
.
getClusterIsPresent
(
clusterId
))
{
retryCount
++;
log
.
warn
(
"cluster id: {} is still running, recheck at 1s later"
,
clusterId
);
if
(
retryCount
>
60
)
{
throw
new
GatewayException
(
"The cluster "
+
clusterId
+
" still running, abort wait kill cluster, please check your k8s cluster."
);
}
Thread
.
sleep
(
1000
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
else
{
logger
.
info
(
"Cluster {} is not present, ignore kill"
,
clusterId
);
}
}
}
}
...
...
dinky-gateway/src/main/java/org/dinky/gateway/kubernetes/utils/K8sClientHelper.java
View file @
be747e50
...
@@ -26,6 +26,7 @@ import org.apache.flink.configuration.Configuration;
...
@@ -26,6 +26,7 @@ import org.apache.flink.configuration.Configuration;
import
org.apache.flink.kubernetes.configuration.KubernetesConfigOptions
;
import
org.apache.flink.kubernetes.configuration.KubernetesConfigOptions
;
import
org.apache.flink.kubernetes.kubeclient.FlinkKubeClient
;
import
org.apache.flink.kubernetes.kubeclient.FlinkKubeClient
;
import
org.apache.flink.kubernetes.kubeclient.FlinkKubeClientFactory
;
import
org.apache.flink.kubernetes.kubeclient.FlinkKubeClientFactory
;
import
org.apache.flink.kubernetes.kubeclient.decorators.ExternalServiceDecorator
;
import
org.apache.http.util.TextUtils
;
import
org.apache.http.util.TextUtils
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayInputStream
;
...
@@ -33,6 +34,7 @@ import java.io.InputStream;
...
@@ -33,6 +34,7 @@ import java.io.InputStream;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
org.yaml.snakeyaml.DumperOptions
;
import
org.yaml.snakeyaml.DumperOptions
;
import
org.yaml.snakeyaml.Yaml
;
import
org.yaml.snakeyaml.Yaml
;
...
@@ -68,6 +70,25 @@ public class K8sClientHelper {
...
@@ -68,6 +70,25 @@ public class K8sClientHelper {
initKubeClient
(
kubeConfig
);
initKubeClient
(
kubeConfig
);
}
}
public
Optional
<
Deployment
>
getJobService
(
String
clusterId
)
{
String
serviceName
=
ExternalServiceDecorator
.
getExternalServiceName
(
clusterId
);
Deployment
deployment
=
kubernetesClient
.
apps
()
.
deployments
()
.
inNamespace
(
configuration
.
getString
(
KubernetesConfigOptions
.
NAMESPACE
))
.
withName
(
configuration
.
getString
(
KubernetesConfigOptions
.
CLUSTER_ID
))
.
get
();
if
(
deployment
==
null
)
{
log
.
debug
(
"Service {} does not exist"
,
serviceName
);
return
Optional
.
empty
();
}
return
Optional
.
of
(
deployment
);
}
public
boolean
getClusterIsPresent
(
String
clusterId
)
{
return
getJobService
(
clusterId
).
isPresent
();
}
/**
/**
* initKubeClient
* initKubeClient
*/
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment