integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java
public static void callShellScriptByExecToPod(
      String podName, String domainNS, String scriptsLocInPod, String shScriptName,
      String[] args, int retriesToCallScript)
      throws Exception {
    StringBuffer cmdKubectlSh = new StringBuffer("kubectl -n ");
    cmdKubectlSh
        .append(domainNS)
        .append(" exec -it ")
        .append(podName)
        .append(" -- bash -c 'chmod +x -R ")
        .append(scriptsLocInPod)
        .append("  && ")
        .append(scriptsLocInPod)
        .append("/")
        .append(shScriptName)
        .append(" ")
        .append(String.join(" ", args).toString())
        .append("'");

    for (int i = 1; i <= retriesToCallScript; i++) {
      LoggerHelper.getLocal().log(Level.INFO, "Iteration " + i
          + "/" + retriesToCallScript + ", Command to call kubectl sh file " + cmdKubectlSh);
      ExecResult result = ExecCommand.exec(cmdKubectlSh.toString());
      if (result.exitValue() != 0) {
        if (i == retriesToCallScript) {
          new RuntimeException("FAILURE: Command "
              + cmdKubectlSh
              + " failed with stderr = "
              + result.stderr()
              + " \n stdout = "
              + result.stdout());
        } else {
          LoggerHelper.getLocal().log(Level.INFO, "Command failed with stdout = "
              + result.stdout() + " stderr = " + result.stderr() + ", retrying");
          Thread.sleep(10 * 1000);
        }
      } else {
        LoggerHelper.getLocal().log(Level.INFO, "Script invoked successfully, stdout = " + result.stdout());
        break;
      }
    }

  }
/**
   * exec into the pod and call the shell script with given arguments.
   *
   * @param podName         pod name
   * @param domainNS        namespace
   * @param scriptsLocInPod script location
   * @param shScriptName    script name
   * @param args            script arguments
   * @param retriesToCallScript number of retries to execute the script if it fails
   * @throws Exception exception
   */
exec into the pod and call the shell script with given arguments.
exec into the pod and call the shell script with given arguments .
public static void callShellScriptByExecToPod(
      String podName, String domainNS, String scriptsLocInPod, String shScriptName,
      String[] args, int retriesToCallScript)
      throws Exception {
    StringBuffer cmdKubectlSh = new StringBuffer("kubectl -n ");
    cmdKubectlSh
        .append(domainNS)
        .append(" exec -it ")
        .append(podName)
        .append(" -- bash -c 'chmod +x -R ")
        .append(scriptsLocInPod)
        .append("  && ")
        .append(scriptsLocInPod)
        .append("/")
        .append(shScriptName)
        .append(" ")
        .append(String.join(" ", args).toString())
        .append("'");
    for (int i = 1; i <= retriesToCallScript; i++) {
      LoggerHelper.getLocal().log(Level.INFO, "Iteration " + i
          + "/" + retriesToCallScript + ", Command to call kubectl sh file " + cmdKubectlSh);
      ExecResult result = ExecCommand.exec(cmdKubectlSh.toString());
      if (result.exitValue() != 0) {
        if (i == retriesToCallScript) {
          new RuntimeException("FAILURE: Command "
              + cmdKubectlSh
              + " failed with stderr = "
              + result.stderr()
              + " \n stdout = "
              + result.stdout());
        } else {
          LoggerHelper.getLocal().log(Level.INFO, "Command failed with stdout = "
              + result.stdout() + " stderr = " + result.stderr() + ", retrying");
          Thread.sleep(10 * 1000);
        }
      } else {
        LoggerHelper.getLocal().log(Level.INFO, "Script invoked successfully, stdout = " + result.stdout());
        break;
      }
    }
  }
public static void callShellScriptByExecToPod ( String podName , String domainNS , String scriptsLocInPod , String shScriptName , String [ ] args , int retriesToCallScript ) throws Exception { StringBuffer cmdKubectlSh = new StringBuffer ( "kubectl -n " ) ; cmdKubectlSh . append ( domainNS ) . append ( " exec -it " ) . append ( podName ) . append ( " -- bash -c 'chmod +x -R " ) . append ( scriptsLocInPod ) . append ( "  && " ) . append ( scriptsLocInPod ) . append ( "/" ) . append ( shScriptName ) . append ( " " ) . append ( String . join ( " " , args ) . toString ( ) ) . append ( "'" ) ; for ( int i = 1 ; i <= retriesToCallScript ; i ++ ) { LoggerHelper . getLocal ( ) . log ( Level . INFO , "Iteration " + i + "/" + retriesToCallScript + ", Command to call kubectl sh file " + cmdKubectlSh ) ; ExecResult result = ExecCommand . exec ( cmdKubectlSh . toString ( ) ) ; if ( result . exitValue ( ) != 0 ) { if ( i == retriesToCallScript ) { new RuntimeException ( "FAILURE: Command " + cmdKubectlSh + " failed with stderr = " + result . stderr ( ) + " \n stdout = " + result . stdout ( ) ) ; } else { LoggerHelper . getLocal ( ) . log ( Level . INFO , "Command failed with stdout = " + result . stdout ( ) + " stderr = " + result . stderr ( ) + ", retrying" ) ; Thread . sleep ( 10 * 1000 ) ; } } else { LoggerHelper . getLocal ( ) . log ( Level . INFO , "Script invoked successfully, stdout = " + result . stdout ( ) ) ; break ; } } }
exec into the pod and call the shell script with given arguments.
exec into the pod and call the shell script with given arguments .