mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
feature(kubeconfig): access to all kube environment contexts from within the Portainer UI [EE-1727] (#5966)
This commit is contained in:
parent
c0a4727114
commit
6be1ff4d9c
22 changed files with 404 additions and 434 deletions
|
@ -1,45 +0,0 @@
|
|||
export default class KubeConfigController {
|
||||
/* @ngInject */
|
||||
constructor($async, $window, KubernetesConfigService, SettingsService) {
|
||||
this.$async = $async;
|
||||
this.$window = $window;
|
||||
this.KubernetesConfigService = KubernetesConfigService;
|
||||
this.SettingsService = SettingsService;
|
||||
}
|
||||
|
||||
async downloadKubeconfig() {
|
||||
await this.KubernetesConfigService.downloadConfig();
|
||||
}
|
||||
|
||||
async expiryHoverMessage() {
|
||||
const settings = await this.SettingsService.publicSettings();
|
||||
const expiryDays = settings.KubeconfigExpiry;
|
||||
switch (expiryDays) {
|
||||
case '0':
|
||||
this.state.expiryDays = 'not expire';
|
||||
break;
|
||||
case '24h':
|
||||
this.state.expiryDays = 'expire in 1 day';
|
||||
break;
|
||||
case '168h':
|
||||
this.state.expiryDays = 'expire in 7 days';
|
||||
break;
|
||||
case '720h':
|
||||
this.state.expiryDays = 'expire in 30 days';
|
||||
break;
|
||||
case '8640h':
|
||||
this.state.expiryDays = 'expire in 1 year';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
return this.$async(async () => {
|
||||
this.state = {
|
||||
isHTTPS: this.$window.location.protocol === 'https:',
|
||||
expiryDays: '',
|
||||
};
|
||||
await this.expiryHoverMessage();
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
<span
|
||||
class="interactive"
|
||||
tooltip-append-to-body="true"
|
||||
tooltip-placement="bottom"
|
||||
tooltip-class="portainer-tooltip"
|
||||
uib-tooltip="Kubeconfig file will {{ $ctrl.state.expiryDays }}"
|
||||
>
|
||||
<button
|
||||
ng-if="$ctrl.state.isHTTPS"
|
||||
type="button"
|
||||
class="btn btn-xs btn-primary"
|
||||
ng-click="$ctrl.downloadKubeconfig()"
|
||||
analytics-on
|
||||
analytics-category="kubernetes"
|
||||
analytics-event="kubernetes-kubectl-kubeconfig"
|
||||
>
|
||||
Kubeconfig <i class="fas fa-download space-right"></i>
|
||||
</button>
|
||||
</span>
|
|
@ -1,7 +0,0 @@
|
|||
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,
|
||||
});
|
|
@ -11,8 +11,6 @@
|
|||
<i class="fa fa-terminal space-right"></i> kubectl shell
|
||||
</button>
|
||||
|
||||
<kube-config-download-button></kube-config-download-button>
|
||||
|
||||
<div ng-if="$ctrl.state.shell.connected" class="{{ $ctrl.state.css }}-kubectl-shell">
|
||||
<div class="shell-container">
|
||||
<div class="shell-item"><i class="fas fa-terminal" style="margin-right: 5px;"></i>kubectl shell</div>
|
||||
|
|
|
@ -6,11 +6,11 @@ angular.module('portainer.kubernetes').factory('KubernetesConfig', KubernetesCon
|
|||
function KubernetesConfigFactory($http, EndpointProvider, API_ENDPOINT_KUBERNETES) {
|
||||
return { get };
|
||||
|
||||
async function get() {
|
||||
const endpointID = EndpointProvider.endpointID();
|
||||
async function get(environmentIDs) {
|
||||
return $http({
|
||||
method: 'GET',
|
||||
url: `${API_ENDPOINT_KUBERNETES}/${endpointID}/config`,
|
||||
url: `${API_ENDPOINT_KUBERNETES}/config`,
|
||||
params: { ids: environmentIDs.map((x) => parseInt(x)) },
|
||||
responseType: 'blob',
|
||||
headers: {
|
||||
Accept: 'text/yaml',
|
||||
|
|
|
@ -2,18 +2,38 @@ import angular from 'angular';
|
|||
|
||||
class KubernetesConfigService {
|
||||
/* @ngInject */
|
||||
constructor(KubernetesConfig, FileSaver) {
|
||||
constructor(KubernetesConfig, FileSaver, SettingsService) {
|
||||
this.KubernetesConfig = KubernetesConfig;
|
||||
this.FileSaver = FileSaver;
|
||||
this.SettingsService = SettingsService;
|
||||
}
|
||||
|
||||
async downloadConfig() {
|
||||
const response = await this.KubernetesConfig.get();
|
||||
async downloadKubeconfigFile(environmentIDs) {
|
||||
const response = await this.KubernetesConfig.get(environmentIDs);
|
||||
const headers = response.headers();
|
||||
const contentDispositionHeader = headers['content-disposition'];
|
||||
const filename = contentDispositionHeader.replace('attachment;', '').trim();
|
||||
return this.FileSaver.saveAs(response.data, filename);
|
||||
}
|
||||
|
||||
async expiryMessage() {
|
||||
const settings = await this.SettingsService.publicSettings();
|
||||
const expiryDays = settings.KubeconfigExpiry;
|
||||
const prefix = 'Kubeconfig file will ';
|
||||
switch (expiryDays) {
|
||||
case '0':
|
||||
return prefix + 'not expire.';
|
||||
case '24h':
|
||||
return prefix + 'expire in 1 day.';
|
||||
case '168h':
|
||||
return prefix + 'expire in 7 days.';
|
||||
case '720h':
|
||||
return prefix + 'expire in 30 days.';
|
||||
case '8640h':
|
||||
return prefix + 'expire in 1 year.';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
export default KubernetesConfigService;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue