integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java
public static String callShellScriptByExecToPod(
      String scriptPath, String arguments, String podName, String namespace) throws Exception {

    StringBuffer cmdKubectlSh = new StringBuffer("kubectl -n ");
    cmdKubectlSh
        .append(namespace)
        .append(" exec -it ")
        .append(podName)
        .append(" -- bash -c 'chmod +x -R /shared && ")
        .append(scriptPath)
        .append(" ")
        .append(arguments)
        .append("'");
    LoggerHelper.getLocal().log(Level.INFO, "Command to call kubectl sh file " + cmdKubectlSh);
    ExecResult result = ExecCommand.exec(cmdKubectlSh.toString());
    if (result.exitValue() != 0) {
      throw new RuntimeException(
          "FAILURE: command " + cmdKubectlSh + " failed, returned " + result.stderr());
    }
    return result.stdout().trim();
  }
/**
   * Call shell script in pod.
   * @param scriptPath script path
   * @param arguments args
   * @param podName pod name
   * @param namespace namespace
   * @return command
   * @throws Exception on failure
   */
Call shell script in pod.
Call shell script in pod .
public static String callShellScriptByExecToPod(
      String scriptPath, String arguments, String podName, String namespace) throws Exception {
    StringBuffer cmdKubectlSh = new StringBuffer("kubectl -n ");
    cmdKubectlSh
        .append(namespace)
        .append(" exec -it ")
        .append(podName)
        .append(" -- bash -c 'chmod +x -R /shared && ")
        .append(scriptPath)
        .append(" ")
        .append(arguments)
        .append("'");
    LoggerHelper.getLocal().log(Level.INFO, "Command to call kubectl sh file " + cmdKubectlSh);
    ExecResult result = ExecCommand.exec(cmdKubectlSh.toString());
    if (result.exitValue() != 0) {
      throw new RuntimeException(
          "FAILURE: command " + cmdKubectlSh + " failed, returned " + result.stderr());
    }
    return result.stdout().trim();
  }
public static String callShellScriptByExecToPod ( String scriptPath , String arguments , String podName , String namespace ) throws Exception { StringBuffer cmdKubectlSh = new StringBuffer ( "kubectl -n " ) ; cmdKubectlSh . append ( namespace ) . append ( " exec -it " ) . append ( podName ) . append ( " -- bash -c 'chmod +x -R /shared && " ) . append ( scriptPath ) . append ( " " ) . append ( arguments ) . append ( "'" ) ; LoggerHelper . getLocal ( ) . log ( Level . INFO , "Command to call kubectl sh file " + cmdKubectlSh ) ; ExecResult result = ExecCommand . exec ( cmdKubectlSh . toString ( ) ) ; if ( result . exitValue ( ) != 0 ) { throw new RuntimeException ( "FAILURE: command " + cmdKubectlSh + " failed, returned " + result . stderr ( ) ) ; } return result . stdout ( ) . trim ( ) ; }
Call shell script in pod.
Call shell script in pod .