diff --git a/public/app/features/apiserver/client.ts b/public/app/features/apiserver/client.ts index 2af5503674f..317b5f1ddd7 100644 --- a/public/app/features/apiserver/client.ts +++ b/public/app/features/apiserver/client.ts @@ -20,6 +20,7 @@ import { K8sAPIGroupList, AnnoKeySavedFromUI, ResourceEvent, + ResourceClientWriteParams, GroupVersionResource, } from './types'; @@ -97,8 +98,8 @@ export class ScopedResourceClient implements ); } - public async subresource(name: string, path: string): Promise { - return getBackendSrv().get(`${this.url}/${name}/${path}`); + public async subresource(name: string, path: string, params?: Record): Promise { + return getBackendSrv().get(`${this.url}/${name}/${path}`, params); } public async list(opts?: ListOptions | undefined): Promise> { @@ -109,7 +110,7 @@ export class ScopedResourceClient implements return getBackendSrv().get>(this.url, opts); } - public async create(obj: ResourceForCreate): Promise> { + public async create(obj: ResourceForCreate, params?: ResourceClientWriteParams): Promise> { if (!obj.metadata.name && !obj.metadata.generateName) { const login = contextSrv.user.login; // GenerateName lets the apiserver create a new uid for the name @@ -117,12 +118,17 @@ export class ScopedResourceClient implements obj.metadata.generateName = login ? login.slice(0, 2) : 'g'; } setSavedFromUIAnnotation(obj.metadata); - return getBackendSrv().post(this.url, obj); + return getBackendSrv().post(this.url, obj, { + params, + }); } - public async update(obj: Resource): Promise> { + public async update(obj: Resource, params?: ResourceClientWriteParams): Promise> { setSavedFromUIAnnotation(obj.metadata); - return getBackendSrv().put>(`${this.url}/${obj.metadata.name}`, obj); + const url = `${this.url}/${obj.metadata.name}`; + return getBackendSrv().put>(url, obj, { + params, + }); } public async delete(name: string, showSuccessAlert: boolean): Promise { diff --git a/public/app/features/apiserver/types.ts b/public/app/features/apiserver/types.ts index 631f56f505c..72bbbc052d1 100644 --- a/public/app/features/apiserver/types.ts +++ b/public/app/features/apiserver/types.ts @@ -232,14 +232,19 @@ export interface ResourceEvent { object: Resource; } +export type ResourceClientWriteParams = { + dryRun?: 'All'; + fieldValidation?: 'Ignore' | 'Warn' | 'Strict'; +}; + export interface ResourceClient { - create(obj: ResourceForCreate): Promise>; get(name: string): Promise>; - watch(opts?: WatchOptions): Observable>; - subresource(name: string, path: string): Promise; - list(opts?: ListOptions): Promise>; - update(obj: ResourceForCreate): Promise>; + create(obj: ResourceForCreate, params?: ResourceClientWriteParams): Promise>; + update(obj: ResourceForCreate, params?: ResourceClientWriteParams): Promise>; delete(name: string, showSuccessAlert?: boolean): Promise; + list(opts?: ListOptions): Promise>; + subresource(name: string, path: string, params?: Record): Promise; + watch(opts?: WatchOptions): Observable>; } export interface K8sAPIGroup { diff --git a/public/app/features/dashboard/api/v1.ts b/public/app/features/dashboard/api/v1.ts index 6cd98ab3e67..62599ccb100 100644 --- a/public/app/features/dashboard/api/v1.ts +++ b/public/app/features/dashboard/api/v1.ts @@ -58,11 +58,13 @@ export class K8sDashboardAPI implements DashboardAPI { }; } + // for v1 in g12, we will ignore the schema version validation from all default clients, + // as we implement the necessary backend conversions, we will drop this query param if (dashboard.uid) { obj.metadata.name = dashboard.uid; - return this.client.update(obj).then((v) => this.asSaveDashboardResponseDTO(v)); + return this.client.update(obj, { fieldValidation: 'Ignore' }).then((v) => this.asSaveDashboardResponseDTO(v)); } - return this.client.create(obj).then((v) => this.asSaveDashboardResponseDTO(v)); + return this.client.create(obj, { fieldValidation: 'Ignore' }).then((v) => this.asSaveDashboardResponseDTO(v)); } asSaveDashboardResponseDTO(v: Resource): SaveDashboardResponseDTO { diff --git a/public/app/features/dashboard/api/v2.test.ts b/public/app/features/dashboard/api/v2.test.ts index 9c2ca0470c8..1c6be876e9a 100644 --- a/public/app/features/dashboard/api/v2.test.ts +++ b/public/app/features/dashboard/api/v2.test.ts @@ -219,7 +219,8 @@ describe('v2 dashboard API', () => { ...defaultSaveCommand.dashboard, title: 'chaing-title-dashboard', }, - } + }, + { params: undefined } ); }); });