serviceBuilder = serviceBuilder .withNewMetadata() .withName(serviceName) .withNamespace(namespace) .withLabels(serviceLabels) .endMetadata() .withNewSpec() .withSelector(serviceSelector)
client.services().createNew() .editOrNewMetadata() .withName(options.getRestapiRouteName()) .addToLabels("app", "enmasse") .endMetadata() .editOrNewSpec() .addNewPort()
serviceBuilder.editOrNewMetadata().addToLabels( labelName, labelValue).and().buildMetadata(); log.info("Add %s label: \"%s\" : \"%s\"", PREFIX, labelName, labelValue); annotationName, annotations.get(annotationName)); serviceBuilder.editMetadata().addToAnnotations(annotations).and().buildMetadata();
serviceBuilder = serviceBuilder .withNewMetadata() .withName(serviceName) .withNamespace(namespace) .withLabels(serviceLabels) .endMetadata() .withNewSpec() .withSelector(serviceSelector)
return new TemplateBuilder() .withNewMetadata() .withName(NAME) .addToLabels("name", NAME) .endMetadata() .addNewParameter().withName("LETSCHAT_DEFAULT_ROOMS").withValue("fabric8_default") .withDescription("Default rooms to create and for hubot to join").endParameter()
} else { kube.services().inNamespace(namespace).createNew() .withNewMetadata().withName(serviceName).endMetadata() .withNewSpec() .addToSelector("app", "drools")
.withNamespace(NAMESPACE) .withName(RESOURCE_NAME) .endMetadata() .withNewSpec() .withType("NodePort") .withNamespace(NAMESPACE) .withName(RESOURCE_NAME) .endMetadata() .withNewSpec() .withType("NodePort")
.withName(serviceName) .withNamespace(namespace) .addToAnnotations(exposeSpec.getAnnotations()) .addToAnnotations(AnnotationKeys.ADDRESS_SPACE, addressSpace.getMetadata().getName()) .addToAnnotations(AnnotationKeys.SERVICE_NAME, KubeUtil.getAddressSpaceServiceName(endpointSpec.getService(), addressSpace)) .addToLabels(LabelKeys.INFRA_TYPE, addressSpace.getSpec().getType()) .addToLabels(LabelKeys.INFRA_UUID, infraUuid) .endMetadata() .editOrNewSpec() .withPorts(servicePorts)
client.services().createNew().withNewMetadata().withName(appId) .withLabels(idMap).withAnnotations(annotations).addToLabels(SPRING_MARKER_KEY, SPRING_MARKER_VALUE) .endMetadata().withSpec(spec.build()).done();
.withName(service.getName()) .withAnnotations(getAnnotations(service)) .withLabels(getLabels(service)) .endMetadata();
KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class); Service serviceCreating = new ServiceBuilder() .withNewMetadata().withName(serviceName).withLabels(labels) .endMetadata().withSpec(serviceSpec).build(); service = getEndpoint().getKubernetesClient().services() .inNamespace(namespaceName).create(serviceCreating);
Service service = new ServiceBuilder() .withNewMetadata() .withName(serviceModel.getName()) .withNamespace(dataHolder.getNamespace()) .addToLabels(serviceModel.getLabels()) .endMetadata() .withNewSpec() .addNewPort()
private Service getDefaultService() { // No image config, no service if (!hasImageConfiguration()) { return null; } String serviceName = getConfig(Config.name, MavenUtil.createDefaultResourceName(getContext().getGav().getSanitizedArtifactId())); // Create service only for all images which are supposed to live in a single pod List<ServicePort> ports = extractPorts(getImages().get()); ServiceBuilder builder = new ServiceBuilder() .withNewMetadata() .withName(serviceName) .withLabels(extractLabels()) .endMetadata(); ServiceFluent.SpecNested<ServiceBuilder> specBuilder = builder.withNewSpec(); if (!ports.isEmpty()) { specBuilder.withPorts(ports); } else if (Configs.asBoolean(getConfig(Config.headless))) { specBuilder.withClusterIP("None"); } else { // No ports, no headless --> no service return null; } if (hasConfig(Config.type)) { specBuilder.withType(getConfig(Config.type)); } specBuilder.endSpec(); return builder.build(); }
private Service getDefaultService() { // No image config, no service if (!hasImageConfiguration()) { return null; } // Create service only for all images which are supposed to live in a single pod List<ServicePort> ports = extractPorts(getImages()); ServiceBuilder builder = new ServiceBuilder() .withNewMetadata() .withName(getConfig(Config.name, MavenUtil.createDefaultResourceName(getProject()))) .withLabels(extractLabels()) .endMetadata(); ServiceFluent.SpecNested<ServiceBuilder> specBuilder = builder.withNewSpec(); if (!ports.isEmpty()) { specBuilder.withPorts(ports); } else if (Configs.asBoolean(getConfig(Config.headless))) { specBuilder.withClusterIP("None"); } else { // No ports, no headless --> no service return null; } if (hasConfig(Config.type)) { specBuilder.withType(getConfig(Config.type)); } specBuilder.endSpec(); return builder.build(); }
public void onTemplate(TemplateBuilder builder) { builder.addNewServiceObject() .withNewMetadata() .withName("elasticsearch-cluster") .endMetadata() .withNewSpec() .withClusterIP("None") .addNewPort() .withName("") .withProtocol("TCP") .withPort(9300) .withNewTargetPort(9300) .endPort() .addToSelector("component", "elasticsearch") .addToSelector("provider", "fabric8") .endSpec() .and() .build(); }
private void ensureService(String name, DeploymentData deploymentData) { final Map<String, String> labels = prepareServiceLabels(deploymentData); final Map<String, String> annotations = prepareServiceAnnotations(deploymentData); openShiftClient.services().withName(name).createOrReplaceWithNew() .withNewMetadata() .withName(name) .addToAnnotations(annotations) .addToLabels(labels) .endMetadata() .withNewSpec() .addToSelector(INTEGRATION_NAME_LABEL, name) .addNewPort() .withName("http") .withProtocol("TCP") .withPort(INTEGRATION_SERVICE_PORT) .withNewTargetPort(INTEGRATION_SERVICE_PORT) .endPort() .endSpec() .done(); }
protected Service exposeService(String namespace, Map<String, String> metadata, String serviceName, Iterable<Integer> inboundPorts) { List<ServicePort> servicePorts = Lists.newArrayList(); for (Integer inboundPort : inboundPorts) { servicePorts.add(new ServicePortBuilder().withName(Integer.toString(inboundPort)).withPort(inboundPort).build()); } Service service = new ServiceBuilder().withNewMetadata().withName(serviceName).endMetadata() .withNewSpec() .addToSelector(metadata) .addToPorts(Iterables.toArray(servicePorts, ServicePort.class)) .withType(NODE_PORT) .endSpec() .build(); client.services().inNamespace(namespace).create(service); service = getService(namespace, serviceName); LOG.debug("Exposed service {} in namespace {}.", service, namespace); return service; }
private static Service getMessagingClientServiceResource() { return new ServiceBuilder() .withNewMetadata() .withName(SystemtestsOpenshiftApp.MESSAGING_CLIENTS.toString()) .addToLabels("run", SystemtestsOpenshiftApp.MESSAGING_CLIENTS.toString()) .endMetadata() .withNewSpec() .withSelector(Collections.singletonMap("app", SystemtestsOpenshiftApp.MESSAGING_CLIENTS.toString())) .addNewPort() .withName("http") .withPort(4242) .withProtocol("TCP") .endPort() .endSpec() .build(); } }
protected Service createHeadlessService(List<ServicePort> ports, Map<String, String> annotations) { Service service = new ServiceBuilder() .withNewMetadata() .withName(headlessServiceName) .withLabels(getLabelsWithName(headlessServiceName, templateHeadlessServiceLabels)) .withNamespace(namespace) .withAnnotations(mergeAnnotations(annotations, templateHeadlessServiceAnnotations)) .withOwnerReferences(createOwnerReference()) .endMetadata() .withNewSpec() .withType("ClusterIP") .withClusterIP("None") .withSelector(getSelectorLabels()) .withPorts(ports) .endSpec() .build(); log.trace("Created headless service {}", service); return service; }
@Override public void provideCert(AddressSpace addressSpace, EndpointInfo endpointInfo) { Secret secret = client.secrets().inNamespace(namespace).withName(endpointInfo.getCertSpec().getSecretName()).get(); if (secret == null) { String serviceName = KubeUtil.getAddressSpaceServiceName(endpointInfo.getServiceName(), addressSpace); Service service = client.services().withName(serviceName).get(); if (service != null && (service.getMetadata().getAnnotations() == null || service.getMetadata().getAnnotations().get(AnnotationKeys.OPENSHIFT_SERVING_CERT_SECRET_NAME) == null)) { log.info("Adding service annotation to generate OpenShift cert"); client.services().withName(serviceName).edit() .editMetadata() .addToAnnotations(AnnotationKeys.OPENSHIFT_SERVING_CERT_SECRET_NAME, endpointInfo.getCertSpec().getSecretName()) .endMetadata() .done(); } } } }