Skip to content

Commit

Permalink
fix(provider/azure): Enable Azure Load Balancer from Azure VM Scale …
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Ye authored and Scott committed Apr 10, 2019
1 parent 2020bf6 commit ca3fcef
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 35 deletions.
2 changes: 2 additions & 0 deletions app/scripts/modules/azure/help/azure.help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const helpContents: { [key: string]: string } = {
'azure.serverGroup.customTags': `Custom tags on Virtual Machine Scale Set. Allow ${
Utility.TAG_LIMITATION
} tags at most.`,
'azure.serverGroup.enableInboundNAT':
'An Azure load balancer of the basic sku will be created with adding inbound NAT port-forwarding rules to facilitate loggin on VM instances. There is no charge for creating an Azure load balancer of the basic sku.',
};

Object.keys(helpContents).forEach(key => HelpContentsRegistry.register(key, helpContents[key]));
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ const angular = require('angular');
import { NameUtils } from '@spinnaker/core';

module.exports = angular
.module('spinnaker.azure.serverGroupCommandBuilder.service', [require('../../image/image.reader').name])
.module('spinnaker.azure.serverGroupCommandBuilder.service', [
require('../../image/image.reader').name,
require('../serverGroup.transformer').name,
])
.factory('azureServerGroupCommandBuilder', [
'$q',
'azureImageReader',
function($q, azureImageReader) {
'azureServerGroupTransformer',
function($q, azureImageReader, azureServerGroupTransformer) {
function buildNewServerGroupCommand(application, defaults) {
defaults = defaults || {};

Expand Down Expand Up @@ -50,6 +54,7 @@ module.exports = angular
networkSettingsConfigured: false,
securityGroupsConfigured: false,
},
enableInboundNAT: false,
};
});
}
Expand Down Expand Up @@ -91,6 +96,7 @@ module.exports = angular
},
tags: [],
instanceTags: serverGroup.instanceTags,
instanceType: serverGroup.sku.name,
selectedProvider: 'azure',
source: {
account: serverGroup.account,
Expand All @@ -107,8 +113,20 @@ module.exports = angular
mode: mode,
disableStrategySelection: true,
},
enableInboundNAT: serverGroup.enableInboundNAT,
};

if (typeof serverGroup.customScriptsSettings !== 'undefined') {
command.customScriptsSettings = {};
command.customScriptsSettings.commandToExecute = serverGroup.customScriptsSettings.commandToExecute;
if (
typeof serverGroup.customScriptsSettings.fileUris !== 'undefined' &&
serverGroup.customScriptsSettings.fileUris != ''
) {
azureServerGroupTransformer.parseCustomScriptsSettings(serverGroup, command);
}
}

return $q.when(command);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,14 @@
/>
</div>
</div>
<div class="form-group">
<div class="col-md-4 sm-label-right">
<input type="checkbox" ng-model="adv.command.enableInboundNAT" />
</div>
<div class="col-md-7">
<b>Enable inbound NAT port-forwarding rules to connect to VM instances</b>
<help-field key="azure.serverGroup.enableInboundNAT"></help-field>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@ module.exports = angular
function($scope, loadBalancerReader) {
ModalWizard.markClean('load-balancers');

if ($scope.command.credentials && $scope.command.region && $scope.command.loadBalancerName) {
$scope.command.viewState.networkSettingsConfigured = true;
}

this.loadBalancerChanged = function(item) {
$scope.command.viewState.networkSettingsConfigured = true;
ModalWizard.markComplete('load-balancers');
$scope.command.selectedVnetSubnets = [];
$scope.command.selectedSubnet = null;
InfrastructureCaches.clearCache('networks');

function loadVnetSubnets(item) {
loadBalancerReader
.getLoadBalancerDetails('azure', $scope.command.credentials, $scope.command.region, item)
.then(function(LBs) {
Expand Down Expand Up @@ -57,6 +47,21 @@ module.exports = angular
});
}
});
}

if ($scope.command.credentials && $scope.command.region && $scope.command.loadBalancerName) {
$scope.command.viewState.networkSettingsConfigured = true;
$scope.command.selectedVnetSubnets = [];
loadVnetSubnets($scope.command.loadBalancerName);
}

this.loadBalancerChanged = function(item) {
$scope.command.viewState.networkSettingsConfigured = true;
ModalWizard.markComplete('load-balancers');
$scope.command.selectedVnetSubnets = [];
$scope.command.selectedSubnet = null;
InfrastructureCaches.clearCache('networks');
loadVnetSubnets(item);
};
},
]);
48 changes: 27 additions & 21 deletions app/scripts/modules/azure/serverGroup/serverGroup.transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@ module.exports = angular
return serverGroup;
}

function parseCustomScriptsSettings(command, configuration) {
/*
At the first time this wizard pops up, the type of command.customScriptsSettings.fileUris is String. As for the following
occurrences of its pop up with this field unchanged, its type becomes an array. So here differentiate the two scenarios
to assign the correct value to model.
*/
if (Array.isArray(command.customScriptsSettings.fileUris)) {
configuration.customScriptsSettings.fileUris = command.customScriptsSettings.fileUris;
} else {
var fileUrisTemp = command.customScriptsSettings.fileUris;
if (fileUrisTemp.includes(',')) {
configuration.customScriptsSettings.fileUris = fileUrisTemp.split(',');
} else if (fileUrisTemp.includes(';')) {
configuration.customScriptsSettings.fileUris = fileUrisTemp.split(';');
} else {
configuration.customScriptsSettings.fileUris = [fileUrisTemp];
}

configuration.customScriptsSettings.fileUris.forEach(function(v, index) {
configuration.customScriptsSettings.fileUris[index] = v.trim();
});
}
}

function convertServerGroupCommandToDeployConfiguration(command) {
var tempImage;

Expand Down Expand Up @@ -79,6 +103,7 @@ module.exports = angular
},
zonesEnabled: command.zonesEnabled,
zones: command.zonesEnabled ? command.zones : [],
enableInboundNAT: command.enableInboundNAT,
};

if (typeof command.stack !== 'undefined') {
Expand All @@ -94,27 +119,7 @@ module.exports = angular
typeof command.customScriptsSettings.fileUris !== 'undefined' &&
command.customScriptsSettings.fileUris != ''
) {
/*
At the first time this wizard pops up, the type of command.customScriptsSettings.fileUris is String. As for the following
occurrences of its pop up with this field unchanged, its type becomes an array. So here differentiate the two scenarios
to assign the correct value to model.
*/
if (Array.isArray(command.customScriptsSettings.fileUris)) {
configuration.customScriptsSettings.fileUris = command.customScriptsSettings.fileUris;
} else {
var fileUrisTemp = command.customScriptsSettings.fileUris;
if (fileUrisTemp.includes(',')) {
configuration.customScriptsSettings.fileUris = fileUrisTemp.split(',');
} else if (fileUrisTemp.includes(';')) {
configuration.customScriptsSettings.fileUris = fileUrisTemp.split(';');
} else {
configuration.customScriptsSettings.fileUris = [fileUrisTemp];
}

configuration.customScriptsSettings.fileUris.forEach(function(v, index) {
configuration.customScriptsSettings.fileUris[index] = v.trim();
});
}
parseCustomScriptsSettings(command, configuration);
}
}

Expand All @@ -134,5 +139,6 @@ module.exports = angular
return {
convertServerGroupCommandToDeployConfiguration: convertServerGroupCommandToDeployConfiguration,
normalizeServerGroup: normalizeServerGroup,
parseCustomScriptsSettings: parseCustomScriptsSettings,
};
});
2 changes: 1 addition & 1 deletion app/scripts/modules/azure/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export enum TagError {
}

export default class Utility {
public static readonly TAG_LIMITATION: number = 12;
public static readonly TAG_LIMITATION: number = 8;
public static readonly TAG_KEY_LENGTH_LIMITATION: number = 512;
public static readonly TAG_VALUE_LENGTH_LIMITATION: number = 256;
public static readonly TAG_INVALID_CHAR_REG_EXR: RegExp = /[<>%&\\?/]/;
Expand Down

0 comments on commit ca3fcef

Please sign in to comment.