@dovetail-v2/refine 0.0.2 → 0.0.3-0.beta-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{MonacoYamlDiffEditor.a7832cec.js → MonacoYamlDiffEditor-7505595f.js} +5 -4
- package/dist/assets/{yaml.worker.bb17811d.js → yaml.worker-5e5f190c.js} +2153 -992
- package/dist/index-d02782c8.js +19445 -0
- package/dist/refine.js +119 -13
- package/dist/refine.umd.cjs +13392 -3776
- package/dist/style.css +1221 -32362
- package/lib/src/App.d.ts +0 -3
- package/lib/src/App.js +91 -0
- package/lib/src/Dovetail.d.ts +8 -4
- package/lib/src/Dovetail.js +45 -0
- package/lib/src/components/Breadcrumb/index.js +20 -0
- package/lib/src/components/ConditionsTable/ConditionsTable.js +56 -0
- package/lib/src/components/ConditionsTable/index.js +1 -0
- package/lib/src/components/CreateButton/index.js +10 -0
- package/lib/src/components/CronJobDropdown/index.d.ts +2 -2
- package/lib/src/components/CronJobDropdown/index.js +26 -0
- package/lib/src/components/CronjobJobsTable/index.js +49 -0
- package/lib/src/components/DeleteButton/index.js +13 -0
- package/lib/src/components/DeleteManyButton/index.js +16 -0
- package/lib/src/components/DrawerShow/DrawerShow.d.ts +6 -7
- package/lib/src/components/DrawerShow/DrawerShow.js +13 -0
- package/lib/src/components/DrawerShow/index.js +1 -0
- package/lib/src/components/EditButton/index.js +13 -0
- package/lib/src/components/EditField/index.d.ts +15 -0
- package/lib/src/components/EditField/index.js +47 -0
- package/lib/src/components/ErrorContent/index.d.ts +12 -0
- package/lib/src/components/ErrorContent/index.js +36 -0
- package/lib/src/components/EventsTable/EventsTable.d.ts +2 -0
- package/lib/src/components/EventsTable/EventsTable.js +59 -0
- package/lib/src/components/EventsTable/index.d.ts +1 -0
- package/lib/src/components/EventsTable/index.js +1 -0
- package/lib/src/components/Form/KeyValueListWidget.js +56 -0
- package/lib/src/components/Form/MetadataForm.js +9 -0
- package/lib/src/components/Form/NameInputWidget.js +50 -0
- package/lib/src/components/Form/NamespaceSelectWidget.js +21 -0
- package/lib/src/components/Form/index.js +4 -0
- package/lib/src/components/Form/widget.js +1 -0
- package/lib/src/components/FormErrorAlert/index.d.ts +8 -0
- package/lib/src/components/FormErrorAlert/index.js +8 -0
- package/lib/src/components/FormLayout/index.d.ts +5 -1
- package/lib/src/components/FormLayout/index.js +21 -0
- package/lib/src/components/FormModal/index.d.ts +10 -0
- package/lib/src/components/FormModal/index.js +51 -0
- package/lib/src/components/ImageNames/index.js +14 -0
- package/lib/src/components/IngressRulesComponent/index.d.ts +5 -0
- package/lib/src/components/IngressRulesComponent/index.js +11 -0
- package/lib/src/components/IngressRulesTable/IngressRulesTable.d.ts +7 -0
- package/lib/src/components/IngressRulesTable/IngressRulesTable.js +51 -0
- package/lib/src/components/IngressRulesTable/index.d.ts +1 -0
- package/lib/src/components/IngressRulesTable/index.js +1 -0
- package/lib/src/components/K8sDropdown/index.d.ts +2 -2
- package/lib/src/components/K8sDropdown/index.js +31 -0
- package/lib/src/components/KeyValue/KeyValue.js +27 -0
- package/lib/src/components/KeyValue/index.js +1 -0
- package/lib/src/components/KeyValueData/index.d.ts +6 -0
- package/lib/src/components/KeyValueData/index.js +50 -0
- package/lib/src/components/Layout/index.js +39 -0
- package/lib/src/components/ListPage/index.d.ts +3 -3
- package/lib/src/components/ListPage/index.js +25 -0
- package/lib/src/components/Menu/index.js +36 -0
- package/lib/src/components/NamespacesFilter/index.js +34 -0
- package/lib/src/components/NetworkPolicyRulesTable/NetworkPolicyRulesTable.d.ts +7 -0
- package/lib/src/components/NetworkPolicyRulesTable/NetworkPolicyRulesTable.js +77 -0
- package/lib/src/components/NetworkPolicyRulesTable/index.d.ts +1 -0
- package/lib/src/components/NetworkPolicyRulesTable/index.js +1 -0
- package/lib/src/components/PageShow/PageShow.d.ts +7 -8
- package/lib/src/components/PageShow/PageShow.js +11 -0
- package/lib/src/components/PageShow/index.js +1 -0
- package/lib/src/components/PodContainersTable/PodContainersTable.js +78 -0
- package/lib/src/components/PodContainersTable/index.js +1 -0
- package/lib/src/components/PodLog/index.d.ts +6 -0
- package/lib/src/components/PodLog/index.js +136 -0
- package/lib/src/components/ReferenceLink/index.d.ts +8 -0
- package/lib/src/components/ReferenceLink/index.js +17 -0
- package/lib/src/components/ResourceCRUD/ResourceCRUD.d.ts +3 -3
- package/lib/src/components/ResourceCRUD/ResourceCRUD.js +15 -0
- package/lib/src/components/ResourceCRUD/create/index.d.ts +6 -6
- package/lib/src/components/ResourceCRUD/create/index.js +13 -0
- package/lib/src/components/ResourceCRUD/index.d.ts +3 -0
- package/lib/src/components/ResourceCRUD/index.js +4 -0
- package/lib/src/components/ResourceCRUD/list/index.d.ts +4 -5
- package/lib/src/components/ResourceCRUD/list/index.js +19 -0
- package/lib/src/components/ResourceCRUD/show/index.d.ts +6 -7
- package/lib/src/components/ResourceCRUD/show/index.js +6 -0
- package/lib/src/components/ResourceLink/index.d.ts +8 -0
- package/lib/src/components/ResourceLink/index.js +21 -0
- package/lib/src/components/ResourceUsageBar/index.d.ts +8 -0
- package/lib/src/components/ResourceUsageBar/index.js +81 -0
- package/lib/src/components/Separator/index.js +11 -0
- package/lib/src/components/ShowContent/ShowContent.d.ts +7 -8
- package/lib/src/components/ShowContent/ShowContent.js +157 -0
- package/lib/src/components/ShowContent/fields.d.ts +34 -10
- package/lib/src/components/ShowContent/fields.js +157 -0
- package/lib/src/components/ShowContent/index.js +2 -0
- package/lib/src/components/StateTag/StateTag.d.ts +3 -1
- package/lib/src/components/StateTag/StateTag.js +22 -0
- package/lib/src/components/StateTag/index.js +1 -0
- package/lib/src/components/Table/ErrorContent.js +36 -0
- package/lib/src/components/Table/TableToolBar.js +14 -0
- package/lib/src/components/Table/TableWidgets.js +28 -0
- package/lib/src/components/Table/index.d.ts +9 -4
- package/lib/src/components/Table/index.js +69 -0
- package/lib/src/components/Tags/index.d.ts +1 -1
- package/lib/src/components/Tags/index.js +22 -0
- package/lib/src/components/Time/index.js +14 -0
- package/lib/src/components/WorkloadDropdown/index.d.ts +2 -2
- package/lib/src/components/WorkloadDropdown/index.js +24 -0
- package/lib/src/components/WorkloadPodsTable/WorkloadPodsTable.d.ts +5 -2
- package/lib/src/components/WorkloadPodsTable/WorkloadPodsTable.js +39 -0
- package/lib/src/components/WorkloadPodsTable/index.js +1 -0
- package/lib/src/components/WorkloadReplicas/index.d.ts +7 -4
- package/lib/src/components/WorkloadReplicas/index.js +50 -0
- package/lib/src/components/YamlEditor/MonacoYamlDiffEditor.js +34 -0
- package/lib/src/components/YamlEditor/MonacoYamlEditor.d.ts +1 -1
- package/lib/src/components/YamlEditor/MonacoYamlEditor.js +149 -0
- package/lib/src/components/YamlEditor/YamlEditorComponent.d.ts +2 -1
- package/lib/src/components/YamlEditor/YamlEditorComponent.js +90 -0
- package/lib/src/components/YamlEditor/index.js +1 -0
- package/lib/src/components/YamlEditor/style.js +102 -0
- package/lib/src/components/YamlEditor/yaml.worker.js +1 -0
- package/lib/src/components/YamlForm/index.d.ts +14 -1
- package/lib/src/components/YamlForm/index.js +61 -0
- package/lib/src/components/index.d.ts +38 -0
- package/lib/src/components/index.js +38 -0
- package/lib/src/constants/index.d.ts +2 -0
- package/lib/src/constants/index.js +2 -0
- package/lib/src/constants/k8s.d.ts +65 -0
- package/lib/src/constants/k8s.js +203 -0
- package/lib/src/constants/state.d.ts +13 -0
- package/lib/src/constants/state.js +15 -0
- package/lib/src/contexts/component.d.ts +6 -0
- package/lib/src/contexts/component.js +3 -0
- package/lib/src/contexts/configs.d.ts +4 -0
- package/lib/src/contexts/configs.js +3 -0
- package/lib/src/contexts/global-store.d.ts +6 -0
- package/lib/src/contexts/global-store.js +3 -0
- package/lib/src/contexts/index.d.ts +3 -0
- package/lib/src/contexts/index.js +3 -0
- package/lib/src/hooks/index.d.ts +5 -0
- package/lib/src/hooks/index.js +7 -0
- package/lib/src/hooks/useDeleteModal/index.js +1 -0
- package/lib/src/hooks/useDeleteModal/useDeleteManyModal.js +31 -0
- package/lib/src/hooks/useDeleteModal/useDeleteModal.js +38 -0
- package/lib/src/hooks/useDownloadYAML.d.ts +2 -2
- package/lib/src/hooks/useDownloadYAML.js +10 -0
- package/lib/src/hooks/useEagleForm.d.ts +17 -9
- package/lib/src/hooks/useEagleForm.js +177 -0
- package/lib/src/hooks/useEagleTable/columns.d.ts +18 -14
- package/lib/src/hooks/useEagleTable/columns.js +246 -0
- package/lib/src/hooks/useEagleTable/index.d.ts +2 -52
- package/lib/src/hooks/useEagleTable/index.js +2 -0
- package/lib/src/hooks/useEagleTable/useEagleTable.d.ts +51 -0
- package/lib/src/hooks/useEagleTable/useEagleTable.js +63 -0
- package/lib/src/hooks/useEdit.js +19 -0
- package/lib/src/hooks/useGlobalStore.d.ts +3 -0
- package/lib/src/hooks/useGlobalStore.js +5 -0
- package/lib/src/hooks/useK8sYamlEditor.d.ts +5 -0
- package/lib/src/hooks/useK8sYamlEditor.js +37 -0
- package/lib/src/hooks/useOpenForm.d.ts +5 -0
- package/lib/src/hooks/useOpenForm.js +43 -0
- package/lib/src/hooks/useSchema.d.ts +9 -2
- package/lib/src/hooks/useSchema.js +37 -0
- package/lib/src/hooks/useSubmitForm.d.ts +14 -0
- package/lib/src/hooks/useSubmitForm.js +42 -0
- package/lib/src/i18n.d.ts +46 -1
- package/lib/src/i18n.js +19 -0
- package/lib/src/index.d.ts +7 -2
- package/lib/src/index.js +13 -0
- package/lib/src/locales/en-US/dovetail.json +18 -0
- package/lib/src/locales/en-US/index.d.ts +6 -0
- package/lib/src/locales/en-US/index.js +4 -0
- package/lib/src/locales/index.js +6 -0
- package/lib/src/locales/zh-CN/dovetail.json +91 -0
- package/lib/src/locales/zh-CN/index.d.ts +40 -1
- package/lib/src/locales/zh-CN/index.js +4 -0
- package/lib/src/main.d.ts +2 -0
- package/lib/src/main.js +12 -0
- package/lib/src/models/cronjob-model.d.ts +16 -0
- package/lib/src/models/cronjob-model.js +32 -0
- package/lib/src/models/daemonset-model.d.ts +14 -0
- package/lib/src/models/daemonset-model.js +17 -0
- package/lib/src/models/deployment-model.d.ts +14 -0
- package/lib/src/models/deployment-model.js +17 -0
- package/lib/src/models/event-model.d.ts +8 -0
- package/lib/src/models/event-model.js +11 -0
- package/lib/src/models/index.d.ts +14 -0
- package/lib/src/models/index.js +14 -0
- package/lib/src/models/ingress-model.d.ts +18 -0
- package/lib/src/models/ingress-model.js +24 -0
- package/lib/src/models/job-model.d.ts +19 -0
- package/lib/src/models/job-model.js +56 -0
- package/lib/src/models/network-policy-model.d.ts +10 -0
- package/lib/src/models/network-policy-model.js +10 -0
- package/lib/src/models/pod-metrics-model.d.ts +9 -0
- package/lib/src/models/pod-metrics-model.js +34 -0
- package/lib/src/models/pod-model.d.ts +21 -0
- package/lib/src/models/pod-model.js +78 -0
- package/lib/src/models/resource-model.d.ts +21 -0
- package/lib/src/models/resource-model.js +34 -0
- package/lib/src/models/service-model.d.ts +10 -0
- package/lib/src/models/service-model.js +17 -0
- package/lib/src/models/statefulset-model.d.ts +14 -0
- package/lib/src/models/statefulset-model.js +17 -0
- package/lib/src/models/types/index.d.ts +1 -0
- package/lib/src/models/types/index.js +1 -0
- package/lib/src/models/types/metric.d.ts +25 -0
- package/lib/src/models/types/metric.js +1 -0
- package/lib/src/models/workload-base-model.d.ts +13 -0
- package/lib/src/models/workload-base-model.js +22 -0
- package/lib/src/models/workload-model.d.ts +19 -0
- package/lib/src/models/workload-model.js +51 -0
- package/lib/src/pages/configmaps/index.d.ts +4 -3
- package/lib/src/pages/configmaps/index.js +15 -0
- package/lib/src/pages/cronjobs/create/index.js +6 -0
- package/lib/src/pages/cronjobs/index.js +3 -0
- package/lib/src/pages/cronjobs/list/index.js +42 -0
- package/lib/src/pages/cronjobs/show/index.js +16 -0
- package/lib/src/pages/daemonsets/create/index.js +6 -0
- package/lib/src/pages/daemonsets/index.js +3 -0
- package/lib/src/pages/daemonsets/list/index.js +32 -0
- package/lib/src/pages/daemonsets/show/index.js +16 -0
- package/lib/src/pages/deployments/create/index.d.ts +2 -2
- package/lib/src/pages/deployments/create/index.js +7 -0
- package/lib/src/pages/deployments/index.js +3 -0
- package/lib/src/pages/deployments/list/index.js +26 -0
- package/lib/src/pages/deployments/show/index.js +16 -0
- package/lib/src/pages/ingresses/index.d.ts +4 -0
- package/lib/src/pages/ingresses/index.js +26 -0
- package/lib/src/pages/jobs/index.d.ts +4 -4
- package/lib/src/pages/jobs/index.js +34 -0
- package/lib/src/pages/networkPolicies/index.d.ts +4 -0
- package/lib/src/pages/networkPolicies/index.js +67 -0
- package/lib/src/pages/pods/create/index.js +6 -0
- package/lib/src/pages/pods/index.js +3 -0
- package/lib/src/pages/pods/list/index.js +81 -0
- package/lib/src/pages/pods/show/index.js +54 -0
- package/lib/src/pages/secrets/index.d.ts +4 -3
- package/lib/src/pages/secrets/index.js +15 -0
- package/lib/src/pages/services/index.d.ts +4 -0
- package/lib/src/pages/services/index.js +26 -0
- package/lib/src/pages/statefulsets/create/index.js +6 -0
- package/lib/src/pages/statefulsets/index.js +3 -0
- package/lib/src/pages/statefulsets/list/index.js +26 -0
- package/lib/src/pages/statefulsets/show/index.js +16 -0
- package/lib/src/plugins/index.d.ts +2 -0
- package/lib/src/plugins/index.js +3 -0
- package/lib/src/plugins/model-plugin.d.ts +12 -0
- package/lib/src/plugins/model-plugin.js +46 -0
- package/lib/src/plugins/relation-plugin.d.ts +27 -0
- package/lib/src/plugins/relation-plugin.js +81 -0
- package/lib/src/plugins/type.d.ts +8 -0
- package/lib/src/plugins/type.js +1 -0
- package/lib/src/providers/index.js +1 -0
- package/lib/src/providers/router-provider/index.d.ts +1 -1
- package/lib/src/providers/router-provider/index.js +100 -0
- package/lib/src/types/index.js +1 -0
- package/lib/src/types/resource.d.ts +19 -22
- package/lib/src/types/resource.js +12 -0
- package/lib/src/utils/addId.js +8 -0
- package/lib/src/utils/download.js +9 -0
- package/lib/src/utils/error.d.ts +3 -3
- package/lib/src/utils/error.js +53 -0
- package/lib/src/utils/form.d.ts +3 -0
- package/lib/src/utils/form.js +9 -0
- package/lib/src/utils/k8s.js +6 -0
- package/lib/src/utils/labels.js +15 -0
- package/lib/src/utils/match-selector.d.ts +3 -0
- package/lib/src/utils/match-selector.js +12 -0
- package/lib/src/utils/openapi.js +33 -0
- package/lib/src/utils/schema.js +117 -0
- package/lib/src/utils/selector.d.ts +3 -0
- package/lib/src/utils/selector.js +12 -0
- package/lib/src/utils/string.js +6 -0
- package/lib/src/utils/time.d.ts +6 -1
- package/lib/src/utils/time.js +46 -0
- package/lib/src/utils/unit.d.ts +12 -0
- package/lib/src/utils/unit.js +69 -0
- package/lib/src/utils/yaml.js +44 -0
- package/lib/vite.config.d.ts +1 -1
- package/lib/vite.config.js +60 -0
- package/package.json +24 -9
- package/dist/index.bd5d18c4.js +0 -9820
- package/lib/src/model/cronjob-model.d.ts +0 -9
- package/lib/src/model/index.d.ts +0 -5
- package/lib/src/model/job-model.d.ts +0 -10
- package/lib/src/model/pod-model.d.ts +0 -10
- package/lib/src/model/resource-model.d.ts +0 -17
- package/lib/src/model/workload-model.d.ts +0 -17
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { CronJobModel, DaemonSetModel, DeploymentModel, EventModel, IngressModel, JobModel, PodModel, ResourceModel, StatefulSetModel, NetworkPolicyModel, } from '../models';
|
|
2
|
+
const ModelMap = {
|
|
3
|
+
Deployment: DeploymentModel,
|
|
4
|
+
DaemonSet: DaemonSetModel,
|
|
5
|
+
StatefulSet: StatefulSetModel,
|
|
6
|
+
CronJob: CronJobModel,
|
|
7
|
+
Job: JobModel,
|
|
8
|
+
Pod: PodModel,
|
|
9
|
+
Event: EventModel,
|
|
10
|
+
Ingress: IngressModel,
|
|
11
|
+
NetworkPolicy: NetworkPolicyModel,
|
|
12
|
+
};
|
|
13
|
+
class ModelPlugin {
|
|
14
|
+
_globalStore;
|
|
15
|
+
init(globalStore) {
|
|
16
|
+
this._globalStore = globalStore;
|
|
17
|
+
}
|
|
18
|
+
async processData(res) {
|
|
19
|
+
const { kind, apiVersion } = res;
|
|
20
|
+
const items = await Promise.all(res.items.map(item => {
|
|
21
|
+
const newItem = { ...item };
|
|
22
|
+
newItem.kind = kind.replace(/List$/g, '');
|
|
23
|
+
newItem.apiVersion = apiVersion;
|
|
24
|
+
return this.processItem(newItem);
|
|
25
|
+
}));
|
|
26
|
+
return {
|
|
27
|
+
...res,
|
|
28
|
+
items,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async processItem(item) {
|
|
32
|
+
const Model = ModelMap[item.kind] || ResourceModel;
|
|
33
|
+
const result = new Model(item, this._globalStore);
|
|
34
|
+
await result.init();
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
restoreData(res) {
|
|
38
|
+
const newRes = { ...res };
|
|
39
|
+
newRes.items = res.items.map(item => this.restoreItem(item));
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
restoreItem(item) {
|
|
43
|
+
return item._rawYaml;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export const modelPlugin = new ModelPlugin();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { GlobalStore, Unstructured, UnstructuredList } from 'k8s-api-provider';
|
|
2
|
+
import { LabelSelector, ObjectMeta } from 'kubernetes-types/meta/v1';
|
|
3
|
+
import { ResourceModel } from '../models';
|
|
4
|
+
export type Relation = {
|
|
5
|
+
kind: string;
|
|
6
|
+
apiVersion: string;
|
|
7
|
+
type: 'creates' | 'uses' | 'applies' | 'owner' | 'selects';
|
|
8
|
+
inbound: boolean;
|
|
9
|
+
name?: string;
|
|
10
|
+
namespace?: string;
|
|
11
|
+
selector?: LabelSelector;
|
|
12
|
+
};
|
|
13
|
+
export type ExtendObjectMeta = ObjectMeta & {
|
|
14
|
+
relations?: Relation[];
|
|
15
|
+
};
|
|
16
|
+
declare class RelationPlugin {
|
|
17
|
+
private globalStore?;
|
|
18
|
+
init(globalStore: GlobalStore): void;
|
|
19
|
+
processData(res: UnstructuredList): Promise<UnstructuredList>;
|
|
20
|
+
processItem(item: Unstructured): Promise<ResourceModel>;
|
|
21
|
+
restoreData(res: UnstructuredList): UnstructuredList;
|
|
22
|
+
restoreItem(item: Unstructured): Unstructured;
|
|
23
|
+
private processPodSelector;
|
|
24
|
+
private appendRelation;
|
|
25
|
+
}
|
|
26
|
+
export declare const relationPlugin: RelationPlugin;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { omit } from 'lodash';
|
|
2
|
+
class RelationPlugin {
|
|
3
|
+
globalStore;
|
|
4
|
+
init(globalStore) {
|
|
5
|
+
this.globalStore = globalStore;
|
|
6
|
+
}
|
|
7
|
+
async processData(res) {
|
|
8
|
+
const { kind, apiVersion } = res;
|
|
9
|
+
const items = await Promise.all(res.items.map(item => this.processItem({
|
|
10
|
+
// TODO: unify this with data-provider getOne method
|
|
11
|
+
kind: kind.replace(/List$/g, ''),
|
|
12
|
+
apiVersion,
|
|
13
|
+
...omit(item, ['apiVersion', 'kind']),
|
|
14
|
+
})));
|
|
15
|
+
return {
|
|
16
|
+
...res,
|
|
17
|
+
items,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async processItem(item) {
|
|
21
|
+
this.processPodSelector(item);
|
|
22
|
+
return item;
|
|
23
|
+
}
|
|
24
|
+
restoreData(res) {
|
|
25
|
+
res.items = res.items.map(item => this.restoreItem(item));
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
restoreItem(item) {
|
|
29
|
+
return {
|
|
30
|
+
...item,
|
|
31
|
+
metadata: omit(item.metadata, 'relations'),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
processPodSelector(item) {
|
|
35
|
+
const { spec, kind } = item;
|
|
36
|
+
const selector = spec?.selector;
|
|
37
|
+
if (!selector) {
|
|
38
|
+
return item;
|
|
39
|
+
}
|
|
40
|
+
// TODO: also check apiVersion along with kind
|
|
41
|
+
if (!kind ||
|
|
42
|
+
![
|
|
43
|
+
'Deployment',
|
|
44
|
+
'DaemonSet',
|
|
45
|
+
'StatefulSet',
|
|
46
|
+
'ReplicaSet',
|
|
47
|
+
'Job',
|
|
48
|
+
'Service',
|
|
49
|
+
].includes(kind)) {
|
|
50
|
+
return item;
|
|
51
|
+
}
|
|
52
|
+
// empty selector or legacy resources like Service
|
|
53
|
+
if (!selector.matchLabels && !selector.matchExpressions) {
|
|
54
|
+
selector.matchLabels = {};
|
|
55
|
+
for (const key of Object.keys(selector)) {
|
|
56
|
+
if (key === 'matchLabels') {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
selector.matchLabels[key] = selector[key];
|
|
60
|
+
delete selector[key];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
this.appendRelation(item, {
|
|
64
|
+
kind: 'Pod',
|
|
65
|
+
apiVersion: 'v1',
|
|
66
|
+
type: kind === 'Service' ? 'selects' : 'creates',
|
|
67
|
+
selector,
|
|
68
|
+
inbound: false,
|
|
69
|
+
});
|
|
70
|
+
return item;
|
|
71
|
+
}
|
|
72
|
+
appendRelation(item, relation) {
|
|
73
|
+
const metadata = item.metadata;
|
|
74
|
+
if (!metadata.relations) {
|
|
75
|
+
metadata.relations = [];
|
|
76
|
+
}
|
|
77
|
+
metadata.relations.push(relation);
|
|
78
|
+
return item;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export const relationPlugin = new RelationPlugin();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Unstructured } from 'k8s-api-provider';
|
|
2
|
+
import { ListMeta } from 'kubernetes-types/meta/v1';
|
|
3
|
+
export type DataList<Output extends Unstructured = Unstructured> = {
|
|
4
|
+
apiVersion: string;
|
|
5
|
+
kind: string;
|
|
6
|
+
metadata: ListMeta;
|
|
7
|
+
items: Array<Unstructured & Output>;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { routerProvider } from './router-provider';
|
|
@@ -11,7 +11,7 @@ export declare const convertToNumberIfPossible: (value: string | undefined) => s
|
|
|
11
11
|
export declare const routerProvider: {
|
|
12
12
|
go: () => ({ to, type, query, hash, options: { keepQuery, keepHash } }: GoConfig) => string | void;
|
|
13
13
|
back: () => () => void;
|
|
14
|
-
parse: () => () => ParseResponse
|
|
14
|
+
parse: () => () => ParseResponse;
|
|
15
15
|
Link: React.ForwardRefExoticComponent<Pick<{
|
|
16
16
|
[prop: string]: any;
|
|
17
17
|
to: string;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
3
|
+
import { matchResourceFromRoute, ResourceContext, } from '@refinedev/core';
|
|
4
|
+
import { parse, stringify } from 'qs';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { useCallback, useContext } from 'react';
|
|
7
|
+
import { useHistory, useLocation, Link, matchPath, useParams } from 'react-router-dom';
|
|
8
|
+
export const stringifyConfig = {
|
|
9
|
+
addQueryPrefix: true,
|
|
10
|
+
skipNulls: true,
|
|
11
|
+
arrayFormat: 'indices',
|
|
12
|
+
encode: false,
|
|
13
|
+
encodeValuesOnly: true,
|
|
14
|
+
};
|
|
15
|
+
export const convertToNumberIfPossible = (value) => {
|
|
16
|
+
if (typeof value === 'undefined') {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
const num = Number(value);
|
|
20
|
+
if (`${num}` === value) {
|
|
21
|
+
return num;
|
|
22
|
+
}
|
|
23
|
+
return value;
|
|
24
|
+
};
|
|
25
|
+
export const routerProvider = {
|
|
26
|
+
go: () => {
|
|
27
|
+
const { search: existingSearch, hash: existingHash } = useLocation();
|
|
28
|
+
const history = useHistory();
|
|
29
|
+
const fn = useCallback(({ to, type, query, hash, options: { keepQuery, keepHash } = {} }) => {
|
|
30
|
+
/** Construct query params */
|
|
31
|
+
const urlQuery = {
|
|
32
|
+
...(keepQuery &&
|
|
33
|
+
existingSearch &&
|
|
34
|
+
parse(existingSearch, { ignoreQueryPrefix: true })),
|
|
35
|
+
...query,
|
|
36
|
+
};
|
|
37
|
+
if (urlQuery.to) {
|
|
38
|
+
urlQuery.to = encodeURIComponent(`${urlQuery.to}`);
|
|
39
|
+
}
|
|
40
|
+
const hasUrlQuery = Object.keys(urlQuery).length > 0;
|
|
41
|
+
/** Get hash */
|
|
42
|
+
const urlHash = `#${(hash || (keepHash && existingHash) || '').replace(/^#/, '')}`;
|
|
43
|
+
const hasUrlHash = urlHash.length > 1;
|
|
44
|
+
const urlTo = to || '';
|
|
45
|
+
const fullPath = `${urlTo}${hasUrlQuery ? stringify(urlQuery, stringifyConfig) : ''}${hasUrlHash ? urlHash : ''}`;
|
|
46
|
+
if (type === 'path') {
|
|
47
|
+
return fullPath;
|
|
48
|
+
}
|
|
49
|
+
/** Navigate to the url */
|
|
50
|
+
return history[type || 'push'](fullPath);
|
|
51
|
+
}, [existingHash, existingSearch, history]);
|
|
52
|
+
return fn;
|
|
53
|
+
},
|
|
54
|
+
back: () => {
|
|
55
|
+
const history = useHistory();
|
|
56
|
+
const fn = useCallback(() => {
|
|
57
|
+
history.go(-1);
|
|
58
|
+
}, [history]);
|
|
59
|
+
return fn;
|
|
60
|
+
},
|
|
61
|
+
parse: () => {
|
|
62
|
+
let params = useParams();
|
|
63
|
+
const { pathname, search } = useLocation();
|
|
64
|
+
const { resources } = useContext(ResourceContext);
|
|
65
|
+
const { resource, action, matchedRoute } = React.useMemo(() => {
|
|
66
|
+
return matchResourceFromRoute(pathname, resources);
|
|
67
|
+
}, [resources, pathname]);
|
|
68
|
+
// params is empty when useParams is used in a component that is not a child of a Route
|
|
69
|
+
if (Object.entries(params).length === 0 && matchedRoute) {
|
|
70
|
+
params = matchPath(matchedRoute, pathname)?.params || {};
|
|
71
|
+
}
|
|
72
|
+
const fn = useCallback(() => {
|
|
73
|
+
const parsedSearch = parse(search, { ignoreQueryPrefix: true });
|
|
74
|
+
const combinedParams = {
|
|
75
|
+
...params,
|
|
76
|
+
...parsedSearch,
|
|
77
|
+
};
|
|
78
|
+
const response = {
|
|
79
|
+
...(resource && { resource }),
|
|
80
|
+
...(action && { action }),
|
|
81
|
+
...(parsedSearch?.id && { id: decodeURIComponent(parsedSearch.id) }),
|
|
82
|
+
// ...(params?.action && { action: params.action }), // lets see if there is a need for this
|
|
83
|
+
pathname,
|
|
84
|
+
params: {
|
|
85
|
+
...combinedParams,
|
|
86
|
+
current: convertToNumberIfPossible(combinedParams.current),
|
|
87
|
+
pageSize: convertToNumberIfPossible(combinedParams.pageSize),
|
|
88
|
+
to: combinedParams.to
|
|
89
|
+
? decodeURIComponent(combinedParams.to)
|
|
90
|
+
: undefined,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
return response;
|
|
94
|
+
}, [pathname, search, params, resource, action]);
|
|
95
|
+
return fn;
|
|
96
|
+
},
|
|
97
|
+
Link: React.forwardRef(function RefineLink(props, ref) {
|
|
98
|
+
return _jsx(Link, { ...props, ref: ref });
|
|
99
|
+
}),
|
|
100
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './resource';
|
|
@@ -1,39 +1,36 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { ShowField } from '../components/ShowContent';
|
|
2
|
+
import { FormModalProps } from 'src/components/FormModal';
|
|
3
|
+
import { ShowConfig } from '../components/ShowContent';
|
|
5
4
|
import { Column } from '../components/Table';
|
|
6
|
-
import { ResourceModel } from '../
|
|
5
|
+
import { ResourceModel } from '../models';
|
|
7
6
|
export declare enum RESOURCE_GROUP {
|
|
8
7
|
WORKLOAD = "WORKLOAD",
|
|
9
|
-
|
|
8
|
+
STORAGE = "STORAGE",
|
|
9
|
+
NETWORK = "NETWORK",
|
|
10
|
+
CLUSTER = "CLUSTER"
|
|
11
|
+
}
|
|
12
|
+
export declare enum FormType {
|
|
13
|
+
PAGE = "PAGE",
|
|
14
|
+
MODAL = "MODAL"
|
|
10
15
|
}
|
|
11
16
|
export type WithId<T> = T & {
|
|
12
17
|
id: string;
|
|
13
18
|
};
|
|
14
|
-
export
|
|
15
|
-
id: string;
|
|
16
|
-
apiVersion?: string;
|
|
17
|
-
/**
|
|
18
|
-
* Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
|
|
19
|
-
*/
|
|
20
|
-
kind?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
|
|
23
|
-
*/
|
|
24
|
-
metadata?: ObjectMeta;
|
|
25
|
-
}
|
|
26
|
-
export type ResourceConfig<Raw extends Resource = Resource, Model extends ResourceModel = ResourceModel> = {
|
|
19
|
+
export type ResourceConfig<Model extends ResourceModel = ResourceModel> = {
|
|
27
20
|
name: string;
|
|
28
21
|
kind: string;
|
|
29
22
|
basePath: string;
|
|
30
23
|
apiVersion: string;
|
|
24
|
+
label: string;
|
|
31
25
|
parent?: RESOURCE_GROUP;
|
|
32
|
-
formatter?: (v:
|
|
26
|
+
formatter?: (v: Model) => Model;
|
|
33
27
|
initValue?: Record<string, unknown>;
|
|
34
|
-
columns?: (
|
|
35
|
-
|
|
28
|
+
columns?: () => Column<Model>[];
|
|
29
|
+
showConfig?: () => ShowConfig<Model>;
|
|
36
30
|
Dropdown?: React.FC<{
|
|
37
|
-
|
|
31
|
+
record: Model;
|
|
38
32
|
}>;
|
|
33
|
+
formType?: FormType;
|
|
34
|
+
FormModal?: React.FC<FormModalProps>;
|
|
35
|
+
isCustom?: boolean;
|
|
39
36
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export var RESOURCE_GROUP;
|
|
2
|
+
(function (RESOURCE_GROUP) {
|
|
3
|
+
RESOURCE_GROUP["WORKLOAD"] = "WORKLOAD";
|
|
4
|
+
RESOURCE_GROUP["STORAGE"] = "STORAGE";
|
|
5
|
+
RESOURCE_GROUP["NETWORK"] = "NETWORK";
|
|
6
|
+
RESOURCE_GROUP["CLUSTER"] = "CLUSTER";
|
|
7
|
+
})(RESOURCE_GROUP || (RESOURCE_GROUP = {}));
|
|
8
|
+
export var FormType;
|
|
9
|
+
(function (FormType) {
|
|
10
|
+
FormType["PAGE"] = "PAGE";
|
|
11
|
+
FormType["MODAL"] = "MODAL";
|
|
12
|
+
})(FormType || (FormType = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function download(filename, content) {
|
|
2
|
+
const element = document.createElement('a');
|
|
3
|
+
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content));
|
|
4
|
+
element.setAttribute('download', filename);
|
|
5
|
+
element.style.display = 'none';
|
|
6
|
+
document.body.appendChild(element);
|
|
7
|
+
element.click();
|
|
8
|
+
document.body.removeChild(element);
|
|
9
|
+
}
|
package/lib/src/utils/error.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ type Cause = {
|
|
|
5
5
|
message: string;
|
|
6
6
|
field?: string;
|
|
7
7
|
};
|
|
8
|
-
type
|
|
8
|
+
export type ErrorResponseBody = {
|
|
9
9
|
message?: string;
|
|
10
10
|
code?: number;
|
|
11
11
|
reason?: string;
|
|
@@ -15,6 +15,6 @@ type ErrorResponse = {
|
|
|
15
15
|
graphQLErrors?: Cause[];
|
|
16
16
|
};
|
|
17
17
|
export declare function isNetworkError(errors?: Cause[]): boolean;
|
|
18
|
-
export declare function getSubmitError(errorResponse:
|
|
19
|
-
export declare function getCommonErrors(
|
|
18
|
+
export declare function getSubmitError(errorResponse: ErrorResponseBody | undefined, text: string, i18n: I18n): string;
|
|
19
|
+
export declare function getCommonErrors(responseBody: ErrorResponseBody, i18n: I18n): string[];
|
|
20
20
|
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export function isNetworkError(errors) {
|
|
2
|
+
if (errors?.some(error => error?.code || error?.reason)) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
else {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function getSubmitError(errorResponse, text, i18n) {
|
|
10
|
+
return !errorResponse ? i18n.t('dovetail.network_error') : text;
|
|
11
|
+
}
|
|
12
|
+
export function getCommonErrors(responseBody, i18n) {
|
|
13
|
+
if (!(responseBody?.message ||
|
|
14
|
+
responseBody?.code ||
|
|
15
|
+
responseBody?.reason ||
|
|
16
|
+
responseBody?.details ||
|
|
17
|
+
responseBody?.graphQLErrors)) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const causes = responseBody.details?.causes || responseBody.graphQLErrors || [];
|
|
21
|
+
if (causes.length) {
|
|
22
|
+
return causes.map(cause => {
|
|
23
|
+
let params = {};
|
|
24
|
+
let message = cause.message;
|
|
25
|
+
try {
|
|
26
|
+
const info = JSON.parse(cause.message);
|
|
27
|
+
params = info.params;
|
|
28
|
+
message = info.message;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return i18n.t([
|
|
32
|
+
`error.${cause.reason}`,
|
|
33
|
+
`error.${cause.code}`,
|
|
34
|
+
`${message}${cause.field ? `(${cause.field})` : ''}`,
|
|
35
|
+
], {
|
|
36
|
+
...params,
|
|
37
|
+
fallbackLng: '',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return i18n.t([
|
|
41
|
+
`error.${cause.reason}`,
|
|
42
|
+
`error.${cause.code}`,
|
|
43
|
+
`${message}${cause.field ? `(${cause.field})` : ''}`,
|
|
44
|
+
], {
|
|
45
|
+
...params,
|
|
46
|
+
fallbackLng: '',
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return [
|
|
51
|
+
i18n.t([`error.${responseBody.code}`, `error.${responseBody.reason}`, responseBody.message || ''], { fallbackLng: '' }),
|
|
52
|
+
];
|
|
53
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function toLabelStrings(labels = {}) {
|
|
2
|
+
return Object.keys(labels).map(key => `${key}/${labels[key]}`);
|
|
3
|
+
}
|
|
4
|
+
export function toLabelsArray(labels = {}) {
|
|
5
|
+
return Object.keys(labels).map(key => ({
|
|
6
|
+
key,
|
|
7
|
+
value: labels[key],
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
export function toLabelsRecord(labels) {
|
|
11
|
+
return labels.reduce((prev, cur) => {
|
|
12
|
+
prev[cur.key] = cur.value;
|
|
13
|
+
return prev;
|
|
14
|
+
}, {});
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function matchSelector(pod, selector) {
|
|
2
|
+
let match = true;
|
|
3
|
+
// TODO: support complete selector match strategy
|
|
4
|
+
// https://github.com/rancher/dashboard/blob/master/shell/utils/selector.js#L166
|
|
5
|
+
for (const key in selector.matchLabels) {
|
|
6
|
+
if (!pod.metadata?.labels?.[key] ||
|
|
7
|
+
pod.metadata.labels?.[key] !== selector.matchLabels[key]) {
|
|
8
|
+
match = false;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return match;
|
|
12
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getApiVersion } from 'src/utils/k8s';
|
|
2
|
+
import { resolveRef } from 'src/utils/schema';
|
|
3
|
+
class K8sOpenAPI {
|
|
4
|
+
resourceBasePath;
|
|
5
|
+
response = null;
|
|
6
|
+
apiVersion;
|
|
7
|
+
constructor(resourceBasePath) {
|
|
8
|
+
this.resourceBasePath = resourceBasePath;
|
|
9
|
+
this.apiVersion = getApiVersion(resourceBasePath);
|
|
10
|
+
}
|
|
11
|
+
async fetch() {
|
|
12
|
+
const response = await fetch(`/api/sks/api/v1/clusters/sks-mgmt/proxy/openapi/v3${this.resourceBasePath}`);
|
|
13
|
+
return response.json();
|
|
14
|
+
}
|
|
15
|
+
async findSchema(kind) {
|
|
16
|
+
const result = this.response || (await this.fetch());
|
|
17
|
+
const schema = Object.values(result.components.schemas).find(schema => schema['x-kubernetes-group-version-kind']?.some(({ kind: schemaKind, version: schemaVersion, group: schemaGroup }) => kind === schemaKind &&
|
|
18
|
+
this.apiVersion === `${schemaGroup ? schemaGroup + '/' : ''}${schemaVersion}`));
|
|
19
|
+
if (schema) {
|
|
20
|
+
resolveRef(schema, result.components.schemas, {
|
|
21
|
+
prune: {
|
|
22
|
+
description: true,
|
|
23
|
+
optional: false,
|
|
24
|
+
fields: [],
|
|
25
|
+
metadata: true,
|
|
26
|
+
xProperty: true,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return schema;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export default K8sOpenAPI;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { pick } from 'lodash';
|
|
2
|
+
export function generateValueFromSchema(schema, options) {
|
|
3
|
+
const { generateValue } = options;
|
|
4
|
+
if (!schema) {
|
|
5
|
+
return {};
|
|
6
|
+
}
|
|
7
|
+
switch (true) {
|
|
8
|
+
case schema.type === 'string' && 'enum' in schema && Boolean(schema.enum?.length):
|
|
9
|
+
return generateValue?.(schema) || schema.enum?.[0];
|
|
10
|
+
case schema.type === 'string':
|
|
11
|
+
return generateValue?.(schema) || '';
|
|
12
|
+
case schema.type === 'boolean':
|
|
13
|
+
return generateValue?.(schema) || false;
|
|
14
|
+
case schema.type === 'array':
|
|
15
|
+
if (!schema.minItems ||
|
|
16
|
+
!schema.items ||
|
|
17
|
+
typeof schema.items === 'boolean' ||
|
|
18
|
+
Array.isArray(schema.items)) {
|
|
19
|
+
return generateValue?.(schema) || [];
|
|
20
|
+
}
|
|
21
|
+
return new Array(schema.minItems).fill(generateValueFromSchema(schema.items, options));
|
|
22
|
+
case schema.type === 'number':
|
|
23
|
+
case schema.type === 'integer':
|
|
24
|
+
return generateValue?.(schema) || 0;
|
|
25
|
+
case schema.type === 'object': {
|
|
26
|
+
const obj = {};
|
|
27
|
+
for (const key in schema.properties) {
|
|
28
|
+
obj[key] = generateValueFromSchema(schema.properties[key], options);
|
|
29
|
+
}
|
|
30
|
+
return obj;
|
|
31
|
+
}
|
|
32
|
+
case Array.isArray(schema.type) && 'anyOf' in schema && Boolean(schema.anyOf?.length):
|
|
33
|
+
case Array.isArray(schema.type) &&
|
|
34
|
+
'oneOf' in schema &&
|
|
35
|
+
Boolean(schema.oneOf?.length):
|
|
36
|
+
{
|
|
37
|
+
const subSchema = (schema.anyOf || schema.oneOf)?.[0];
|
|
38
|
+
return generateValueFromSchema(subSchema, options);
|
|
39
|
+
}
|
|
40
|
+
case 'allOf' in schema && Boolean(schema.allOf?.length):
|
|
41
|
+
return generateValueFromSchema(schema.allOf?.[0], options);
|
|
42
|
+
default:
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function generateSchemaTypeValue(schema) {
|
|
47
|
+
return generateValueFromSchema(schema, {
|
|
48
|
+
generateValue(schema) {
|
|
49
|
+
if (schema.type === 'array' && schema.items) {
|
|
50
|
+
return generateSchemaTypeValue(schema.items);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return schema.type;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export function resolveRef(schema, schemas, options) {
|
|
59
|
+
const { prune } = options;
|
|
60
|
+
if (schema.$ref) {
|
|
61
|
+
const refKey = schema.$ref.replace('#/components/schemas/', '');
|
|
62
|
+
Object.assign(schema, schemas[refKey]);
|
|
63
|
+
if (prune.metadata &&
|
|
64
|
+
[
|
|
65
|
+
'io.k8s.apimachinery.pkg.apis.meta.v1.ListMeta',
|
|
66
|
+
'io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta',
|
|
67
|
+
].some(k => refKey.includes(k)) &&
|
|
68
|
+
schema.properties) {
|
|
69
|
+
schema.properties = pick(schema.properties, [
|
|
70
|
+
'name',
|
|
71
|
+
'namespace',
|
|
72
|
+
'annotations',
|
|
73
|
+
'labels',
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
delete schema.$ref;
|
|
77
|
+
}
|
|
78
|
+
for (const schemaKey in schema) {
|
|
79
|
+
if (prune.xProperty &&
|
|
80
|
+
schemaKey.startsWith('x-') &&
|
|
81
|
+
schemaKey !== 'x-kubernetes-group-version-kind') {
|
|
82
|
+
delete schema[schemaKey];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
switch (true) {
|
|
86
|
+
case schema.type === 'array':
|
|
87
|
+
if (Array.isArray(schema.items)) {
|
|
88
|
+
schema.items.forEach(item => resolveRef(item, schemas, options));
|
|
89
|
+
}
|
|
90
|
+
else if (typeof schema.items === 'object') {
|
|
91
|
+
resolveRef(schema.items, schemas, options);
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
case schema.type === 'object':
|
|
95
|
+
for (const key in schema.properties) {
|
|
96
|
+
const subSchema = schema.properties[key];
|
|
97
|
+
if (prune.optional && !schema.required?.includes(key)) {
|
|
98
|
+
delete schema.properties[key];
|
|
99
|
+
}
|
|
100
|
+
if (prune.fields.includes(key)) {
|
|
101
|
+
delete schema.properties[key];
|
|
102
|
+
}
|
|
103
|
+
resolveRef(subSchema, schemas, options);
|
|
104
|
+
}
|
|
105
|
+
if (schema.additionalProperties) {
|
|
106
|
+
resolveRef(schema.additionalProperties, schemas, options);
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
case !!(schema.allOf && schema.allOf[0]):
|
|
110
|
+
resolveRef(schema.allOf?.[0], schemas, options);
|
|
111
|
+
default:
|
|
112
|
+
}
|
|
113
|
+
if (prune.description) {
|
|
114
|
+
delete schema.description;
|
|
115
|
+
}
|
|
116
|
+
return schema;
|
|
117
|
+
}
|