Search in sources :

Example 1 with OwnerReference

use of io.fabric8.kubernetes.api.model.OwnerReference in project flink by apache.

the class Fabric8FlinkKubeClient method createTaskManagerPod.

@Override
public CompletableFuture<Void> createTaskManagerPod(KubernetesPod kubernetesPod) {
    return CompletableFuture.runAsync(() -> {
        final Deployment masterDeployment = this.internalClient.apps().deployments().withName(KubernetesUtils.getDeploymentName(clusterId)).get();
        if (masterDeployment == null) {
            throw new RuntimeException("Failed to find Deployment named " + clusterId + " in namespace " + this.namespace);
        }
        // Note that we should use the uid of the master Deployment for the
        // OwnerReference.
        setOwnerReference(masterDeployment, Collections.singletonList(kubernetesPod.getInternalResource()));
        LOG.debug("Start to create pod with spec {}{}", System.lineSeparator(), KubernetesUtils.tryToGetPrettyPrintYaml(kubernetesPod.getInternalResource()));
        this.internalClient.pods().create(kubernetesPod.getInternalResource());
    }, kubeClientExecutorService);
}
Also used : FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment)

Example 2 with OwnerReference

use of io.fabric8.kubernetes.api.model.OwnerReference in project flink by apache.

the class Fabric8FlinkKubeClient method setOwnerReference.

private void setOwnerReference(Deployment deployment, List<HasMetadata> resources) {
    final OwnerReference deploymentOwnerReference = new OwnerReferenceBuilder().withName(deployment.getMetadata().getName()).withApiVersion(deployment.getApiVersion()).withUid(deployment.getMetadata().getUid()).withKind(deployment.getKind()).withController(true).withBlockOwnerDeletion(true).build();
    resources.forEach(resource -> resource.getMetadata().setOwnerReferences(Collections.singletonList(deploymentOwnerReference)));
}
Also used : OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder)

Example 3 with OwnerReference

use of io.fabric8.kubernetes.api.model.OwnerReference in project flink by apache.

the class Fabric8FlinkKubeClient method createJobManagerComponent.

@Override
public void createJobManagerComponent(KubernetesJobManagerSpecification kubernetesJMSpec) {
    final Deployment deployment = kubernetesJMSpec.getDeployment();
    final List<HasMetadata> accompanyingResources = kubernetesJMSpec.getAccompanyingResources();
    // create Deployment
    LOG.debug("Start to create deployment with spec {}{}", System.lineSeparator(), KubernetesUtils.tryToGetPrettyPrintYaml(deployment));
    final Deployment createdDeployment = this.internalClient.apps().deployments().create(deployment);
    // Note that we should use the uid of the created Deployment for the OwnerReference.
    setOwnerReference(createdDeployment, accompanyingResources);
    this.internalClient.resourceList(accompanyingResources).createOrReplace();
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment)

Aggregations

Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 OwnerReference (io.fabric8.kubernetes.api.model.OwnerReference)1 OwnerReferenceBuilder (io.fabric8.kubernetes.api.model.OwnerReferenceBuilder)1 FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)1