/** * Returns name of the resource from it's Metadata * * @param entity MetaData of kubernetes resource * @return */ public static String getName(ObjectMeta entity) { if (entity != null) { return Utils.coalesce(entity.getName(), getAdditionalPropertyText(entity.getAdditionalProperties(), "id"), entity.getUid()); } else { return null; } }
private static String getPodUid(Pod resource) { if (resource == null || resource.getMetadata() == null) { return NO_UID; } return resource.getMetadata().getUid(); } }
@DELETE @Produces({MediaType.APPLICATION_JSON}) @Path("{addressSpace}") public Response deleteAddressSpace(@Context SecurityContext securityContext, @PathParam("namespace") String namespace, @PathParam("addressSpace") String addressSpaceName) throws Exception { return doRequest("Error deleting address space " + addressSpaceName, () -> { verifyAuthorized(securityContext, namespace, ResourceVerb.delete); AddressSpace addressSpace = addressSpaceApi.getAddressSpaceWithName(namespace, addressSpaceName).orElse(null); if (addressSpace == null) { return Response.status(404).entity(Status.notFound("AddressSpace", addressSpaceName)).build(); } addressSpaceApi.deleteAddressSpace(addressSpace); return Response.ok(Status.successStatus(200, "AddressSpace", addressSpaceName, addressSpace.getMetadata().getUid())).build(); }); }
public void scanNamespace(Namespace ns) { ObjectNode n = mapper.createObjectNode(); ObjectMeta md = ns.getMetadata(); n.put("uid", ns.getMetadata().getUid()); n.put("name", ns.getMetadata().getName()); n.put("selfLink", md.getSelfLink()); n.put("clusterId", getClusterId()); getNeoRxClient().execCypher("merge (a:KubeNamespace {uid:{uid}}) set a+={props}, a.updateTs=timestamp()", "uid", md.getUid(), "props", n); }
private void logEvent(Watcher.Action action, Pod pod, String resourceVersion, boolean polled) { final String podName = pod.getMetadata().getName(); final String workflowInstance = Optional.ofNullable(pod.getMetadata().getAnnotations()) .map(annotations -> annotations.get(STYX_WORKFLOW_INSTANCE_ANNOTATION)) .orElse("N/A"); final String status = readStatus(pod); LOG.info("{}Pod event for {} ({}) at resource version {}, action: {}, workflow instance: {}, status: {}", polled ? "Polled: " : "", podName, pod.getMetadata().getUid(), resourceVersion, action, workflowInstance, status); }
Response internalDeleteAddress(SecurityContext securityContext, String namespace, String addressSpace, String addressName) throws Exception { return doRequest("Error deleting address", () -> { verifyAuthorized(securityContext, namespace, ResourceVerb.delete); Address address = apiHelper.deleteAddress(namespace, addressSpace, addressName); if (address == null) { return Response.status(404).entity(Status.notFound("Address", addressName)).build(); } return Response.ok(Status.successStatus(200, "Address", addressName, address.getMetadata().getUid())).build(); }); }
public static String getName(ObjectMeta entity) { if (entity != null) { for (String name : new String[]{ entity.getName(), getAdditionalPropertyText(entity.getAdditionalProperties(), "id"), entity.getUid() }) { if (StringUtils.isNotBlank(name)) { return name; } } } return null; }
/** * Set fields needed to generate the OwnerReference object * * @param parent The resource which should be used as parent. It will be used to gather the date needed for generating OwnerReferences. */ protected void setOwnerReference(HasMetadata parent) { this.ownerApiVersion = parent.getApiVersion(); this.ownerKind = parent.getKind(); this.ownerUid = parent.getMetadata().getUid(); }
public BuildConfig getBuildConfig() { BuildConfig bc = getOpenShiftClient().buildConfigs().inNamespace(namespace).withName(name).get(); if (bc != null && bc.getMetadata().getUid().equals(uid)) { return bc; } return null; }
private void setOwnership(HasMetadata owned, HasMetadata ...owners) { ArrayList<OwnerReference> ownerReferences = new ArrayList<>(owners.length); for (HasMetadata owner: owners) { ownerReferences.add(new OwnerReferenceBuilder() .withApiVersion(owner.getApiVersion()) .withKind(owner.getKind()) .withBlockOwnerDeletion(false) .withName(owner.getMetadata().getName()) .withUid(owner.getMetadata().getUid()) .build()); } owned.getMetadata().setOwnerReferences(ownerReferences); }
public static Job getJobFromBuild(Build build) { String buildConfigName = build.getStatus().getConfig().getName(); if (StringUtils.isEmpty(buildConfigName)) { return null; } BuildConfig buildConfig = getOpenShiftClient().buildConfigs().inNamespace(build.getMetadata().getNamespace()).withName(buildConfigName).get(); if (buildConfig == null) { return null; } return BuildTrigger.DESCRIPTOR.getJobFromBuildConfigUid(buildConfig.getMetadata().getUid()); } }
public BuildConfigProjectProperty(BuildConfig bc) { this( bc.getMetadata().getNamespace(), bc.getMetadata().getName(), bc.getMetadata().getUid(), bc.getMetadata().getResourceVersion(), bc.getSpec().getSource().getContextDir() ); }
protected void replicationControllerChanged(ReplicationController entity, boolean remove) { if (remove) { String id = getName(entity); if (Strings.isNotBlank(id)) { memoryModel.deleteReplicationController(id, KubernetesHelper.getNamespace(entity)); replicationControllerListeners.entityDeleted(id, entity); } } else { String id = memoryModel.getOrCreateId(getName(entity), NodeHelper.KIND_REPLICATION_CONTROLLER); if (entity.getMetadata().getUid() == null) { entity.getMetadata().setUid(getNamespace() + '/' + id); } memoryModel.updateReplicationController(id, entity); replicationControllerListeners.entityChanged(id, entity); } }
public ObjectMetaBuilder( ObjectMetaFluent<?> fluent , ObjectMeta instance ){ this.fluent = fluent; fluent.withAnnotations(instance.getAnnotations()); fluent.withCreationTimestamp(instance.getCreationTimestamp()); fluent.withDeletionTimestamp(instance.getDeletionTimestamp()); fluent.withGenerateName(instance.getGenerateName()); fluent.withLabels(instance.getLabels()); fluent.withName(instance.getName()); fluent.withNamespace(instance.getNamespace()); fluent.withResourceVersion(instance.getResourceVersion()); fluent.withSelfLink(instance.getSelfLink()); fluent.withUid(instance.getUid()); } public ObjectMetaBuilder( ObjectMeta instance ){
public ObjectMetaBuilder( ObjectMetaFluent<?> fluent , ObjectMeta instance ){ this.fluent = fluent; fluent.withAnnotations(instance.getAnnotations()); fluent.withCreationTimestamp(instance.getCreationTimestamp()); fluent.withDeletionTimestamp(instance.getDeletionTimestamp()); fluent.withGenerateName(instance.getGenerateName()); fluent.withLabels(instance.getLabels()); fluent.withName(instance.getName()); fluent.withNamespace(instance.getNamespace()); fluent.withResourceVersion(instance.getResourceVersion()); fluent.withSelfLink(instance.getSelfLink()); fluent.withUid(instance.getUid()); } public ObjectMetaBuilder( ObjectMeta instance ){
public ObjectMetaBuilder( ObjectMeta instance ){ this.fluent = this; this.withAnnotations(instance.getAnnotations()); this.withCreationTimestamp(instance.getCreationTimestamp()); this.withDeletionTimestamp(instance.getDeletionTimestamp()); this.withGenerateName(instance.getGenerateName()); this.withLabels(instance.getLabels()); this.withName(instance.getName()); this.withNamespace(instance.getNamespace()); this.withResourceVersion(instance.getResourceVersion()); this.withSelfLink(instance.getSelfLink()); this.withUid(instance.getUid()); }
public ObjectMetaBuilder( ObjectMeta instance ){ this.fluent = this; this.withAnnotations(instance.getAnnotations()); this.withCreationTimestamp(instance.getCreationTimestamp()); this.withDeletionTimestamp(instance.getDeletionTimestamp()); this.withGenerateName(instance.getGenerateName()); this.withLabels(instance.getLabels()); this.withName(instance.getName()); this.withNamespace(instance.getNamespace()); this.withResourceVersion(instance.getResourceVersion()); this.withSelfLink(instance.getSelfLink()); this.withUid(instance.getUid()); }
Future<ReconciliationState> clusterOperatorSecret() { Labels labels = Labels.userLabels(kafkaAssembly.getMetadata().getLabels()).withKind(reconciliation.type().toString()).withCluster(reconciliation.name()); OwnerReference ownerRef = new OwnerReferenceBuilder() .withApiVersion(kafkaAssembly.getApiVersion()) .withKind(kafkaAssembly.getKind()) .withName(kafkaAssembly.getMetadata().getName()) .withUid(kafkaAssembly.getMetadata().getUid()) .withBlockOwnerDeletion(false) .withController(false) .build(); Secret secret = ModelUtils.buildSecret(clusterCa, clusterCa.clusterOperatorSecret(), namespace, ClusterOperator.secretName(name), "cluster-operator", "cluster-operator", labels, ownerRef); return withVoid(secretOperations.reconcile(namespace, ClusterOperator.secretName(name), secret)); }
public ObjectMetaFluentImpl(ObjectMeta instance){ this.withAnnotations(instance.getAnnotations()); this.withCreationTimestamp(instance.getCreationTimestamp()); this.withDeletionGracePeriodSeconds(instance.getDeletionGracePeriodSeconds()); this.withDeletionTimestamp(instance.getDeletionTimestamp()); this.withFinalizers(instance.getFinalizers()); this.withGenerateName(instance.getGenerateName()); this.withGeneration(instance.getGeneration()); this.withLabels(instance.getLabels()); this.withName(instance.getName()); this.withNamespace(instance.getNamespace()); this.withOwnerReferences(instance.getOwnerReferences()); this.withResourceVersion(instance.getResourceVersion()); this.withSelfLink(instance.getSelfLink()); this.withUid(instance.getUid()); }
public ObjectMetaBuilder(ObjectMetaFluent<?> fluent,ObjectMeta instance,Boolean validationEnabled){ this.fluent = fluent; fluent.withAnnotations(instance.getAnnotations()); fluent.withCreationTimestamp(instance.getCreationTimestamp()); fluent.withDeletionGracePeriodSeconds(instance.getDeletionGracePeriodSeconds()); fluent.withDeletionTimestamp(instance.getDeletionTimestamp()); fluent.withFinalizers(instance.getFinalizers()); fluent.withGenerateName(instance.getGenerateName()); fluent.withGeneration(instance.getGeneration()); fluent.withLabels(instance.getLabels()); fluent.withName(instance.getName()); fluent.withNamespace(instance.getNamespace()); fluent.withOwnerReferences(instance.getOwnerReferences()); fluent.withResourceVersion(instance.getResourceVersion()); fluent.withSelfLink(instance.getSelfLink()); fluent.withUid(instance.getUid()); this.validationEnabled = validationEnabled; } public ObjectMetaBuilder(ObjectMeta instance){