Class KubectlWrapper

java.lang.Object
com.google.jenkins.plugins.k8sengine.KubectlWrapper

public class KubectlWrapper extends Object
Encapsulates the logic of executing kubectl commands in the workspace. NOTE(craigatgoogle): This is a temporary stop-gap measure which will be replaced once the Kubernetes server-side apply method is added: issue#555.
  • Method Details

    • runKubectlCommand

      public String runKubectlCommand(String command, com.google.common.collect.ImmutableList<String> args) throws IOException, InterruptedException
      Runs the specified kubectl command.
      Parameters:
      command - The kubectl command to be run.
      args - Arguments for the command.
      Returns:
      result From kubectl command.
      Throws:
      IOException - If an error occurred while executing the command.
      InterruptedException - If an error occured while executing the command.
    • getObject

      public Object getObject(String kind, String name) throws IOException, InterruptedException
      Using the kubectl CLI tool as the API client for the caller, this method unmarshalls the JSON output of the CLI to a JSON Object.
      Parameters:
      kind - The kind of Kubernetes Object.
      name - The name of the Kubernetes Object.
      Returns:
      The JSON object unmarshalled from the kubectl get command's output.
      Throws:
      IOException - If an error occurred while executing the command.
      InterruptedException - If an error occurred while executing the command.
    • getObjectsThatMatchLabels

      public com.google.common.collect.ImmutableList<Object> getObjectsThatMatchLabels(String kind, Map<String,String> labels) throws IOException, InterruptedException, com.jayway.jsonpath.InvalidJsonException
      Using the kubectl CLI tool as the API client for the caller, this method unmarshalls the JSON output of objects matching the supplied labels.
      Parameters:
      kind - The kind of Kubernetes Object.
      labels - The key-value labels set represented as a map.
      Returns:
      A list of JSON Objects unmarshalled from the kubectl get command's output.
      Throws:
      IOException - If an error occurred while executing the command.
      InterruptedException - If an error occurred while executing the command.
      com.jayway.jsonpath.InvalidJsonException - If an error occurred parsing the JSON return value.