From b4f4ef701aaac8b19e120309966b788da1423078 Mon Sep 17 00:00:00 2001 From: zees-dev <63374656+zees-dev@users.noreply.github.com> Date: Tue, 31 Aug 2021 10:07:50 +1200 Subject: [PATCH] feat(kubeconfig): kubeconfig download functionality EE-1202 (#5386) * backend migration/backport * Feat(kubeconfig): kubeconfig download button frontend EE-1202 (#5385) * kubeconfig download button frontend * fix kubeconfig download button * backend migration/backport * moved ng-if up one level Co-authored-by: zees-dev * resolved conflicts, updated code * - kube-config -> kube-config-download-button - fixed kubeconfig file name (bug) Co-authored-by: Richard Wei <54336863+WaysonWei@users.noreply.github.com> --- .../handler/endpointproxy/proxy_kubernetes.go | 2 +- api/portainer.go | 2 +- .../kube-config-download-button.controller.js | 15 +++++++++++++++ .../kube-config-download-button.html | 11 +++++++++++ .../kube-config-download-button.js | 7 +++++++ .../kubectl-shell/kubectl-shell.controller.js | 10 ++-------- .../components/kubectl-shell/kubectl-shell.html | 8 +++----- app/kubernetes/services/kubeconfigService.js | 1 - 8 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 app/kubernetes/components/kube-config-download-button/kube-config-download-button.controller.js create mode 100644 app/kubernetes/components/kube-config-download-button/kube-config-download-button.html create mode 100644 app/kubernetes/components/kube-config-download-button/kube-config-download-button.js diff --git a/api/http/handler/endpointproxy/proxy_kubernetes.go b/api/http/handler/endpointproxy/proxy_kubernetes.go index 88a369486..82d922ca1 100644 --- a/api/http/handler/endpointproxy/proxy_kubernetes.go +++ b/api/http/handler/endpointproxy/proxy_kubernetes.go @@ -79,4 +79,4 @@ func (handler *Handler) proxyRequestsToKubernetesAPI(w http.ResponseWriter, r *h http.StripPrefix(requestPrefix, proxy).ServeHTTP(w, r) return nil -} \ No newline at end of file +} diff --git a/api/portainer.go b/api/portainer.go index aa737fe21..2bc64277f 100644 --- a/api/portainer.go +++ b/api/portainer.go @@ -1214,8 +1214,8 @@ type ( // KubeClient represents a service used to query a Kubernetes environment KubeClient interface { - GetServiceAccount(tokendata *TokenData) (*v1.ServiceAccount, error) SetupUserServiceAccount(userID int, teamIDs []int, restrictDefaultNamespace bool) error + GetServiceAccount(tokendata *TokenData) (*v1.ServiceAccount, error) GetServiceAccountBearerToken(userID int) (string, error) CreateUserShellPod(ctx context.Context, serviceAccountName string) (*KubernetesShellPod, error) StartExecProcess(token string, useAdminToken bool, namespace, podName, containerName string, command []string, stdin io.Reader, stdout io.Writer) error diff --git a/app/kubernetes/components/kube-config-download-button/kube-config-download-button.controller.js b/app/kubernetes/components/kube-config-download-button/kube-config-download-button.controller.js new file mode 100644 index 000000000..643dcefa0 --- /dev/null +++ b/app/kubernetes/components/kube-config-download-button/kube-config-download-button.controller.js @@ -0,0 +1,15 @@ +export default class KubeConfigController { + /* @ngInject */ + constructor($window, KubernetesConfigService) { + this.$window = $window; + this.KubernetesConfigService = KubernetesConfigService; + } + + async downloadKubeconfig() { + await this.KubernetesConfigService.downloadConfig(); + } + + $onInit() { + this.state = { isHTTPS: this.$window.location.protocol === 'https:' }; + } +} diff --git a/app/kubernetes/components/kube-config-download-button/kube-config-download-button.html b/app/kubernetes/components/kube-config-download-button/kube-config-download-button.html new file mode 100644 index 000000000..b2bae2cdf --- /dev/null +++ b/app/kubernetes/components/kube-config-download-button/kube-config-download-button.html @@ -0,0 +1,11 @@ + diff --git a/app/kubernetes/components/kube-config-download-button/kube-config-download-button.js b/app/kubernetes/components/kube-config-download-button/kube-config-download-button.js new file mode 100644 index 000000000..1732e50f2 --- /dev/null +++ b/app/kubernetes/components/kube-config-download-button/kube-config-download-button.js @@ -0,0 +1,7 @@ +import angular from 'angular'; +import controller from './kube-config-download-button.controller'; + +angular.module('portainer.kubernetes').component('kubeConfigDownloadButton', { + templateUrl: './kube-config-download-button.html', + controller, +}); diff --git a/app/kubernetes/components/kubectl-shell/kubectl-shell.controller.js b/app/kubernetes/components/kubectl-shell/kubectl-shell.controller.js index 6fa2a5f58..d60ae0b36 100644 --- a/app/kubernetes/components/kubectl-shell/kubectl-shell.controller.js +++ b/app/kubernetes/components/kubectl-shell/kubectl-shell.controller.js @@ -3,13 +3,12 @@ import * as fit from 'xterm/lib/addons/fit/fit'; export default class KubectlShellController { /* @ngInject */ - constructor(TerminalWindow, $window, $async, EndpointProvider, LocalStorage, KubernetesConfigService, Notifications) { + constructor(TerminalWindow, $window, $async, EndpointProvider, LocalStorage, Notifications) { this.$async = $async; this.$window = $window; this.TerminalWindow = TerminalWindow; this.EndpointProvider = EndpointProvider; this.LocalStorage = LocalStorage; - this.KubernetesConfigService = KubernetesConfigService; this.Notifications = Notifications; } @@ -83,7 +82,7 @@ export default class KubectlShellController { endpointId: this.EndpointProvider.endpointID(), }; - const wsProtocol = this.state.isHTTPS ? 'wss://' : 'ws://'; + const wsProtocol = this.$window.location.protocol === 'https:' ? 'wss://' : 'ws://'; const path = '/api/websocket/kubernetes-shell'; const queryParams = Object.entries(params) .map(([k, v]) => `${k}=${v}`) @@ -97,17 +96,12 @@ export default class KubectlShellController { this.configureSocketAndTerminal(this.state.shell.socket, this.state.shell.term); } - async downloadKubeconfig() { - await this.KubernetesConfigService.downloadConfig(); - } - $onInit() { return this.$async(async () => { this.state = { css: 'normal', checked: false, icon: 'fa-window-minimize', - isHTTPS: this.$window.location.protocol === 'https:', shell: { connected: false, socket: null, diff --git a/app/kubernetes/components/kubectl-shell/kubectl-shell.html b/app/kubernetes/components/kubectl-shell/kubectl-shell.html index a88209326..76dae9afe 100644 --- a/app/kubernetes/components/kubectl-shell/kubectl-shell.html +++ b/app/kubernetes/components/kubectl-shell/kubectl-shell.html @@ -1,14 +1,12 @@ + +
kubectl shell
-