mirror of https://github.com/rancher/ui.git
refactor the logic backing GKE network/subnetwork selections
While working on a ticket to provide the ability to de-select subnetworks when using the create subnetwork option I discovered the options were all messed up and allowed you to misconfigure yourself into a hole. I've moved ipalias and related networks settings out of advanced becuase depending on what you select for your subnetwork the ability to choose ipalias and the other settings changes. This change allows you deselect a node subnet so you can create a subnetwork automatically. rancher/rancher#21079
This commit is contained in:
parent
62bee3bdf0
commit
3399b66bc3
|
|
@ -1,15 +1,15 @@
|
|||
import Component from '@ember/component'
|
||||
import ClusterDriver from 'shared/mixins/cluster-driver';
|
||||
import layout from './template';
|
||||
|
||||
import {
|
||||
get, set, computed, observer, setProperties
|
||||
} from '@ember/object';
|
||||
import { sortableNumericSuffix } from 'shared/utils/util';
|
||||
import { reject, all } from 'rsvp';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { equal } from '@ember/object/computed'
|
||||
import { equal } from '@ember/object/computed';
|
||||
import $ from 'jquery';
|
||||
import { isEmpty } from '@ember/utils';
|
||||
|
||||
const times = [
|
||||
{
|
||||
|
|
@ -224,6 +224,8 @@ export default Component.extend(ClusterDriver, {
|
|||
diskType: 'pd-standard',
|
||||
region: 'us-west2',
|
||||
taints: [],
|
||||
useIpAliases: true,
|
||||
ipPolicyCreateSubnetwork: true,
|
||||
});
|
||||
|
||||
setProperties(this, {
|
||||
|
|
@ -448,8 +450,14 @@ export default Component.extend(ClusterDriver, {
|
|||
|
||||
const subNetworkContent = get(this, 'subNetworkContent') || []
|
||||
|
||||
if (subNetworkContent.length > 0) {
|
||||
set(this, 'config.subNetwork', subNetworkContent[0] && subNetworkContent[0].value)
|
||||
if (subNetworkContent.length > 1) {
|
||||
const firstNonNullSubnetMatch = subNetworkContent.find((sn) => !isEmpty(sn.value));
|
||||
|
||||
setProperties(this, {
|
||||
'config.subNetwork': firstNonNullSubnetMatch.value,
|
||||
'config.ipPolicyCreateSubnetwork': false,
|
||||
})
|
||||
|
||||
const secondaryIpRangeContent = get(this, 'secondaryIpRangeContent') || []
|
||||
|
||||
if (secondaryIpRangeContent.length > 0) {
|
||||
|
|
@ -463,6 +471,20 @@ export default Component.extend(ClusterDriver, {
|
|||
}
|
||||
}),
|
||||
|
||||
subnetworkChange: observer('config.subNetwork', function() {
|
||||
if (this.saving) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { config: { subNetwork } } = this;
|
||||
|
||||
if (isEmpty(subNetwork)) {
|
||||
set(this, 'config.ipPolicyCreateSubnetwork', true);
|
||||
} else {
|
||||
set(this, 'config.ipPolicyCreateSubnetwork', false);
|
||||
}
|
||||
}),
|
||||
|
||||
secondaryIpRangeContentChange: observer('secondaryIpRangeContent.[]', 'config.useIpAliases', function() {
|
||||
if (this.saving) {
|
||||
return;
|
||||
|
|
@ -480,8 +502,15 @@ export default Component.extend(ClusterDriver, {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!get(this, 'config.useIpAliases')) {
|
||||
set(this, 'config.enablePrivateNodes', false)
|
||||
if (get(this, 'config.useIpAliases')) {
|
||||
if (!isEmpty(this.config.subNetwork)) {
|
||||
set(this, 'config.ipPolicyCreateSubnetwork', false);
|
||||
}
|
||||
} else {
|
||||
setProperties(this, {
|
||||
'config.enablePrivateNodes': false,
|
||||
'config.ipPolicyCreateSubnetwork': false,
|
||||
});
|
||||
}
|
||||
}),
|
||||
|
||||
|
|
@ -544,43 +573,62 @@ export default Component.extend(ClusterDriver, {
|
|||
return zoneChoices.filter((z) => (z.name || '').startsWith(locationName) && z.name !== zone)
|
||||
}),
|
||||
|
||||
networkContent: computed('networks', function() {
|
||||
networkContent: computed('networks', 'config.zone', function() {
|
||||
return get(this, 'networks')
|
||||
}),
|
||||
|
||||
subNetworkContent: computed('subNetworks.[]', 'config.network', function() {
|
||||
const subNetworks = get(this, 'subNetworks') || []
|
||||
const networkName = get(this, 'config.network')
|
||||
subNetworkContent: computed('subNetworks.[]', 'config.network', 'config.zone', function() {
|
||||
const {
|
||||
config: { network: networkName },
|
||||
networkContent,
|
||||
subNetworks = [],
|
||||
} = this;
|
||||
|
||||
const out = subNetworks.filter((s) => {
|
||||
const { network = '' } = s
|
||||
const arr = network.split('/') || []
|
||||
const networkDisplayName = arr[arr.length - 1]
|
||||
const filteredSubnets = (subNetworks || []).filter((s) => {
|
||||
const network = networkContent.findBy('selfLink', s.network);
|
||||
const networkDisplayName = network.name;
|
||||
|
||||
if (networkDisplayName === networkName) {
|
||||
return true
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const mappedSubnets = filteredSubnets.map((o) => {
|
||||
const network = networkContent.findBy('selfLink', o.network);
|
||||
const networkDisplayName = network.name;
|
||||
|
||||
return out.map((o) => {
|
||||
return {
|
||||
label: `${ o.name }(${ o.ipCidrRange })`,
|
||||
value: o.name,
|
||||
secondaryIpRanges: o.secondaryIpRanges,
|
||||
networkDisplayName
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const defaultSubnetAry = [{
|
||||
label: this.intl.t('clusterNew.googlegke.ipPolicyCreateSubnetwork.autoLabel'),
|
||||
value: '',
|
||||
}];
|
||||
|
||||
return [...defaultSubnetAry, ...mappedSubnets];
|
||||
}),
|
||||
|
||||
secondaryIpRangeContent: computed('subNetworkContent.[]', 'config.network', function() {
|
||||
const subNetworkContent = get(this, 'subNetworkContent')
|
||||
const { secondaryIpRanges = [] } = subNetworkContent
|
||||
const { subNetworkContent = [], config: { network } } = this;
|
||||
const subNetwork = subNetworkContent.findBy('networkDisplayName', network);
|
||||
|
||||
if (subNetwork) {
|
||||
const { secondaryIpRanges = [] } = subNetwork;
|
||||
|
||||
return secondaryIpRanges.map((s) => {
|
||||
return {
|
||||
lable: `${ s.rangeName }(${ s.ipCidrRange })`,
|
||||
label: `${ s.rangeName }(${ s.ipCidrRange })`,
|
||||
value: s.rangeName,
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
return [];
|
||||
}),
|
||||
|
||||
serviceAccountContent: computed('serviceAccounts', function() {
|
||||
|
|
@ -593,6 +641,24 @@ export default Component.extend(ClusterDriver, {
|
|||
return get(this, 'maintenanceWindowTimes').findBy('value', get(this, 'config.maintenanceWindow')) || { label: 'Any Time' };
|
||||
}),
|
||||
|
||||
shouldAllowDisableCreateSubNetwork: computed('config.subNetwork', function() {
|
||||
const {
|
||||
config: { subNetwork },
|
||||
secondaryIpRangeContent,
|
||||
editing,
|
||||
} = this;
|
||||
|
||||
if (isEmpty(subNetwork)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (editing && isEmpty(secondaryIpRangeContent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}),
|
||||
|
||||
fetchZones() {
|
||||
return get(this, 'globalStore').rawRequest({
|
||||
url: '/meta/gkeZones',
|
||||
|
|
|
|||
|
|
@ -315,14 +315,16 @@
|
|||
selection=config.enableHorizontalPodAutoscaling
|
||||
value=true
|
||||
disabled=editing
|
||||
}} {{t "generic.enabled"}}
|
||||
}}
|
||||
{{t "generic.enabled"}}
|
||||
</label>
|
||||
<label class={{concat (if editing "text-muted") " hand"}}>
|
||||
{{radio-button
|
||||
selection=config.enableHorizontalPodAutoscaling
|
||||
value=false
|
||||
disabled=editing
|
||||
}} {{t "generic.disabled"}}
|
||||
}}
|
||||
{{t "generic.disabled"}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -345,6 +347,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col span-6">
|
||||
<label class="acc-label">
|
||||
|
|
@ -385,9 +388,6 @@
|
|||
{{/if}}
|
||||
</div>
|
||||
|
||||
{{#advanced-section advanced=clusterAdvanced}}
|
||||
<h4 class="mt-20 mb-10">{{t "clusterNew.googlegke.header.iPAllocationPolicy"}}</h4>
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col span-6">
|
||||
<label class="acc-label">
|
||||
|
|
@ -400,43 +400,18 @@
|
|||
value=true
|
||||
disabled=editing
|
||||
}}
|
||||
{{t "generic.yes"}}
|
||||
{{t "generic.enabled"}}
|
||||
</label>
|
||||
<label class={{concat (if editing "text-muted") " hand"}}>
|
||||
{{radio-button
|
||||
selection=config.useIpAliases
|
||||
value=false
|
||||
disabled=editing
|
||||
}}
|
||||
{{t "generic.no"}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{{#if config.useIpAliases}}
|
||||
<div class="col span-6">
|
||||
<label class="acc-label">
|
||||
{{t "clusterNew.googlegke.ipPolicyCreateSubnetwork.label"}}
|
||||
</label>
|
||||
<div class="form-control-static">
|
||||
<label class={{concat (if editing "text-muted") " mr-20 hand"}}>
|
||||
{{radio-button
|
||||
selection=config.ipPolicyCreateSubnetwork
|
||||
value=true
|
||||
disabled=editing
|
||||
}}
|
||||
{{t "generic.enabled"}}
|
||||
</label>
|
||||
<label class={{concat (if editing "text-muted") " hand"}} class={{concat (if (eq secondaryIpRangeContent.length 0) "text-muted") " hand"}}>
|
||||
{{radio-button
|
||||
selection=config.ipPolicyCreateSubnetwork
|
||||
value=false
|
||||
disabled=(or editing (eq secondaryIpRangeContent.length 0))
|
||||
disabled=(or editing (not config.subNetwork))
|
||||
}}
|
||||
{{t "generic.disabled"}}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{{/if}}
|
||||
</div>
|
||||
{{#if config.useIpAliases}}
|
||||
{{#if (and config.ipPolicyCreateSubnetwork config.useIpAliases)}}
|
||||
|
|
@ -490,6 +465,8 @@
|
|||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
|
||||
{{#advanced-section advanced=clusterAdvanced}}
|
||||
<h4 class="mt-20 mb-10">
|
||||
{{t "clusterNew.googlegke.header.privateCluster"}}
|
||||
</h4>
|
||||
|
|
|
|||
|
|
@ -3620,12 +3620,13 @@ clusterNew:
|
|||
label: Master IP range
|
||||
placeholder: e.g. 10.42.0.0/28
|
||||
useIpAliases:
|
||||
label: Use Ip Aliases
|
||||
label: Ip Aliases
|
||||
ipPolicySubnetworkName:
|
||||
label: Subnetwork Name
|
||||
placeholder: Your Subnetwork Name
|
||||
ipPolicyCreateSubnetwork:
|
||||
label: Create Subnetwork
|
||||
autoLabel: Auto Create Subnetwork
|
||||
ipPolicyClusterSecondaryRangeName:
|
||||
label: Cluster Secondary Range Name
|
||||
placeholder: Your Cluster Secondary Range Name
|
||||
|
|
|
|||
Loading…
Reference in New Issue