mirror of
https://github.com/portainer/portainer.git
synced 2025-07-29 10:19:41 +02:00
feat(kubernetes/summary): summary of k8s actions upon deploying/updating resources EE-436 (#5137)
* feat EE-440/EE-436 kubernetes-resources-summary-panel * bugfix: returning created resources after update * fixed patch based bugs - displaying accurate updates for k8s resources Co-authored-by: Simon Meng <simon.meng@portainer.io>
This commit is contained in:
parent
267968e099
commit
eae2f5c9fc
16 changed files with 539 additions and 7 deletions
89
app/kubernetes/views/summary/summaryController.js
Normal file
89
app/kubernetes/views/summary/summaryController.js
Normal file
|
@ -0,0 +1,89 @@
|
|||
import angular from 'angular';
|
||||
import { KubernetesConfigurationFormValues } from 'Kubernetes/models/configuration/formvalues';
|
||||
import { KubernetesResourcePoolFormValues } from 'Kubernetes/models/resource-pool/formValues';
|
||||
import { KubernetesApplicationFormValues } from 'Kubernetes/models/application/formValues';
|
||||
import { KubernetesResourceActions, KubernetesResourceTypes } from 'Kubernetes/models/resource-types/models';
|
||||
import getApplicationResources from './resources/applicationResources';
|
||||
import getNamespaceResources from './resources/namespaceResources';
|
||||
import getConfigurationResources from './resources/configurationResources';
|
||||
|
||||
class KubernetesSummaryController {
|
||||
/* @ngInject */
|
||||
constructor($scope, LocalStorage, KubernetesResourcePoolService) {
|
||||
this.LocalStorage = LocalStorage;
|
||||
this.KubernetesResourcePoolService = KubernetesResourcePoolService;
|
||||
|
||||
this.toggleSummary = this.toggleSummary.bind(this);
|
||||
this.generateResourceSummaryList = this.generateResourceSummaryList.bind(this);
|
||||
|
||||
// Deep-watch changes on formValues property
|
||||
$scope.$watch(
|
||||
'$ctrl.formValues',
|
||||
(formValues) => {
|
||||
this.state.resources = this.generateResourceSummaryList(formValues);
|
||||
},
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
getArticle(resourceType, resourceAction) {
|
||||
let article = 'a';
|
||||
if (resourceAction === KubernetesResourceActions.CREATE) {
|
||||
if (resourceType === KubernetesResourceTypes.INGRESS) {
|
||||
article = 'an';
|
||||
}
|
||||
} else {
|
||||
article = 'the';
|
||||
}
|
||||
|
||||
return article;
|
||||
}
|
||||
|
||||
/**
|
||||
* toggleSummary toggles the summary panel state and persists it to browser localstorage
|
||||
*/
|
||||
toggleSummary() {
|
||||
this.state.expandedTemplate = !this.state.expandedTemplate;
|
||||
this.LocalStorage.storeKubernetesSummaryToggle(this.state.expandedTemplate);
|
||||
}
|
||||
|
||||
/**
|
||||
* generateResourceSummaryList maps formValues to custom object
|
||||
* @param {object} formValues
|
||||
* @returns {object} => { action: "string", kind: "string", name: "string" }
|
||||
*/
|
||||
generateResourceSummaryList(formValues) {
|
||||
const oldFormValues = this.oldFormValues;
|
||||
|
||||
if (formValues instanceof KubernetesConfigurationFormValues) {
|
||||
// Configuration
|
||||
return getConfigurationResources(formValues);
|
||||
} else if (formValues instanceof KubernetesResourcePoolFormValues) {
|
||||
// Namespaces
|
||||
return getNamespaceResources(formValues, oldFormValues);
|
||||
} else if (formValues instanceof KubernetesApplicationFormValues) {
|
||||
// Applications
|
||||
|
||||
// extract cpu and memory requests & limits for pod
|
||||
this.state.limits = { cpu: formValues.CpuLimit, memory: formValues.MemoryLimit };
|
||||
|
||||
return getApplicationResources(formValues, oldFormValues);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
const toggleValue = this.LocalStorage.getKubernetesSummaryToggle();
|
||||
const expanded = typeof toggleValue === 'boolean' ? toggleValue : true;
|
||||
|
||||
this.state = {
|
||||
expandedTemplate: expanded,
|
||||
resources: [],
|
||||
limits: { cpu: null, memory: null },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default KubernetesSummaryController;
|
||||
angular.module('portainer.kubernetes').controller('KubernetesSummaryController', KubernetesSummaryController);
|
Loading…
Add table
Add a link
Reference in a new issue