Class K8sCluster<K extends K8sCluster>

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class K8sCluster<K extends K8sCluster>
    extends Object
    implements Closeable
    A representation of a Kubernetes cluster.

    Copyright (c) 2018. All Rights Reserved. Oracle Corporation.
    Oracle is a registered trademark of Oracle Corporation and/or its affiliates.

    Author:
    Jonathan Knight
    • Field Detail

      • PROP_KUBECTL

        public static final String PROP_KUBECTL
        The System property value used to override the location of the kubectl executable.
        See Also:
        Constant Field Values
      • DEFAULT_KUBECTL

        public static final File DEFAULT_KUBECTL
        The default location of kubectl.

        Defaults to "/usr/local/bin/kubectl" but can be overridden using the "bedrock.kubectl" System property.

      • DEFAULT_NAMESPACE

        public static final String DEFAULT_NAMESPACE
        The name of the default namespace if none is provided for a Pod.
        See Also:
        Constant Field Values
    • Constructor Detail

      • K8sCluster

        public K8sCluster()
        Create a K8sCluster.
    • Method Detail

      • withKubectlAt

        public K withKubectlAt​(File kubectl)
        Set the location of the kubectl executable.
        Parameters:
        kubectl - the location of kubectl
        Returns:
        this K8sCluster
      • getKubectl

        public File getKubectl()
        Obtain the location of kubectl.
        Returns:
        the location of kubectl
      • withKubectlConfig

        public K withKubectlConfig​(File config)
        Set the path to the kubeconfig file to use for CLI requests.
        Parameters:
        config - path to the kubeconfig file to use for CLI requests
        Returns:
        this K8sCluster
      • getKubectlConfig

        public File getKubectlConfig()
        Obtain the path to the kubeconfig file to use for CLI requests.
        Returns:
        the path to the kubeconfig file to use for CLI requests
      • withKubectlContext

        public K withKubectlContext​(String context)
        Set the name of the kubeconfig context to use.
        Parameters:
        context - the name of the kubeconfig context to use
        Returns:
        this K8sCluster
      • getKubectlContext

        public String getKubectlContext()
        Obtain the name of the kubeconfig context to use.
        Returns:
        the name of the kubeconfig context to use
      • withKubectlInsecure

        public K withKubectlInsecure​(boolean insecure)
        Set the value to apply to the kubectl --insecure-skip-tls-verify option.
        Parameters:
        insecure - the value to apply to kubectl --insecure-skip-tls-verify
        Returns:
        this K8sCluster
      • isKubectlInsecure

        public boolean isKubectlInsecure()
        Obtain the value to apply to the kubectl --insecure-skip-tls-verify.
        Returns:
        the value to apply to the kubectl --insecure-skip-tls-verify
      • isMasterReady

        public boolean isMasterReady()
        Determine whether the K8s Master ready.
        Returns:
        true if the K8s Master ready
      • kubectlAndWait

        public int kubectlAndWait​(com.oracle.bedrock.Option... options)
        Execute a kubectl command against the k8s cluster and wait for the command to complete.
        Parameters:
        options - the options to use to run the kubectl command
        Returns:
        the exit code from the kubectl command
      • kubectlAndWait

        public int kubectlAndWait​(com.oracle.bedrock.options.Timeout timeout,
                                  com.oracle.bedrock.Option... options)
        Execute a kubectl command against the k8s cluster and wait for the command to complete.
        Parameters:
        timeout - the time to wait for the command to complete
        options - the options to use to run the kubectl command
        Returns:
        the exit code from the kubectl command
      • kubectl

        public Application kubectl​(com.oracle.bedrock.Option... options)
        Execute a kubectl command against the k8s cluster
        Parameters:
        options - the options to use to run the kubectl command
        Returns:
        the Application representing the running kubectl command
      • kubectl

        public <A extends Application> A kubectl​(Class<A> applicationClass,
                                                 com.oracle.bedrock.Option... options)
        Execute a kubectl command against the k8s cluster
        Parameters:
        applicationClass - Class of Application to launch
        options - the options to use to run the kubectl command
        Returns:
        the Application representing the running kubectl command
      • start

        public void start()
      • isNodeLine

        public boolean isNodeLine​(String name,
                                  String line)
        Determine whether a kubectl get nodes output line is for a specific node
        Parameters:
        name - the name of the node
        line - the line to test
        Returns:
        true if the line is for the specified node
      • isMasterNodeLine

        public boolean isMasterNodeLine​(String line)
        Determine whether a kubectl get nodes output line is for the master node.
        Parameters:
        line - the line to test
        Returns:
        true if the line is for the master node
      • getNodeStatus

        public String getNodeStatus​(String line)
        Obtain the node status from the node status line.
        Parameters:
        line - the node status line
        Returns:
        the node status from the node status line
      • getPod

        public Pod getPod​(String podName)
        Obtain the Pod with the specified name.
        Parameters:
        podName - the name of the Pod
        Returns:
        the requested Pod or an null if the Pod does not exist
      • getPod

        public Pod getPod​(String namespace,
                          String podName)
        Obtain the Pod with the specified name.
        Parameters:
        podName - the name of the Pod
        Returns:
        the requested Pod or an null if the Pod does not exist