@spinnaker/cloudrun 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/LICENSE.txt +203 -0
  3. package/dist/cloudrun.module.d.ts +4 -0
  4. package/dist/cloudrun.settings.d.ts +7 -0
  5. package/dist/common/cloudrunHealth.d.ts +3 -0
  6. package/dist/common/componentUrlDetails.component.d.ts +1 -0
  7. package/dist/common/conditionalDescriptionListItem.component.d.ts +1 -0
  8. package/dist/common/domain/ICloudrunInstance.d.ts +20 -0
  9. package/dist/common/domain/ICloudrunLoadBalancer.d.ts +18 -0
  10. package/dist/common/domain/index.d.ts +2 -0
  11. package/dist/common/loadBalancerMessage.component.d.ts +1 -0
  12. package/dist/help/cloudrun.help.d.ts +1 -0
  13. package/dist/index.d.ts +3 -0
  14. package/dist/index.js +2 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/instance/details/details.controller.d.ts +1 -0
  17. package/dist/interfaces/index.d.ts +1 -0
  18. package/dist/interfaces/infrastructure.types.d.ts +18 -0
  19. package/dist/loadBalancer/configure/wizard/allocationConfigurationRow.component.d.ts +1 -0
  20. package/dist/loadBalancer/configure/wizard/basicSettings.component.d.ts +1 -0
  21. package/dist/loadBalancer/configure/wizard/stageAllocationConfigurationRow.component.d.ts +1 -0
  22. package/dist/loadBalancer/configure/wizard/wizard.controller.d.ts +2 -0
  23. package/dist/loadBalancer/details/details.controller.d.ts +1 -0
  24. package/dist/loadBalancer/index.d.ts +3 -0
  25. package/dist/loadBalancer/loadBalancerTransformer.d.ts +38 -0
  26. package/dist/manifest/ManifestSource.d.ts +4 -0
  27. package/dist/manifest/index.d.ts +2 -0
  28. package/dist/manifest/manifest.service.d.ts +25 -0
  29. package/dist/manifest/manifestCommandBuilder.service.d.ts +30 -0
  30. package/dist/manifest/wizard/BasicSettings.d.ts +17 -0
  31. package/dist/pipeline/pipeline.module.d.ts +1 -0
  32. package/dist/pipeline/stages/deployManifest/DeployStageConfig.d.ts +15 -0
  33. package/dist/pipeline/stages/deployManifest/DeployStageForm.d.ts +23 -0
  34. package/dist/pipeline/stages/deployManifest/ManifestBindArtifactsSelector.d.ts +17 -0
  35. package/dist/pipeline/stages/deployManifest/deploy.validator.d.ts +2 -0
  36. package/dist/pipeline/stages/deployManifest/deployStage.d.ts +1 -0
  37. package/dist/pipeline/stages/deployManifest/manifestStatus/DeployStatus.d.ts +22 -0
  38. package/dist/pipeline/stages/deployManifest/manifestStatus/DeployStatusPills.d.ts +8 -0
  39. package/dist/pipeline/stages/deployManifest/manifestStatus/ManifestDetailsLink.d.ts +20 -0
  40. package/dist/pipeline/stages/deployManifest/manifestStatus/ManifestEvents.d.ts +9 -0
  41. package/dist/pipeline/stages/deployManifest/manifestStatus/ManifestStatus.d.ts +8 -0
  42. package/dist/pipeline/stages/deployManifest/serverGroupNamePreview.d.ts +9 -0
  43. package/dist/pipeline/stages/editLoadBalancer/cloudrunEditLoadBalancerStage.d.ts +1 -0
  44. package/dist/pipeline/stages/editLoadBalancer/loadBalancerChoice.modal.controller.d.ts +1 -0
  45. package/dist/rolloutStrategy/redblack.strategy.d.ts +2 -0
  46. package/dist/serverGroup/configure/serverGroupCommandBuilder.service.d.ts +74 -0
  47. package/dist/serverGroup/configure/wizard/BasicSettings.d.ts +29 -0
  48. package/dist/serverGroup/configure/wizard/ConfigFiles.d.ts +15 -0
  49. package/dist/serverGroup/configure/wizard/serverGroupWizard.d.ts +25 -0
  50. package/dist/serverGroup/details/details.controller.d.ts +1 -0
  51. package/dist/serverGroup/index.d.ts +3 -0
  52. package/dist/serverGroup/serverGroupTransformer.service.d.ts +31 -0
  53. package/package.json +57 -0
  54. package/src/cloudrun.module.ts +73 -0
  55. package/src/cloudrun.settings.ts +14 -0
  56. package/src/common/cloudrunHealth.ts +3 -0
  57. package/src/common/componentUrlDetails.component.ts +22 -0
  58. package/src/common/conditionalDescriptionListItem.component.ts +37 -0
  59. package/src/common/domain/ICloudrunInstance.ts +21 -0
  60. package/src/common/domain/ICloudrunLoadBalancer.ts +18 -0
  61. package/src/common/domain/index.ts +2 -0
  62. package/src/common/loadBalancerMessage.component.html +11 -0
  63. package/src/common/loadBalancerMessage.component.ts +13 -0
  64. package/src/help/cloudrun.help.ts +99 -0
  65. package/src/index.ts +3 -0
  66. package/src/instance/details/details.controller.ts +84 -0
  67. package/src/instance/details/details.html +68 -0
  68. package/src/interfaces/index.ts +1 -0
  69. package/src/interfaces/infrastructure.types.ts +23 -0
  70. package/src/loadBalancer/configure/wizard/allocationConfigurationRow.component.ts +70 -0
  71. package/src/loadBalancer/configure/wizard/basicSettings.component.html +44 -0
  72. package/src/loadBalancer/configure/wizard/basicSettings.component.ts +86 -0
  73. package/src/loadBalancer/configure/wizard/stageAllocationConfigurationRow.component.html +45 -0
  74. package/src/loadBalancer/configure/wizard/stageAllocationConfigurationRow.component.ts +84 -0
  75. package/src/loadBalancer/configure/wizard/wizard.controller.ts +157 -0
  76. package/src/loadBalancer/configure/wizard/wizard.html +39 -0
  77. package/src/loadBalancer/configure/wizard/wizard.less +9 -0
  78. package/src/loadBalancer/details/details.controller.ts +140 -0
  79. package/src/loadBalancer/details/details.html +89 -0
  80. package/src/loadBalancer/index.ts +3 -0
  81. package/src/loadBalancer/loadBalancerTransformer.ts +168 -0
  82. package/src/logo/cloudrun.icon.svg +27 -0
  83. package/src/logo/cloudrun.logo.less +6 -0
  84. package/src/logo/cloudrun.logo.png +0 -0
  85. package/src/manifest/ManifestSource.ts +4 -0
  86. package/src/manifest/index.ts +2 -0
  87. package/src/manifest/manifest.service.ts +89 -0
  88. package/src/manifest/manifestCommandBuilder.service.ts +116 -0
  89. package/src/manifest/wizard/BasicSettings.tsx +57 -0
  90. package/src/pipeline/pipeline.module.ts +6 -0
  91. package/src/pipeline/stages/deployManifest/DeployStageConfig.tsx +73 -0
  92. package/src/pipeline/stages/deployManifest/DeployStageForm.tsx +185 -0
  93. package/src/pipeline/stages/deployManifest/ManifestBindArtifactsSelector.tsx +69 -0
  94. package/src/pipeline/stages/deployManifest/deploy.validator.ts +38 -0
  95. package/src/pipeline/stages/deployManifest/deployStage.ts +28 -0
  96. package/src/pipeline/stages/deployManifest/manifestStatus/DeployStatus.tsx +108 -0
  97. package/src/pipeline/stages/deployManifest/manifestStatus/DeployStatusPills.tsx +47 -0
  98. package/src/pipeline/stages/deployManifest/manifestStatus/ManifestDetailsLink.tsx +92 -0
  99. package/src/pipeline/stages/deployManifest/manifestStatus/ManifestEvents.tsx +87 -0
  100. package/src/pipeline/stages/deployManifest/manifestStatus/ManifestStatus.less +24 -0
  101. package/src/pipeline/stages/deployManifest/manifestStatus/ManifestStatus.tsx +46 -0
  102. package/src/pipeline/stages/deployManifest/serverGroupNamePreview.tsx +28 -0
  103. package/src/pipeline/stages/editLoadBalancer/cloudrunEditLoadBalancerStage.ts +74 -0
  104. package/src/pipeline/stages/editLoadBalancer/editLoadBalancerExecutionDetails.html +33 -0
  105. package/src/pipeline/stages/editLoadBalancer/editLoadBalancerStage.html +51 -0
  106. package/src/pipeline/stages/editLoadBalancer/loadBalancerChoice.modal.controller.ts +65 -0
  107. package/src/pipeline/stages/editLoadBalancer/loadBalancerChoice.modal.html +53 -0
  108. package/src/rolloutStrategy/redblack.strategy.ts +7 -0
  109. package/src/serverGroup/configure/serverGroupCommandBuilder.service.ts +254 -0
  110. package/src/serverGroup/configure/wizard/BasicSettings.tsx +160 -0
  111. package/src/serverGroup/configure/wizard/ConfigFiles.tsx +75 -0
  112. package/src/serverGroup/configure/wizard/serverGroupWizard.tsx +150 -0
  113. package/src/serverGroup/details/details.controller.ts +134 -0
  114. package/src/serverGroup/details/details.html +94 -0
  115. package/src/serverGroup/index.ts +3 -0
  116. package/src/serverGroup/serverGroupTransformer.service.ts +61 -0
@@ -0,0 +1,99 @@
1
+ import { HelpContentsRegistry } from '@spinnaker/core';
2
+
3
+ const helpContents = [
4
+ {
5
+ key: 'cloudrun.serverGroup.stack',
6
+ value:
7
+ '(Optional) <b>Stack</b> is one of the core naming components of a cluster, used to create vertical stacks of dependent services for integration testing.',
8
+ },
9
+
10
+ {
11
+ key: 'cloudrun.serverGroup.file',
12
+ value: `<pre>
13
+ apiVersion: serving.knative.dev/v1
14
+ kind: Service
15
+ metadata:
16
+ name: spinappcloud1
17
+ namespace: '135005621049'
18
+ labels:
19
+ cloud.googleapis.com/location: us-central1
20
+ annotations:
21
+ run.googleapis.com/client-name: cloud-console
22
+ serving.knative.dev/creator: kiran@opsmx.io
23
+ serving.knative.dev/lastModifier: kiran@opsmx.io
24
+ client.knative.dev/user-image: us-docker.pkg.dev/cloudrun/container/hello
25
+ run.googleapis.com/ingress-status: all
26
+ spec:
27
+ template:
28
+ metagoogleapis.com/ingress: all
29
+ run.data:
30
+ name: spinappcloud1
31
+ annotations:
32
+ run.googleapis.com/client-name: cloud-console
33
+ autoscaling.knative.dev/minScale: '1'
34
+ autoscaling.knative.dev/maxScale: '3'
35
+ spec:
36
+ containerConcurrency: 80
37
+ timeoutSeconds: 200
38
+ serviceAccountName:spinnaker-cloudrun-account@my-orbit-project-71824.iam.gserviceaccount.com
39
+ containers:
40
+ - image:us-docker.pkg.dev/cloudrun/container/hello
41
+ ports:
42
+ - name: http1
43
+ containerPort: 8080
44
+ resources:
45
+ limits:
46
+ cpu: 1000m
47
+ memory: 256Mi
48
+ </pre>
49
+ `,
50
+ },
51
+
52
+ {
53
+ key: 'cloudrun.serverGroup.detail',
54
+ value:
55
+ ' (Optional) <b>Detail</b> is a string of free-form alphanumeric characters and hyphens to describe any other variables.',
56
+ },
57
+ {
58
+ key: 'cloudrun.serverGroup.configFiles',
59
+ value: `<p> The contents of a Cloud Run Service yaml </p>`,
60
+ },
61
+ {
62
+ key: 'cloudrun.loadBalancer.allocations',
63
+ value: 'An allocation is the percent of traffic directed to a server group.',
64
+ },
65
+ {
66
+ key: 'cloudrun.manifest.source',
67
+ value: `
68
+ <p>Where the manifest file content is read from.</p>
69
+ <p>
70
+ <b>text:</b> The manifest is supplied statically to the pipeline from the below text-box.
71
+ </p>
72
+ <p>
73
+ <b>artifact:</b> The manifest is read from an artifact supplied/created upstream. The expected artifact must be referenced here, and will be bound at runtime.
74
+ </p>`,
75
+ },
76
+ {
77
+ key: 'cloudrun.manifest.expectedArtifact',
78
+ value:
79
+ 'The artifact that is to be applied to the Cloud Run account for this stage. The artifact should represent a valid Cloud Run manifest.',
80
+ },
81
+ {
82
+ key: 'cloudrun.manifest.skipExpressionEvaluation',
83
+ value:
84
+ '<p>Skip SpEL expression evaluation of the manifest artifact in this stage. Can be paired with the "Evaluate SpEL expressions in overrides at bake time" option in the Bake Manifest stage when baking a third-party manifest artifact with expressions not meant for Spinnaker to evaluate as SpEL.</p>',
85
+ },
86
+ {
87
+ key: 'cloudrun.manifest.requiredArtifactsToBind',
88
+ value:
89
+ 'These artifacts must be present in the context for this stage to successfully complete. Artifacts specified will be <a href="https://www.spinnaker.io/reference/artifacts/in-cloudrun-v2/#binding-artifacts-in-manifests" target="_blank">bound to the deployed manifest.</a>',
90
+ },
91
+ {
92
+ key: 'cloudrun.manifest.account',
93
+ value: `
94
+ <p>A Spinnaker account corresponds to a physical Cloud Run cluster. If you are unsure which account to use, talk to your Spinnaker admin.</p>
95
+ `,
96
+ },
97
+ ];
98
+
99
+ helpContents.forEach((entry) => HelpContentsRegistry.register(entry.key, entry.value));
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './cloudrun.module';
2
+ export * from './serverGroup';
3
+ export * from './loadBalancer';
@@ -0,0 +1,84 @@
1
+ import type { IController, IQService } from 'angular';
2
+ import { module } from 'angular';
3
+ import { flattenDeep } from 'lodash';
4
+
5
+ import type { Application, ILoadBalancer } from '@spinnaker/core';
6
+ import { InstanceReader, RecentHistoryService } from '@spinnaker/core';
7
+ import type { ICloudrunInstance } from '../../common/domain';
8
+
9
+ interface InstanceFromStateParams {
10
+ instanceId: string;
11
+ }
12
+
13
+ interface InstanceManager {
14
+ account: string;
15
+ region: string;
16
+ category: string; // e.g., serverGroup, loadBalancer.
17
+ name: string; // Parent resource name, not instance name.
18
+ instances: ICloudrunInstance[];
19
+ }
20
+
21
+ class CloudrunInstanceDetailsController implements IController {
22
+ public state = { loading: true };
23
+ public instance: ICloudrunInstance;
24
+ public instanceIdNotFound: string;
25
+ public upToolTip = "A Cloud Run instance is 'Up' if a load balancer is directing traffic to its server group.";
26
+ public outOfServiceToolTip = `
27
+ A Cloud Run instance is 'Out Of Service' if no load balancers are directing traffic to its server group.`;
28
+
29
+ public static $inject = ['$q', 'app', 'instance'];
30
+
31
+ constructor(private $q: IQService, private app: Application, instance: InstanceFromStateParams) {
32
+ this.app
33
+ .ready()
34
+ .then(() => this.retrieveInstance(instance))
35
+ .then((instanceDetails) => {
36
+ this.instance = instanceDetails;
37
+ this.state.loading = false;
38
+ })
39
+ .catch(() => {
40
+ this.instanceIdNotFound = instance.instanceId;
41
+ this.state.loading = false;
42
+ });
43
+ }
44
+
45
+ private retrieveInstance(instance: InstanceFromStateParams): PromiseLike<ICloudrunInstance> {
46
+ const instanceLocatorPredicate = (dataSource: InstanceManager) => {
47
+ return dataSource.instances.some((possibleMatch) => possibleMatch.id === instance.instanceId);
48
+ };
49
+
50
+ const dataSources: InstanceManager[] = flattenDeep([
51
+ this.app.getDataSource('serverGroups').data,
52
+ this.app.getDataSource('loadBalancers').data,
53
+ this.app.getDataSource('loadBalancers').data.map((loadBalancer: ILoadBalancer) => loadBalancer.serverGroups),
54
+ ]);
55
+
56
+ const instanceManager = dataSources.find(instanceLocatorPredicate);
57
+
58
+ if (instanceManager) {
59
+ const recentHistoryExtraData: { [key: string]: string } = {
60
+ region: instanceManager.region,
61
+ account: instanceManager.account,
62
+ };
63
+ if (instanceManager.category === 'serverGroup') {
64
+ recentHistoryExtraData.serverGroup = instanceManager.name;
65
+ }
66
+ RecentHistoryService.addExtraDataToLatest('instances', recentHistoryExtraData);
67
+
68
+ return InstanceReader.getInstanceDetails(
69
+ instanceManager.account,
70
+ instanceManager.region,
71
+ instance.instanceId,
72
+ ).then((instanceDetails: ICloudrunInstance) => {
73
+ instanceDetails.account = instanceManager.account;
74
+ instanceDetails.region = instanceManager.region;
75
+ return instanceDetails;
76
+ });
77
+ } else {
78
+ return this.$q.reject();
79
+ }
80
+ }
81
+ }
82
+
83
+ export const CLOUDRUN_INSTANCE_DETAILS_CTRL = 'spinnaker.cloudrun.instanceDetails.controller';
84
+ module(CLOUDRUN_INSTANCE_DETAILS_CTRL, []).controller('cloudrunInstanceDetailsCtrl', CloudrunInstanceDetailsController);
@@ -0,0 +1,68 @@
1
+ <div class="details-panel">
2
+ <div class="header">
3
+ <instance-details-header
4
+ health-state="ctrl.instance.healthState"
5
+ instance-id="ctrl.instance ? ctrl.instance.name : ctrl.instanceIdNotFound"
6
+ loading="ctrl.state.loading"
7
+ standalone="false"
8
+ ></instance-details-header>
9
+ <div ng-if="!ctrl.state.loading">
10
+ <div class="actions">
11
+ <div class="dropdown" uib-dropdown dropdown-append-to-body>
12
+ <button type="button" class="btn btn-sm btn-primary dropdown-toggle" uib-dropdown-toggle>
13
+ Instance Actions <span class="caret"></span>
14
+ </button>
15
+ </div>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ <div class="content" ng-if="!ctrl.state.loading && ctrl.instance">
20
+ <collapsible-section heading="Instance Information" expanded="true">
21
+ <dl class="dl-horizontal dl-narrow">
22
+ <dt>Launched</dt>
23
+ <dd ng-if="ctrl.instance.launchTime">{{ctrl.instance.launchTime | timestamp}}</dd>
24
+ <dt>In</dt>
25
+ <dd><account-tag account="ctrl.instance.account" pad="right"></account-tag>{{}}</dd>
26
+ <dt ng-if="ctrl.instance.serverGroup">Server Group</dt>
27
+ <dd ng-if="ctrl.instance.serverGroup">
28
+ <a
29
+ ui-sref="^.serverGroup({region: ctrl.instance.region,
30
+ accountId: ctrl.instance.account,
31
+ serverGroup: ctrl.instance.serverGroup,
32
+ provider: 'cloudrun'})"
33
+ >{{ctrl.instance.serverGroup}}</a
34
+ >
35
+ </dd>
36
+ <dt>Region</dt>
37
+ <dd>{{ctrl.instance.region}}</dd>
38
+ <cloudrun-conditional-dt-dd
39
+ component="ctrl.instance"
40
+ key="vmZoneName"
41
+ label="Zone"
42
+ ></cloudrun-conditional-dt-dd>
43
+ </dl>
44
+ </collapsible-section>
45
+ <collapsible-section heading="Status" expanded="true">
46
+ <dl>
47
+ <dt>Load Balancer</dt>
48
+ <dd>
49
+ <span
50
+ class="pull-left"
51
+ uib-tooltip="{{ctrl.instance.healthState === 'Up' ? ctrl.upToolTip : ctrl.outOfServiceToolTip}}"
52
+ tooltip-placement="right"
53
+ >
54
+ <span class="glyphicon glyphicon-{{ctrl.instance.healthState}}-triangle"></span>
55
+ {{ctrl.instance.loadBalancers[0]}}
56
+ </span>
57
+ </dd>
58
+ </dl>
59
+ </collapsible-section>
60
+ </div>
61
+ <div class="content" ng-if="!ctrl.state.loading && !ctrl.instance">
62
+ <div class="content-section">
63
+ <div class="content-body text-center">
64
+ <h3>Instance not found.</h3>
65
+ </div>
66
+ </div>
67
+ </div>
68
+ </div>
@@ -0,0 +1 @@
1
+ export * from './infrastructure.types';
@@ -0,0 +1,23 @@
1
+ import type { IInstance, ILoadBalancer, IMoniker, IServerGroup } from '@spinnaker/core';
2
+
3
+ export interface ICloudrunResource {
4
+ apiVersion: string;
5
+ createdTime?: number;
6
+ displayName: string;
7
+ kind: string;
8
+ namespace: string;
9
+ }
10
+
11
+ export interface ICloudrunInstance extends IInstance, ICloudrunResource {
12
+ humanReadableName: string;
13
+ moniker: IMoniker;
14
+ publicDnsName?: string;
15
+ }
16
+
17
+ export interface ICloudrunLoadBalancer extends ILoadBalancer, ICloudrunResource {}
18
+
19
+ export interface ICloudrunServerGroup extends IServerGroup, ICloudrunResource {
20
+ disabled: boolean;
21
+ }
22
+
23
+ //export interface ICloudrunServerGroupManager extends IServerGroupManager, ICloudrunResource {}
@@ -0,0 +1,70 @@
1
+ import type { IComponentOptions, IController } from 'angular';
2
+ import { module } from 'angular';
3
+ import { uniq } from 'lodash';
4
+
5
+ import type { ICloudrunAllocationDescription } from '../../loadBalancerTransformer';
6
+
7
+ class CloudrunAllocationConfigurationRowCtrl implements IController {
8
+ public allocationDescription: ICloudrunAllocationDescription;
9
+ public serverGroupOptions: string[];
10
+
11
+ public getServerGroupOptions(): string[] {
12
+ if (this.allocationDescription.revisionName) {
13
+ return uniq(this.serverGroupOptions.concat(this.allocationDescription.revisionName));
14
+ } else {
15
+ return this.serverGroupOptions;
16
+ }
17
+ }
18
+ }
19
+
20
+ const cloudrunAllocationConfigurationRowComponent: IComponentOptions = {
21
+ bindings: {
22
+ allocationDescription: '<',
23
+ removeAllocation: '&',
24
+ serverGroupOptions: '<',
25
+ onAllocationChange: '&',
26
+ },
27
+ template: `
28
+ <div class="form-group">
29
+ <div class="row">
30
+ <div class="col-md-7">
31
+ <ui-select ng-model="$ctrl.allocationDescription.revisionName"
32
+ on-select="$ctrl.onAllocationChange()"
33
+ class="form-control input-sm">
34
+ <ui-select-match placeholder="Select...">
35
+ {{$select.selected}}
36
+ </ui-select-match>
37
+ <ui-select-choices repeat="serverGroup as serverGroup in $ctrl.getServerGroupOptions() | filter: $select.search">
38
+ <div ng-bind-html="serverGroup | highlight: $select.search"></div>
39
+ </ui-select-choices>
40
+ </ui-select>
41
+ </div>
42
+ <div class="col-md-3">
43
+ <div class="input-group input-group-sm">
44
+ <input type="number"
45
+ ng-model="$ctrl.allocationDescription.percent"
46
+ required
47
+ class="form-control input-sm"
48
+ min="0"
49
+ ng-change="$ctrl.onAllocationChange()"
50
+ max="100"/>
51
+ <span class="input-group-addon">%</span>
52
+ </div>
53
+ </div>
54
+ <div class="col-md-2">
55
+ <a class="btn btn-link sm-label" ng-click="$ctrl.removeAllocation()">
56
+ <span class="glyphicon glyphicon-trash"></span>
57
+ </a>
58
+ </div>
59
+ </div>
60
+ </div>
61
+ `,
62
+ controller: CloudrunAllocationConfigurationRowCtrl,
63
+ };
64
+
65
+ export const CLOUDRUN_ALLOCATION_CONFIGURATION_ROW = 'spinnaker.cloudrun.allocationConfigurationRow.component';
66
+
67
+ module(CLOUDRUN_ALLOCATION_CONFIGURATION_ROW, []).component(
68
+ 'cloudrunAllocationConfigurationRow',
69
+ cloudrunAllocationConfigurationRowComponent,
70
+ );
@@ -0,0 +1,44 @@
1
+ <ng-form name="basicSettingsForm">
2
+ <div class="row">
3
+ <div class="form-group">
4
+ <div class="col-md-3 sm-label-right">
5
+ Allocations
6
+ <help-field key="cloudrun.loadBalancer.allocations"></help-field>
7
+ </div>
8
+ <div class="col-md-9">
9
+ <div ng-if="!$ctrl.forPipelineConfig">
10
+ <cloudrun-allocation-configuration-row
11
+ ng-repeat="description in $ctrl.loadBalancer.splitDescription.allocationDescriptions"
12
+ allocation-description="description"
13
+ server-group-options="$ctrl.serverGroupOptions"
14
+ on-allocation-change="$ctrl.updateServerGroupOptions()"
15
+ remove-allocation="$ctrl.removeAllocation($index)"
16
+ >
17
+ </cloudrun-allocation-configuration-row>
18
+ </div>
19
+ <div ng-if="$ctrl.forPipelineConfig">
20
+ <cloudrun-stage-allocation-configuration-row
21
+ ng-repeat="description in $ctrl.loadBalancer.splitDescription.allocationDescriptions"
22
+ allocation-description="description"
23
+ application="$ctrl.application"
24
+ region="{{ $ctrl.loadBalancer.region }}"
25
+ account="{{ $ctrl.loadBalancer.account || $ctrl.loadBalancer.credentials }}"
26
+ name="{{ $ctrl.loadBalancer.name }}"
27
+ server-group-options="$ctrl.serverGroupOptions"
28
+ on-allocation-change="$ctrl.updateServerGroupOptions()"
29
+ remove-allocation="$ctrl.removeAllocation($index)"
30
+ >
31
+ </cloudrun-stage-allocation-configuration-row>
32
+ </div>
33
+ <button class="add-new col-md-11" ng-if="$ctrl.showAddButton()" ng-click="$ctrl.addAllocation()">
34
+ <span class="glyphicon glyphicon-plus-sign"></span> Add allocation
35
+ </button>
36
+ </div>
37
+ </div>
38
+ <div class="form-group" ng-if="$ctrl.allocationIsInvalid()">
39
+ <div class="col-md-12 text-center">
40
+ <p class="alert alert-warning">Allocations must sum to 100%.</p>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ </ng-form>
@@ -0,0 +1,86 @@
1
+ import type { IController } from 'angular';
2
+ import { module } from 'angular';
3
+ import { difference } from 'lodash';
4
+
5
+ import type { CloudrunLoadBalancerUpsertDescription } from '../../loadBalancerTransformer';
6
+
7
+ class CloudrunLoadBalancerSettingsController implements IController {
8
+ public loadBalancer: CloudrunLoadBalancerUpsertDescription;
9
+ public serverGroupOptions: string[];
10
+ public forPipelineConfig: boolean;
11
+
12
+ public $onInit(): void {
13
+ this.updateServerGroupOptions();
14
+ }
15
+
16
+ public addAllocation(): void {
17
+ const remainingServerGroups = this.serverGroupsWithoutAllocation();
18
+ if (remainingServerGroups.length) {
19
+ this.loadBalancer.splitDescription.allocationDescriptions.push({
20
+ revisionName: remainingServerGroups[0],
21
+ percent: 0,
22
+ });
23
+ this.updateServerGroupOptions();
24
+ } else if (this.forPipelineConfig) {
25
+ this.loadBalancer.splitDescription.allocationDescriptions.push({
26
+ percent: 0,
27
+ revisionName: '',
28
+ });
29
+ }
30
+ }
31
+
32
+ public removeAllocation(index: number): void {
33
+ this.loadBalancer.splitDescription.allocationDescriptions.splice(index, 1);
34
+ this.updateServerGroupOptions();
35
+ }
36
+
37
+ public allocationIsInvalid(): boolean {
38
+ return (
39
+ this.loadBalancer.splitDescription.allocationDescriptions.reduce(
40
+ (sum, allocationDescription) => sum + allocationDescription.percent,
41
+ 0,
42
+ ) !== 100
43
+ );
44
+ }
45
+
46
+ public updateServerGroupOptions(): void {
47
+ this.serverGroupOptions = this.serverGroupsWithoutAllocation();
48
+ }
49
+
50
+ public showAddButton(): boolean {
51
+ if (this.forPipelineConfig) {
52
+ return true;
53
+ } else {
54
+ return this.serverGroupsWithoutAllocation().length > 0;
55
+ }
56
+ }
57
+
58
+ public initializeAsTextInput(serverGroupName: string): boolean {
59
+ if (this.forPipelineConfig) {
60
+ return !this.loadBalancer.serverGroups.map((serverGroup) => serverGroup.name).includes(serverGroupName);
61
+ } else {
62
+ return false;
63
+ }
64
+ }
65
+
66
+ private serverGroupsWithoutAllocation(): string[] {
67
+ const serverGroupsWithAllocation = this.loadBalancer.splitDescription.allocationDescriptions.map(
68
+ (description) => description.revisionName,
69
+ );
70
+ const allServerGroups = this.loadBalancer.serverGroups.map((serverGroup) => serverGroup.name);
71
+ return difference(allServerGroups, serverGroupsWithAllocation);
72
+ }
73
+ }
74
+
75
+ const cloudrunLoadBalancerSettingsComponent: ng.IComponentOptions = {
76
+ bindings: { loadBalancer: '=', forPipelineConfig: '<', application: '<' },
77
+ controller: CloudrunLoadBalancerSettingsController,
78
+ templateUrl: require('./basicSettings.component.html'),
79
+ };
80
+
81
+ export const CLOUDRUN_LOAD_BALANCER_BASIC_SETTINGS = 'spinnaker.cloudrun.loadBalancerSettings.component';
82
+
83
+ module(CLOUDRUN_LOAD_BALANCER_BASIC_SETTINGS, []).component(
84
+ 'cloudrunLoadBalancerBasicSettings',
85
+ cloudrunLoadBalancerSettingsComponent,
86
+ );
@@ -0,0 +1,45 @@
1
+ <div class="form-group">
2
+ <div class="row">
3
+ <div class="col-md-7">
4
+ <cloudrun-stage-allocation-label allocation-description="$ctrl.allocationDescription">
5
+ </cloudrun-stage-allocation-label>
6
+ </div>
7
+ <div class="col-md-3">
8
+ <div class="input-group input-group-sm">
9
+ <input
10
+ type="number"
11
+ ng-model="$ctrl.allocationDescription.percent"
12
+ required
13
+ class="form-control input-sm"
14
+ min="0"
15
+ ng-change="$ctrl.onAllocationChange()"
16
+ max="100"
17
+ />
18
+ <span class="input-group-addon">%</span>
19
+ </div>
20
+ </div>
21
+ <div class="col-md-2">
22
+ <a class="btn btn-link sm-label" ng-click="$ctrl.removeAllocation()">
23
+ <span class="glyphicon glyphicon-trash"></span>
24
+ </a>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ <div class="form-group">
29
+ <div class="well col-md-11" style="padding-top: 5px; padding-bottom: 10px">
30
+ <div class="row">
31
+ <div class="form-group">
32
+ <div>
33
+ <div class="col-md-3 sm-label-right">Cluster</div>
34
+ <div class="col-md-7" style="margin-bottom: 10px">
35
+ <input ng-model="$ctrl.allocationDescription.cluster" type="text" class="form-control input-sm" readonly />
36
+ </div>
37
+ <div class="col-md-3 sm-label-right">Target</div>
38
+ <div class="col-md-7">
39
+ <target-select model="$ctrl.allocationDescription" options="$ctrl.targets"></target-select>
40
+ </div>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ </div>
@@ -0,0 +1,84 @@
1
+ import type { IComponentOptions, IController } from 'angular';
2
+ import { module } from 'angular';
3
+ import { uniq } from 'lodash';
4
+
5
+ import { StageConstants } from '@spinnaker/core';
6
+
7
+ import type { ICloudrunAllocationDescription } from '../../loadBalancerTransformer';
8
+
9
+ class CloudrunStageAllocationLabelCtrl implements IController {
10
+ public inputViewValue: string;
11
+ private allocationDescription: ICloudrunAllocationDescription;
12
+
13
+ private static mapTargetCoordinateToLabel(targetCoordinate: string): string {
14
+ const target = StageConstants.TARGET_LIST.find((t) => t.val === targetCoordinate);
15
+ if (target) {
16
+ return target.label;
17
+ } else {
18
+ return null;
19
+ }
20
+ }
21
+
22
+ public $doCheck(): void {
23
+ this.setInputViewValue();
24
+ }
25
+
26
+ private setInputViewValue(): void {
27
+ if (this.allocationDescription.cluster && this.allocationDescription.target) {
28
+ const targetLabel = CloudrunStageAllocationLabelCtrl.mapTargetCoordinateToLabel(
29
+ this.allocationDescription.target,
30
+ );
31
+ this.inputViewValue = `${targetLabel} (${this.allocationDescription.cluster})`;
32
+ } else {
33
+ this.inputViewValue = null;
34
+ }
35
+ }
36
+ }
37
+
38
+ const cloudrunStageAllocationLabel: IComponentOptions = {
39
+ bindings: { allocationDescription: '<' },
40
+ controller: CloudrunStageAllocationLabelCtrl,
41
+ template: `<input ng-model="$ctrl.inputViewValue" type="text" class="form-control input-sm" readonly/>`,
42
+ };
43
+
44
+ class CloudrunStageAllocationConfigurationRowCtrl implements IController {
45
+ public allocationDescription: ICloudrunAllocationDescription;
46
+ public serverGroupOptions: string[];
47
+ public targets = StageConstants.TARGET_LIST;
48
+ public clusterList: string[];
49
+ public onAllocationChange: Function;
50
+ private name: string;
51
+
52
+ public $onInit() {
53
+ this.allocationDescription.cluster = this.name;
54
+ }
55
+
56
+ public getServerGroupOptions(): string[] {
57
+ if (this.allocationDescription.revisionName) {
58
+ return uniq(this.serverGroupOptions.concat(this.allocationDescription.revisionName));
59
+ } else {
60
+ return this.serverGroupOptions;
61
+ }
62
+ }
63
+ }
64
+
65
+ const cloudrunStageAllocationConfigurationRow: IComponentOptions = {
66
+ bindings: {
67
+ application: '<',
68
+ region: '@',
69
+ account: '@',
70
+ name: '@',
71
+ allocationDescription: '<',
72
+ removeAllocation: '&',
73
+ serverGroupOptions: '<',
74
+ onAllocationChange: '&',
75
+ },
76
+ controller: CloudrunStageAllocationConfigurationRowCtrl,
77
+ templateUrl: require('./stageAllocationConfigurationRow.component.html'),
78
+ };
79
+
80
+ export const CLOUDRUN_STAGE_ALLOCATION_CONFIGURATION_ROW =
81
+ 'spinnaker.cloudrun.stageAllocationConfigurationRow.component';
82
+ module(CLOUDRUN_STAGE_ALLOCATION_CONFIGURATION_ROW, [])
83
+ .component('cloudrunStageAllocationConfigurationRow', cloudrunStageAllocationConfigurationRow)
84
+ .component('cloudrunStageAllocationLabel', cloudrunStageAllocationLabel);