Skip to content

Commit

Permalink
update model serving compatibility for connection types
Browse files Browse the repository at this point in the history
  • Loading branch information
christianvogt committed Nov 1, 2024
1 parent 1cd4f29 commit 0d8a09e
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 156 deletions.
7 changes: 6 additions & 1 deletion frontend/src/__mocks__/mockConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type MockConnection = {
displayName?: string;
description?: string;
data?: { [key: string]: string };
managed?: boolean;
};

export const mockConnection = ({
Expand All @@ -16,13 +17,17 @@ export const mockConnection = ({
displayName,
description,
data = {},
managed = true,
}: MockConnection): Connection => ({
kind: 'Secret',
apiVersion: 'v1',
metadata: {
name,
namespace,
labels: { 'opendatahub.io/dashboard': 'true', 'opendatahub.io/managed': 'true' },
labels: {
'opendatahub.io/dashboard': 'true',
...(managed ? { 'opendatahub.io/managed': 'true' } : {}),
},
annotations: {
'opendatahub.io/connection-type': connectionType,
...(displayName && { 'openshift.io/display-name': displayName }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,6 @@ class ConnectionTypeRow extends TableRow {
return this;
}

shouldHaveModelServingCompatibility() {
this.findConnectionTypeCompatibility().should('have.text', 'Model serving');
return this;
}

shouldHaveCreator(creator: string) {
this.findConnectionTypeCreator().should('have.text', creator);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('Connection types', () => {
row2.shouldHaveDescription('description 2');
row2.shouldShowPreInstalledLabel();
row2.shouldBeDisabled();
row2.shouldHaveModelServingCompatibility();
row2.findConnectionTypeCompatibility().should('have.text', 'S3 compatible object storage');

row2.findKebabAction('Preview').click();
connectionTypePreviewModal.shouldBeOpen();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ describe('Connections', () => {
projectDetails.shouldBeEmptyState('Connections', 'connections', true);
});

it('List connections', () => {
it.only('List connections', () => {

Check failure on line 54 in frontend/src/__tests__/cypress/cypress/tests/mocked/projects/connections.cy.ts

View workflow job for this annotation

GitHub Actions / Tests (18.x)

it.only not permitted
initIntercepts();
projectDetails.visitSection('test-project', 'connections');
projectDetails.shouldBeEmptyState('Connections', 'connections', false);
const row1 = connectionsPage.getConnectionRow('test1');
row1.find().findByText('test1').should('exist');
row1.find().findByText('s3').should('exist');
row1.find().findByText('Model serving').should('exist');
row1.find().findByText('S3 compatible object storage').should('exist');
const row2 = connectionsPage.getConnectionRow('test2');
row2.find().findByText('test2').should('exist');
row2.find().findByText('postgres').should('exist');
row1.find().findByText('Model serving').should('exist');
row2.find().findByText('S3 compatible object storage').should('not.exist');
});

it('Delete a connection', () => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/concepts/connectionTypes/CompatibilityLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import { Label } from '@patternfly/react-core';
import { CompatibleTypes } from '~/concepts/connectionTypes/utils';
import { ModelServingCompatibleTypes } from '~/concepts/connectionTypes/utils';

type Props = {
type: CompatibleTypes;
type: ModelServingCompatibleTypes;
};

const CompatibilityLabel: React.FC<Props> = ({ type }) => <Label color="blue">{type}</Label>;
Expand Down
195 changes: 142 additions & 53 deletions frontend/src/concepts/connectionTypes/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mockConnection } from '~/__mocks__/mockConnection';
import { mockConnectionTypeConfigMapObj } from '~/__mocks__/mockConnectionType';
import {
ConnectionTypeFieldType,
Expand All @@ -6,15 +7,14 @@ import {
TextField,
} from '~/concepts/connectionTypes/types';
import {
CompatibleTypes,
defaultValueToString,
fieldNameToEnvVar,
fieldTypeToString,
getCompatibleTypes,
isModelServingCompatible,
getConnectionModelServingCompatibleTypes,
isModelServingCompatibleConnection,
isModelServingTypeCompatible,
isValidEnvVar,
ModelServingCompatibleConnectionTypes,
ModelServingCompatibleTypes,
toConnectionTypeConfigMap,
toConnectionTypeConfigMapObj,
} from '~/concepts/connectionTypes/utils';
Expand Down Expand Up @@ -268,75 +268,164 @@ describe('isValidEnvVar', () => {
});
});

describe('isModelServingCompatible', () => {
it('should identify model serving compatible env vars', () => {
expect(isModelServingCompatible([])).toBe(false);
describe('isModelServingCompatibleConnection', () => {
it('should identify model serving compatible connections', () => {
expect(isModelServingCompatibleConnection(mockConnection({}))).toBe(false);
expect(
isModelServingCompatible([
'AWS_ACCESS_KEY_ID',
'AWS_SECRET_ACCESS_KEY',
'AWS_S3_ENDPOINT',
'AWS_S3_BUCKET',
]),
isModelServingCompatibleConnection(
mockConnection({
data: {
AWS_ACCESS_KEY_ID: 'test',
AWS_SECRET_ACCESS_KEY: 'test',
AWS_S3_ENDPOINT: 'test',
AWS_S3_BUCKET: 'test',
},
}),
),
).toBe(true);
expect(isModelServingCompatible(['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY'])).toBe(false);
expect(
isModelServingCompatible([
'AWS_ACCESS_KEY_ID',
'AWS_SECRET_ACCESS_KEY',
'AWS_S3_ENDPOINT',
'AWS_S3_BUCKET',
'URI',
]),
isModelServingCompatibleConnection(
mockConnection({
connectionType: 'test',
data: {
AWS_ACCESS_KEY_ID: 'test',
AWS_SECRET_ACCESS_KEY: 'test',
AWS_S3_ENDPOINT: 'test',
AWS_S3_BUCKET: 'test',
},
}),
),
).toBe(false);
expect(
isModelServingCompatibleConnection(
mockConnection({
managed: false,
data: {
AWS_ACCESS_KEY_ID: 'test',
AWS_SECRET_ACCESS_KEY: 'test',
AWS_S3_ENDPOINT: 'test',
AWS_S3_BUCKET: 'test',
},
}),
),
).toBe(false);
expect(
isModelServingCompatibleConnection(
mockConnection({
data: {
AWS_ACCESS_KEY_ID: 'test',
},
}),
),
).toBe(false);
expect(
isModelServingCompatibleConnection(
mockConnection({
data: {
URI: 'test',
},
}),
),
).toBe(true);
});
});

describe('getCompatibleTypes', () => {
it('should return compatible types', () => {
expect(getCompatibleTypes(['AWS_ACCESS_KEY_ID'])).toEqual([]);
describe('getConnectionModelServingCompatibleTypes', () => {
it('should identify model serving compatible connections', () => {
expect(getConnectionModelServingCompatibleTypes(mockConnection({}))).toEqual([]);
expect(
getConnectionModelServingCompatibleTypes(
mockConnection({
data: {
AWS_ACCESS_KEY_ID: 'test',
AWS_SECRET_ACCESS_KEY: 'test',
AWS_S3_ENDPOINT: 'test',
AWS_S3_BUCKET: 'test',
},
}),
),
).toEqual([ModelServingCompatibleTypes.S3ObjectStorage]);
expect(
getCompatibleTypes([
'AWS_ACCESS_KEY_ID',
'AWS_SECRET_ACCESS_KEY',
'AWS_S3_ENDPOINT',
'AWS_S3_BUCKET',
]),
).toEqual([CompatibleTypes.ModelServing]);
getConnectionModelServingCompatibleTypes(
mockConnection({
connectionType: 'test',
data: {
AWS_ACCESS_KEY_ID: 'test',
AWS_SECRET_ACCESS_KEY: 'test',
AWS_S3_ENDPOINT: 'test',
AWS_S3_BUCKET: 'test',
},
}),
),
).toEqual([]);
expect(
getConnectionModelServingCompatibleTypes(
mockConnection({
managed: false,
data: {
AWS_ACCESS_KEY_ID: 'test',
AWS_SECRET_ACCESS_KEY: 'test',
AWS_S3_ENDPOINT: 'test',
AWS_S3_BUCKET: 'test',
},
}),
),
).toEqual([]);
expect(
getConnectionModelServingCompatibleTypes(
mockConnection({
data: {
AWS_ACCESS_KEY_ID: 'test',
},
}),
),
).toEqual([]);
expect(
getConnectionModelServingCompatibleTypes(
mockConnection({
data: {
URI: 'test',
},
}),
),
).toEqual([ModelServingCompatibleTypes.OCI, ModelServingCompatibleTypes.URI]);
expect(
getCompatibleTypes([
'AWS_ACCESS_KEY_ID',
'AWS_SECRET_ACCESS_KEY',
'AWS_S3_ENDPOINT',
'AWS_S3_BUCKET',
'URI',
]),
).toEqual([CompatibleTypes.ModelServing]);
getConnectionModelServingCompatibleTypes(
mockConnection({
data: {
AWS_ACCESS_KEY_ID: 'test',
AWS_SECRET_ACCESS_KEY: 'test',
AWS_S3_ENDPOINT: 'test',
AWS_S3_BUCKET: 'test',
URI: 'test',
},
}),
),
).toEqual([
ModelServingCompatibleTypes.S3ObjectStorage,
ModelServingCompatibleTypes.OCI,
ModelServingCompatibleTypes.URI,
]);
});
});

describe('isModelServingTypeCompatible', () => {
it('should identify model serving compatible env vars', () => {
expect(
isModelServingTypeCompatible(['invalid'], ModelServingCompatibleConnectionTypes.ModelServing),
isModelServingTypeCompatible(
['AWS_ACCESS_KEY_ID'],
ModelServingCompatibleTypes.S3ObjectStorage,
),
).toBe(false);
expect(
isModelServingTypeCompatible(
['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_S3_ENDPOINT', 'AWS_S3_BUCKET'],
ModelServingCompatibleConnectionTypes.ModelServing,
ModelServingCompatibleTypes.S3ObjectStorage,
),
).toBe(true);
expect(
isModelServingTypeCompatible(['invalid'], ModelServingCompatibleConnectionTypes.OCI),
).toBe(false);
expect(isModelServingTypeCompatible(['URI'], ModelServingCompatibleConnectionTypes.OCI)).toBe(
true,
);
expect(
isModelServingTypeCompatible(['invalid'], ModelServingCompatibleConnectionTypes.URI),
).toBe(false);
expect(isModelServingTypeCompatible(['URI'], ModelServingCompatibleConnectionTypes.URI)).toBe(
true,
);
expect(isModelServingTypeCompatible(['invalid'], ModelServingCompatibleTypes.OCI)).toBe(false);
expect(isModelServingTypeCompatible(['URI'], ModelServingCompatibleTypes.OCI)).toBe(true);
expect(isModelServingTypeCompatible(['invalid'], ModelServingCompatibleTypes.URI)).toBe(false);
expect(isModelServingTypeCompatible(['URI'], ModelServingCompatibleTypes.URI)).toBe(true);
});
});
2 changes: 1 addition & 1 deletion frontend/src/concepts/connectionTypes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export type ConnectionTypeValueType = ConnectionTypeDataField['properties']['def
export type Connection = SecretKind & {
metadata: {
labels: DashboardLabels & {
'opendatahub.io/managed': 'true';
'opendatahub.io/managed'?: 'true';
};
annotations: DisplayNameAnnotations & {
'opendatahub.io/connection-type': string;
Expand Down
Loading

0 comments on commit 0d8a09e

Please sign in to comment.