Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
QA
holmes
Commits
a9be479e
Commit
a9be479e
authored
Sep 30, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
获取namespace列表时,兼容mysql有多个pod的情况
parent
a2223d20
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
6 deletions
+30
-6
K8sService.java
src/main/java/cn/qg/holmes/service/k8s/K8sService.java
+30
-6
No files found.
src/main/java/cn/qg/holmes/service/k8s/K8sService.java
View file @
a9be479e
...
...
@@ -141,9 +141,17 @@ public class K8sService {
if
(
service
!=
null
)
{
port
=
service
.
getSpec
().
getPorts
().
get
(
0
).
getNodePort
();
}
if
(
podList
.
size
()
>
0
)
{
if
(
podList
.
size
()
==
1
)
{
host
=
podList
.
get
(
0
).
getStatus
().
getHostIP
();
}
if
(
podList
.
size
()
>=
2
)
{
for
(
Pod
pod:
podList
)
{
if
(
pod
.
getStatus
().
getHostIP
()
!=
null
)
{
host
=
pod
.
getStatus
().
getHostIP
();
break
;
}
}
}
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
df
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
SimpleDateFormat
df2
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
...
...
@@ -176,9 +184,17 @@ public class K8sService {
if
(
service
!=
null
)
{
port
=
service
.
getSpec
().
getPorts
().
get
(
0
).
getNodePort
();
}
if
(
podList
.
size
()
>
0
)
{
if
(
podList
.
size
()
==
1
)
{
host
=
podList
.
get
(
0
).
getStatus
().
getHostIP
();
}
if
(
podList
.
size
()
>=
2
)
{
for
(
Pod
pod:
podList
)
{
if
(
pod
.
getStatus
().
getHostIP
()
!=
null
)
{
host
=
pod
.
getStatus
().
getHostIP
();
break
;
}
}
}
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd'T'HH:mm:ss'Z'"
);
df
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"UTC"
));
SimpleDateFormat
df2
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
...
...
@@ -2303,14 +2319,22 @@ public class K8sService {
Map
<
String
,
String
>
labels
=
new
HashMap
<>();
labels
.
put
(
"qcloud-app"
,
"mysql"
);
labels
.
put
(
"type"
,
"base"
);
Pod
pod
=
kubernetesClient
.
pods
().
inNamespace
(
"k8s"
).
withLabels
(
labels
).
list
().
getItems
().
get
(
0
);
System
.
out
.
println
(
pod
);
List
<
Pod
>
podList
=
kubernetesClient
.
pods
().
inNamespace
(
"vcc"
).
withLabels
(
labels
).
list
().
getItems
();
String
host
=
null
;
for
(
Pod
pod:
podList
)
{
if
(
pod
.
getStatus
().
getHostIP
()
!=
null
)
{
host
=
pod
.
getStatus
().
getHostIP
();
break
;
}
}
System
.
out
.
println
(
podList
.
size
());
System
.
out
.
println
(
host
);
}
public
static
void
main
(
String
[]
args
)
{
K8sService
k8sService
=
new
K8sService
();
k8sService
.
createNewNamespace
(
"test6"
,
"dev"
,
"黎博"
);
//
k8sService.podTest();
//
k8sService.createNewNamespace("test6", "dev", "黎博");
k8sService
.
podTest
();
// k8sService.getPodList("k8s");
// System.out.println(JSON.toJSONString(k8sService.getPodListNew("fe")));
// if (!k8sService.queryIfServiceExistByName("fe", "lxq-ui")) {
...
...
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