io.kubernetes.client.custom.IntOrString Java Examples

The following examples show how to use io.kubernetes.client.custom.IntOrString. 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: KubeServiceBuilder.java    From dew with 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 #2
Source File: KubernetesClient.java    From cubeai with 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 #3
Source File: AppsV1beta1RollingUpdateDeployment.java    From java with 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 #4
Source File: V1RollingUpdateDeployment.java    From java with 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 #5
Source File: V1beta2RollingUpdateDaemonSet.java    From java with 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 File: ExtensionsV1beta1RollingUpdateDeployment.java    From java with 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 #7
Source File: V1RollingUpdateDeployment.java    From java with 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 #8
Source File: ExtensionsV1beta1RollingUpdateDeployment.java    From java with 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 #9
Source File: KubernetesNatManagerTest.java    From besu with 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 #10
Source File: V1beta1PodDisruptionBudgetSpec.java    From java with 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 #11
Source File: V1beta1PodDisruptionBudgetSpec.java    From java with 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 File: V1beta1NetworkPolicyPort.java    From java with 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 #13
Source File: V1NetworkPolicyPort.java    From java with 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 #14
Source File: V1beta1RollingUpdateDaemonSet.java    From java with 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 #15
Source File: YamlExample.java    From java with 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 #16
Source File: Yaml.java    From java with 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 #17
Source File: V1RollingUpdateDaemonSet.java    From java with 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 File: Yaml.java    From java with 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 #19
Source File: Yaml.java    From java with 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 #20
Source File: V1beta2RollingUpdateDeployment.java    From java with 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 File: AppsV1beta1RollingUpdateDeployment.java    From java with 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 #22
Source File: Yaml.java    From java with 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 #23
Source File: V1beta2RollingUpdateDeployment.java    From java with 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 #24
Source File: JobMasterRequestObject.java    From twister2 with 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 #25
Source File: V1ServicePort.java    From java with 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 #26
Source File: V1RollingUpdateDeployment.java    From java with Apache License 2.0 4 votes vote down vote up
public void setMaxUnavailable(IntOrString maxUnavailable) {
  this.maxUnavailable = maxUnavailable;
}
 
Example #27
Source File: V1HTTPGetAction.java    From java with Apache License 2.0 4 votes vote down vote up
public void setPort(IntOrString port) {
  this.port = port;
}
 
Example #28
Source File: V1RollingUpdateDeployment.java    From java with Apache License 2.0 4 votes vote down vote up
public void setMaxSurge(IntOrString maxSurge) {
  this.maxSurge = maxSurge;
}
 
Example #29
Source File: KubeServiceBuilder.java    From dew with Apache License 2.0 4 votes vote down vote up
@Override
public V1Service build(FinalProjectConfig config) {

    Map<String, String> annotations = new HashMap<>();
    annotations.put(VersionController.FLAG_KUBE_RESOURCE_GIT_COMMIT, config.getGitCommit());
    annotations.put("dew.idealworld.group/scm-url", config.getScmUrl());
    if (config.getApp().getTraceLogEnabled()) {
        annotations.put("sidecar.jaegertracing.io/inject", "true");
    }
    annotations.putAll(config.getApp().getAnnotations());

    Map<String, String> labels = new HashMap<>();
    labels.put("app", config.getAppName());
    labels.put(VersionController.FLAG_KUBE_RESOURCE_APP_VERSION, config.getAppVersion());
    labels.put("group", config.getAppGroup());
    labels.put("provider", "dew");
    labels.put("expose", "true");
    labels.putAll(config.getApp().getLabels());

    Map<String, String> selectorLabels = new HashMap<>(labels);
    selectorLabels.remove("version");
    selectorLabels.remove("expose");
    selectorLabels.remove("provider");

    List<V1ServicePort> ports = new ArrayList<>();
    ports.add(new V1ServicePortBuilder()
            .withName("http")
            .withPort(config.getApp().getPort())
            .withProtocol("TCP")
            .withTargetPort(new IntOrString(config.getApp().getPort()))
            .build());
    if (config.getApp().getExtendedPorts() != null) {
        config.getApp().getExtendedPorts().forEach(port -> {
            ports.add(new V1ServicePortBuilder()
                    .withName(port.getName())
                    .withPort(port.getContainerPort())
                    .withProtocol(port.getProtocol())
                    .withTargetPort(new IntOrString(port.getContainerPort()))
                    .build());
        });
    }

    V1ServiceBuilder builder = new V1ServiceBuilder();
    builder.withKind(KubeRES.SERVICE.getVal())
            .withApiVersion("v1")
            .withMetadata(new V1ObjectMetaBuilder()
                    .withAnnotations(annotations)
                    .withLabels(labels)
                    .withName(config.getAppName())
                    .withNamespace(config.getNamespace())
                    .build())
            .withSpec(new V1ServiceSpecBuilder()
                    .withSelector(selectorLabels)
                    .withPorts(ports)
                    .build())
            .build();
    return builder.build();
}
 
Example #30
Source File: V1beta1NetworkPolicyPort.java    From java with Apache License 2.0 4 votes vote down vote up
public void setPort(IntOrString port) {
  this.port = port;
}