Skip to content

Commit

Permalink
Change flow of creating servingruntime
Browse files Browse the repository at this point in the history
  • Loading branch information
lucferbux committed May 25, 2023
1 parent 09b2271 commit f1ae4f7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ import {
requestsUnderLimits,
resourcesArePositive,
setUpTokenAuth,
createSecrets,
} from '~/pages/modelServing/utils';
import useCustomServingRuntimesEnabled from '~/pages/modelServing/customServingRuntimes/useCustomServingRuntimesEnabled';
import { getServingRuntimeFromName } from '~/pages/modelServing/customServingRuntimes/utils';
import { CreatingServingRuntimeObject } from '~/pages/modelServing/screens/types';
import { translateDisplayNameForK8s } from '~/pages/projects/utils';
import ServingRuntimeReplicaSection from './ServingRuntimeReplicaSection';
import ServingRuntimeSizeSection from './ServingRuntimeSizeSection';
Expand Down Expand Up @@ -131,15 +129,28 @@ const ManageServingRuntimeModal: React.FC<ManageServingRuntimeModalProps> = ({
const createRolebinding = servingRuntimeData.tokenAuth && allowCreate;

Promise.all<ServingRuntimeKind | string | void>([
createServingRuntime(
servingRuntimeData,
namespace,
servingRuntimeSelected,
customServingRuntimesEnabled,
{
dryRun: true,
},
),
...(editInfo?.servingRuntime
? [
updateServingRuntime(
servingRuntimeData,
editInfo?.servingRuntime,
customServingRuntimesEnabled,
{
dryRun: true,
},
),
]
: [
createServingRuntime(
servingRuntimeData,
namespace,
servingRuntimeSelected,
customServingRuntimesEnabled,
{
dryRun: true,
},
),
]),
setUpTokenAuth(
servingRuntimeData,
servingRuntimeName,
Expand All @@ -153,15 +164,25 @@ const ManageServingRuntimeModal: React.FC<ManageServingRuntimeModalProps> = ({
])
.then(() =>
Promise.all<ServingRuntimeKind | string | void>([
...(currentProject.metadata.labels?.['modelmesh-enabled']
...(currentProject.metadata.labels?.['modelmesh-enabled'] && allowCreate
? [addSupportModelMeshProject(currentProject.metadata.name)]
: []),
createServingRuntime(
servingRuntimeData,
namespace,
servingRuntimeSelected,
customServingRuntimesEnabled,
),
...(editInfo?.servingRuntime
? [
updateServingRuntime(
servingRuntimeData,
editInfo?.servingRuntime,
customServingRuntimesEnabled,
),
]
: [
createServingRuntime(
servingRuntimeData,
namespace,
servingRuntimeSelected,
customServingRuntimesEnabled,
),
]),
setUpTokenAuth(
servingRuntimeData,
servingRuntimeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ServingRuntimeTokenInput: React.FC<ServingRuntimeTokenInputProps> = ({
data,
setData,
token,
disabled
disabled,
}) => {
const checkDuplicates = (name: string): boolean => {
const duplicates = data.tokens.filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import IndentSection from '~/pages/projects/components/IndentSection';
import { UpdateObjectAtPropAndValue } from '~/pages/projects/types';
import { CreatingServingRuntimeObject } from '~/pages/modelServing/screens/types';
import ServingRuntimeTokenInput from './ServingRuntimeTokenInput';
import { AccessReviewResourceAttributes } from '~/k8sTypes';
import { useAccessReview } from '~/api';

type ServingRuntimeTokenSectionProps = {
data: CreatingServingRuntimeObject;
Expand Down Expand Up @@ -67,16 +65,23 @@ const ServingRuntimeTokenSection: React.FC<ServingRuntimeTokenSectionProps> = ({
/>
</FormGroup>

{!allowCreate && (
<Alert variant="warning" isInline title="You need admin permission to edit this section." />
)}

{data.tokenAuth && (
<IndentSection>
<Stack hasGutter>
<StackItem>
<Alert
variant="info"
isInline
title="The actual tokens will be created and displayed when the model server is configured."
/>
</StackItem>
{allowCreate && (
<StackItem>
<Alert
variant="info"
isInline
title="The actual tokens will be created and displayed when the model server is configured."
/>
</StackItem>
)}

{data.tokens.map((token) => (
<StackItem key={token.uuid}>
<ServingRuntimeTokenInput
Expand Down
21 changes: 6 additions & 15 deletions frontend/src/pages/modelServing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,10 @@ import {
replaceSecret,
assembleServiceAccount,
createServiceAccount,
getServiceAccount,
getRoleBinding,
} from '~/api';
import {
SecretKind,
K8sStatus,
K8sAPIOptions,
ServiceAccountKind,
RoleBindingKind,
} from '~/k8sTypes';
import { SecretKind, K8sStatus, K8sAPIOptions, RoleBindingKind } from '~/k8sTypes';
import { ContainerResources } from '~/types';
import { allSettledPromises } from '~/utilities/allSettledPromises';
import { translateDisplayNameForK8s } from '~/pages/projects/utils';
import { CreatingServingRuntimeObject } from '~/pages/modelServing/screens/types';

Expand Down Expand Up @@ -60,7 +52,7 @@ export const setUpTokenAuth = async (
namespace,
);
return Promise.all([
...( existingSecrets === undefined ? [createServiceAccount(serviceAccount, opts)] : []),
...(existingSecrets === undefined ? [createServiceAccount(serviceAccount, opts)] : []),
...(createRolebinding ? [createRoleBindingIfMissing(roleBinding, namespace, opts)] : []),
])
.then(() => createSecrets(fillData, servingRuntimeName, namespace, existingSecrets, opts))
Expand All @@ -71,14 +63,13 @@ export const createRoleBindingIfMissing = async (
rolebinding: RoleBindingKind,
namespace: string,
opts?: K8sAPIOptions,
): Promise<RoleBindingKind> => {
return getRoleBinding(namespace, rolebinding.metadata.name).catch((e) => {
if (e.status === 404) {
): Promise<RoleBindingKind> =>
getRoleBinding(namespace, rolebinding.metadata.name).catch((e) => {
if (e.statusObject?.code === 404) {
return createRoleBinding(rolebinding, opts);
}
throw e;
return Promise.reject(e);
});
};

export const createSecrets = async (
fillData: CreatingServingRuntimeObject,
Expand Down

0 comments on commit f1ae4f7

Please sign in to comment.