-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial support for adding OVA providers
Signed-off-by: yaacov <yzamir@redhat.com>
- Loading branch information
Showing
20 changed files
with
448 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: forklift.konveyor.io/v1beta1 | ||
kind: Provider | ||
metadata: | ||
name: ova-test | ||
namespace: konveyor-forklift | ||
spec: | ||
secret: {} | ||
type: ova | ||
url: 'https://fake.coml:5000/files/ova' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
.../forklift-console-plugin/src/modules/Providers/modals/EditProviderURL/OVAEditURLModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import { useForkliftTranslation } from 'src/utils/i18n'; | ||
|
||
import { ProviderModel } from '@kubev2v/types'; | ||
import { ModalVariant } from '@patternfly/react-core'; | ||
|
||
import { EditModal, ValidationHookType } from '../EditModal'; | ||
|
||
import { patchProviderURL } from './utils/patchProviderURL'; | ||
import { EditProviderURLModalProps } from './EditProviderURLModal'; | ||
|
||
export const OVAEditURLModal: React.FC<EditProviderURLModalProps> = (props) => { | ||
const { t } = useForkliftTranslation(); | ||
|
||
const urlValidationHook: ValidationHookType = (value) => { | ||
const isValidURL = true; | ||
|
||
return isValidURL | ||
? { | ||
validationHelpText: undefined, | ||
validated: 'success', | ||
} | ||
: { | ||
validationHelpText: t( | ||
'URL must start with https:// or http:// and contain valid hostname and path', | ||
), | ||
validated: 'error', | ||
}; | ||
}; | ||
|
||
return ( | ||
<EditModal | ||
{...props} | ||
jsonPath={'spec.url'} | ||
title={props?.title || t('Edit URL')} | ||
label={props?.label || t('URL')} | ||
model={ProviderModel} | ||
variant={ModalVariant.large} | ||
body={t('Specify the end point to the NFS server path serving the OVA file[s].')} | ||
helperText={t('Please enter URL.')} | ||
onConfirmHook={patchProviderURL} | ||
validationHook={urlValidationHook} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/forklift-console-plugin/src/modules/Providers/utils/validators/provider/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ft-console-plugin/src/modules/Providers/utils/validators/provider/ovaProviderValidator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { V1beta1Provider } from '@kubev2v/types'; | ||
|
||
import { validateK8sName } from '../common'; | ||
|
||
export function ovaProviderValidator(provider: V1beta1Provider) { | ||
const name = provider?.metadata?.name; | ||
|
||
if (!validateK8sName(name)) { | ||
return new Error('invalided kubernetes resource name'); | ||
} | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...ft-console-plugin/src/modules/Providers/views/create/components/OVAProviderCreateForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React, { useCallback, useReducer } from 'react'; | ||
import { Validation } from 'src/modules/Providers/utils'; | ||
import { useForkliftTranslation } from 'src/utils/i18n'; | ||
|
||
import { V1beta1Provider } from '@kubev2v/types'; | ||
import { Form, FormGroup, TextInput } from '@patternfly/react-core'; | ||
|
||
export interface OVAProviderCreateFormProps { | ||
provider: V1beta1Provider; | ||
onChange: (newValue: V1beta1Provider) => void; | ||
} | ||
|
||
export const OVAProviderCreateForm: React.FC<OVAProviderCreateFormProps> = ({ | ||
provider, | ||
onChange, | ||
}) => { | ||
const { t } = useForkliftTranslation(); | ||
|
||
const url = provider?.spec?.url || ''; | ||
|
||
const initialState = { | ||
validation: { | ||
url: 'default' as Validation, | ||
}, | ||
}; | ||
|
||
const reducer = (state, action) => { | ||
switch (action.type) { | ||
case 'SET_FIELD_VALIDATED': | ||
return { | ||
...state, | ||
validation: { | ||
...state.validation, | ||
[action.payload.field]: action.payload.validationState, | ||
}, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
const [state, dispatch] = useReducer(reducer, initialState); | ||
|
||
const handleChange = useCallback( | ||
(id, value) => { | ||
const trimmedValue = value.trim(); | ||
|
||
if (id === 'url') { | ||
const validationState = 'success'; | ||
dispatch({ type: 'SET_FIELD_VALIDATED', payload: { field: id, validationState } }); | ||
|
||
onChange({ ...provider, spec: { ...provider.spec, url: trimmedValue } }); | ||
} | ||
}, | ||
[provider], | ||
); | ||
|
||
return ( | ||
<Form isWidthLimited className="forklift-section-provider-edit"> | ||
<FormGroup | ||
label={t('URL')} | ||
fieldId="url" | ||
helperText={t('URL of the OVA provider')} | ||
validated={state.validation.url} | ||
helperTextInvalid={t('Error: URL must be valid.')} | ||
> | ||
<TextInput | ||
type="text" | ||
id="url" | ||
name="url" | ||
value={url} | ||
validated={state.validation.url} | ||
onChange={(value) => handleChange('url', value)} | ||
/> | ||
</FormGroup> | ||
</Form> | ||
); | ||
}; |
2 changes: 2 additions & 0 deletions
2
packages/forklift-console-plugin/src/modules/Providers/views/create/components/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.