Java Code Examples for io.fabric8.kubernetes.client.dsl.Resource#get()
The following examples show how to use
io.fabric8.kubernetes.client.dsl.Resource#get() .
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: ApplyService.java From jkube with Eclipse Public License 2.0 | 6 votes |
public void applyImageStream(ImageStream entity, String sourceName) { OpenShiftClient openShiftClient = getOpenShiftClient(); if (openShiftClient != null) { String kind = getKind(entity); String name = getName(entity); String namespace = getNamespace(); try { Resource<ImageStream, DoneableImageStream> resource = openShiftClient.imageStreams().inNamespace(namespace).withName(name); ImageStream old = resource.get(); if (old == null) { log.info("Creating " + kind + " " + name + " from " + sourceName); resource.create(entity); } else { log.info("Updating " + kind + " " + name + " from " + sourceName); copyAllImageStreamTags(entity, old); entity = patchService.compareAndPatchEntity(namespace, entity, old); openShiftClient.resource(entity).inNamespace(namespace).createOrReplace(); } } catch (Exception e) { onApplyError("Failed to create " + kind + " from " + sourceName + ". " + e, e); } } }
Example 2
Source File: KubernetesConnection.java From vault-crd with Apache License 2.0 | 6 votes |
@Bean public MixedOperation<Vault, VaultList, DoneableVault, Resource<Vault, DoneableVault>> customResource( KubernetesClient client, @Value("${kubernetes.crd.name}") String crdName) { Resource<CustomResourceDefinition, DoneableCustomResourceDefinition> crdResource = client.customResourceDefinitions().withName(crdName); // Hack for bug in Kubernetes-Client for CRDs https://github.com/fabric8io/kubernetes-client/issues/1099 String kind = StringUtils.substringAfter(crdName, ".") + "/v1#Vault"; KubernetesDeserializer.registerCustomKind(kind, Vault.class); CustomResourceDefinition customResourceDefinition = crdResource.get(); if (customResourceDefinition == null) { log.error("Please first apply custom resource definition and then restart vault-crd"); System.exit(1); } return client.customResources(customResourceDefinition, Vault.class, VaultList.class, DoneableVault.class); }
Example 3
Source File: KubernetesService.java From vault-crd with Apache License 2.0 | 6 votes |
void modifySecret(Vault resource, VaultSecret vaultSecret) { Resource<Secret, DoneableSecret> secretDoneableSecretResource = client.secrets().inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()); Secret secret; if (secretDoneableSecretResource.get() != null) { secret = secretDoneableSecretResource.get(); } else { secret = newSecretInstance(resource, vaultSecret); } secret.setType(vaultSecret.getType()); updateAnnotations(secret, vaultSecret.getCompare()); secret.setData(vaultSecret.getData()); secretDoneableSecretResource.createOrReplace(secret); log.info("Modified secret {} in namespace {}", resource.getMetadata().getName(), resource.getMetadata().getNamespace()); }
Example 4
Source File: ConfigMapSupplier.java From data-highway with Apache License 2.0 | 5 votes |
@Autowired public ConfigMapSupplier(KubernetesClient client, @Value(TruckParkConstants.TRUCK_PARK) String name) { this.name = name; Resource<ConfigMap, DoneableConfigMap> resource = client.configMaps().withName(name); configMap = resource.get(); if (configMap == null) { throw new RuntimeException(String.format("ConfigMap %s does not exist.", name)); } watch = resource.watch(this); }
Example 5
Source File: SpringBootWatcher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private String getServiceExposeUrl(KubernetesClient kubernetes, Set<HasMetadata> resources) throws InterruptedException { long serviceUrlWaitTimeSeconds = Configs.asInt(getConfig(Config.serviceUrlWaitTimeSeconds)); for (HasMetadata entity : resources) { if (entity instanceof Service) { Service service = (Service) entity; String name = KubernetesHelper.getName(service); Resource<Service, DoneableService> serviceResource = kubernetes.services() .inNamespace(getContext().getJKubeServiceHub().getClusterAccess().getNamespace()) .withName(name); String url = null; // lets wait a little while until there is a service URL in case the exposecontroller is running slow for (int i = 0; i < serviceUrlWaitTimeSeconds; i++) { if (i > 0) { Thread.sleep(1000); } Service s = serviceResource.get(); if (s != null) { url = KubernetesHelper.getOrCreateAnnotations(s).get(JKubeAnnotations.SERVICE_EXPOSE_URL.value()); if (StringUtils.isNotBlank(url)) { break; } } if (!isExposeService(service)) { break; } } // lets not wait for other services serviceUrlWaitTimeSeconds = 1; if (StringUtils.isNotBlank(url) && url.startsWith("http")) { return url; } } } log.info("No exposed service found for connecting the dev tools"); return null; }
Example 6
Source File: WebServerController.java From java-operator-sdk with Apache License 2.0 | 5 votes |
@Override public boolean deleteResource(WebServer nginx) { log.info("Execution deleteResource for: {}", nginx.getMetadata().getName()); log.info("Deleting ConfigMap {}", configMapName(nginx)); Resource<ConfigMap, DoneableConfigMap> configMap = kubernetesClient.configMaps() .inNamespace(nginx.getMetadata().getNamespace()) .withName(configMapName(nginx)); if (configMap.get() != null) { configMap.delete(); } log.info("Deleting Deployment {}", deploymentName(nginx)); RollableScalableResource<Deployment, DoneableDeployment> deployment = kubernetesClient.apps().deployments() .inNamespace(nginx.getMetadata().getNamespace()) .withName(deploymentName(nginx)); if (deployment.get() != null) { deployment.cascading(true).delete(); } log.info("Deleting Service {}", serviceName(nginx)); ServiceResource<Service, DoneableService> service = kubernetesClient.services() .inNamespace(nginx.getMetadata().getNamespace()) .withName(serviceName(nginx)); if (service.get() != null) { service.delete(); } return true; }
Example 7
Source File: RouteOperator.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
/** * Checks if the Route already has an assigned address. * * @param namespace The namespace. * @param name The route name. * @return Whether the address is ready. */ public boolean isAddressReady(String namespace, String name) { Resource<Route, DoneableRoute> resourceOp = operation().inNamespace(namespace).withName(name); Route resource = resourceOp.get(); if (resource != null && resource.getStatus() != null && resource.getStatus().getIngress() != null && resource.getStatus().getIngress().size() > 0) { if (resource.getStatus().getIngress().get(0).getHost() != null) { return true; } } return false; }
Example 8
Source File: KubernetesService.java From vault-crd with Apache License 2.0 | 4 votes |
public Secret getSecretByVault(Vault resource) { Resource<Secret, DoneableSecret> secretDoneableSecretResource = client.secrets().inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()); return secretDoneableSecretResource.get(); }
Example 9
Source File: ResourceManager.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
public static <T extends CustomResource, L extends CustomResourceList<T>, D extends Doneable<T>> void replaceCrdResource(Class<T> crdClass, Class<L> listClass, Class<D> doneableClass, String resourceName, Consumer<T> editor) { Resource<T, D> namedResource = Crds.operation(kubeClient().getClient(), crdClass, listClass, doneableClass).inNamespace(kubeClient().getNamespace()).withName(resourceName); T resource = namedResource.get(); editor.accept(resource); namedResource.replace(resource); }