K8s/Client: Ignore validation from dashboards frontend v1 (#103641)
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
K8sAPIGroupList,
|
||||
AnnoKeySavedFromUI,
|
||||
ResourceEvent,
|
||||
ResourceClientWriteParams,
|
||||
GroupVersionResource,
|
||||
} from './types';
|
||||
|
||||
@@ -97,8 +98,8 @@ export class ScopedResourceClient<T = object, S = object, K = string> implements
|
||||
);
|
||||
}
|
||||
|
||||
public async subresource<S>(name: string, path: string): Promise<S> {
|
||||
return getBackendSrv().get<S>(`${this.url}/${name}/${path}`);
|
||||
public async subresource<S>(name: string, path: string, params?: Record<string, unknown>): Promise<S> {
|
||||
return getBackendSrv().get<S>(`${this.url}/${name}/${path}`, params);
|
||||
}
|
||||
|
||||
public async list(opts?: ListOptions | undefined): Promise<ResourceList<T, S, K>> {
|
||||
@@ -109,7 +110,7 @@ export class ScopedResourceClient<T = object, S = object, K = string> implements
|
||||
return getBackendSrv().get<ResourceList<T, S, K>>(this.url, opts);
|
||||
}
|
||||
|
||||
public async create(obj: ResourceForCreate<T, K>): Promise<Resource<T, S, K>> {
|
||||
public async create(obj: ResourceForCreate<T, K>, params?: ResourceClientWriteParams): Promise<Resource<T, S, K>> {
|
||||
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<T = object, S = object, K = string> 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<T, S, K>): Promise<Resource<T, S, K>> {
|
||||
public async update(obj: Resource<T, S, K>, params?: ResourceClientWriteParams): Promise<Resource<T, S, K>> {
|
||||
setSavedFromUIAnnotation(obj.metadata);
|
||||
return getBackendSrv().put<Resource<T, S, K>>(`${this.url}/${obj.metadata.name}`, obj);
|
||||
const url = `${this.url}/${obj.metadata.name}`;
|
||||
return getBackendSrv().put<Resource<T, S, K>>(url, obj, {
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
public async delete(name: string, showSuccessAlert: boolean): Promise<MetaStatus> {
|
||||
|
||||
@@ -232,14 +232,19 @@ export interface ResourceEvent<T = object, S = object, K = string> {
|
||||
object: Resource<T, S, K>;
|
||||
}
|
||||
|
||||
export type ResourceClientWriteParams = {
|
||||
dryRun?: 'All';
|
||||
fieldValidation?: 'Ignore' | 'Warn' | 'Strict';
|
||||
};
|
||||
|
||||
export interface ResourceClient<T = object, S = object, K = string> {
|
||||
create(obj: ResourceForCreate<T, K>): Promise<Resource<T, S, K>>;
|
||||
get(name: string): Promise<Resource<T, S, K>>;
|
||||
watch(opts?: WatchOptions): Observable<ResourceEvent<T, S, K>>;
|
||||
subresource<S>(name: string, path: string): Promise<S>;
|
||||
list(opts?: ListOptions): Promise<ResourceList<T, S, K>>;
|
||||
update(obj: ResourceForCreate<T, K>): Promise<Resource<T, S, K>>;
|
||||
create(obj: ResourceForCreate<T, K>, params?: ResourceClientWriteParams): Promise<Resource<T, S, K>>;
|
||||
update(obj: ResourceForCreate<T, K>, params?: ResourceClientWriteParams): Promise<Resource<T, S, K>>;
|
||||
delete(name: string, showSuccessAlert?: boolean): Promise<MetaStatus>;
|
||||
list(opts?: ListOptions): Promise<ResourceList<T, S, K>>;
|
||||
subresource<S>(name: string, path: string, params?: Record<string, unknown>): Promise<S>;
|
||||
watch(opts?: WatchOptions): Observable<ResourceEvent<T, S, K>>;
|
||||
}
|
||||
|
||||
export interface K8sAPIGroup {
|
||||
|
||||
@@ -58,11 +58,13 @@ export class K8sDashboardAPI implements DashboardAPI<DashboardDTO, Dashboard> {
|
||||
};
|
||||
}
|
||||
|
||||
// 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<DashboardDataDTO>): SaveDashboardResponseDTO {
|
||||
|
||||
@@ -219,7 +219,8 @@ describe('v2 dashboard API', () => {
|
||||
...defaultSaveCommand.dashboard,
|
||||
title: 'chaing-title-dashboard',
|
||||
},
|
||||
}
|
||||
},
|
||||
{ params: undefined }
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user