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
483c3ef7
Commit
483c3ef7
authored
Aug 18, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增创建namespace接口
parent
ef25ec83
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
4 deletions
+43
-4
K8sController.java
src/main/java/cn/qg/holmes/controller/k8s/K8sController.java
+10
-3
K8sService.java
src/main/java/cn/qg/holmes/service/k8s/K8sService.java
+33
-1
No files found.
src/main/java/cn/qg/holmes/controller/k8s/K8sController.java
View file @
483c3ef7
...
...
@@ -5,12 +5,9 @@ import cn.qg.holmes.entity.k8s.DockerProject;
import
cn.qg.holmes.entity.k8s.ServiceCreateVo
;
import
cn.qg.holmes.service.k8s.*
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
io.fabric8.kubernetes.api.model.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -252,4 +249,14 @@ public class K8sController {
return
JsonResult
.
buildErrorStateResult
(
"redis清除失败!"
,
false
);
}
}
/**
* 创建新的namespace
*/
@PostMapping
(
"/namespace/create"
)
public
JsonResult
createNewNamespace
(
@RequestParam
String
name
,
@RequestParam
String
desc
,
@RequestParam
String
owner
)
{
return
JsonResult
.
buildSuccessResult
(
k8sService
.
createNewNamespace
(
name
,
desc
,
owner
));
}
}
src/main/java/cn/qg/holmes/service/k8s/K8sService.java
View file @
483c3ef7
...
...
@@ -1897,8 +1897,40 @@ public class K8sService {
return
map
;
}
/**
* 创建新的namespace
* @param name namespace名称
* @param desc dev/test
* @param owner
* @return
*/
public
Namespace
createNewNamespace
(
String
name
,
String
desc
,
String
owner
)
{
Namespace
namespace
=
new
Namespace
();
ObjectMeta
objectMeta
=
new
ObjectMeta
();
Map
<
String
,
String
>
annotations
=
new
HashMap
<>();
annotations
.
put
(
"description"
,
desc
);
annotations
.
put
(
"owner"
,
owner
);
objectMeta
.
setAnnotations
(
annotations
);
objectMeta
.
setName
(
name
);
NamespaceSpec
namespaceSpec
=
new
NamespaceSpec
();
List
<
String
>
finalizers
=
new
ArrayList
<>();
finalizers
.
add
(
"kubernetes"
);
namespaceSpec
.
setFinalizers
(
finalizers
);
NamespaceStatus
namespaceStatus
=
new
NamespaceStatus
();
namespaceStatus
.
setPhase
(
"Active"
);
namespace
.
setApiVersion
(
"v1"
);
namespace
.
setKind
(
"Namespace"
);
namespace
.
setMetadata
(
objectMeta
);
namespace
.
setSpec
(
namespaceSpec
);
namespace
.
setStatus
(
namespaceStatus
);
return
kubernetesClient
.
namespaces
().
create
(
namespace
);
}
public
static
void
main
(
String
[]
args
)
{
K8sService
k8sService
=
new
K8sService
();
System
.
out
.
println
(
k8sService
.
getPodDetail
(
"k8s"
,
"base"
,
"redis"
)
);
k8sService
.
createNewNamespace
(
"test6"
,
"dev"
,
"黎博"
);
}
}
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