Search in sources :

Example 71 with Deployment

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

the class KubernetesJobManagerFactoryTest method testDeploymentMetadata.

@Test
public void testDeploymentMetadata() throws IOException {
    kubernetesJobManagerSpecification = KubernetesJobManagerFactory.buildKubernetesJobManagerSpecification(flinkPod, kubernetesJobManagerParameters);
    final Deployment resultDeployment = this.kubernetesJobManagerSpecification.getDeployment();
    assertEquals(Constants.APPS_API_VERSION, resultDeployment.getApiVersion());
    assertEquals(KubernetesUtils.getDeploymentName(CLUSTER_ID), resultDeployment.getMetadata().getName());
    final Map<String, String> expectedLabels = getCommonLabels();
    expectedLabels.put(Constants.LABEL_COMPONENT_KEY, Constants.LABEL_COMPONENT_JOB_MANAGER);
    expectedLabels.putAll(userLabels);
    assertEquals(expectedLabels, resultDeployment.getMetadata().getLabels());
    assertThat(resultDeployment.getMetadata().getAnnotations(), equalTo(userAnnotations));
    assertThat(resultDeployment.getMetadata().getOwnerReferences(), Matchers.containsInAnyOrder(OWNER_REFERENCES.toArray()));
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Test(org.junit.Test)

Example 72 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment 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 73 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment 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 74 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project syndesis-qe by syndesisio.

the class Syndesis method deployOperator.

public void deployOperator() {
    List<HasMetadata> resourceList = getOperatorResources();
    final String operatorResourcesName = "syndesis-operator";
    Optional<HasMetadata> serviceAccount = resourceList.stream().filter(resource -> "ServiceAccount".equals(resource.getKind()) && operatorResourcesName.equals(resource.getMetadata().getName())).findFirst();
    if (serviceAccount.isPresent()) {
        ((ServiceAccount) serviceAccount.get()).getImagePullSecrets().add(new LocalObjectReference(TestConfiguration.syndesisPullSecretName()));
    } else {
        log.error("Service account not found in resources");
    }
    OpenShiftUtils.getInstance().serviceAccounts().withName("default").edit().addToImagePullSecrets(new LocalObjectReference(TestConfiguration.syndesisPullSecretName())).done();
    List<EnvVar> envVarsToAdd = new ArrayList<>();
    envVarsToAdd.add(new EnvVar("TEST_SUPPORT", "true", null));
    // For upgrade, we want to override images only for "current" version
    if (operatorImage.equals(TestConfiguration.syndesisOperatorImage())) {
        Set<Image> images = EnumSet.allOf(Image.class);
        for (Image image : images) {
            if (TestConfiguration.image(image) != null) {
                // override image, e.g. from BUILD_PROPERTIES
                log.info("Overriding " + image.name().toLowerCase() + " image with " + TestConfiguration.image(image));
                envVarsToAdd.add(new EnvVar("RELATED_IMAGE_" + image.name(), TestConfiguration.image(image), null));
            } else {
                // use images from Quay instead of DockerHub for Syndesis components
                switch(image) {
                    case META:
                    case S2I:
                    case UI:
                    case SERVER:
                    case UPGRADE:
                        log.info("Overriding " + image.name().toLowerCase() + " image with quay variant");
                        String version = TestConfiguration.syndesisInstallVersion() != null ? TestConfiguration.syndesisInstallVersion() : "latest";
                        envVarsToAdd.add(new EnvVar("RELATED_IMAGE_" + image.name(), String.format("%s/syndesis/syndesis-%s:%s", TestConfiguration.get().readValue(SYNDESIS_DOCKER_REGISTRY), image.name().toLowerCase(), version), null));
                }
            }
        }
    }
    if ((TestUtils.isProdBuild() && getOperatorImage().contains("1.8")) || getOperatorImage().contains("1.11")) {
        // apply this hotfix for 1.8 prod version, needs for OSD because it doesn't see proxy eng repo
        if (TestUtils.isProdBuild()) {
            envVarsToAdd.add(new EnvVar("RELATED_IMAGE_PSQL_EXPORTER", "registry.redhat.io/fuse7/fuse-postgres-exporter-rhel7:1.8", null));
        }
        // needs for upgrade test when previous version is 1.11
        DeploymentConfig dc = (DeploymentConfig) resourceList.stream().filter(r -> "DeploymentConfig".equals(r.getKind()) && operatorResourcesName.equals(r.getMetadata().getName())).findFirst().orElseThrow(() -> new RuntimeException("Unable to find deployment config in operator resources"));
        dc.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv().addAll(envVarsToAdd);
    } else {
        Deployment deployment = (Deployment) resourceList.stream().filter(r -> "Deployment".equals(r.getKind()) && operatorResourcesName.equals(r.getMetadata().getName())).findFirst().orElseThrow(() -> new RuntimeException("Unable to find deployment in operator resources"));
        deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv().addAll(envVarsToAdd);
    }
    OpenShiftUtils.asRegularUser(() -> OpenShiftUtils.getInstance().resourceList(resourceList).createOrReplace());
    log.info("Waiting for syndesis-operator to be ready");
    try {
        OpenShiftUtils.getInstance().waiters().areExactlyNPodsReady(1, "syndesis.io/component", operatorResourcesName).interval(TimeUnit.SECONDS, 20).timeout(TimeUnit.MINUTES, 10).waitFor();
    } catch (WaiterException e) {
        InfraFail.fail("Unable to find operator pod in 10 minutes");
    }
}
Also used : URL(java.net.URL) TodoUtils(io.syndesis.qe.utils.TodoUtils) TimeoutException(java.util.concurrent.TimeoutException) RawCustomResourceOperationsImpl(io.fabric8.kubernetes.client.dsl.internal.RawCustomResourceOperationsImpl) StringUtils(org.apache.commons.lang3.StringUtils) JSONException(org.json.JSONException) CustomResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext) JSONObject(org.json.JSONObject) Map(java.util.Map) Addon(io.syndesis.qe.addon.Addon) Bundle(io.syndesis.qe.marketplace.manifests.Bundle) WaiterException(cz.xtf.core.waiting.WaiterException) EnumSet(java.util.EnumSet) QuayUser(io.syndesis.qe.marketplace.quay.QuayUser) TestConfiguration(io.syndesis.qe.TestConfiguration) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) InfraFail(io.syndesis.qe.test.InfraFail) Opm(io.syndesis.qe.marketplace.manifests.Opm) Set(java.util.Set) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) CommonSteps(io.syndesis.qe.common.CommonSteps) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Assertions.fail(org.assertj.core.api.Assertions.fail) Index(io.syndesis.qe.marketplace.manifests.Index) ResourceFactory(io.syndesis.qe.resource.ResourceFactory) Optional(java.util.Optional) Component(io.syndesis.qe.component.Component) SYNDESIS_DOCKER_REGISTRY(io.syndesis.qe.TestConfiguration.SYNDESIS_DOCKER_REGISTRY) OpenShiftWaitUtils(io.syndesis.qe.wait.OpenShiftWaitUtils) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Setter(lombok.Setter) Getter(lombok.Getter) OpenShiftService(io.syndesis.qe.marketplace.openshift.OpenShiftService) ComponentUtils(io.syndesis.qe.component.ComponentUtils) ArrayUtils(org.apache.commons.lang3.ArrayUtils) HashMap(java.util.HashMap) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) Yaml(org.yaml.snakeyaml.Yaml) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PortForwardUtils(io.syndesis.qe.utils.PortForwardUtils) Image(io.syndesis.qe.image.Image) CustomResourceDefinitionVersion(io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionVersion) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException) OpenShiftUtils(io.syndesis.qe.utils.OpenShiftUtils) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Resource(io.syndesis.qe.resource.Resource) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition) TestUtils(io.syndesis.qe.utils.TestUtils) ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) JSONArray(org.json.JSONArray) InputStream(java.io.InputStream) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) WaiterException(cz.xtf.core.waiting.WaiterException) Image(io.syndesis.qe.image.Image) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig)

Example 75 with Deployment

use of io.fabric8.kubernetes.api.model.extensions.Deployment in project syndesis-qe by syndesisio.

the class OpenshiftValidationSteps method setResourceValues.

@When("set resources for deployment config {string}")
public void setResourceValues(String dcName, DataTable dataTable) {
    DeploymentConfig dc = OpenShiftUtils.getInstance().getDeploymentConfig(dcName);
    Map<String, Quantity> currentLimits = dc.getSpec().getTemplate().getSpec().getContainers().get(0).getResources().getLimits();
    Map<String, Quantity> currentRequests = dc.getSpec().getTemplate().getSpec().getContainers().get(0).getResources().getRequests();
    Map<String, Quantity> limits = currentLimits == null ? new HashMap<>() : new HashMap<>(currentLimits);
    Map<String, Quantity> requests = currentRequests == null ? new HashMap<>() : new HashMap<>(currentRequests);
    for (List<String> l : dataTable.asLists()) {
        if ("limits".equals(l.get(0))) {
            limits.put(l.get(1), new Quantity(l.get(2)));
        } else {
            requests.put(l.get(1), new Quantity(l.get(2)));
        }
    }
    // @formatter:off
    OpenShiftUtils.getInstance().deploymentConfigs().withName(dcName).edit().editSpec().editTemplate().editSpec().editFirstContainer().editResources().withLimits(limits).withRequests(requests).endResources().endContainer().endSpec().endTemplate().endSpec().done();
// @formatter:on
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) When(io.cucumber.java.en.When)

Aggregations

Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)52 Test (org.junit.Test)28 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)27 InputStream (java.io.InputStream)26 Service (io.fabric8.kubernetes.api.model.Service)24 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)22 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)21 Asset (org.jboss.shrinkwrap.api.asset.Asset)21 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)21 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 CommandSupport (io.fabric8.itests.support.CommandSupport)18 Logger (org.slf4j.Logger)18 Pod (io.fabric8.kubernetes.api.model.Pod)17 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)17 IOException (java.io.IOException)17 FabricService (io.fabric8.api.FabricService)16 ServiceLocator (io.fabric8.api.gravia.ServiceLocator)16 ArrayList (java.util.ArrayList)16 StartLevelAware (org.jboss.arquillian.osgi.StartLevelAware)16