Class 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 Detail

      • Pod

        public Pod​(K8sCluster k8s,
                   String podName)
        Create a Pod in the default namespace.
        Parameters:
        k8s - the K8sCluster containing this Pod
        podName - the name of this Pod
      • Pod

        public Pod​(K8sCluster k8s,
                   String podName,
                   String namespace)
        Create a Pod.
        Parameters:
        k8s - the K8sCluster containing this Pod
        podName - the name of this Pod
        namespace - the namespace that this Pod is running in
    • Method Detail

      • getPodName

        public String getPodName()
        Obtain the name of this Pod.
        Returns:
        the name of this Pod
      • getNamespace

        public String getNamespace()
        Obtain the namespace that this Pod is running in.
        Returns:
        the namespace that this Pod is 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 copy
        destination - 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 Pod
        destination - 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
      • 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 Application wrapping the kubectl log command that allows stopping of log following by calling Application.close()
        Throws:
        IOException - if an error occurs obtaining the log
      • 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 exec
        options - extra Options 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 Map of 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 -i in the command
        args - 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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object