|
|
@@ -0,0 +1,66 @@
|
|
|
+package nju.seec.SEECdemo.logic.api.k8s.vo;
|
|
|
+
|
|
|
+import io.kubernetes.client.models.*;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.ToString;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * author: rale
|
|
|
+ * createdAt: 12/22/18
|
|
|
+ */
|
|
|
+@ToString
|
|
|
+@Data
|
|
|
+public class Namespace {
|
|
|
+
|
|
|
+ private static final String VERSION = "v1";
|
|
|
+
|
|
|
+ private static final String KIND = "Namespace";
|
|
|
+
|
|
|
+ @NotNull
|
|
|
+ private String name;
|
|
|
+
|
|
|
+ private String description;
|
|
|
+
|
|
|
+ @NotNull
|
|
|
+ private String type;
|
|
|
+
|
|
|
+ public V1Namespace toV1Namespace(){
|
|
|
+ V1ObjectMeta v1ObjectMeta = new V1ObjectMetaBuilder()
|
|
|
+ .withName(name)
|
|
|
+ .withLabels(Collections.singletonMap(Constants.TYPE_LABEL, type))
|
|
|
+ .addToAnnotations(Constants.DESCRIPTION_LABEL, description == null ? name : description)
|
|
|
+ .build();
|
|
|
+ V1NamespaceSpec v1NamespaceSpec = new V1NamespaceSpecBuilder()
|
|
|
+ .build();
|
|
|
+ V1Namespace v1Namespace = new V1NamespaceBuilder()
|
|
|
+ .withApiVersion(VERSION)
|
|
|
+ .withKind(KIND)
|
|
|
+ .withMetadata(v1ObjectMeta)
|
|
|
+ .withSpec(v1NamespaceSpec)
|
|
|
+ .build();
|
|
|
+ return v1Namespace;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public Namespace fromV1Namespace(V1Namespace v1Namespace) {
|
|
|
+ Namespace namespace = new Namespace();
|
|
|
+ V1ObjectMeta v1ObjectMeta = v1Namespace.getMetadata();
|
|
|
+ if (v1ObjectMeta != null) {
|
|
|
+ namespace.setName(v1Namespace.getMetadata().getName());
|
|
|
+ Map<String, String> annotations = v1ObjectMeta.getAnnotations();
|
|
|
+ if (!CollectionUtils.isEmpty(annotations)) {
|
|
|
+ namespace.setDescription(annotations.get(Constants.DESCRIPTION_LABEL));
|
|
|
+ }
|
|
|
+ Map<String, String> labels = v1ObjectMeta.getLabels();
|
|
|
+ if (!CollectionUtils.isEmpty(labels)) {
|
|
|
+ namespace.setType(labels.get(Constants.TYPE_LABEL));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return namespace;
|
|
|
+ }
|
|
|
+}
|