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();
}
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);
}
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());
}
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);
}
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
}
Aggregations