Skip to content

Commit

Permalink
Merge pull request #202 from jtomasek/fix-machine-cidr-dhcp
Browse files Browse the repository at this point in the history
Fix machine cidr dhcp
  • Loading branch information
Jiri Tomasek authored Sep 15, 2020
2 parents 2582c08 + 4eac778 commit 210efa3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/components/clusterConfiguration/BasicNetworkFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type BasicNetworkFieldsProps = {

const BasicNetworkFields: React.FC<BasicNetworkFieldsProps> = ({ cluster, hostSubnets }) => {
const { validateField, values, setFieldValue } = useFormikContext<ClusterConfigurationValues>();

// Automatically set hostSubnet if hostSubnets become available
React.useEffect(() => {
if (
!values.hostSubnet ||
Expand Down Expand Up @@ -89,8 +91,10 @@ const BasicNetworkFields: React.FC<BasicNetworkFieldsProps> = ({ cluster, hostSu
: undefined;
}}
onChange={() => {
validateField('ingressVip');
validateField('apiVip');
if (!values.vipDhcpAllocation) {
validateField('ingressVip');
validateField('apiVip');
}
}}
isRequired
/>
Expand Down
17 changes: 13 additions & 4 deletions src/components/clusterConfiguration/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Netmask } from 'netmask';
import { HostSubnets, ClusterConfigurationValues } from '../../types/clusters';
import { Cluster, Inventory, ManagedDomain } from '../../api/types';
import { stringToJSON } from '../../api/utils';
import { computeHostname } from '../hosts/Hostname';

export const NO_SUBNETS_AVAILABLE = 'No subnets available';

Expand Down Expand Up @@ -37,7 +38,7 @@ export const getHostSubnets = (cluster: Cluster): HostSubnets => {
const inventory = stringToJSON<Inventory>(host.inventory) || {};
acc = {
...acc,
[host.id]: inventory.hostname,
[host.id]: computeHostname(host, inventory),
};
return acc;
}, {}) || {};
Expand All @@ -54,6 +55,11 @@ export const getHostSubnets = (cluster: Cluster): HostSubnets => {
);
};

export const getSubnetFromMachineNetworkCidr = (machineNetworkCidr: string) => {
const subnet = new Netmask(machineNetworkCidr as string);
return `${subnet.toString()} (${subnet.first}-${subnet.last})`;
};

export const getInitialValues = (
cluster: Cluster,
managedDomains: ManagedDomain[],
Expand All @@ -63,10 +69,13 @@ export const getInitialValues = (
clusterNetworkCidr: cluster.clusterNetworkCidr || '',
clusterNetworkHostPrefix: cluster.clusterNetworkHostPrefix || 0,
serviceNetworkCidr: cluster.serviceNetworkCidr || '',
apiVip: cluster.apiVip || '',
ingressVip: cluster.ingressVip || '',
apiVip: cluster.vipDhcpAllocation ? '' : cluster.apiVip || '',
ingressVip: cluster.vipDhcpAllocation ? '' : cluster.ingressVip || '',
sshPublicKey: cluster.sshPublicKey || '',
hostSubnet: findMatchingSubnet(cluster.ingressVip, cluster.apiVip, getHostSubnets(cluster)),
hostSubnet:
cluster.vipDhcpAllocation && cluster.machineNetworkCidr
? getSubnetFromMachineNetworkCidr(cluster.machineNetworkCidr)
: findMatchingSubnet(cluster.ingressVip, cluster.apiVip, getHostSubnets(cluster)),
useRedHatDnsService:
!!cluster.baseDnsDomain && managedDomains.map((d) => d.domain).includes(cluster.baseDnsDomain),
shareDiscoverySshKey:
Expand Down

0 comments on commit 210efa3

Please sign in to comment.