update gke proxy calls to send cluster id if editing

This commit is contained in:
Westly Wright 2021-05-03 16:56:49 -07:00
parent caa794ec1f
commit 727b160b13
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
3 changed files with 39 additions and 33 deletions

View File

@ -151,10 +151,8 @@ export default Component.extend(ClusterDriver, {
loadZones(cb = () => {}) {
set(this, 'errors', []);
const config = get(this, `cluster.${ this.configField }`);
return all([
this.google.fetchZones(config, this.saved),
this.google.fetchZones(this.cluster, this.saved),
]).then((resp) => {
const [zones] = resp;
@ -186,16 +184,16 @@ export default Component.extend(ClusterDriver, {
const config = get(this, `cluster.${ this.configField }`);
const promises = [
this.google.fetchVersions(config, this.saved),
this.google.fetchMachineTypes(config, this.saved),
this.google.fetchNetworks(config, this.saved),
this.google.fetchSubnetworks(config, get(this, 'locationType'), this.saved),
this.google.fetchSharedSubnets(config, this.saved),
this.google.fetchServiceAccounts(config, this.saved),
this.google.fetchVersions(this.cluster, this.saved),
this.google.fetchMachineTypes(this.cluster, this.saved),
this.google.fetchNetworks(this.cluster, this.saved),
this.google.fetchSubnetworks(this.cluster, get(this, 'locationType'), this.saved),
this.google.fetchSharedSubnets(this.cluster, this.saved),
this.google.fetchServiceAccounts(this.cluster, this.saved),
];
if (this.editing) {
promises.push(this.google.fetchClusters(config, this.saved));
promises.push(this.google.fetchClusters(this.cluster, this.saved));
}
return all(promises).then((resp) => {

View File

@ -84,10 +84,8 @@ export default Component.extend(ClusterDriver, {
checkServiceAccount(cb) {
set(this, 'errors', []);
const config = get(this, `cluster.${ this.configField }`);
return all([
this.google.fetchZones(config, this.saved),
this.google.fetchZones(this.model.cluster, this.saved),
]).then((resp) => {
const [zones] = resp;
@ -116,9 +114,7 @@ export default Component.extend(ClusterDriver, {
set(this, 'loadingClusters', true);
try {
const config = get(this, `cluster.${ this.configField }`);
allClusters = await this.google.fetchClusters(config, this.saved ?? false);
allClusters = await this.google.fetchClusters(this.cluster, this.saved ?? false);
setProperties(this, {
allClusters: (allClusters || []).map((c) => {

View File

@ -267,7 +267,7 @@ export default Service.extend({
});
},
parseRequestData(url, config) {
parseRequestData(url, config, clusterId) {
const {
googleCredentialSecret,
projectID: projectId,
@ -288,17 +288,22 @@ export default Service.extend({
if (!isEmpty(projectId)) {
set(data, 'projectId', projectId);
}
if (!isEmpty(clusterId)) {
set(data, 'clusterID', clusterId);
}
}
return addQueryParams(url, data);
},
async fetchClusters(config, saved = false) {
async fetchClusters(cluster, saved = false) {
if (saved) {
return;
}
const config = get(cluster, 'gkeConfig');
let neuURL = this.parseRequestData('/meta/gkeClusters', config);
let neuURL = this.parseRequestData('/meta/gkeClusters', config, cluster?.id);
try {
const xhr = await this.request(neuURL, 'GET');
@ -310,12 +315,13 @@ export default Service.extend({
}
},
async fetchZones(config, saved = false) {
async fetchZones(cluster, saved = false) {
if (saved) {
return;
}
const config = get(cluster, 'gkeConfig');
const neuURL = this.parseRequestData('/meta/gkeZones', config);
const neuURL = this.parseRequestData('/meta/gkeZones', config, cluster?.id);
try {
const xhr = await this.request(neuURL, 'GET');
@ -336,10 +342,11 @@ export default Service.extend({
}
},
async fetchVersions(config, saved = false) {
async fetchVersions(cluster, saved = false) {
if (saved) {
return;
}
const config = get(cluster, 'gkeConfig');
const zone = get(config, 'zone') || `${ get(config, 'region') }-b`;
const neuConfig = { ...config };
@ -348,7 +355,7 @@ export default Service.extend({
set(neuConfig, 'zone', zone);
const neuURL = this.parseRequestData('/meta/gkeVersions', neuConfig);
const neuURL = this.parseRequestData('/meta/gkeVersions', neuConfig, cluster?.id);
try {
const xhr = await this.request(neuURL, 'GET');
@ -360,10 +367,11 @@ export default Service.extend({
}
},
async fetchMachineTypes(config, saved = false) {
async fetchMachineTypes(cluster, saved = false) {
if (saved) {
return;
}
const config = get(cluster, 'gkeConfig');
const zone = get(config, 'zone') || `${ get(config, 'region') }-b`;
const neuConfig = { ...config };
@ -372,7 +380,7 @@ export default Service.extend({
set(neuConfig, 'zone', zone);
const neuURL = this.parseRequestData('/meta/gkeMachineTypes', neuConfig);
const neuURL = this.parseRequestData('/meta/gkeMachineTypes', neuConfig, cluster?.id);
try {
const xhr = await this.request(neuURL, 'GET');
@ -384,10 +392,11 @@ export default Service.extend({
}
},
async fetchNetworks(config, saved = false) {
async fetchNetworks(cluster, saved = false) {
if (saved) {
return;
}
const config = get(cluster, 'gkeConfig');
const zone = get(config, 'zone') || `${ get(config, 'region') }-b`;
const neuConfig = { ...config };
@ -396,7 +405,7 @@ export default Service.extend({
set(neuConfig, 'zone', zone);
const neuURL = this.parseRequestData('/meta/gkeNetworks', neuConfig);
const neuURL = this.parseRequestData('/meta/gkeNetworks', neuConfig, cluster?.id);
try {
const xhr = await this.request(neuURL, 'GET');
@ -408,10 +417,11 @@ export default Service.extend({
}
},
async fetchSubnetworks(config, locationType, saved = false) {
async fetchSubnetworks(cluster, locationType, saved = false) {
if (saved) {
return;
}
const config = get(cluster, 'gkeConfig');
const region = locationType === this.defaultZoneType ? `${ config.zone.split('-')[0] }-${ config.zone.split('-')[1] }` : config.region;
const neuConfig = { ...config };
@ -419,7 +429,7 @@ export default Service.extend({
set(neuConfig, 'region', region);
const neuURL = this.parseRequestData('/meta/gkeSubnetworks', neuConfig);
const neuURL = this.parseRequestData('/meta/gkeSubnetworks', neuConfig, cluster?.id);
try {
const xhr = await this.request(neuURL, 'GET');
@ -431,16 +441,17 @@ export default Service.extend({
}
},
async fetchSharedSubnets(config, saved = false) {
async fetchSharedSubnets(cluster, saved = false) {
if (saved) {
return;
}
const config = get(cluster, 'gkeConfig');
const neuConfig = { ...config };
delete neuConfig?.zone;
delete neuConfig?.region;
const neuURL = this.parseRequestData('/meta/gkeSharedSubnets', neuConfig);
const neuURL = this.parseRequestData('/meta/gkeSharedSubnets', neuConfig, cluster?.id);
try {
const xhr = await this.request(neuURL, 'GET');
@ -471,10 +482,11 @@ export default Service.extend({
}
},
async fetchServiceAccounts(config, saved = false) {
async fetchServiceAccounts(cluster, saved = false) {
if (saved) {
return;
}
const config = get(cluster, 'gkeConfig');
const zone = get(config, 'zone') || `${ get(config, 'region') }-b`;
const neuConfig = { ...config };
@ -482,7 +494,7 @@ export default Service.extend({
set(neuConfig, 'zone', zone);
const neuURL = this.parseRequestData('/meta/gkeServiceAccounts', neuConfig);
const neuURL = this.parseRequestData('/meta/gkeServiceAccounts', neuConfig, cluster?.id);
try {
const xhr = await this.request(neuURL, 'GET');