Package com.oracle.bedrock.runtime.k8s
Class K8sCluster<K extends K8sCluster>
- java.lang.Object
-
- com.oracle.bedrock.runtime.k8s.K8sCluster<K>
-
- 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 Summary
Fields Modifier and Type Field Description static FileDEFAULT_KUBECTLThe default location of kubectl.static StringDEFAULT_NAMESPACEThe name of the default namespace if none is provided for a Pod.static StringPROP_KUBECTLThe System property value used to override the location of the kubectl executable.
-
Constructor Summary
Constructors Constructor Description K8sCluster()Create aK8sCluster.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected RuntimeExceptionensureRuntimeException(Throwable t)FilegetKubectl()Obtain the location of kubectl.FilegetKubectlConfig()Obtain the path to the kubeconfig file to use for CLI requests.StringgetKubectlContext()Obtain the name of the kubeconfig context to use.StringgetNodeStatus(String line)Obtain the node status from the node status line.PodgetPod(String podName)Obtain thePodwith the specified name.PodgetPod(String namespace, String podName)Obtain thePodwith the specified name.booleanisKubectlInsecure()Obtain the value to apply to the kubectl--insecure-skip-tls-verify.booleanisMasterNodeLine(String line)Determine whether a kubectl get nodes output line is for the master node.booleanisMasterReady()Determine whether the K8s Master ready.booleanisNodeLine(String name, String line)Determine whether a kubectl get nodes output line is for a specific nodeApplicationkubectl(com.oracle.bedrock.Option... options)Execute a kubectl command against the k8s cluster<A extends Application>
Akubectl(Class<A> applicationClass, com.oracle.bedrock.Option... options)Execute a kubectl command against the k8s clusterintkubectlAndWait(com.oracle.bedrock.Option... options)Execute a kubectl command against the k8s cluster and wait for the command to complete.intkubectlAndWait(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.voidstart()KwithKubectlAt(File kubectl)Set the location of the kubectl executable.KwithKubectlConfig(File config)Set the path to the kubeconfig file to use for CLI requests.KwithKubectlContext(String context)Set the name of the kubeconfig context to use.KwithKubectlInsecure(boolean insecure)Set the value to apply to the kubectl--insecure-skip-tls-verifyoption.
-
-
-
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 aK8sCluster.
-
-
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-verifyoption.- 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:
trueif 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 completeoptions- 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
Applicationrepresenting 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-ClassofApplicationto launchoptions- the options to use to run the kubectl command- Returns:
- the
Applicationrepresenting the running kubectl command
-
start
public void start()
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
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 nodeline- the line to test- Returns:
trueif 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:
trueif 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 thePodwith the specified name.- Parameters:
podName- the name of the Pod- Returns:
- the requested Pod or an
nullif the Pod does not exist
-
getPod
public Pod getPod(String namespace, String podName)
Obtain thePodwith the specified name.- Parameters:
podName- the name of the Pod- Returns:
- the requested Pod or an
nullif the Pod does not exist
-
ensureRuntimeException
protected RuntimeException ensureRuntimeException(Throwable t)
-
-