Search in sources :

Example 6 with Status

use of io.fabric8.kubernetes.api.model.Status in project spring-cloud-kubernetes by spring-cloud.

the class Fabric8InsideInfoContributorTest method stubPod.

private static Pod stubPod() {
    PodStatus status = new PodStatus();
    status.setPodIP("10.1.1.1");
    status.setHostIP("192.160.10.3");
    PodSpec spec = new PodSpec();
    spec.setServiceAccountName("serviceAccountName");
    spec.setNodeName("nodeName");
    return new PodBuilder().withNewMetadata().withName("pod").withNamespace("namespace").endMetadata().withStatus(status).withSpec(spec).build();
}
Also used : PodStatus(io.fabric8.kubernetes.api.model.PodStatus) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder)

Example 7 with Status

use of io.fabric8.kubernetes.api.model.Status in project spring-cloud-kubernetes by spring-cloud.

the class Fabric8InfoContributor method getDetails.

@Override
public Map<String, Object> getDetails() {
    Pod current = this.utils.currentPod().get();
    if (current != null) {
        Map<String, Object> details = CollectionUtils.newHashMap(7);
        details.put(INSIDE, true);
        ObjectMeta metadata = current.getMetadata();
        details.put(NAMESPACE, metadata.getNamespace());
        details.put(POD_NAME, metadata.getName());
        PodStatus status = current.getStatus();
        details.put(POD_IP, status.getPodIP());
        details.put(HOST_IP, status.getHostIP());
        PodSpec spec = current.getSpec();
        details.put(SERVICE_ACCOUNT, spec.getServiceAccountName());
        details.put(NODE_NAME, spec.getNodeName());
        return details;
    }
    return Collections.singletonMap(INSIDE, false);
}
Also used : PodStatus(io.fabric8.kubernetes.api.model.PodStatus) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Pod(io.fabric8.kubernetes.api.model.Pod) PodSpec(io.fabric8.kubernetes.api.model.PodSpec)

Example 8 with Status

use of io.fabric8.kubernetes.api.model.Status in project quarkus-test-framework by quarkus-qe.

the class OpenShiftClient method installOperator.

public void installOperator(Service service, String name, String channel, String source, String sourceNamespace) {
    if (!ENABLED_EPHEMERAL_NAMESPACES.getAsBoolean()) {
        throw new UnsupportedOperationException("Operators not supported with ephemeral namespaces disabled");
    }
    // Install the operator group
    OperatorGroup groupModel = new OperatorGroup();
    groupModel.setMetadata(new ObjectMeta());
    groupModel.getMetadata().setName(service.getName());
    groupModel.setSpec(new OperatorGroupSpec());
    groupModel.getSpec().setTargetNamespaces(Arrays.asList(currentNamespace));
    client.resource(groupModel).createOrReplace();
    // Install the subscription
    Subscription subscriptionModel = new Subscription();
    subscriptionModel.setMetadata(new ObjectMeta());
    subscriptionModel.getMetadata().setName(name);
    subscriptionModel.getMetadata().setNamespace(currentNamespace);
    subscriptionModel.setSpec(new SubscriptionSpec());
    subscriptionModel.getSpec().setChannel(channel);
    subscriptionModel.getSpec().setName(name);
    subscriptionModel.getSpec().setSource(source);
    subscriptionModel.getSpec().setSourceNamespace(sourceNamespace);
    Log.info("Installing operator... %s", service.getName());
    client.operatorHub().subscriptions().create(subscriptionModel);
    // Wait for the operator to be installed
    untilIsTrue(() -> {
        // Get Cluster Service Version
        Subscription subscription = client.operatorHub().subscriptions().withName(name).get();
        String installedCsv = subscription.getStatus().getInstalledCSV();
        if (StringUtils.isEmpty(installedCsv)) {
            return false;
        }
        // Check Cluster Service Version status
        ClusterServiceVersion operatorService = client.operatorHub().clusterServiceVersions().withName(installedCsv).get();
        return OPERATOR_PHASE_INSTALLED.equals(operatorService.getStatus().getPhase());
    }, AwaitilitySettings.defaults().withService(service).usingTimeout(service.getConfiguration().getAsDuration(OPERATOR_INSTALL_TIMEOUT, TIMEOUT_DEFAULT)));
    Log.info("Operator installed... %s", service.getName());
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) OperatorGroupSpec(io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroupSpec) ClusterServiceVersion(io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion) Subscription(io.fabric8.openshift.api.model.operatorhub.v1alpha1.Subscription) OperatorGroup(io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroup) SubscriptionSpec(io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionSpec)

Example 9 with Status

use of io.fabric8.kubernetes.api.model.Status in project che-server by eclipse-che.

the class OpenShiftProjectTest method testDoNotFailWhenNoPermissionsToUpdateNamespace.

@Test
public void testDoNotFailWhenNoPermissionsToUpdateNamespace() throws InfrastructureException {
    // given
    Map<String, String> labels = Map.of("label.with.this", "yes", "and.this", "of courese");
    prepareProject(PROJECT_NAME);
    prepareNamespaceGet(PROJECT_NAME);
    OpenShiftProject openShiftProject = new OpenShiftProject(clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, executor, PROJECT_NAME, WORKSPACE_ID);
    KubernetesClient cheKubeClient = mock(KubernetesClient.class);
    lenient().doReturn(cheKubeClient).when(cheClientFactory).create();
    NonNamespaceOperation nonNamespaceOperation = mock(NonNamespaceOperation.class);
    lenient().doReturn(nonNamespaceOperation).when(cheKubeClient).namespaces();
    ArgumentCaptor<Namespace> namespaceArgumentCaptor = ArgumentCaptor.forClass(Namespace.class);
    lenient().doThrow(new KubernetesClientException("No permissions.", 403, new Status())).when(nonNamespaceOperation).createOrReplace(namespaceArgumentCaptor.capture());
    // when
    openShiftProject.prepare(true, true, labels, Map.of());
    // then
    Namespace updatedNamespace = namespaceArgumentCaptor.getValue();
    assertTrue(updatedNamespace.getMetadata().getLabels().entrySet().containsAll(labels.entrySet()));
    assertEquals(updatedNamespace.getMetadata().getName(), PROJECT_NAME);
}
Also used : Status(io.fabric8.kubernetes.api.model.Status) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) Namespace(io.fabric8.kubernetes.api.model.Namespace) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) Test(org.testng.annotations.Test)

Example 10 with Status

use of io.fabric8.kubernetes.api.model.Status in project che-server by eclipse-che.

the class OpenShiftProjectFactoryTest method throwAnExceptionWhenErrorListingNamespaces.

@Test(expectedExceptions = InfrastructureException.class)
public void throwAnExceptionWhenErrorListingNamespaces() throws Exception {
    // given
    doThrow(new KubernetesClientException("Not allowed.", 500, new Status())).when(projectList).getItems();
    projectFactory = new OpenShiftProjectFactory("<userid>-che", true, true, true, NAMESPACE_LABELS, NAMESPACE_ANNOTATIONS, true, emptySet(), clientFactory, cheClientFactory, cheServerOpenshiftClientFactory, userManager, preferenceManager, pool, NO_OAUTH_IDENTITY_PROVIDER);
    // when
    projectFactory.list();
// then throw
}
Also used : Status(io.fabric8.kubernetes.api.model.Status) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) Test(org.testng.annotations.Test)

Aggregations

Test (org.junit.jupiter.api.Test)210 Pod (io.fabric8.kubernetes.api.model.Pod)147 Reconciliation (io.strimzi.operator.common.Reconciliation)146 Checkpoint (io.vertx.junit5.Checkpoint)128 List (java.util.List)128 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)126 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)118 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)118 Future (io.vertx.core.Future)111 SecretOperator (io.strimzi.operator.common.operator.resource.SecretOperator)104 Vertx (io.vertx.core.Vertx)102 Optional (java.util.Optional)98 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)97 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)97 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)94 VertxExtension (io.vertx.junit5.VertxExtension)92 VertxTestContext (io.vertx.junit5.VertxTestContext)92 Map (java.util.Map)89 CoreMatchers.is (org.hamcrest.CoreMatchers.is)86 ArrayList (java.util.ArrayList)84