Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MR fixes identified during architecture review #3263

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/routes/api/modelRegistries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default async (fastify: KubeFastifyInstance): Promise<void> => {
const { modelRegistryName } = request.params;
try {
const modelRegistryNamespace = getModelRegistryNamespace(fastify);
deleteModelRegistryAndSecret(
return deleteModelRegistryAndSecret(
fastify,
modelRegistryName,
modelRegistryNamespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,19 @@ export const createModelRegistryRoleBinding = async (
rbRequest: V1RoleBinding,
mrNamespace: string,
mturley marked this conversation as resolved.
Show resolved Hide resolved
): Promise<V1RoleBinding> => {
// Re-inject the namespace value that was omitted by the client
// (see createModelRegistryRoleBinding in frontend/src/services/modelRegistrySettingsService.ts)
// This will be unnecessary when we remove the backend service as part of https://issues.redhat.com/browse/RHOAIENG-12077
const roleBindingWithNamespace = {
...rbRequest,
metadata: { ...rbRequest.metadata, namespace: mrNamespace },
};
const response = await (fastify.kube.customObjectsApi.createNamespacedCustomObject(
MODEL_REGISTRY_ROLE_BINDING_API_GROUP,
MODEL_REGISTRY_ROLE_BINDING_API_VERSION,
mrNamespace,
MODEL_REGISTRY_ROLE_BINDING_PLURAL,
rbRequest,
roleBindingWithNamespace,
) as Promise<{ body: V1RoleBinding }>);
return response.body;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ describe('MR Permissions', () => {
cy.interceptOdh(
'POST /api/modelRegistryRoleBindings',
mockRoleBindingK8sResource({
namespace: MODEL_REGISTRY_DEFAULT_NAMESPACE,
subjects: projectSubjects,
roleRefName: 'registry-user-example-mr',
modelRegistryName: 'example-mr',
Expand All @@ -443,9 +442,6 @@ describe('MR Permissions', () => {

cy.wait('@addProject').then((interception) => {
expect(interception.request.body).to.containSubset({
metadata: {
namespace: 'odh-model-registries',
},
roleRef: {
apiGroup: 'rbac.authorization.k8s.io',
kind: 'Role',
Expand Down Expand Up @@ -484,9 +480,6 @@ describe('MR Permissions', () => {

cy.wait('@editProject').then((interception) => {
expect(interception.request.body).to.containSubset({
metadata: {
namespace: 'odh-model-registries',
},
roleRef: {
apiGroup: 'rbac.authorization.k8s.io',
kind: 'Role',
Expand Down
1 change: 0 additions & 1 deletion frontend/src/api/modelRegistry/errorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const handleModelRegistryFailures = <T>(promise: Promise<T>): Promise<T>
}
if (isCommonStateError(e)) {
// Common state errors are handled by useFetchState at storage level, let them deal with it
// TODO: check whether we need this or not
throw e;
}
// eslint-disable-next-line no-console
Expand Down
15 changes: 12 additions & 3 deletions frontend/src/services/modelRegistrySettingsService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as _ from 'lodash-es';
import { K8sStatus } from '@openshift/dynamic-plugin-sdk-utils';
import axios from '~/utilities/axios';
import { ModelRegistryKind, RoleBindingKind } from '~/k8sTypes';
Expand Down Expand Up @@ -66,13 +67,21 @@ export const listModelRegistryRoleBindings = (): Promise<RoleBindingKind[]> =>
throw new Error(e.response.data.message);
});

export const createModelRegistryRoleBinding = (data: RoleBindingKind): Promise<RoleBindingKind> =>
axios
.post(mrRoleBindingsUrl, data)
export const createModelRegistryRoleBinding = (data: RoleBindingKind): Promise<RoleBindingKind> => {
// Don't include the namespace in the object we pass because it would get rejected by requestSecurityGuard.
// (see backend/src/utils/route-security.ts)
// Instead the namespace will be reinjected by the backend
// (see backend/src/routes/api/modelRegistries/modelRegistryUtils.ts)
// This will be unnecessary when we remove this service as part of https://issues.redhat.com/browse/RHOAIENG-12077
const roleBindingWithoutNamespace: RoleBindingKind & { metadata: { namespace?: string } } =
_.omit(data, 'metadata.namespace');
return axios
.post(mrRoleBindingsUrl, roleBindingWithoutNamespace)
.then((response) => response.data)
.catch((e) => {
throw new Error(e.response.data.message);
});
};

export const deleteModelRegistryRoleBinding = (roleBindingName: string): Promise<K8sStatus> =>
axios
Expand Down
Loading