1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

feat(kubernetes): edit yaml support EE-2855 (#8016)

This commit is contained in:
Prabhat Khera 2022-11-22 09:40:44 +13:00 committed by GitHub
parent 7006c17ce4
commit 0f0513c684
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 195 additions and 0 deletions

View file

@ -21,5 +21,7 @@
<span id="copyNotificationYAML" style="display: none" class="small vertical-center ml-1">
<pr-icon class="vertical-center" icon="'check'" size="'md'" mode="'success'" feather="true"></pr-icon> copied
</span>
<yaml-replace class="float-right" feature-id="$ctrl.limitedFeature"></yaml-replace>
</div>
</div>

View file

@ -1,4 +1,6 @@
import angular from 'angular';
import YAML from 'yaml';
import { FeatureId } from '@/react/portainer/feature-flags/enums';
class KubernetesYamlInspectorController {
/* @ngInject */
@ -8,6 +10,23 @@ class KubernetesYamlInspectorController {
this.expanded = false;
}
cleanYamlUnwantedFields(yml) {
try {
const ymls = yml.split('---');
const cleanYmls = ymls.map((yml) => {
const y = YAML.parse(yml);
if (y.metadata) {
delete y.metadata.managedFields;
delete y.metadata.resourceVersion;
}
return YAML.stringify(y);
});
return cleanYmls.join('---\n');
} catch (e) {
return yml;
}
}
copyYAML() {
this.clipboard.copyText(this.data);
$('#copyNotificationYAML').show().fadeOut(2500);
@ -19,6 +38,11 @@ class KubernetesYamlInspectorController {
$(selector).css({ height: height });
this.expanded = !this.expanded;
}
$onInit() {
this.data = this.cleanYamlUnwantedFields(this.data);
this.limitedFeature = FeatureId.K8S_EDIT_YAML;
}
}
export default KubernetesYamlInspectorController;

View file

@ -4,6 +4,7 @@ import { r2a } from '@/react-tools/react2angular';
import { withCurrentUser } from '@/react-tools/withCurrentUser';
import { withReactQuery } from '@/react-tools/withReactQuery';
import { withUIRouter } from '@/react-tools/withUIRouter';
import { YAMLReplace } from '@/kubernetes/react/views/yamlReplace';
import { IngressesDatatableView } from '@/react/kubernetes/ingresses/IngressDatatable';
import { CreateIngressView } from '@/react/kubernetes/ingresses/CreateIngressView';
@ -19,4 +20,10 @@ export const viewsModule = angular
.component(
'kubernetesIngressesCreateView',
r2a(withUIRouter(withReactQuery(withCurrentUser(CreateIngressView))), [])
)
.component(
'yamlReplace',
r2a(withUIRouter(withReactQuery(withCurrentUser(YAMLReplace))), [
'featureId',
])
).name;

View file

@ -0,0 +1,28 @@
import { FeatureId } from '@/react/portainer/feature-flags/enums';
import { Button } from '@@/buttons';
import { TooltipWithChildren } from '@@/Tip/TooltipWithChildren';
interface Props {
featureId: FeatureId;
}
export function YAMLReplace({ featureId }: Props) {
return (
<TooltipWithChildren
className="float-right"
heading="Apply YAML changes"
BEFeatureID={featureId}
message="Applies any changes that you make in the YAML editor by calling the Kubernetes API to patch the relevant resources. Any resource removals or unexpected resource additions that you make in the YAML will be ignored. Note that editing is disabled for resources in namespaces marked as system."
>
<Button
type="button"
color="warninglight"
size="small"
onClick={() => {}}
disabled
>
Apply changes
</Button>
</TooltipWithChildren>
);
}