io.fabric8.kubernetes.api.model.KubernetesResourceList Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.KubernetesResourceList.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HistoryServerOperator.java From spark-operator with Apache License 2.0 | 6 votes |
@Override protected void onAdd(SparkHistoryServer hs) { log.info("Spark history server added"); KubernetesResourceList list = deployer.getResourceList(hs, namespace, isOpenshift); if (isOpenshift && hs.getExpose() && !osClient) { // we will create openshift specific resource (Route) this.client = new DefaultOpenShiftClient(); osClient = true; } client.resourceList(list).inNamespace(namespace).createOrReplace(); cache.put(hs.getName(), list); updateStatus(hs, "ready"); put(hs); }
Example #2
Source File: KubernetesTaskLauncher.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 6 votes |
private KubernetesResourceList<?> getTaskResources(Optional<String> taskName, boolean isCreateJob) { KubernetesResourceList<?> resourceList; if (taskName.isPresent()) { if (isCreateJob) { resourceList = client.batch().jobs().withLabel("task-name", taskName.get()).list(); } else { resourceList = client.pods().withLabel("task-name", taskName.get()).list(); } } else { if (isCreateJob) { resourceList = client.batch().jobs().withLabel("task-name").list(); } else { resourceList = client.pods().withLabel("task-name").list(); } } return resourceList; }
Example #3
Source File: BaseOperation.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Override public T get() { try { T answer = getMandatory(); if (answer instanceof HasMetadata) { HasMetadata hasMetadata = (HasMetadata) answer; updateApiVersion(hasMetadata); } else if (answer instanceof KubernetesResourceList) { KubernetesResourceList list = (KubernetesResourceList) answer; updateApiVersion(list); } return answer; } catch (KubernetesClientException e) { if (e.getCode() != HttpURLConnection.HTTP_NOT_FOUND) { throw e; } return null; } }
Example #4
Source File: BaseOperation.java From kubernetes-client with Apache License 2.0 | 6 votes |
@Override public T require() throws ResourceNotFoundException { try { T answer = getMandatory(); if (answer == null) { throw new ResourceNotFoundException("The resource you request doesn't exist or couldn't be fetched."); } if (answer instanceof HasMetadata) { HasMetadata hasMetadata = (HasMetadata) answer; updateApiVersion(hasMetadata); } else if (answer instanceof KubernetesResourceList) { KubernetesResourceList list = (KubernetesResourceList) answer; updateApiVersion(list); } return answer; } catch (KubernetesClientException e) { if (e.getCode() != HttpURLConnection.HTTP_NOT_FOUND) { throw e; } throw new ResourceNotFoundException("Resource not found : " + e.getMessage()); } }
Example #5
Source File: DefaultKubernetesClient.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Override public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinitionContext crdContext, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) { return new CustomResourceOperationsImpl<>(new CustomResourceOperationContext().withOkhttpClient(httpClient).withConfig(getConfiguration()) .withCrdContext(crdContext) .withType(resourceType) .withListType(listClass) .withPropagationPolicy(DEFAULT_PROPAGATION_POLICY) .withDoneableType(doneClass)); }
Example #6
Source File: MockKube.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
public <T extends CustomResource, L extends KubernetesResourceList<T>, D extends Doneable<T>, S> MockedCrd<T, L, D, S> withCustomResourceDefinition(CustomResourceDefinition crd, Class<T> instanceClass, Class<L> instanceListClass, Class<D> doneableInstanceClass, Function<T, S> getStatus, BiConsumer<T, S> setStatus) { MockedCrd<T, L, D, S> mockedCrd = new MockedCrd<>(crd, instanceClass, instanceListClass, doneableInstanceClass, getStatus, setStatus); this.mockedCrds.add(mockedCrd); return mockedCrd; }
Example #7
Source File: MockBuilder.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private KubernetesResourceList<T> mockList(Predicate<? super T> predicate) { KubernetesResourceList<T> l = mock(listClass); Collection<T> values; synchronized (db) { values = db.values().stream().filter(predicate).map(resource -> copyResource(resource)).collect(Collectors.toList()); } when(l.getItems()).thenAnswer(i3 -> { LOGGER.debug("{} list -> {}", resourceTypeClass.getSimpleName(), values); return values; }); return l; }
Example #8
Source File: KubernetesTaskLauncher.java From spring-cloud-deployer-kubernetes with Apache License 2.0 | 5 votes |
private List<String> getIdsForTasks(Optional<String> taskName, boolean isCreateJob) { List<String> ids = new ArrayList<>(); try { KubernetesResourceList<?> resourceList = getTaskResources(taskName, isCreateJob); for (HasMetadata hasMetadata : resourceList.getItems()) { ids.add(hasMetadata.getMetadata().getName()); } } catch (KubernetesClientException kce) { logger.warn(String.format("Failed to retrieve pods for task: %s", taskName), kce); } return ids; }
Example #9
Source File: BaseOperation.java From kubernetes-client with Apache License 2.0 | 5 votes |
/** * Updates the list or single item if it has a missing or incorrect apiGroupVersion * * @param resource resource object */ protected void updateApiVersionResource(Object resource) { if (resource instanceof HasMetadata) { HasMetadata hasMetadata = (HasMetadata) resource; updateApiVersion(hasMetadata); } else if (resource instanceof KubernetesResourceList) { KubernetesResourceList list = (KubernetesResourceList) resource; updateApiVersion(list); } }
Example #10
Source File: BaseOperation.java From kubernetes-client with Apache License 2.0 | 5 votes |
/** * Updates the list items if they have missing or default apiGroupVersion values and the resource is currently * using API Groups with custom version strings * * @param list Kubernetes resource list */ protected void updateApiVersion(KubernetesResourceList list) { String version = getApiVersion(); if (list != null && version != null && version.length() > 0) { List items = list.getItems(); if (items != null) { for (Object item : items) { if (item instanceof HasMetadata) { updateApiVersion((HasMetadata) item); } } } } }
Example #11
Source File: NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java From kubernetes-client with Apache License 2.0 | 5 votes |
private static <T> List<HasMetadata> asHasMetadata(T item, Boolean enableProccessing) { List<HasMetadata> result = new ArrayList<>(); if (item instanceof KubernetesList) { result.addAll(((KubernetesList) item).getItems()); } else if (item instanceof Template) { if (!enableProccessing) { result.addAll(((Template) item).getObjects()); } else { result.addAll(processTemplate((Template)item, false)); } } else if (item instanceof KubernetesResourceList) { result.addAll(((KubernetesResourceList) item).getItems()); } else if (item instanceof HasMetadata) { result.add((HasMetadata) item); } else if (item instanceof String) { try (InputStream is = new ByteArrayInputStream(((String)item).getBytes(StandardCharsets.UTF_8))) { return asHasMetadata(unmarshal(is), enableProccessing); } catch (IOException e) { throw KubernetesClientException.launderThrowable(e); } } else if (item instanceof Collection) { for (Object o : (Collection)item) { if (o instanceof HasMetadata) { result.add((HasMetadata) o); } } } return result; }
Example #12
Source File: BindingOperationsImpl.java From kubernetes-client with Apache License 2.0 | 5 votes |
public BindingOperationsImpl(OperationContext context) { super(context .withApiGroupVersion("v1") .withPlural("bindings")); this.type = Binding.class; this.listType = (Class<KubernetesResourceList<Binding>>)new TypeReference<KubernetesResourceList<Binding>>(){}.getType(); this.doneableType = DoneableBinding.class; }
Example #13
Source File: DefaultKubernetesClient.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Override public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) { return new CustomResourceOperationsImpl<>(new CustomResourceOperationContext().withOkhttpClient(httpClient).withConfig(getConfiguration()) .withCrd(crd) .withType(resourceType) .withListType(listClass) .withPropagationPolicy(DEFAULT_PROPAGATION_POLICY) .withDoneableType(doneClass)); }
Example #14
Source File: OpenShiftServiceImpl.java From syndesis with Apache License 2.0 | 5 votes |
@Override public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> Watch watchCR(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType, BiConsumer<Watcher.Action,T> watcher){ return getCRDClient(crd, resourceType, resourceListType, doneableResourceType).inNamespace(config.getNamespace()).watch(new Watcher<T>() { @Override public void eventReceived(Action action, T t) { watcher.accept(action, t); } @Override public void onClose(KubernetesClientException e) { LOGGER.info("Closing watcher "+this+" on crd "+crd.getMetadata().getName(), e); } }); }
Example #15
Source File: HistoryServerOperator.java From spark-operator with Apache License 2.0 | 5 votes |
@Override protected void onDelete(SparkHistoryServer hs) { log.info("Spark history server removed"); String name = hs.getName(); updateStatus(hs, "deleted"); delete(name); KubernetesResourceList list = Optional.ofNullable(cache.get(name)).orElse(deployer.getResourceList(hs, namespace, isOpenshift)); client.resourceList(list).inNamespace(namespace).delete(); cache.remove(name); }
Example #16
Source File: AppOperator.java From spark-operator with Apache License 2.0 | 5 votes |
@Override protected void onAdd(SparkApplication app) { KubernetesResourceList list = deployer.getResourceList(app, namespace); client.resourceList(list).inNamespace(namespace).createOrReplace(); updateStatus(app, "ready" ); put(app); }
Example #17
Source File: SparkClusterOperator.java From spark-operator with Apache License 2.0 | 5 votes |
@Override protected void onAdd(SparkCluster cluster) { KubernetesResourceList list = getDeployer().getResourceList(cluster); client.resourceList(list).inNamespace(namespace).createOrReplace(); getClusters().put(cluster); updateStatus(cluster, "ready"); }
Example #18
Source File: OpenShiftServiceImpl.java From syndesis with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings({"unchecked"}) public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> boolean deleteCR(CustomResourceDefinition crd, Class<T> resourceType, Class<L> resourceListType, Class<D> doneableResourceType, String customResourceName, boolean cascading){ return getCRDClient(crd, resourceType, resourceListType, doneableResourceType).inNamespace(config.getNamespace()).withName(customResourceName) .cascading(cascading) .delete(); }
Example #19
Source File: ReflectUtils.java From kubernetes-client with Apache License 2.0 | 5 votes |
public static <ApiType> List<ApiType> getItems(Object listObj) throws ReflectiveOperationException { if (listObj instanceof KubernetesResourceList) { return ((KubernetesResourceList) listObj).getItems(); } try { Method getItemsMethod = listObj.getClass().getMethod("getItems"); return (List<ApiType>) getItemsMethod.invoke(listObj); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new ReflectiveOperationException(e); } }
Example #20
Source File: ReflectUtils.java From kubernetes-client with Apache License 2.0 | 5 votes |
public static ListMeta listMetadata(Object listObj) throws ReflectiveOperationException { if (listObj instanceof KubernetesResourceList) { return ((KubernetesResourceList<?>) listObj).getMetadata(); } try { Method mdField = listObj.getClass().getMethod("getMetadata"); return (ListMeta) mdField.invoke(listObj); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new ReflectiveOperationException(e); } }
Example #21
Source File: AutoAdaptableKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public NamespaceListVisitFromServerGetDeleteRecreateWaitApplicable<HasMetadata, Boolean> resourceList(KubernetesResourceList is) { return delegate.resourceList(is); }
Example #22
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public NamespaceListVisitFromServerGetDeleteRecreateWaitApplicable<HasMetadata, Boolean> resourceList(KubernetesResourceList is) { return delegate.resourceList(is); }
Example #23
Source File: DefaultKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public NamespaceListVisitFromServerGetDeleteRecreateWaitApplicable<HasMetadata, Boolean> resourceList(KubernetesResourceList item) { return new NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl(httpClient, getConfiguration(), getNamespace(), null, false, false, new ArrayList<>(), item, null, DeletionPropagation.BACKGROUND, true) { }; }
Example #24
Source File: DefaultKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResource(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) { return customResources(crd, resourceType, listClass, doneClass); }
Example #25
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
public MixedOperation<Binding, KubernetesResourceList<Binding>, DoneableBinding, Resource<Binding, DoneableBinding>> bindings() { return delegate.bindings(); }
Example #26
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinitionContext crdContext, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) { return delegate.customResources(crdContext, resourceType, listClass, doneClass); }
Example #27
Source File: KubeClient.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
public <T extends HasMetadata, L extends KubernetesResourceList, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) { return client.customResources(crd, resourceType, listClass, doneClass); //TODO namespace here }
Example #28
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResources(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) { return delegate.customResources(crd, resourceType, listClass, doneClass); }
Example #29
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public <T extends HasMetadata, L extends KubernetesResourceList<T>, D extends Doneable<T>> MixedOperation<T, L, D, Resource<T, D>> customResource(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass, Class<D> doneClass) { return customResources(crd, resourceType, listClass, doneClass); }
Example #30
Source File: DefaultKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<Binding, KubernetesResourceList<Binding>, DoneableBinding, Resource<Binding, DoneableBinding>> bindings() { return new BindingOperationsImpl(httpClient, getConfiguration()); }