Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(google): fix autohealing health checks in deploy stages #6804

Merged
merged 1 commit into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/scripts/modules/google/src/domain/autoHealingPolicy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { IGceHealthCheckKind } from 'google/domain/healthCheck';

export interface IGceAutoHealingPolicy {
healthCheck?: string;
healthCheckKind?: IGceHealthCheckKind;
healthCheck?: string; // received from server as health check URL, but posted as health check name
healthCheckKind?: IGceHealthCheckKind; // used by Clouddriver to disambiguate health checks
healthCheckUrl?: string; // used by Deck as unique ID
initialDelaySec?: number;
maxUnavailable?: IMaxUnavailable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import _ from 'lodash';

import { AccountService, ExpectedArtifactService, INSTANCE_TYPE_SERVICE } from '@spinnaker/core';
import { GCEProviderSettings } from 'google/gce.settings';
import { parseHealthCheckUrl } from 'google/healthCheck/healthCheckUtils';

module.exports = angular
.module('spinnaker.gce.serverGroupCommandBuilder.service', [
Expand Down Expand Up @@ -194,14 +195,18 @@ module.exports = angular
}

function populateAutoHealingPolicy(serverGroup, command) {
if (serverGroup.autoHealingPolicy) {
let autoHealingPolicy = serverGroup.autoHealingPolicy;
const healthCheckUrl = autoHealingPolicy.healthCheck;
const autoHealingPolicyHealthCheck = healthCheckUrl ? _.last(healthCheckUrl.split('/')) : null;

if (autoHealingPolicyHealthCheck) {
const autoHealingPolicy = serverGroup.autoHealingPolicy;
if (autoHealingPolicy) {
const healthCheckUrl = autoHealingPolicy.healthCheckUrl
? autoHealingPolicy.healthCheckUrl
: autoHealingPolicy.healthCheck;

if (healthCheckUrl) {
const { healthCheckName, healthCheckKind } = parseHealthCheckUrl(healthCheckUrl);
command.autoHealingPolicy = {
healthCheck: healthCheckUrl,
healthCheck: healthCheckName,
healthCheckKind: healthCheckKind,
healthCheckUrl: healthCheckUrl,
initialDelaySec: autoHealingPolicy.initialDelaySec,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = angular
if (
!_.chain(healthChecks)
.map('selfLink')
.includes(command.autoHealingPolicy.healthCheck)
.includes(command.autoHealingPolicy.healthCheckUrl)
.value()
) {
healthCheckReloader = refreshHealthChecks(command, true);
Expand Down Expand Up @@ -406,7 +406,7 @@ module.exports = angular
_.has(command, 'autoHealingPolicy.healthCheck') &&
!_.chain(filteredData.healthChecks)
.map('selfLink')
.includes(command.autoHealingPolicy.healthCheck)
.includes(command.autoHealingPolicy.healthCheckUrl)
.value()
) {
delete command.autoHealingPolicy.healthCheck;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
<b>Health Check</b>
</div>
<div class="col-md-6">
<ui-select ng-model="$ctrl.autoHealingPolicy.healthCheck" class="form-control input-sm" required>
<ui-select
ng-model="$ctrl.autoHealingPolicy.healthCheckUrl"
on-select="$ctrl.onHealthCheckChange($item, $model)"
class="form-control input-sm"
required
>
<ui-select-match placeholder="Select...">{{ $select.selected.displayName }}</ui-select-match>
<ui-select-choices
repeat="healthCheck.selfLink as healthCheck in $ctrl.healthChecks | orderBy: 'displayName' | filter: { displayName: $select.search }"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IComponentOptions, IController, module } from 'angular';
import { set } from 'lodash';
import { IGceAutoHealingPolicy } from 'google/domain/autoHealingPolicy';
import { IGceHealthCheckOption, parseHealthCheckUrl } from 'google/healthCheck/healthCheckUtils';

class GceAutoHealingPolicySelector implements IController {
public healthChecks: string[];
Expand Down Expand Up @@ -36,6 +37,14 @@ class GceAutoHealingPolicySelector implements IController {
set(this.autoHealingPolicy, ['maxUnavailable', toDeleteKey], undefined);
}
}

public onHealthCheckChange(_healthCheck: IGceHealthCheckOption, healthCheckUrl: string) {
if (healthCheckUrl) {
const { healthCheckName, healthCheckKind } = parseHealthCheckUrl(healthCheckUrl);
this.autoHealingPolicy.healthCheck = healthCheckName;
this.autoHealingPolicy.healthCheckKind = healthCheckKind;
}
}
}

const gceAutoHealingPolicySelectorComponent: IComponentOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import _ from 'lodash';

import { FirewallLabels, INSTANCE_TYPE_SERVICE, ModalWizard, TaskMonitor } from '@spinnaker/core';

import { parseHealthCheckUrl } from 'google/healthCheck/healthCheckUtils';

module.exports = angular
.module('spinnaker.serverGroup.configure.gce.cloneServerGroup', [
require('@uirouter/angularjs').default,
Expand Down Expand Up @@ -393,13 +391,6 @@ module.exports = angular
return $uibModalInstance.close($scope.command);
}

const healthCheckUrl = _.get($scope.command, 'autoHealingPolicy.healthCheck');
if (healthCheckUrl) {
const { healthCheckName, healthCheckKind } = parseHealthCheckUrl(healthCheckUrl);
$scope.command.autoHealingPolicy.healthCheck = healthCheckName;
$scope.command.autoHealingPolicy.healthCheckKind = healthCheckKind;
}

$scope.taskMonitor.submit(function() {
const promise = serverGroupWriter.cloneServerGroup(angular.copy($scope.command), application);

Expand All @@ -410,10 +401,6 @@ module.exports = angular
$scope.command.loadBalancers = origLoadBalancers;
$scope.command.securityGroups = gceTagManager.inferSecurityGroupIdsFromTags($scope.command.tags);

if (healthCheckUrl) {
$scope.command.autoHealingPolicy.healthCheck = healthCheckUrl;
}

return promise;
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Application, TaskMonitor } from '@spinnaker/core';

import { IGceAutoHealingPolicy, IGceServerGroup } from 'google/domain/index';
import { GCE_HEALTH_CHECK_READER, GceHealthCheckReader } from 'google/healthCheck/healthCheck.read.service';
import { getHealthCheckOptions, IGceHealthCheckOption, parseHealthCheckUrl } from 'google/healthCheck/healthCheckUtils';
import { getHealthCheckOptions, IGceHealthCheckOption } from 'google/healthCheck/healthCheckUtils';

import './upsertAutoHealingPolicy.modal.less';

Expand Down Expand Up @@ -37,9 +37,6 @@ class GceUpsertAutoHealingPolicyModalCtrl implements IController {

public submit(): void {
const submitMethod = () => {
const { healthCheckName, healthCheckKind } = parseHealthCheckUrl(this.autoHealingPolicy.healthCheck);
this.autoHealingPolicy.healthCheck = healthCheckName;
this.autoHealingPolicy.healthCheckKind = healthCheckKind;
return this.gceAutoscalingPolicyWriter.upsertAutoHealingPolicy(
this.application,
this.serverGroup,
Expand Down