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

feat(xo-web/recipes): static network config for k8s recipe #6598

Merged
merged 23 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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: 2 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@

<!--packages-start-->

- xo-web minor
ggunullu marked this conversation as resolved.
Show resolved Hide resolved

<!--packages-end-->
5 changes: 5 additions & 0 deletions packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,11 @@ const messages = {
recipeMasterNameLabel: 'Master name',
recipeNumberOfNodesLabel: 'Number of nodes',
recipeSshKeyLabel: 'SSH key',
recipeStaticIpAddresses: 'Static IP addresses',
recipeMasterIpAddress: 'Master node IP address',
recipeWorkerIpAddress: 'Worker node { i } IP address',
recipeNetworkMask: 'Network Mask',
recipeGatewayIpAddress: 'Gateway IP address',

// Audit
auditActionEvent: 'Action/Event',
Expand Down
76 changes: 76 additions & 0 deletions packages/xo-web/src/xo-app/hub/recipes/recipe-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export default decorate([
[name]: value,
})
},
toggleStaticIpAddress(__, sip) {
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
const { name } = sip.target
const { onChange, value: prevValue } = this.props
onChange({
...prevValue,
[name]: sip.target.checked,
})
},
},
computed: {
networkPredicate:
Expand Down Expand Up @@ -100,6 +108,74 @@ export default decorate([
value={value.nbNodes}
/>
</FormGrid.Row>
<FormGrid.Row>
<label>
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
{_('recipeStaticIpAddresses')}
<input
className='form-control'
name='staticIpAddress'
onChange={effects.toggleStaticIpAddress}
type='checkbox'
value={value.staticIpAddress}
/>
pdonias marked this conversation as resolved.
Show resolved Hide resolved
</label>
</FormGrid.Row>
{value.staticIpAddress && [
<FormGrid.Row key='masterIpAddrRow'>
<label>{_('recipeMasterIpAddress')}</label>
<input
className='form-control'
name='masterIpAddress'
onChange={effects.onChangeValue}
placeholder={formatMessage(messages.recipeMasterIpAddress)}
required
type='text'
value={value.masterIpAddress}
/>
</FormGrid.Row>,
<FormGrid.Row key='netmaskRow'>
<label>{_('recipeNetworkMask')}</label>
<input
className='form-control'
name='networkMask'
onChange={effects.onChangeValue}
placeholder={formatMessage(messages.recipeNetworkMask)}
required
type='text'
value={value.networkMask}
/>
</FormGrid.Row>,
<FormGrid.Row key='gatewayRow'>
<label>{_('recipeGatewayIpAddress')}</label>
<input
className='form-control'
name='gatewayIpAddress'
onChange={effects.onChangeValue}
placeholder={formatMessage(messages.recipeGatewayIpAddress)}
required
type='text'
value={value.gatewayIpAddress}
/>
</FormGrid.Row>,
]}
{value.staticIpAddress &&
[...Array(+value.nbNodes)].map((v, i) => {
const workerIpAddress = 'workerIpAddress' + (i + 1)
ggunullu marked this conversation as resolved.
Show resolved Hide resolved
return (
<FormGrid.Row key={i}>
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
<label>{_('recipeWorkerIpAddress', { i: i + 1 })}</label>
<input
className='form-control'
name={workerIpAddress}
onChange={effects.onChangeValue}
placeholder={formatMessage(messages.recipeWorkerIpAddress, { i: i + 1 })}
required
type='text'
value={value.workerIpAddress}
/>
</FormGrid.Row>
)
})}
<FormGrid.Row>
<label>{_('recipeSshKeyLabel')}</label>
<input
Expand Down
27 changes: 25 additions & 2 deletions packages/xo-web/src/xo-app/hub/recipes/recipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default decorate([
defaultValue: {
pool: {},
},
render: props => <RecipeForm {...props} />,
render: props => <RecipeForm {...props} value={{ nbNodes: 1, ...props.value }} />,
header: (
<span>
<Icon icon='hub-recipe' /> {RECIPE_INFO.name}
Expand All @@ -51,15 +51,38 @@ export default decorate([
size: 'medium',
})

const { masterName, nbNodes, network, sr, sshKey } = recipeParams
const {
gatewayIpAddress,
masterIpAddress,
masterName,
nbNodes,
network,
networkMask,
sr,
sshKey,
staticIpAddress,
} = recipeParams

let workerNodeIpAddresses
if (staticIpAddress === true) {
ggunullu marked this conversation as resolved.
Show resolved Hide resolved
workerNodeIpAddresses = []
for (let i = 0; i < nbNodes; i++) {
const key = 'workerIpAddress' + (i + 1)
workerNodeIpAddresses[i] = recipeParams[key]
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
}
}

markRecipeAsCreating(RECIPE_INFO.id)
const tag = await createKubernetesCluster({
gatewayIpAddress,
masterIpAddress,
masterName,
nbNodes: +nbNodes,
network: network.id,
networkMask,
sr: sr.id,
sshKey,
workerNodeIpAddresses,
ggunullu marked this conversation as resolved.
Show resolved Hide resolved
})
markRecipeAsDone(RECIPE_INFO.id)

Expand Down