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:36 UTC
[camel-karavan] 01/02: kube command
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!"}
+ }
+}