public static Deployment fromContainerDescriptionToDeployment( ContainerDescription description, String templateName) { if (description == null) { return null; } Deployment deployment = new Deployment(); deployment.apiVersion = KUBERNETES_API_VERSION_V1_BETA1; deployment.kind = DEPLOYMENT_TYPE; deployment.metadata = new ObjectMeta(); deployment.metadata.name = description.name; deployment.metadata.labels = new HashMap<>(); deployment.metadata.labels.put(KUBERNETES_LABEL_APP, templateName); deployment.spec = new DeploymentSpec(); deployment.spec.replicas = (description._cluster == null) ? Integer.valueOf(1) : description ._cluster; deployment.spec.template = new PodTemplateSpec(); deployment.spec.template.metadata = new ObjectMeta(); deployment.spec.template.metadata.labels = new HashMap<>(); deployment.spec.template.metadata.labels.put(KUBERNETES_LABEL_APP, templateName); deployment.spec.template.metadata.labels.put(KUBERNETES_LABEL_TIER, description.name); deployment.spec.template.spec = new PodSpec(); deployment.spec.template.spec.restartPolicy = fromContainerDescriptionRestartPolicyToPodRestartPolicy(description.restartPolicy); Container podContainer = fromContainerDescriptionToPodContainer(description); deployment.spec.template.spec.containers = Collections.singletonList(podContainer); return deployment; }
private PodState createPodState() throws Throwable { PodState podState = new PodState(); podState.pod = new Pod(); podState.pod.spec = new PodSpec(); podState.pod.spec.containers = new ArrayList<>(); Container container1 = new Container(); container1.name = "container1"; Container container2 = new Container(); container2.name = "container2"; Container container3 = new Container(); container3.name = "container3"; Container container4 = new Container(); container4.name = "container4"; Container container5 = new Container(); container5.name = "container5"; Container container6 = new Container(); container6.name = "container6"; podState.pod.spec.containers.add(container1); podState.pod.spec.containers.add(container2); podState.pod.spec.containers.add(container3); podState.pod.spec.containers.add(container4); podState.pod.spec.containers.add(container5); podState.pod.spec.containers.add(container6); podState.pod.metadata = new ObjectMeta(); podState.pod.metadata.selfLink = "/api/v1/namespaces/default/pods/test-pod"; podState.pod.metadata.uid = UUID.randomUUID().toString(); podState.documentSelfLink = podState.pod.metadata.uid; podState = doPost(podState, PodFactoryService.SELF_LINK); return podState; }
@Test public void testFromPodContainerToContainerDescription() { Container podContainer = createPodContainer(); PodSpec spec = new PodSpec(); spec.restartPolicy = RestartPolicy.Always; ContainerDescription containerDescription = KubernetesConverter .fromPodContainerToContainerDescription(podContainer, spec); assertNotNull(containerDescription); assertEquals(podContainer.name, containerDescription.name); assertEquals(podContainer.image, containerDescription.image); assertEquals(podContainer.command, Arrays.asList(containerDescription.command[0])); assertEquals(podContainer.args, Arrays.asList(containerDescription.command[1])); assertEquals(podContainer.workingDir, containerDescription.workingDir); assertEquals(podContainer.ports.get(0).containerPort.toString(), containerDescription.portBindings[0].containerPort); assertEquals(podContainer.ports.get(0).hostPort.toString(), containerDescription.portBindings[0].hostPort); assertEquals(podContainer.ports.get(0).protocol, containerDescription.portBindings[0].protocol); assertEquals(podContainer.env.get(0).name + "=" + podContainer.env.get(0).value, containerDescription.env[0]); assertEquals(podContainer.securityContext.privileged, containerDescription.privileged); assertEquals(spec.restartPolicy.toString().toLowerCase(), containerDescription.restartPolicy); assertEquals(podContainer.livenessProbe.timeoutSeconds, Integer.valueOf(containerDescription.healthConfig.timeoutMillis / 1000)); }
@Test public void testAdapterRequestOnPeriodicMaintenance() throws Throwable { PodState podState = new PodState(); podState.pod = new Pod(); podState.pod.spec = new PodSpec(); podState.pod.spec.containers = new ArrayList<>(); Container container1 = new Container(); container1.name = "container1"; container1.image = "test-image"; podState.pod.spec.containers.add(container1); podState.pod.metadata = new ObjectMeta(); podState.pod.metadata.selfLink = "/api/v1/namespaces/default/pods/test-pod"; podState.pod.metadata.name = "test-pod"; podState = doPost(podState, PodFactoryService.SELF_LINK); waitFor(() -> MockKubernetesAdapterService.requestOnInspect != null); assertNotNull(MockKubernetesAdapterService.requestOnInspect); assertEquals(KubernetesOperationType.INSPECT.id, MockKubernetesAdapterService .requestOnInspect.operationTypeId); assertEquals(podState.documentSelfLink, MockKubernetesAdapterService.requestOnInspect .resourceReference.getPath()); }
PodState podState = new PodState(); podState.pod = new Pod(); podState.pod.spec = new PodSpec(); podState.pod.spec.containers = new ArrayList<>(); Container container1 = new Container();
podState.pod.spec = new PodSpec(); podState.pod.spec.containers = new ArrayList<>(); Container container1 = new Container();
PodState podState = new PodState(); podState.pod = new Pod(); podState.pod.spec = new PodSpec(); podState.pod.spec.containers = new ArrayList<>(); Container container1 = new Container(); updatedPod.metadata.name = "test-pod"; updatedPod.metadata.selfLink = "/api/v1/namespaces/default/pods/test-pod"; updatedPod.spec = new PodSpec(); updatedPod.spec.containers = new ArrayList<>(); Container updatedContainer = new Container();
@Test public void testCreate() throws Throwable { PodState podState = new PodState(); podState.pod = new Pod(); podState.pod.spec = new PodSpec(); podState.pod.spec.containers = new ArrayList<>(); Container container1 = new Container(); podState.pod.spec.containers.add(container1); podState.pod.metadata = new ObjectMeta(); podState.pod.metadata.selfLink = "/api/v1/namespaces/default/pods/test-pod"; podState.parentLink = kubernetesHostState.documentSelfLink; podState = doPost(podState, PodFactoryService.SELF_LINK); provisioningTaskLink = createProvisioningTask(); AdapterRequest request = new AdapterRequest(); request.resourceReference = UriUtils.buildUri(host, podState.documentSelfLink); request.serviceTaskCallback = ServiceTaskCallback.create(provisioningTaskLink); request.operationTypeId = KubernetesOperationType.CREATE.id; doOperation(KubernetesAdapterService.SELF_LINK, request); waitForPropertyValue(provisioningTaskLink, MockTaskState.class, "taskInfo.stage", TaskState.TaskStage.FAILED); }
PodService.PodState state = new PodService.PodState(); state.pod = new Pod(); state.pod.spec = new PodSpec(); state.pod.spec.containers = new ArrayList<>(); Container c = new Container();