- java.lang.Object
-
- com.oracle.bedrock.runtime.k8s.Pod
-
- Direct Known Subclasses:
PodContainer
public class Pod extends Object
A representation of a Kubernetes Pod.Copyright (c) 2019. All Rights Reserved. Oracle Corporation.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates.- Author:
- Jonathan Knight
-
-
Constructor Summary
Constructors Constructor Description Pod(K8sCluster k8s, String podName)Create aPodin the default namespace.Pod(K8sCluster k8s, String podName, String namespace)Create aPod.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcopyFrom(Path source, Path destination)Copy a file from this Pod to a local destination.voidcopyTo(Path source, Path destination)Copy a local file to this Pod.booleanequals(Object o)Applicationexec(Arguments args, com.oracle.bedrock.Option... options)Exec a command on this Pod.ApplicationfollowLog(ApplicationConsole console)Tail and follow this Pod's log.ApplicationfollowLog(File file)Tail and follow this Pod's log.protected List<String>getArgs(String command)Obtain the base kubectl arguments.Map<String,PodContainer>getContainers()Obtain the containers for this Pod.protected List<String>getExecArgs(boolean termainal, String... args)Obtain the kubectl exec command line to use for this Pod.K8sClustergetK8sCluster()Obtain theK8sClustercontaining thisPodStringgetNamespace()Obtain the namespace that thisPodis running in.StringgetPodName()Obtain the name of thisPod.inthashCode()voidlog(ApplicationConsole console)Capture this Pod's log.voidlog(File file)Write this Pod's log to the specified file.List<String>ls()Execute the ls command in this Pod and return the list of files.List<String>ls(Path path)Execute the ls command in this Pod and return the list of files.voidmkdir(Path path)Execute the mkdir command in this Pod to create a directory or directory pathvoidrm(Path path)Execute the rm command in this Pod to remove a file or directory
-
-
-
Constructor Detail
-
Pod
public Pod(K8sCluster k8s, String podName)
Create aPodin the default namespace.- Parameters:
k8s- theK8sClustercontaining thisPodpodName- the name of thisPod
-
Pod
public Pod(K8sCluster k8s, String podName, String namespace)
Create aPod.- Parameters:
k8s- theK8sClustercontaining thisPodpodName- the name of thisPodnamespace- the namespace that thisPodis running in
-
-
Method Detail
-
getK8sCluster
public K8sCluster getK8sCluster()
Obtain theK8sClustercontaining thisPod- Returns:
- the
K8sClustercontaining thisPod
-
getNamespace
public String getNamespace()
Obtain the namespace that thisPodis running in.- Returns:
- the namespace that this
Podis running in
-
copyTo
public void copyTo(Path source, Path destination) throws Exception
Copy a local file to this Pod.- Parameters:
source- the location of the file to copydestination- the destination to copy to in the Pod- Throws:
Exception- if an error occurs copying the file
-
copyFrom
public void copyFrom(Path source, Path destination) throws Exception
Copy a file from this Pod to a local destination.- Parameters:
source- the source file to copy from this Poddestination- the destination to copy to- Throws:
Exception- if an error occurs copying the file
-
log
public void log(File file) throws IOException
Write this Pod's log to the specified file.- Parameters:
file- the file to write the log to- Throws:
IOException- if an error occurs obtaining the log
-
log
public void log(ApplicationConsole console) throws IOException
Capture this Pod's log.- Parameters:
console- theApplicationConsoleto write the log to- Throws:
IOException- if an error occurs obtaining the log
-
followLog
public Application followLog(File file) throws IOException
Tail and follow this Pod's log.- Parameters:
file- the file to write the log to- Returns:
- the
Applicationwrapping the kubectl log command that allows stopping of log following by callingApplication.close() - Throws:
IOException- if an error occurs obtaining the log
-
followLog
public Application followLog(ApplicationConsole console)
Tail and follow this Pod's log.- Parameters:
console- theApplicationConsoleto write the log to- Returns:
- the
Applicationwrapping the kubectl log command that allows stopping of log following by callingApplication.close()
-
exec
public Application exec(Arguments args, com.oracle.bedrock.Option... options)
Exec a command on this Pod.- Parameters:
args- the arguments of the command to execoptions- extraOptions to use when exec'ing the command
-
ls
public List<String> ls() throws IOException
Execute the ls command in this Pod and return the list of files.- Returns:
- the list of files in the path
- Throws:
IOException- if an error occurs executing the ls command
-
ls
public List<String> ls(Path path) throws IOException
Execute the ls command in this Pod and return the list of files.- Parameters:
path- the path to perform the ls command in, or null to use the root directory- Returns:
- the list of files in the path
- Throws:
IOException- if an error occurs executing the ls command
-
mkdir
public void mkdir(Path path) throws IOException
Execute the mkdir command in this Pod to create a directory or directory path- Parameters:
path- the path of the directory to create- Throws:
IOException- if an error occurs executing the ls command
-
rm
public void rm(Path path) throws IOException
Execute the rm command in this Pod to remove a file or directory- Parameters:
path- the path to the file or directory to remove- Throws:
IOException- if an error occurs executing the ls command
-
getContainers
public Map<String,PodContainer> getContainers()
Obtain the containers for this Pod.- Returns:
- a
Mapof containers for this Pod keyed by container name
-
getExecArgs
protected List<String> getExecArgs(boolean termainal, String... args)
Obtain the kubectl exec command line to use for this Pod.- Parameters:
termainal- {@link true} to include-iin the commandargs- the additional arguments to append to the command- Returns:
- the kubectl exec command line to use for this Pod
-
getArgs
protected List<String> getArgs(String command)
Obtain the base kubectl arguments.- Parameters:
command- the kubectl command- Returns:
- the base kubectl arguments
-
-