-
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 <[email protected]>
- Loading branch information
Showing
20 changed files
with
454 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
46 changes: 46 additions & 0 deletions
46
.../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,46 @@ | ||
import React from 'react'; | ||
import { useForkliftTranslation } from 'src/utils/i18n'; | ||
|
||
import { ProviderModel } from '@kubev2v/types'; | ||
import { ModalVariant } from '@patternfly/react-core'; | ||
|
||
import { validateURL } from '../../utils'; | ||
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 = validateURL(value.toString().trim()); | ||
|
||
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
18 changes: 18 additions & 0 deletions
18
...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,18 @@ | ||
import { V1beta1Provider } from '@kubev2v/types'; | ||
|
||
import { validateK8sName, validateURL } from '../common'; | ||
|
||
export function ovaProviderValidator(provider: V1beta1Provider) { | ||
const name = provider?.metadata?.name; | ||
const url = provider?.spec?.url || ''; | ||
|
||
if (!validateK8sName(name)) { | ||
return new Error('invalided kubernetes resource name'); | ||
} | ||
|
||
if (!validateURL(url)) { | ||
return new Error('invalided URL'); | ||
} | ||
|
||
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 { validateURL, 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 = validateURL(trimmedValue) ? 'success' : 'error'; | ||
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.