Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
theodolite
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sören Henning
theodolite
Merge requests
!119
Draft: Custom resource wrapper
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Draft: Custom resource wrapper
stu203404/theodolite:CustomResourceWrapper
into
master
Overview
3
Commits
1
Pipelines
0
Changes
3
Closed
Lorenz Boguhn
requested to merge
stu203404/theodolite:CustomResourceWrapper
into
master
3 years ago
Overview
3
Commits
1
Pipelines
0
Changes
3
Expand
Contains the custom resource wrapper for later.
Fix
#203 (closed)
Edited
3 years ago
by
Sören Henning
0
0
Merge request reports
Compare
master
version 1
7d9fe987
3 years ago
master (base)
and
latest version
latest version
7d9fe987
1 commit,
3 years ago
version 1
7d9fe987
1 commit,
3 years ago
3 files
+
74
−
7
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sCustomResourceWrapper.kt
0 → 100644
+
55
−
0
Options
package
theodolite.k8s
import
io.fabric8.kubernetes.client.CustomResource
import
io.fabric8.kubernetes.client.NamespacedKubernetesClient
import
io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext
/**
* Fabric8 handles custom resources as plain HashMaps. These need to be handled differently than normal
* Kubernetes resources. The K8sCustomResourceWrapper class provides a wrapper to deploy and delete
* custom resources in a uniform way.
*
* @property map custom resource as plain hashmap
* @constructor Create empty K8s custom resource wrapper
*/
class
K8sCustomResourceWrapper
(
private
val
map
:
Map
<
String
,
String
>)
:
CustomResource
()
{
/**
* Deploy a custom resource
*
* @param client a namespaced Kubernetes client which are used to deploy the CR object.
*/
fun
deploy
(
client
:
NamespacedKubernetesClient
)
{
val
kind
=
this
.
map
[
"kind"
]
// Search the CustomResourceDefinition to which the CR Object belongs.
// This should be exactly one if the CRD is registered for Kubernetes, zero otherwise.
val
crds
=
client
.
apiextensions
().
v1beta1
().
customResourceDefinitions
().
list
()
crds
.
items
.
filter
{
crd
->
crd
.
toString
().
contains
(
"kind=$kind"
)
}
.
map
{
crd
->
CustomResourceDefinitionContext
.
fromCrd
(
crd
)
}
.
forEach
{
context
->
client
.
customResource
(
context
)
.
createOrReplace
(
client
.
configuration
.
namespace
,
this
.
map
as
Map
<
String
,
Any
>)
}
}
/**
* Delete a custom resource
*
* @param client a namespaced Kubernetes client which are used to delete the CR object.
*/
fun
delete
(
client
:
NamespacedKubernetesClient
)
{
val
kind
=
this
.
map
[
"kind"
]
val
metadata
=
this
.
map
[
"metadata"
]
as
HashMap
<
String
,
String
>
val
name
=
metadata
[
"name"
]
val
crds
=
client
.
apiextensions
().
v1beta1
().
customResourceDefinitions
().
list
()
crds
.
items
.
filter
{
crd
->
crd
.
toString
().
contains
(
"kind=$kind"
)
}
.
map
{
crd
->
CustomResourceDefinitionContext
.
fromCrd
(
crd
)
}
.
forEach
{
context
->
client
.
customResource
(
context
).
delete
(
client
.
configuration
.
namespace
,
name
)
}
}
}
Loading