Java Code Examples for io.fabric8.kubernetes.api.model.ObjectMeta#getName()
The following examples show how to use
io.fabric8.kubernetes.api.model.ObjectMeta#getName() .
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: IstioExecutor.java From istio-apim with Apache License 2.0 | 6 votes |
/** * Setting up custom resources */ public void setupCRDs() { CustomResourceDefinitionList crds = client.customResourceDefinitions().list(); List<CustomResourceDefinition> crdsItems = crds.getItems(); for (CustomResourceDefinition crd : crdsItems) { ObjectMeta metadata = crd.getMetadata(); if (metadata != null) { String name = metadata.getName(); if (RULE_CRD_NAME.equals(name)) { ruleCRD = crd; } else if (HTTPAPISpec_CRD_NAME.equals(name)) { httpAPISpecCRD = crd; } else if (HTTPAPISpecBinding_CRD_NAME.equals(name)) { httpAPISpecBindingCRD = crd; } } } }
Example 2
Source File: AddBasicAuthSecretDecorator.java From dekorate with Apache License 2.0 | 6 votes |
@Override public void visit(KubernetesListBuilder list) { ObjectMeta meta = getMandatoryDeploymentMetadata(list); String name = Strings.isNullOrEmpty(this.name) ? meta.getName() : this.name; Map<String, String> data = new HashMap<String, String>() { { put(USERNAME, username); put(PASSWORD, password); } }; list.addToItems(new SecretBuilder() .withNewMetadata() .withName(name) .withAnnotations(annotations) .endMetadata() .withType(KUBERNETES_IO_BASIC_AUTH).addToStringData(data).build()); }
Example 3
Source File: AddRoleBindingResourceDecorator.java From dekorate with Apache License 2.0 | 6 votes |
public void visit(KubernetesListBuilder list) { ObjectMeta meta = getMandatoryDeploymentMetadata(list); String name = Strings.isNotNullOrEmpty(this.name) ? this.name : meta.getName() + ":view"; String serviceAccount = Strings.isNotNullOrEmpty(this.serviceAccount) ? this.serviceAccount : meta.getName(); list.addToItems(new RoleBindingBuilder() .withNewMetadata() .withName(name) .withLabels(meta.getLabels()) .endMetadata() .withNewRoleRef() .withKind(kind.name()) .withName(role) .withApiGroup(DEFAULT_RBAC_API_GROUP) .endRoleRef() .addNewSubject() .withKind("ServiceAccount") .withName(serviceAccount) .endSubject()); }
Example 4
Source File: TeiidOpenShiftClient.java From syndesis with Apache License 2.0 | 6 votes |
private RouteStatus getRoute(String openShiftName, ProtocolType protocolType) { String namespace = ApplicationProperties.getNamespace(); OpenShiftClient client = openshiftClient(); RouteStatus theRoute = null; debug(openShiftName, "Getting route of type " + protocolType.id() + " for Service"); Route route = client.routes().inNamespace(namespace).withName(openShiftName + StringConstants.HYPHEN + protocolType.id()).get(); if (route != null) { ObjectMeta metadata = route.getMetadata(); String name = metadata.getName(); RouteSpec spec = route.getSpec(); String target = spec.getTo().getName(); theRoute = new RouteStatus(name, protocolType); theRoute.setHost(spec.getHost()); theRoute.setPath(spec.getPath()); theRoute.setPort(spec.getPort().getTargetPort().getStrVal()); theRoute.setTarget(target); theRoute.setSecure(spec.getTls() != null); } return theRoute; }
Example 5
Source File: OpenShiftProjectFactory.java From che with Eclipse Public License 2.0 | 6 votes |
private KubernetesNamespaceMeta asNamespaceMeta(io.fabric8.openshift.api.model.Project project) { Map<String, String> attributes = new HashMap<>(4); ObjectMeta metadata = project.getMetadata(); Map<String, String> annotations = metadata.getAnnotations(); String displayName = annotations.get(Constants.PROJECT_DISPLAY_NAME_ANNOTATION); if (displayName != null) { attributes.put(Constants.PROJECT_DISPLAY_NAME_ATTRIBUTE, displayName); } String description = annotations.get(Constants.PROJECT_DESCRIPTION_ANNOTATION); if (description != null) { attributes.put(Constants.PROJECT_DESCRIPTION_ATTRIBUTE, description); } if (project.getStatus() != null && project.getStatus().getPhase() != null) { attributes.put(PHASE_ATTRIBUTE, project.getStatus().getPhase()); } return new KubernetesNamespaceMetaImpl(metadata.getName(), attributes); }
Example 6
Source File: KubernetesEnvironment.java From che with Eclipse Public License 2.0 | 6 votes |
public PodData(Deployment deployment) { PodTemplateSpec podTemplate = deployment.getSpec().getTemplate(); // it is not required for PodTemplate to have name specified // but many of Che Server components rely that PodData has name // so, provision name from deployment if it is missing ObjectMeta podTemplateMeta = podTemplate.getMetadata(); if (podTemplateMeta == null) { podTemplate.setMetadata( new ObjectMetaBuilder().withName(deployment.getMetadata().getName()).build()); } else { if (podTemplateMeta.getName() == null) { podTemplateMeta.setName(deployment.getMetadata().getName()); } } this.podSpec = podTemplate.getSpec(); this.podMeta = podTemplate.getMetadata(); this.role = PodRole.DEPLOYMENT; }
Example 7
Source File: RouteEnricher.java From jkube with Eclipse Public License 2.0 | 5 votes |
private void addRoute(KubernetesListBuilder listBuilder, ServiceBuilder serviceBuilder, List<Route> routes) { ObjectMeta serviceMetadata = serviceBuilder.buildMetadata(); if (serviceMetadata != null && StringUtils.isNotBlank(serviceMetadata.getName()) && hasExactlyOneServicePort(serviceBuilder, serviceMetadata.getName()) && isExposedService(serviceMetadata)) { String name = serviceMetadata.getName(); if (!hasRoute(listBuilder, name)) { if (StringUtils.isNotBlank(routeDomainPostfix)) { routeDomainPostfix = prepareHostForRoute(routeDomainPostfix, name); } else { routeDomainPostfix = ""; } RoutePort routePort = createRoutePort(serviceBuilder); if (routePort != null) { RouteBuilder routeBuilder = new RouteBuilder(). withMetadata(serviceMetadata). withNewSpec(). withPort(routePort). withNewTo().withKind("Service").withName(name).endTo(). withHost(routeDomainPostfix.isEmpty() ? null : routeDomainPostfix). endSpec(); // removing `expose : true` label from metadata. removeLabel(routeBuilder.buildMetadata(), EXPOSE_LABEL, "true"); removeLabel(routeBuilder.buildMetadata(), JKubeAnnotations.SERVICE_EXPOSE_URL.value(), "true"); routeBuilder.withNewMetadataLike(routeBuilder.buildMetadata()); routes.add(routeBuilder.build()); } } } }
Example 8
Source File: KubernetesHelper.java From jkube with Eclipse Public License 2.0 | 5 votes |
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; }
Example 9
Source File: AddServiceAccountResourceDecorator.java From dekorate with Apache License 2.0 | 5 votes |
public void visit(KubernetesListBuilder list) { ObjectMeta meta = getMandatoryDeploymentMetadata(list); String name = Strings.isNotNullOrEmpty(this.name) ? this.name : meta.getName(); list.addNewServiceAccountItem() .withNewMetadata() .withName(name) .withLabels(meta.getLabels()) .endMetadata() .endServiceAccountItem(); }
Example 10
Source File: K8sTopicWatcher.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Override public void eventReceived(Action action, KafkaTopic kafkaTopic) { ObjectMeta metadata = kafkaTopic.getMetadata(); Map<String, String> labels = metadata.getLabels(); if (kafkaTopic.getSpec() != null) { LogContext logContext = LogContext.kubeWatch(action, kafkaTopic).withKubeTopic(kafkaTopic); String name = metadata.getName(); String kind = kafkaTopic.getKind(); if (!initReconcileFuture.isComplete()) { LOGGER.debug("Ignoring initial event for {} {} during initial reconcile", kind, name); return; } LOGGER.info("{}: event {} on resource {} generation={}, labels={}", logContext, action, name, metadata.getGeneration(), labels); Handler<AsyncResult<Void>> resultHandler = ar -> { if (ar.succeeded()) { LOGGER.info("{}: Success processing event {} on resource {} with labels {}", logContext, action, name, labels); } else { String message; if (ar.cause() instanceof InvalidTopicException) { message = kind + " " + name + " has an invalid spec section: " + ar.cause().getMessage(); LOGGER.error("{}", message); } else { message = "Failure processing " + kind + " watch event " + action + " on resource " + name + " with labels " + labels + ": " + ar.cause().getMessage(); LOGGER.error("{}: {}", logContext, message, ar.cause()); } topicOperator.enqueue(topicOperator.new Event(kafkaTopic, message, TopicOperator.EventType.WARNING, errorResult -> { })); } }; if (!action.equals(Action.ERROR)) { topicOperator.onResourceEvent(logContext, kafkaTopic, action).onComplete(resultHandler); } else { LOGGER.error("Watch received action=ERROR for {} {}", kind, name); } } }
Example 11
Source File: ContainerSearch.java From che with Eclipse Public License 2.0 | 5 votes |
private boolean matchesByName(@Nullable ObjectMeta metaData, @Nullable String name) { if (name == null) { return true; } String metaName = metaData == null ? null : metaData.getName(); String metaGenerateName = metaData == null ? null : metaData.getGenerateName(); // do not compare by the generateName if a name exists if (metaName != null) { return name.equals(metaName); } else { return name.equals(metaGenerateName); } }
Example 12
Source File: DynamicPVCWorkspaceVolume.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@Override public PersistentVolumeClaim createVolume(KubernetesClient client, ObjectMeta podMetaData){ String namespace = podMetaData.getNamespace(); String podId = podMetaData.getName(); LOGGER.log(Level.FINE, "Adding workspace volume from pod: {0}/{1}", new Object[] { namespace, podId }); OwnerReference ownerReference = new OwnerReferenceBuilder(). withApiVersion("v1"). withKind("Pod"). withBlockOwnerDeletion(true). withController(true). withName(podMetaData.getName()). withUid(podMetaData.getUid()).build(); PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder() .withNewMetadata() .withName("pvc-" + podMetaData.getName()) .withOwnerReferences(ownerReference) .withLabels(DEFAULT_POD_LABELS) .endMetadata() .withNewSpec() .withAccessModes(getAccessModesOrDefault()) .withNewResources() .withRequests(getResourceMap()) .endResources() .withStorageClassName(getStorageClassNameOrDefault()) .endSpec() .build(); pvc = client.persistentVolumeClaims().inNamespace(podMetaData.getNamespace()).create(pvc); LOGGER.log(INFO, "Created PVC: {0}/{1}", new Object[] { namespace, pvc.getMetadata().getName() }); return pvc; }
Example 13
Source File: ViewCurrentUser.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test void testShowCurrentUser() throws Exception { OpenShiftClient client = new DefaultOpenShiftClient(); User user = client.currentUser(); System.out.println("Current user is: " + user); assertNotNull(user); ObjectMeta metadata = user.getMetadata(); assertNotNull(metadata); String name = metadata.getName(); System.out.println("User name is: " + name); assertNotNull(name); }
Example 14
Source File: IngressEnricher.java From jkube with Eclipse Public License 2.0 | 4 votes |
protected static Ingress addIngress(KubernetesListBuilder listBuilder, ServiceBuilder serviceBuilder, String routeDomainPostfix, KitLogger log) { ObjectMeta serviceMetadata = serviceBuilder.buildMetadata(); if (serviceMetadata == null) { log.info("No Metadata for service! "); } if (isExposedService(serviceMetadata) && shouldCreateExternalURLForService(serviceBuilder, log)) { Objects.requireNonNull(serviceMetadata); String serviceName = serviceMetadata.getName(); if (!hasIngress(listBuilder, serviceName)) { Integer servicePort = getServicePort(serviceBuilder); if (servicePort != null) { IngressBuilder ingressBuilder = new IngressBuilder(). withMetadata(serviceMetadata). withNewSpec(). endSpec(); // removing `expose : true` label from metadata. removeLabel(ingressBuilder.buildMetadata(), EXPOSE_LABEL, "true"); removeLabel(ingressBuilder.buildMetadata(), JKubeAnnotations.SERVICE_EXPOSE_URL.value(), "true"); ingressBuilder.withNewMetadataLike(ingressBuilder.buildMetadata()); if (StringUtils.isNotBlank(routeDomainPostfix)) { routeDomainPostfix = serviceName + "." + FileUtil.stripPrefix(routeDomainPostfix, "."); ingressBuilder = ingressBuilder.withSpec(new IngressSpecBuilder().addNewRule(). withHost(routeDomainPostfix). withNewHttp(). withPaths(new HTTPIngressPathBuilder() .withNewBackend() .withServiceName(serviceName) .withServicePort(KubernetesHelper.createIntOrString(getServicePort(serviceBuilder))) .endBackend() .build()) .endHttp(). endRule().build()); } else { ingressBuilder.withSpec(new IngressSpecBuilder().withBackend(new IngressBackendBuilder(). withNewServiceName(serviceName) .withNewServicePort(getServicePort(serviceBuilder)) .build()).build()); } return ingressBuilder.build(); } } } return null; }
Example 15
Source File: AppsOperator.java From jhipster-operator with Apache License 2.0 | 4 votes |
private boolean areRequiredCRDsPresent() { try { appService.registerCustomResourcesForRuntime(); CustomResourceDefinitionList crds = k8SCoreRuntime.getCustomResourceDefinitionList(); for (CustomResourceDefinition crd : crds.getItems()) { ObjectMeta metadata = crd.getMetadata(); if (metadata != null) { String name = metadata.getName(); if (AppCRDs.MICROSERVICE_CRD_NAME.equals(name)) { microServiceCRD = crd; } if (AppCRDs.GATEWAY_CRD_NAME.equals(name)) { gatewayCRD = crd; } if (AppCRDs.REGISTRY_CRD_NAME.equals(name)) { registryCRD = crd; } if (AppCRDs.APP_CRD_NAME.equals(name)) { applicationCRD = crd; } } } if (allCRDsFound()) { logger.info("\t > App CRD: " + applicationCRD.getMetadata().getName()); logger.info("\t > MicroService CRD: " + microServiceCRD.getMetadata().getName()); logger.info("\t > Registry CRD: " + registryCRD.getMetadata().getName()); logger.info("\t > Gateway CRD: " + gatewayCRD.getMetadata().getName()); return true; } else { logger.error("> Custom CRDs required to work not found please check your installation!"); logger.error("\t > App CRD: " + ((applicationCRD == null) ? " NOT FOUND " : applicationCRD.getMetadata().getName())); logger.error("\t > MicroService CRD: " + ((microServiceCRD == null) ? " NOT FOUND " : microServiceCRD.getMetadata().getName())); logger.error("\t > Registry CRD: " + ((registryCRD == null) ? " NOT FOUND " : registryCRD.getMetadata().getName())); logger.error("\t > Gateway CRD: " + ((gatewayCRD == null) ? " NOT FOUND " : gatewayCRD.getMetadata().getName())); return false; } } catch (Exception e) { e.printStackTrace(); logger.error("> Init sequence not done"); } return false; }