Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Fix override clean routes (#831)
Browse files Browse the repository at this point in the history
* add step on spinnaker pipeline do remove unused deployments routes

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

* spinnaker pipeline add step to remove unused components from istio routes

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

* add proxy overrides field to octo payload

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

* fix unused component proxy rules and tests

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

* add unused proxy undeployment field to octo struct

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

* fix mock assertion order

TODO: put orderBy clause on findActiveComponents
Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

* write test for spinnaker pipeline

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

* use right property on unused proxy undeployment method

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

* fix wrong property access on unused proxy deployments

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

* add more tests to spinnaker pipeline

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

* add more tests to unusedComponentProxy function

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

* improve test description

Signed-off-by: Cassio Godinho <cassiopgodinho@gmail.com>

Co-authored-by: Lucas Borges Fernandes <lucasbfernandes94@gmail.com>
Co-authored-by: Mônica Ribeiro <monica.ribeiro@zup.com.br>
  • Loading branch information
3 people committed Feb 22, 2021
1 parent 01dfe6b commit 10914cf
Show file tree
Hide file tree
Showing 28 changed files with 4,639 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export interface OctopipeDeploymentRequest {
namespace: string;
deployments: OctopipeDeployment[],
unusedDeployments: OctopipeDeployment[],
proxyDeployments: K8sManifest[]
proxyDeployments: K8sManifest[],
unusedProxyDeployments: K8sManifest[],
callbackUrl: string
clusterConfig?: IEKSClusterConfig | IGenericClusterConfig | null
}
27 changes: 25 additions & 2 deletions butler/src/app/v2/core/integrations/octopipe/request-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { UrlUtils } from '../../utils/url.utils'
import { ConnectorConfiguration } from '../interfaces/connector-configuration.interface'
import { K8sManifest } from '../interfaces/k8s-manifest.interface'
import { CommonTemplateUtils } from '../spinnaker/utils/common-template.utils'
import { componentsToBeRemoved, DeploymentUtils } from '../utils/deployment.utils'
import { componentsToBeRemoved, DeploymentUtils, unusedComponentProxy } from '../utils/deployment.utils'
import { IstioDeploymentManifestsUtils } from '../utils/istio-deployment-manifests.utils'
import { IstioUndeploymentManifestsUtils } from '../utils/istio-undeployment-manifests.utils'
import { HelmConfig, HelmRepositoryConfig } from './interfaces/helm-config.interface'
Expand All @@ -47,7 +47,8 @@ export class OctopipeRequestBuilder {
unusedDeployments: this.getUnusedDeploymentsArray(deployment, activeComponents),
proxyDeployments: this.getProxyDeploymentsArray(deployment, activeComponents),
callbackUrl: UrlUtils.getDeploymentNotificationUrl(configuration.executionId),
clusterConfig: this.getClusterConfig(deployment.cdConfiguration.configurationData as OctopipeConfigurationData)
clusterConfig: this.getClusterConfig(deployment.cdConfiguration.configurationData as OctopipeConfigurationData),
unusedProxyDeployments: this.overrideUnusedRules(deployment, activeComponents)
}
}

Expand Down Expand Up @@ -161,6 +162,28 @@ export class OctopipeRequestBuilder {
})
}

private overrideUnusedRules(deployment: Deployment, activeComponents: Component[]) {
if (!deployment.components) {
return []
}

if (deployment.defaultCircle) {
return []
}

const proxyUndeployments: K8sManifest[] = []
const unused = unusedComponentProxy(deployment, activeComponents)
unused.forEach(component => {
const activeByName: Component[] = DeploymentUtils.getActiveComponentsByName(activeComponents, component.name)
proxyUndeployments.push(IstioUndeploymentManifestsUtils.getDestinationRulesManifest(deployment, component, activeByName))
proxyUndeployments.push(activeByName.length > 1 ?
IstioUndeploymentManifestsUtils.getVirtualServiceManifest(deployment, component, activeByName) :
IstioUndeploymentManifestsUtils.getEmptyVirtualServiceManifest(deployment, component)
)
})
return proxyUndeployments
}

private getHelmRepositoryConfig(component: DeploymentComponent, cdConfiguration: CdConfiguration): HelmRepositoryConfig {
return {
type: (cdConfiguration.configurationData as OctopipeConfigurationData).gitProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
import { DeploymentTemplateUtils } from './utils/deployment-template.utils'
import { UndeploymentTemplateUtils } from './utils/undeployment-template.utils'
import { ConnectorConfiguration } from '../interfaces/connector-configuration.interface'
import { componentsToBeRemoved, DeploymentUtils } from '../utils/deployment.utils'
import { componentsToBeRemoved, DeploymentUtils, unusedComponentProxy } from '../utils/deployment.utils'
import { DeploymentComponent } from '../../../api/deployments/interfaces/deployment.interface'

export class SpinnakerPipelineBuilder {
Expand Down Expand Up @@ -87,6 +87,7 @@ export class SpinnakerPipelineBuilder {
...this.getProxyDeploymentsEvaluationStage(deployment.components),
...this.getRollbackDeploymentsStage(deployment, activeComponents),
...this.getUnusedVersions(deployment, activeComponents),
...this.getProxyUnusedStages(deployment, activeComponents),
...this.getFailureWebhookStage(deployment, configuration),
...this.getSuccessWebhookStage(deployment, configuration)
]
Expand Down Expand Up @@ -142,6 +143,34 @@ export class SpinnakerPipelineBuilder {
return proxyStages
}

private getProxyUnusedStages(deployment: Deployment, activeComponents: Component[]): Stage[] {
if (!deployment?.components) {
return []
}

if (deployment.defaultCircle) {
return []
}
const unusedComponentsProxies = unusedComponentProxy(deployment, activeComponents)

if (unusedComponentsProxies.length === 0) {
return []
}
const proxyStages: Stage[] = []
const evalStageId: number = DeploymentTemplateUtils.getProxyEvalStageId(deployment.components)

unusedComponentsProxies.forEach(component => {
const activeByName: Component[] = DeploymentUtils.getActiveComponentsByName(activeComponents, component.name)
proxyStages.push(getUndeploymentDestinationRulesStage(component, deployment, activeByName, this.currentStageId++, evalStageId))
proxyStages.push(activeByName.length > 1 ?
getUndeploymentVirtualServiceStage(component, deployment, activeByName, this.currentStageId++) :
getUndeploymentEmptyVirtualServiceStage(component, deployment, this.currentStageId++)
)
})

return proxyStages
}

private getDeploymentsEvaluationStage(components: DeploymentComponent[] | undefined): Stage[] {
return components && components.length ?
[getDeploymentsEvaluationStage(components, this.currentStageId++)] :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export const getUndeploymentDestinationRulesStage = (
component: DeploymentComponent,
deployment: Deployment,
activeComponents: Component[],
stageId: number
stageId: number,
evalStageId?: number
): Stage => ({
account: `${(deployment.cdConfiguration.configurationData as ISpinnakerConfigurationData).account}`,
cloudProvider: 'kubernetes',
Expand All @@ -39,7 +40,7 @@ export const getUndeploymentDestinationRulesStage = (
},
name: `Undeploy Destination Rules ${component.name}`,
refId: `${stageId}`,
requisiteStageRefIds: [],
requisiteStageRefIds: evalStageId ? [`${evalStageId}`] : [],
skipExpressionEvaluation: false,
source: 'text',
trafficManagement: {
Expand Down
9 changes: 9 additions & 0 deletions butler/src/app/v2/core/integrations/utils/deployment.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ export const componentsToBeRemoved = (deployment: Deployment, activeComponents:
})
}

export const unusedComponentProxy = (deployment: Deployment, activeComponents: Component[]): DeploymentComponent[] => {
if (componentsToBeRemoved(deployment, activeComponents).length === 0) {
return []
}
const sameCircleComponents = activeComponents.filter(c => c.deployment.circleId === deployment.circleId)

return sameCircleComponents.filter(c => !deployment.components?.map(dc => dc.name).includes(c.name))
}

const removedComponents = (deploymentComponents: DeploymentComponent[] | undefined, activeComponent: Component) => {
return !deploymentComponents?.some(dc => isSameName(dc, activeComponent))
}
Expand Down

0 comments on commit 10914cf

Please sign in to comment.