Java Code Examples for io.kubernetes.client.custom.IntOrString

The following examples show how to use io.kubernetes.client.custom.IntOrString. These examples are extracted from open source projects. 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 Project: cubeai   Source File: KubernetesClient.java    License: Apache License 2.0 6 votes vote down vote up
public boolean createService(String name) {
    try {
        Map<String, String> label = new HashMap<>(8);
        label.put("ucumos", name);
        V1Service serviceYaml = new V1ServiceBuilder()
            .withApiVersion("v1")
            .withKind("Service")
            .withNewMetadata()
            .withNamespace(nameSpace)
            .withName("service-" + name)
            .endMetadata()
            .withNewSpec()
            .withType("NodePort")
            .withSelector(label)
            .addNewPort()
            .withPort(3330)
            .withTargetPort(new IntOrString(3330))
            .endPort()
            .endSpec()
            .build();
        coreApi.createNamespacedService(nameSpace, serviceYaml, null, null, null);
        return true;
    } catch (ApiException e) {
        return false;
    }
}
 
Example 2
Source Project: dew   Source File: KubeServiceBuilder.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Build debug port.
 * <p>
 *
 * @param service     the service
 * @param forwardPort the forward port
 * @param debugPort   the target port
 */
public void buildDebugPort(V1Service service, int debugPort, int forwardPort) {
    service.getSpec().setType("NodePort");
    if (service.getSpec().getPorts().stream().noneMatch(v1ServicePort -> v1ServicePort.getPort() == forwardPort)) {
        service.getSpec().getPorts().add(new V1ServicePortBuilder()
                .withName("http-debug")
                .withPort(forwardPort)
                .withProtocol("TCP")
                .withTargetPort(new IntOrString(forwardPort))
                .build());
    }
    if (service.getSpec().getPorts().stream().noneMatch(v1ServicePort -> v1ServicePort.getPort() == debugPort)) {
        service.getSpec().getPorts().add(new V1ServicePortBuilder()
                .withName("http-new")
                .withPort(debugPort)
                .withProtocol("TCP")
                .withTargetPort(new IntOrString(debugPort))
                .build());
    }
}
 
Example 3
Source Project: besu   Source File: KubernetesNatManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void initialize() throws IOException {
  final V1ServiceStatus v1ServiceStatus =
      new V1ServiceStatus()
          .loadBalancer(
              new V1LoadBalancerStatusBuilder()
                  .addToIngress(
                      new V1LoadBalancerIngressBuilder().withIp(detectedAdvertisedHost).build())
                  .build());
  when(v1Service.getStatus()).thenReturn(v1ServiceStatus);
  when(v1Service.getSpec())
      .thenReturn(
          new V1ServiceSpec()
              .ports(
                  Arrays.asList(
                      new V1ServicePort()
                          .name(NatServiceType.JSON_RPC.getValue())
                          .port(rpcHttpPort)
                          .targetPort(new IntOrString(rpcHttpPort)),
                      new V1ServicePort()
                          .name(NatServiceType.RLPX.getValue())
                          .port(p2pPort)
                          .targetPort(new IntOrString(p2pPort)),
                      new V1ServicePort()
                          .name(NatServiceType.DISCOVERY.getValue())
                          .port(p2pPort)
                          .targetPort(new IntOrString(p2pPort)))));
  when(v1Service.getMetadata()).thenReturn(new V1ObjectMeta().name(DEFAULT_BESU_POD_NAME_FILTER));
  natManager = new KubernetesNatManager(DEFAULT_BESU_POD_NAME_FILTER);
  try {
    natManager.start();
  } catch (Exception ignored) {
    System.err.println("Ignored missing Kube config file in testing context.");
  }
  natManager.updateUsingBesuService(v1Service);
}
 
Example 4
Source Project: java   Source File: YamlExample.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException {
  V1Pod pod =
      new V1PodBuilder()
          .withNewMetadata()
          .withName("apod")
          .endMetadata()
          .withNewSpec()
          .addNewContainer()
          .withName("www")
          .withImage("nginx")
          .withNewResources()
          .withLimits(new HashMap<>())
          .endResources()
          .endContainer()
          .endSpec()
          .build();
  System.out.println(Yaml.dump(pod));

  V1Service svc =
      new V1ServiceBuilder()
          .withNewMetadata()
          .withName("aservice")
          .endMetadata()
          .withNewSpec()
          .withSessionAffinity("ClientIP")
          .withType("NodePort")
          .addNewPort()
          .withProtocol("TCP")
          .withName("client")
          .withPort(8008)
          .withNodePort(8080)
          .withTargetPort(new IntOrString(8080))
          .endPort()
          .endSpec()
          .build();
  System.out.println(Yaml.dump(svc));

  // Read yaml configuration file, and deploy it
  ApiClient client = Config.defaultClient();
  Configuration.setDefaultApiClient(client);

  //  See issue #474. Not needed at most cases, but it is needed if you are using war
  //  packging or running this on JUnit.
  Yaml.addModelMap("v1", "Service", V1Service.class);

  // Example yaml file can be found in $REPO_DIR/test-svc.yaml
  File file = new File("test-svc.yaml");
  V1Service yamlSvc = (V1Service) Yaml.load(file);

  // Deployment and StatefulSet is defined in apps/v1, so you should use AppsV1Api instead of
  // CoreV1API
  CoreV1Api api = new CoreV1Api();
  V1Service createResult = api.createNamespacedService("default", yamlSvc, null, null, null);

  System.out.println(createResult);

  V1Status deleteResult =
      api.deleteNamespacedService(
          yamlSvc.getMetadata().getName(),
          "default",
          null,
          null,
          null,
          null,
          null,
          new V1DeleteOptions());
  System.out.println(deleteResult);
}
 
Example 5
Source Project: java   Source File: V1RollingUpdateDaemonSet.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxUnavailable
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxUnavailable() {
  return maxUnavailable;
}
 
Example 6
Source Project: java   Source File: V1ServicePort.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return targetPort
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getTargetPort() {
  return targetPort;
}
 
Example 7
Source Project: java   Source File: V1beta2RollingUpdateDeployment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxSurge
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxSurge() {
  return maxSurge;
}
 
Example 8
Source Project: java   Source File: V1beta2RollingUpdateDeployment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxUnavailable
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxUnavailable() {
  return maxUnavailable;
}
 
Example 9
Source Project: java   Source File: AppsV1beta1RollingUpdateDeployment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxSurge
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxSurge() {
  return maxSurge;
}
 
Example 10
Source Project: java   Source File: AppsV1beta1RollingUpdateDeployment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxUnavailable
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxUnavailable() {
  return maxUnavailable;
}
 
Example 11
Source Project: java   Source File: V1beta1PodDisruptionBudgetSpec.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxUnavailable
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxUnavailable() {
  return maxUnavailable;
}
 
Example 12
Source Project: java   Source File: V1beta1PodDisruptionBudgetSpec.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return minAvailable
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMinAvailable() {
  return minAvailable;
}
 
Example 13
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxSurge
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxSurge() {
  return maxSurge;
}
 
Example 14
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxUnavailable
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxUnavailable() {
  return maxUnavailable;
}
 
Example 15
Source Project: java   Source File: V1beta2RollingUpdateDaemonSet.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxUnavailable
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxUnavailable() {
  return maxUnavailable;
}
 
Example 16
Source Project: java   Source File: V1RollingUpdateDeployment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxSurge
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxSurge() {
  return maxSurge;
}
 
Example 17
Source Project: java   Source File: V1RollingUpdateDeployment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxUnavailable
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxUnavailable() {
  return maxUnavailable;
}
 
Example 18
Source Project: java   Source File: V1beta1NetworkPolicyPort.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return port
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getPort() {
  return port;
}
 
Example 19
Source Project: java   Source File: V1NetworkPolicyPort.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return port
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getPort() {
  return port;
}
 
Example 20
Source Project: java   Source File: V1beta1RollingUpdateDaemonSet.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.
 * @return maxUnavailable
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "IntOrString is a type that can hold an int32 or a string.  When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type.  This allows you to have, for example, a JSON field that can accept a name or number.")

public IntOrString getMaxUnavailable() {
  return maxUnavailable;
}
 
Example 21
Source Project: java   Source File: Yaml.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Object constructObject(Node node) {
  if (node.getType() == IntOrString.class) {
    return constructIntOrString((ScalarNode) node);
  }
  if (node.getType() == byte[].class) {
    return constructByteArray((ScalarNode) node);
  }

  if (node.getType() == org.joda.time.DateTime.class) {
    return constructDateTime((ScalarNode) node);
  }

  return super.constructObject(node);
}
 
Example 22
Source Project: java   Source File: Yaml.java    License: Apache License 2.0 5 votes vote down vote up
private IntOrString constructIntOrString(ScalarNode node) {
  try {
    return new IntOrString(Integer.parseInt(node.getValue()));
  } catch (NumberFormatException err) {
    return new IntOrString(node.getValue());
  }
}
 
Example 23
Source Project: java   Source File: Yaml.java    License: Apache License 2.0 5 votes vote down vote up
public CustomRepresenter() {
  this.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
  this.representers.put(IntOrString.class, new RepresentIntOrString());
  this.representers.put(byte[].class, new RepresentByteArray());
  this.representers.put(Quantity.class, new RepresentQuantity());
  this.representers.put(DateTime.class, new RepresentDateTime());
}
 
Example 24
Source Project: java   Source File: Yaml.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Node representData(Object data) {
  IntOrString intOrString = (IntOrString) data;
  if (intOrString.isInteger()) {
    return CustomRepresenter.this.representData(intOrString.getIntValue());
  } else {
    return CustomRepresenter.this.representData(intOrString.getStrValue());
  }
}
 
Example 25
Source Project: twister2   Source File: JobMasterRequestObject.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * create regular service for job master
 */
public static V1Service createJobMasterServiceObject() {

  String serviceName = KubernetesUtils.createJobMasterServiceName(jobID);

  V1Service service = new V1Service();
  service.setKind("Service");
  service.setApiVersion("v1");

  // set labels for the jm service
  HashMap<String, String> labels = KubernetesUtils.createJobLabels(jobID);

  // construct and set metadata
  V1ObjectMeta meta = new V1ObjectMeta();
  meta.setName(serviceName);
  meta.setLabels(labels);
  service.setMetadata(meta);

  // construct and set service spec
  V1ServiceSpec serviceSpec = new V1ServiceSpec();
  // set selector
  HashMap<String, String> selectors = new HashMap<String, String>();
  selectors.put("t2-mp", jobID);
  serviceSpec.setSelector(selectors);
  // set port
  V1ServicePort servicePort = new V1ServicePort();
  servicePort.setName("job-master-port");
  servicePort.setPort(JobMasterContext.jobMasterPort(config));
  servicePort.setTargetPort(new IntOrString(JobMasterContext.jobMasterPort(config)));
  servicePort.setProtocol("TCP");
  serviceSpec.setPorts(Arrays.asList(servicePort));

  service.setSpec(serviceSpec);

  return service;
}
 
Example 26
Source Project: cubeai   Source File: KubernetesClient.java    License: Apache License 2.0 4 votes vote down vote up
public boolean createNetworkPolicy(String ipIpTunnelCidr) {
    try {
        if (!readNetworkPolicy()) {
            V1NetworkPolicy networkPolicyYaml = new V1NetworkPolicyBuilder()
                .withApiVersion("networking.k8s.io/v1")
                .withKind("NetworkPolicy")
                .withNewMetadata()
                    .withName("networkpolicy-" + nameSpace)
                    .withNamespace(nameSpace)
                .endMetadata()
                .withNewSpec()
                    .withNewPodSelector()
                    .endPodSelector()
                    .withPolicyTypes(Arrays.asList("Ingress", "Egress"))
                    .addNewIngress()
                        .addNewFrom()
                            .withNewIpBlock()
                                .withCidr(ipIpTunnelCidr)
                            .endIpBlock()
                        .endFrom()
                        .addNewFrom()
                            .withNewPodSelector()
                            .endPodSelector()
                        .endFrom()
                        .withPorts(new V1NetworkPolicyPort().protocol("TCP").port(new IntOrString(3330)))
                    .endIngress()
                    .addNewEgress()
                        .addNewTo()
                            .withNewIpBlock()
                                .withCidr(ipIpTunnelCidr)
                            .endIpBlock()
                        .endTo()
                        .addNewTo()
                            .withNewPodSelector()
                            .endPodSelector()
                        .endTo()
                        .withPorts(new V1NetworkPolicyPort().protocol("TCP").port(new IntOrString(3330)))
                    .endEgress()
                .endSpec()
                .build();
            networkingApi.createNamespacedNetworkPolicy(
                nameSpace, networkPolicyYaml, null, null, null);
        }
        return true;
    } catch (ApiException e) {
        return false;
    }
}
 
Example 27
Source Project: java   Source File: V1RollingUpdateDaemonSet.java    License: Apache License 2.0 4 votes vote down vote up
public void setMaxUnavailable(IntOrString maxUnavailable) {
  this.maxUnavailable = maxUnavailable;
}
 
Example 28
Source Project: java   Source File: V1ServicePort.java    License: Apache License 2.0 4 votes vote down vote up
public void setTargetPort(IntOrString targetPort) {
  this.targetPort = targetPort;
}
 
Example 29
Source Project: java   Source File: V1beta2RollingUpdateDeployment.java    License: Apache License 2.0 4 votes vote down vote up
public void setMaxSurge(IntOrString maxSurge) {
  this.maxSurge = maxSurge;
}
 
Example 30
Source Project: java   Source File: V1beta2RollingUpdateDeployment.java    License: Apache License 2.0 4 votes vote down vote up
public void setMaxUnavailable(IntOrString maxUnavailable) {
  this.maxUnavailable = maxUnavailable;
}