diff --git a/app/models/cluster.js b/app/models/cluster.js index 272635d03..bc8507f43 100644 --- a/app/models/cluster.js +++ b/app/models/cluster.js @@ -102,7 +102,7 @@ export const DEFAULT_GKE_CONFIG = { clusterAddons: { horizontalPodAutoscaling: true, httpLoadBalancing: true, - networkPolicyConfig: true + networkPolicyConfig: false }, clusterIpv4Cidr: null, clusterName: null, diff --git a/lib/global-admin/addon/components/cru-cloud-credential/component.js b/lib/global-admin/addon/components/cru-cloud-credential/component.js index 8d36ddeda..88a038624 100644 --- a/lib/global-admin/addon/components/cru-cloud-credential/component.js +++ b/lib/global-admin/addon/components/cru-cloud-credential/component.js @@ -365,9 +365,17 @@ export default Component.extend(ViewNewEdit, { }, fetchZones() { - const credentials = get(this, 'config.authEncodedJson'); - const config = JSON.parse(credentials || '{}'); - const { project_id: projectId } = config; + let credentials = null; + let config = null; + let projectId = null; + + try { + credentials = get(this, 'config.authEncodedJson'); + config = JSON.parse(credentials || '{}'); + projectId = get(config, 'project_id'); + } catch (error) { + return Promise.reject({ message: 'Invalid JSON' }); + } return get(this, 'globalStore').rawRequest({ url: '/meta/gkeZones', diff --git a/lib/shared/addon/components/cluster-driver/driver-gke/component.js b/lib/shared/addon/components/cluster-driver/driver-gke/component.js index add40c342..6e98ba15b 100644 --- a/lib/shared/addon/components/cluster-driver/driver-gke/component.js +++ b/lib/shared/addon/components/cluster-driver/driver-gke/component.js @@ -227,7 +227,7 @@ export default Component.extend(ClusterDriver, { } }), - clusterSecondaryRangeNameChanged: observer('config.ipAllocationPolicy.clusterSecondaryRangeName', function() { + clusterSecondaryRangeNameChanged: observer('config.ipAllocationPolicy.clusterSecondaryRangeName', 'secondaryIpRangeContent.[]', function() { if (this.isDestroyed || this.isDestroying || this.saving) { return; } @@ -277,22 +277,6 @@ export default Component.extend(ClusterDriver, { 'config.ipAllocationPolicy.subnetworkName': null, 'config.ipAllocationPolicy.nodeIpv4CidrBlock': null, }); - - const secondaryIpRangeContent = get(this, 'secondaryIpRangeContent') || [] - - if (secondaryIpRangeContent.length > 0) { - const value = secondaryIpRangeContent[0] && secondaryIpRangeContent[0].value - - setProperties(this, { - 'config.ipAllocationPolicy.clusterSecondaryRangeName': value, - 'config.ipAllocationPolicy.servicesSecondaryRangeName': value, - }); - } else { - setProperties(this, { - 'config.ipAllocationPolicy.clusterSecondaryRangeName': null, - 'config.ipAllocationPolicy.servicesSecondaryRangeName': null, - }); - } } else { setProperties(this, { 'config.subnetwork': '', @@ -303,7 +287,7 @@ export default Component.extend(ClusterDriver, { } }), - servicesSecondaryRangeNameChanged: observer('config.ipAllocationPolicy.servicesSecondaryRangeName', function() { + servicesSecondaryRangeNameChanged: observer('config.ipAllocationPolicy.servicesSecondaryRangeName', 'secondaryIpRangeContent.[]', function() { if (this.isDestroyed || this.isDestroying || this.saving) { return; } @@ -321,7 +305,7 @@ export default Component.extend(ClusterDriver, { } }), - secondaryIpRangeContentChange: observer('secondaryIpRangeContent.[]', 'config.ipAllocationPolicy.useIpAliases', function() { + secondaryIpRangeContentChange: observer('secondaryIpRangeContent.[]', 'config.ipAllocationPolicy.useIpAliases', 'config.{network,subnetwork}', function() { if (this.isDestroyed || this.isDestroying || this.saving) { return; } @@ -476,12 +460,12 @@ export default Component.extend(ClusterDriver, { return merged; }), - secondaryIpRangeContent: computed('subNetworkContent.[]', 'config.network', function() { - const { subNetworkContent = [], config: { network } } = this; - const subNetwork = subNetworkContent.findBy('networkDisplayName', network); + secondaryIpRangeContent: computed('subNetworkContent.[]', 'config.{network,subnetwork}', function() { + const { subNetworkContent = [], config: { subnetwork } } = this; + const subnetworkMatch = subNetworkContent.findBy('value', subnetwork); - if (subNetwork) { - const { secondaryIpRanges = [] } = subNetwork; + if (subnetworkMatch) { + const { secondaryIpRanges = [] } = subnetworkMatch; return secondaryIpRanges.map((s) => { return { @@ -598,8 +582,26 @@ export default Component.extend(ClusterDriver, { return neu; }, + validatePrivateConfig() { + const config = get(this, 'config') || {} + const { privateClusterConfig } = config; + + if (isEmpty(privateClusterConfig)) { + return true; + } + + if (privateClusterConfig?.enablePrivateNodes && isEmpty(privateClusterConfig?.masterIpv4CidrBlock)) { + this.send('errorHandler', this.intl.t('clusterNew.googlegke.masterIpv4CidrBlock.error')); + + return false; + } + + return true; + }, + willSave() { this.validateNodePools(); + this.validatePrivateConfig(); if (!isEmpty(this.errors)) { return false; diff --git a/lib/shared/addon/components/cluster-driver/driver-googlegke/component.js b/lib/shared/addon/components/cluster-driver/driver-googlegke/component.js index 4c7dd1735..9430e9c91 100644 --- a/lib/shared/addon/components/cluster-driver/driver-googlegke/component.js +++ b/lib/shared/addon/components/cluster-driver/driver-googlegke/component.js @@ -456,12 +456,12 @@ export default Component.extend(ClusterDriver, { return [...defaultSubnetAry, ...mappedSubnets]; }), - secondaryIpRangeContent: computed('subNetworkContent.[]', 'config.network', function() { - const { subNetworkContent = [], config: { network } } = this; - const subNetwork = subNetworkContent.findBy('networkDisplayName', network); + secondaryIpRangeContent: computed('subNetworkContent.[]', 'config.{network,subNetwork}', function() { + const { subNetworkContent = [], config: { subNetwork } } = this; + const subNetworkMatch = subNetworkContent.findBy('value', subNetwork); - if (subNetwork) { - const { secondaryIpRanges = [] } = subNetwork; + if (subNetworkMatch) { + const { secondaryIpRanges = [] } = subNetworkMatch; return secondaryIpRanges.map((s) => { return { diff --git a/lib/shared/addon/components/cluster-driver/driver-import-gke/component.js b/lib/shared/addon/components/cluster-driver/driver-import-gke/component.js index ef66ec4e0..6a3c3d41e 100644 --- a/lib/shared/addon/components/cluster-driver/driver-import-gke/component.js +++ b/lib/shared/addon/components/cluster-driver/driver-import-gke/component.js @@ -158,7 +158,15 @@ export default Component.extend(ClusterDriver, { }, }, - locationOrZoneChanged: observer('locationType', 'config.{region,zone}', function() { + regionOrZoneChanged: observer('config.{region,zone}', function() { + next(this, () => { + if (this.step > 2) { + this.send('loadClusters'); + } + }); + }), + + locationTypeChanged: observer('locationType', function() { const { config, locationType } = this; if (locationType === 'zonal') { @@ -167,20 +175,12 @@ export default Component.extend(ClusterDriver, { } set(this, 'config.zone', 'us-west2-a'); - - if (!isEmpty(config?.zone)) { - this.send('loadClusters'); - } } else { if (!isEmpty(get(config, 'zone'))) { delete this.config.zone; } set(this, 'config.region', 'us-west2'); - - if (!isEmpty(config?.region)) { - this.send('loadClusters'); - } } }), diff --git a/lib/shared/addon/components/cluster-driver/driver-import-gke/template.hbs b/lib/shared/addon/components/cluster-driver/driver-import-gke/template.hbs index 4f8fd6a14..0f09f0073 100644 --- a/lib/shared/addon/components/cluster-driver/driver-import-gke/template.hbs +++ b/lib/shared/addon/components/cluster-driver/driver-import-gke/template.hbs @@ -91,7 +91,7 @@ @optionLabelPath="name" @optionValuePath="name" @prompt="clusterNew.googlegke.zone.prompt" - @value={{config.zone}} + @value={{mut config.zone}} /> {{/if}} diff --git a/lib/shared/addon/components/cru-private-cluster/template.hbs b/lib/shared/addon/components/cru-private-cluster/template.hbs index 290a3c407..bd1da001f 100644 --- a/lib/shared/addon/components/cru-private-cluster/template.hbs +++ b/lib/shared/addon/components/cru-private-cluster/template.hbs @@ -49,6 +49,9 @@
{{input value=config.masterIpv4CidrBlock diff --git a/translations/en-us.yaml b/translations/en-us.yaml index 160dbf52d..b33b3a6b2 100644 --- a/translations/en-us.yaml +++ b/translations/en-us.yaml @@ -3841,9 +3841,10 @@ clusterNew: label: Master Authorized Network CIDR Blocks placeholder: Your Master Authorized Network CIDR Blocks masterIpv4CidrBlock: - label: Master IP CIDR Block + label: Master IPV4 CIDR Block placeholder: e.g. 10.42.0.0/28 help: Master CIDR block size must be /28 + error: A Master IPV4 CIDR block is required when creating a private cluster masterVersion: label: Kubernetes Version prompt: Choose a Version...