You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2022/10/20 22:35:35 UTC

[camel-karavan] branch main updated (6b1643e -> d915c2a)

This is an automated email from the ASF dual-hosted git repository.

marat pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git


    from 6b1643e  Fix label for openshift
     new daa53fe  kube command
     new d915c2a  Openshift client

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 karavan-vscode/package.json                       |  3 +-
 karavan-vscode/{webview/vscode.ts => src/exec.ts} | 16 ++++++--
 karavan-vscode/src/extension.ts                   |  1 -
 karavan-vscode/src/jbang.ts                       | 49 ++++++++++-------------
 4 files changed, 36 insertions(+), 33 deletions(-)
 copy karavan-vscode/{webview/vscode.ts => src/exec.ts} (66%)


[camel-karavan] 02/02: Openshift client

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git

commit d915c2a73a927831e9bf1c2e55c085bbdf683f3a
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Thu Oct 20 18:35:25 2022 -0400

    Openshift client
---
 karavan-vscode/package.json                   |  1 +
 karavan-vscode/src/{kubernetes.ts => exec.ts} | 32 +++-------------
 karavan-vscode/src/jbang.ts                   | 53 +++++++++++----------------
 3 files changed, 29 insertions(+), 57 deletions(-)

diff --git a/karavan-vscode/package.json b/karavan-vscode/package.json
index 9058b3b..8417946 100644
--- a/karavan-vscode/package.json
+++ b/karavan-vscode/package.json
@@ -499,6 +499,7 @@
     "mocha": "^10.0.0",
     "prettier": "2.3.0",
     "run-script-os": "^1.1.6",
+    "@types/shelljs": "^0.8.10",
     "static-site-generator-webpack-plugin": "^3.4.2",
     "style-loader": "^2.0.0",
     "ts-loader": "^8.0.14",
diff --git a/karavan-vscode/src/kubernetes.ts b/karavan-vscode/src/exec.ts
similarity index 50%
rename from karavan-vscode/src/kubernetes.ts
rename to karavan-vscode/src/exec.ts
index 6089d3d..7034981 100644
--- a/karavan-vscode/src/kubernetes.ts
+++ b/karavan-vscode/src/exec.ts
@@ -14,10 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import { workspace, window, Terminal, ThemeIcon } from "vscode";
-import * as path from "path";
 import * as shell from 'shelljs';
-import * as utils from "./utils";
 
 export interface Result {
     result: boolean
@@ -25,26 +22,9 @@ export interface Result {
     error: string
 }
 
-export function hasOcClient(): boolean {
-    const oc = shell.which('oc');
-    return oc !== undefined;
-}
-
-export function getOcUser(): Result {
-    const oc = shell.which('oc');
-    if (oc) {
-        shell.config.execPath = String(oc);
-
-        shell.exec('oc whoami', {silent:true}, function(code, stdout, stderr) {
-            console.log('Exit code:', code);
-            console.log('Program output:', stdout);
-            console.log('Program stderr:', stderr);
-          });
-
-          const { stdout, stderr, code } = shell.exec("oc whoami",  {silent:true});
-        console.log(stdout, stderr, code);
-        return {result: code === 0, value: stdout, error: stderr};
-    } else {
-        return {result: false, value: undefined, error: "Openshift client not found!"}
-    }
-}
+export function execCommand(cmd: string, execPath?: string): Promise<Result> {
+    return new Promise<Result>((resolve) => {
+        if (execPath) shell.cd(execPath);
+        shell.exec(cmd, (code, stdout, stderr) => resolve({ result: code === 0, value: stdout, error: stderr }));
+    });
+}
\ No newline at end of file
diff --git a/karavan-vscode/src/jbang.ts b/karavan-vscode/src/jbang.ts
index 1a48f17..b54183c 100644
--- a/karavan-vscode/src/jbang.ts
+++ b/karavan-vscode/src/jbang.ts
@@ -19,7 +19,7 @@ import * as path from "path";
 import * as shell from 'shelljs';
 import { CamelDefinitionYaml } from "core/api/CamelDefinitionYaml";
 import * as utils from "./utils";
-import * as kubernetes from "./kubernetes";
+import * as exec from "./exec";
 
 const TERMINALS: Map<string, Terminal> = new Map<string, Terminal>();
 
@@ -114,25 +114,20 @@ export function createExportCommand(directory: string) {
 
 export function camelDeploy(directory: string) {
     const command = createExportCommand(directory).concat(" && ").concat(createPackageCommand(directory));
-    const user = kubernetes.getOcUser();
-    console.log("user", user);
-    
-
-    // utils.readFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
-    //     .then((readData: Uint8Array) => {
-    //         const namespace = Buffer.from(readData).toString('utf8');
-    //         utils.readFile("/var/run/secrets/kubernetes.io/serviceaccount/token")
-    //             .then((readData: Uint8Array) => {
-    //                 const token = Buffer.from(readData).toString('utf8');
-    //                 const env = { "TOKEN":token, "NAMESPACE": namespace, "DATE":  Date.now().toString() };
-    //                 camelRunDeploy(command, env);
-                    
-    //             }).catch((reason: any) => {
-    //                 window.showErrorMessage("Token file not found. Set TOKEN environment variable!\n" + reason.message);
-    //             });
-    //     }).catch((reason: any) => {
-    //         window.showErrorMessage("Namespace file not found. Set NAMESPACE environment variable!\n" + reason.message);
-    //     });
+    Promise.all([
+        exec.execCommand("oc whoami"), // get user
+        exec.execCommand("oc whoami --show-token"), // get token
+        exec.execCommand("oc project -q") // get namespace 
+    ]).then(val => {
+        let env: any = { "DATE": Date.now().toString() };
+        if (val[0].result) env.USER = val[0].value;
+        if (val[1].result) env.TOKEN = val[1].value;
+        if (val[2].result) env.NAMESPACE = val[2].value;
+        console.log("env", env);
+        camelRunDeploy(command, env);
+    }).catch((reason: any) => {
+        window.showErrorMessage("Error: \n" + reason.message);
+    });
 }
 
 export function camelRunDeploy(command: string, env?: { [key: string]: string | null | undefined }) {
@@ -150,22 +145,18 @@ export function createPackageCommand(directory: string) {
 }
 
 function executeJbangCommand(rootPath: string, command: string, callback: (code: number, stdout: any, stderr: any) => any) {
-    console.log("excute command", command)
+    console.log("excute command", command);
     const jbang = shell.which('jbang');
     if (jbang) {
-        shell.config.execPath = String(jbang);
-        shell.cd(rootPath);
-        shell.exec(command, { async: false }, (code, stdout, stderr) => {
-            if (code === 0) {
-                // vscode.window.showInformationMessage(stdout);
-            } else {
-                window.showErrorMessage(stderr);
-            }
-            callback(code, stdout, stderr);
+        exec.execCommand(command, rootPath).then(res => {
+            if (res.result) callback(0, res.value, res.error)
+            else window.showErrorMessage(res.error);
+        }).catch(error => {
+            window.showErrorMessage(error);
         });
     } else {
         window.showErrorMessage("JBang not found!");
-    }
+    }    
 }
 
 function setMinikubeEnvVariables(env: string): Map<string, string> {


[camel-karavan] 01/02: kube command

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git

commit daa53feec235304ce7e9142691f326982bfd7924
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Thu Oct 20 17:35:09 2022 -0400

    kube command
---
 karavan-vscode/package.json      |  2 +-
 karavan-vscode/src/extension.ts  |  1 -
 karavan-vscode/src/jbang.ts      | 34 +++++++++++++++------------
 karavan-vscode/src/kubernetes.ts | 50 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 70 insertions(+), 17 deletions(-)

diff --git a/karavan-vscode/package.json b/karavan-vscode/package.json
index ba2204c..9058b3b 100644
--- a/karavan-vscode/package.json
+++ b/karavan-vscode/package.json
@@ -194,7 +194,7 @@
             "quarkus.container-image.push=true",
             "quarkus.container-image.registry=image-registry.openshift-image-registry.svc:5000",
             "quarkus.container-image.insecure=true",
-            "quarkus.container-image.username=sa",
+            "quarkus.container-image.username=${USER}",
             "quarkus.container-image.password=${TOKEN}",
             "quarkus.container-image.tag=${DATE}"
           ],
diff --git a/karavan-vscode/src/extension.ts b/karavan-vscode/src/extension.ts
index 8b54520..b879273 100644
--- a/karavan-vscode/src/extension.ts
+++ b/karavan-vscode/src/extension.ts
@@ -22,7 +22,6 @@ import { selectFileName, inputFileName, OpenApiView, OpenApiItem } from "./opena
 import * as path from "path";
 import * as jbang from "./jbang";
 import * as utils from "./utils";
-import * as fs from "fs";
 
 const KARAVAN_LOADED = "karavan:loaded";
 
diff --git a/karavan-vscode/src/jbang.ts b/karavan-vscode/src/jbang.ts
index c9e3c02..1a48f17 100644
--- a/karavan-vscode/src/jbang.ts
+++ b/karavan-vscode/src/jbang.ts
@@ -19,6 +19,7 @@ import * as path from "path";
 import * as shell from 'shelljs';
 import { CamelDefinitionYaml } from "core/api/CamelDefinitionYaml";
 import * as utils from "./utils";
+import * as kubernetes from "./kubernetes";
 
 const TERMINALS: Map<string, Terminal> = new Map<string, Terminal>();
 
@@ -113,22 +114,25 @@ export function createExportCommand(directory: string) {
 
 export function camelDeploy(directory: string) {
     const command = createExportCommand(directory).concat(" && ").concat(createPackageCommand(directory));
-
-    utils.readFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
-        .then((readData: Uint8Array) => {
-            const namespace = Buffer.from(readData).toString('utf8');
-            utils.readFile("/var/run/secrets/kubernetes.io/serviceaccount/token")
-                .then((readData: Uint8Array) => {
-                    const token = Buffer.from(readData).toString('utf8');
-                    const env = { "TOKEN":token, "NAMESPACE": namespace, "DATE":  Date.now().toString() };
-                    camelRunDeploy(command, env);
+    const user = kubernetes.getOcUser();
+    console.log("user", user);
+    
+
+    // utils.readFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace")
+    //     .then((readData: Uint8Array) => {
+    //         const namespace = Buffer.from(readData).toString('utf8');
+    //         utils.readFile("/var/run/secrets/kubernetes.io/serviceaccount/token")
+    //             .then((readData: Uint8Array) => {
+    //                 const token = Buffer.from(readData).toString('utf8');
+    //                 const env = { "TOKEN":token, "NAMESPACE": namespace, "DATE":  Date.now().toString() };
+    //                 camelRunDeploy(command, env);
                     
-                }).catch((reason: any) => {
-                    window.showErrorMessage("Token file not found. Set TOKEN environment variable!\n" + reason.message);
-                });
-        }).catch((reason: any) => {
-            window.showErrorMessage("Namespace file not found. Set NAMESPACE environment variable!\n" + reason.message);
-        });
+    //             }).catch((reason: any) => {
+    //                 window.showErrorMessage("Token file not found. Set TOKEN environment variable!\n" + reason.message);
+    //             });
+    //     }).catch((reason: any) => {
+    //         window.showErrorMessage("Namespace file not found. Set NAMESPACE environment variable!\n" + reason.message);
+    //     });
 }
 
 export function camelRunDeploy(command: string, env?: { [key: string]: string | null | undefined }) {
diff --git a/karavan-vscode/src/kubernetes.ts b/karavan-vscode/src/kubernetes.ts
new file mode 100644
index 0000000..6089d3d
--- /dev/null
+++ b/karavan-vscode/src/kubernetes.ts
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import { workspace, window, Terminal, ThemeIcon } from "vscode";
+import * as path from "path";
+import * as shell from 'shelljs';
+import * as utils from "./utils";
+
+export interface Result {
+    result: boolean
+    value: any
+    error: string
+}
+
+export function hasOcClient(): boolean {
+    const oc = shell.which('oc');
+    return oc !== undefined;
+}
+
+export function getOcUser(): Result {
+    const oc = shell.which('oc');
+    if (oc) {
+        shell.config.execPath = String(oc);
+
+        shell.exec('oc whoami', {silent:true}, function(code, stdout, stderr) {
+            console.log('Exit code:', code);
+            console.log('Program output:', stdout);
+            console.log('Program stderr:', stderr);
+          });
+
+          const { stdout, stderr, code } = shell.exec("oc whoami",  {silent:true});
+        console.log(stdout, stderr, code);
+        return {result: code === 0, value: stdout, error: stderr};
+    } else {
+        return {result: false, value: undefined, error: "Openshift client not found!"}
+    }
+}