Skip to content

Commit e1003e2

Browse files
committed
Add VirtualMachine CRD
Signed-off-by: loheagn <[email protected]>
1 parent 51de698 commit e1003e2

File tree

11 files changed

+90
-36
lines changed

11 files changed

+90
-36
lines changed

build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
val kotlin_version: String by project
22

33
plugins {
4+
id("java")
45
application
56
kotlin("jvm") version "1.8.0"
67
kotlin("plugin.serialization") version "1.8.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cn.edu.buaa.scs.kube.crd.v1alpha1;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import io.fabric8.kubernetes.api.model.Namespaced;
5+
import io.fabric8.kubernetes.client.CustomResource;
6+
import io.fabric8.kubernetes.model.annotation.Group;
7+
import io.fabric8.kubernetes.model.annotation.Kind;
8+
import io.fabric8.kubernetes.model.annotation.Version;
9+
10+
@JsonInclude(JsonInclude.Include.NON_NULL)
11+
@Group(Constants.GROUP)
12+
@Version(Constants.API_VERSION)
13+
@Kind("VirtualMachine")
14+
public class VirtualMachine extends CustomResource<VirtualMachineSpec, VirtualMachineStatus> implements Namespaced {
15+
16+
}

src/main/kotlin/cn/edu/buaa/scs/kube/KubeModule.kt

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ fun Application.kubeModule() {
2929
}
3030

3131
logger("kube")().info { "connected to official kubernetes apiserver successfully: ${kubeClient.kubernetesVersion.gitVersion}" }
32+
VirtualMachineClient.registerVirtualMachineOperator()
3233

3334
ImageBuildRoutine.run()
3435
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cn.edu.buaa.scs.kube
2+
3+
import cn.edu.buaa.scs.kube.crd.v1alpha1.VirtualMachine
4+
import cn.edu.buaa.scs.kube.crd.v1alpha1.VirtualMachineList
5+
import cn.edu.buaa.scs.kube.crd.v1alpha1.VirtualMachineReconciler
6+
import io.fabric8.kubernetes.client.dsl.MixedOperation
7+
import io.fabric8.kubernetes.client.dsl.Resource
8+
import io.javaoperatorsdk.operator.Operator
9+
10+
object VirtualMachineClient {
11+
private val client by lazy {
12+
kubeClient.resources(
13+
VirtualMachine::class.java,
14+
VirtualMachineList::class.java,
15+
) as MixedOperation<VirtualMachine, VirtualMachineList, Resource<VirtualMachine>>
16+
}
17+
18+
fun registerVirtualMachineOperator() {
19+
val operator = Operator(kubeClient)
20+
operator.register(VirtualMachineReconciler())
21+
operator.start()
22+
}
23+
24+
fun get(name: String, namespace: String): VirtualMachine? {
25+
return client.inNamespace(namespace).withName(name).get()
26+
}
27+
}

src/main/kotlin/cn/edu/buaa/scs/kube/crd/v1alpha1/Builder.kt

-10
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import io.fabric8.kubernetes.client.CustomResource
1010
import io.fabric8.kubernetes.model.annotation.Group
1111
import io.fabric8.kubernetes.model.annotation.Kind
1212
import io.fabric8.kubernetes.model.annotation.Version
13-
import javax.annotation.Generated
1413

1514
/**
1615
* Builder is the Schema for the builders API
1716
*/
1817
@JsonInclude(JsonInclude.Include.NON_NULL)
19-
@Generated("jsonschema2pojo")
2018
@Group(Constants.GROUP)
2119
@Version(Constants.API_VERSION)
2220
@Kind("Builder")
@@ -29,7 +27,6 @@ class BuilderList : DefaultKubernetesResourceList<Builder>()
2927
*/
3028
@JsonInclude(JsonInclude.Include.NON_NULL)
3129
@JsonPropertyOrder("base")
32-
@Generated("jsonschema2pojo")
3330
@JsonDeserialize(using = JsonDeserializer.None::class)
3431
class BuilderStatus : KubernetesResource {
3532
@get:JsonProperty("base")
@@ -75,7 +72,6 @@ class BuilderStatus : KubernetesResource {
7572
*/
7673
@JsonInclude(JsonInclude.Include.NON_NULL)
7774
@JsonPropertyOrder("context", "destination", "dockerfilePath", "pushSecretName", "round")
78-
@Generated("jsonschema2pojo")
7975
@JsonDeserialize(using = JsonDeserializer.None::class)
8076
class BuilderSpec : KubernetesResource {
8177
/**
@@ -175,7 +171,6 @@ class BuilderSpec : KubernetesResource {
175171

176172
@JsonInclude(JsonInclude.Include.NON_NULL)
177173
@JsonPropertyOrder("git", "raw", "s3")
178-
@Generated("jsonschema2pojo")
179174
class BuilderContext {
180175
@get:JsonProperty("git")
181176
@set:JsonProperty("git")
@@ -237,7 +232,6 @@ class BuilderContext {
237232

238233
@JsonInclude(JsonInclude.Include.NON_NULL)
239234
@JsonPropertyOrder("endpoint", "ref", "scheme", "userPassword", "username")
240-
@Generated("jsonschema2pojo")
241235
class GitContext {
242236
/**
243237
* (Required)
@@ -325,7 +319,6 @@ class GitContext {
325319
return (endpoint === rhs.endpoint || endpoint != null && endpoint == rhs.endpoint) && (ref === rhs.ref || ref != null && ref == rhs.ref) && (userPassword === rhs.userPassword || userPassword != null && userPassword == rhs.userPassword) && (scheme == rhs.scheme || scheme != null && scheme == rhs.scheme) && (username === rhs.username || username != null && username == rhs.username)
326320
}
327321

328-
@Generated("jsonschema2pojo")
329322
enum class Scheme(private val value: String) {
330323
HTTP("http"), HTTPS("https");
331324

@@ -358,7 +351,6 @@ class GitContext {
358351

359352
@JsonInclude(JsonInclude.Include.NON_NULL)
360353
@JsonPropertyOrder("accessKeyID", "accessSecretKey", "bucket", "endpoint", "fileType", "objectKey", "region", "scheme")
361-
@Generated("jsonschema2pojo")
362354
class S3Context {
363355
/**
364356
* (Required)
@@ -508,7 +500,6 @@ class S3Context {
508500
return (accessKeyID === rhs.accessKeyID || accessKeyID != null && accessKeyID == rhs.accessKeyID) && (bucket === rhs.bucket || bucket != null && bucket == rhs.bucket) && (endpoint === rhs.endpoint || endpoint != null && endpoint == rhs.endpoint) && (scheme == rhs.scheme || scheme != null && scheme == rhs.scheme) && (objectKey === rhs.objectKey || objectKey != null && objectKey == rhs.objectKey) && (accessSecretKey === rhs.accessSecretKey || accessSecretKey != null && accessSecretKey == rhs.accessSecretKey) && (region === rhs.region || region != null && region == rhs.region) && (fileType == rhs.fileType || fileType != null && fileType == rhs.fileType)
509501
}
510502

511-
@Generated("jsonschema2pojo")
512503
enum class FileType(private val value: String) {
513504
TAR("tar"), TAR_GZ("tar.gz"), ZIP("zip"), RAR("rar"), DIR("dir");
514505

@@ -538,7 +529,6 @@ class S3Context {
538529
}
539530
}
540531

541-
@Generated("jsonschema2pojo")
542532
enum class Scheme(private val value: String) {
543533
HTTP("http"), HTTPS("https");
544534

src/main/kotlin/cn/edu/buaa/scs/kube/crd/v1alpha1/Deployer.kt

-9
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import io.fabric8.kubernetes.client.CustomResource
1010
import io.fabric8.kubernetes.model.annotation.Group
1111
import io.fabric8.kubernetes.model.annotation.Kind
1212
import io.fabric8.kubernetes.model.annotation.Version
13-
import javax.annotation.Generated
1413

1514
/**
1615
* Deployer is the Schema for the deployers API
1716
*/
1817
@JsonInclude(JsonInclude.Include.NON_NULL)
19-
@Generated("jsonschema2pojo")
2018
@Group(Constants.GROUP)
2119
@Version(Constants.API_VERSION)
2220
@Kind("Deployer")
@@ -29,7 +27,6 @@ class DeployerList : DefaultKubernetesResourceList<Deployer>()
2927
*/
3028
@JsonInclude(JsonInclude.Include.NON_NULL)
3129
@JsonPropertyOrder("base")
32-
@Generated("jsonschema2pojo")
3330
@JsonDeserialize(using = JsonDeserializer.None::class)
3431
class DeployerStatus : KubernetesResource {
3532
@get:JsonProperty("base")
@@ -76,7 +73,6 @@ class DeployerStatus : KubernetesResource {
7673
*/
7774
@JsonInclude(JsonInclude.Include.NON_NULL)
7875
@JsonPropertyOrder("containers", "round", "type")
79-
@Generated("jsonschema2pojo")
8076
@JsonDeserialize(using = JsonDeserializer.None::class)
8177
class DeployerSpec : KubernetesResource {
8278
/**
@@ -153,7 +149,6 @@ class DeployerSpec : KubernetesResource {
153149
return (containers === rhs.containers || containers != null && containers == rhs.containers) && (round === rhs.round || round != null && round == rhs.round) && (type == rhs.type || type != null && type == rhs.type)
154150
}
155151

156-
@Generated("jsonschema2pojo")
157152
enum class Type(private val value: String) {
158153
JOB("job"), SERVICE("service");
159154

@@ -186,7 +181,6 @@ class DeployerSpec : KubernetesResource {
186181

187182
@JsonInclude(JsonInclude.Include.NON_NULL)
188183
@JsonPropertyOrder("args", "command", "env", "image", "initial", "name", "ports", "resource")
189-
@Generated("jsonschema2pojo")
190184
class ContainerSpec {
191185
@get:JsonProperty("args")
192186
@set:JsonProperty("args")
@@ -299,7 +293,6 @@ class ContainerSpec {
299293

300294
@JsonInclude(JsonInclude.Include.NON_NULL)
301295
@JsonPropertyOrder("cpu", "memory")
302-
@Generated("jsonschema2pojo")
303296
class Resource {
304297
/**
305298
*
@@ -380,7 +373,6 @@ class Resource {
380373

381374
@JsonInclude(JsonInclude.Include.NON_NULL)
382375
@JsonPropertyOrder("export", "port", "protocol")
383-
@Generated("jsonschema2pojo")
384376
class Port {
385377
@get:JsonProperty("export")
386378
@set:JsonProperty("export")
@@ -447,7 +439,6 @@ class Port {
447439
return (protocol == rhs.protocol || protocol != null && protocol == rhs.protocol) && (export === rhs.export || export != null && export == rhs.export) && (port === rhs.port || port != null && port == rhs.port)
448440
}
449441

450-
@Generated("jsonschema2pojo")
451442
enum class Protocol(private val value: String) {
452443
TCP("tcp"), UDP("udp"), SCTP("sctp");
453444

src/main/kotlin/cn/edu/buaa/scs/kube/crd/v1alpha1/Status.kt

-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import com.fasterxml.jackson.annotation.JsonInclude
44
import com.fasterxml.jackson.annotation.JsonProperty
55
import com.fasterxml.jackson.annotation.JsonPropertyDescription
66
import com.fasterxml.jackson.annotation.JsonPropertyOrder
7-
import javax.annotation.Generated
87

98
@JsonInclude(JsonInclude.Include.NON_NULL)
109
@JsonPropertyOrder("currentRound", "historyList", "message", "status")
11-
@Generated("jsonschema2pojo")
1210
class BaseStatus {
1311
/**
1412
* (Required)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cn.edu.buaa.scs.kube.crd.v1alpha1
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude
4+
import com.fasterxml.jackson.annotation.JsonProperty
5+
import io.fabric8.kubernetes.api.model.DefaultKubernetesResourceList
6+
import io.fabric8.kubernetes.api.model.KubernetesResource
7+
import io.javaoperatorsdk.operator.api.reconciler.*
8+
9+
class VirtualMachineList() : DefaultKubernetesResourceList<VirtualMachine>()
10+
11+
@JsonInclude(JsonInclude.Include.NON_NULL)
12+
data class VirtualMachineSpec(
13+
@JsonProperty("name") val name: String,
14+
) : KubernetesResource
15+
16+
@JsonInclude(JsonInclude.Include.NON_NULL)
17+
data class VirtualMachineStatus(
18+
@JsonProperty("status") val status: String,
19+
)
20+
21+
@ControllerConfiguration(
22+
generationAwareEventProcessing = false,
23+
)
24+
class VirtualMachineReconciler : Reconciler<VirtualMachine>, Cleaner<VirtualMachine> {
25+
override fun reconcile(
26+
resource: VirtualMachine?,
27+
context: Context<VirtualMachine>?
28+
): UpdateControl<VirtualMachine> {
29+
TODO()
30+
}
31+
32+
override fun cleanup(resource: VirtualMachine?, context: Context<VirtualMachine>?): DeleteControl {
33+
TODO()
34+
}
35+
36+
}

src/main/kotlin/cn/edu/buaa/scs/kube/crd/v1alpha1/Workflow.kt

-5
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ import io.fabric8.kubernetes.client.CustomResource
1212
import io.fabric8.kubernetes.model.annotation.Group
1313
import io.fabric8.kubernetes.model.annotation.Kind
1414
import io.fabric8.kubernetes.model.annotation.Version
15-
import javax.annotation.Generated
1615

1716
/**
1817
* Workflow is the Schema for the workflows API
1918
*/
2019
@JsonInclude(JsonInclude.Include.NON_NULL)
21-
@Generated("jsonschema2pojo")
2220
@Group(Constants.GROUP)
2321
@Version(Constants.API_VERSION)
2422
@Kind("Workflow")
@@ -28,7 +26,6 @@ class WorkflowList : DefaultKubernetesResourceList<Workflow>()
2826

2927
@JsonInclude(JsonInclude.Include.NON_NULL)
3028
@JsonPropertyOrder("builderList", "deployerList", "round")
31-
@Generated("jsonschema2pojo")
3229
@JsonDeserialize(using = JsonDeserializer.None::class)
3330
class WorkflowSpec : KubernetesResource {
3431
/**
@@ -111,7 +108,6 @@ class WorkflowSpec : KubernetesResource {
111108
*/
112109
@JsonInclude(JsonInclude.Include.NON_NULL)
113110
@JsonPropertyOrder("base", "stage")
114-
@Generated("jsonschema2pojo")
115111
@JsonDeserialize(using = JsonDeserializer.None::class)
116112
class WorkflowStatus : KubernetesResource {
117113
@get:JsonProperty("base")
@@ -166,7 +162,6 @@ class WorkflowStatus : KubernetesResource {
166162

167163
@JsonInclude(JsonInclude.Include.NON_NULL)
168164
@JsonPropertyOrder("name", "namespace")
169-
@Generated("jsonschema2pojo")
170165
class NamespacedName {
171166
/**
172167
* (Required)

src/test/kotlin/cn/edu/buaa/scs/model/VirtualMachineTest.kt

-10
This file was deleted.

vm-sample.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: cloudapi.scs.buaa.edu.cn/v1alpha1
2+
kind: VirtualMachine
3+
metadata:
4+
name: vm-sample
5+
namespace: default
6+
spec:
7+
name: vm-sample
8+
status:
9+
status: "running"

0 commit comments

Comments
 (0)