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

Butler operator hooks #749

Merged
merged 69 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
83506ce
build project inside dockerfile
cpgo Dec 14, 2020
b5e95a6
base hooks controllers
cpgo Dec 14, 2020
7ad44de
move interface to separate file, add more comments
cpgo Dec 14, 2020
b04f679
working logic to return routes specs only after deployments are ready
cpgo Dec 16, 2020
86e47ee
basic undeploy flow
cpgo Dec 17, 2020
871a300
wip
cpgo Jan 4, 2021
370b158
inject repositories
cpgo Jan 4, 2021
3c11399
add missing validation
cpgo Jan 5, 2021
b5d923a
improve TODO comment
cpgo Jan 5, 2021
0030ee2
add missing injections
cpgo Jan 5, 2021
dabdd4b
Merge branch 'butler-operator' into butler-operator-hooks
cpgo Jan 5, 2021
6a5b97c
fix istio version and hook urls
cpgo Jan 6, 2021
47ad12f
add namespace variable on chart
cpgo Jan 6, 2021
eccaa93
fix controller name
cpgo Jan 6, 2021
528def5
add missing injections on module
cpgo Jan 6, 2021
ca82d27
use namespace to compose routes name
cpgo Jan 6, 2021
4dd6121
update deployment to active if crd apply is successfull
cpgo Jan 6, 2021
2013702
fix operator reconcile logic
cpgo Jan 7, 2021
37d67c8
set deployment.active = false on undeploy request
cpgo Jan 7, 2021
1cec961
begin to implement undeploy hook
cpgo Jan 7, 2021
deb99c8
fix test to use namespace on crd name
cpgo Jan 8, 2021
5917070
fix test to use namespace on crd name
cpgo Jan 8, 2021
110853c
Merge branch 'butler-operator' into butler-operator-hooks
cpgo Jan 8, 2021
c1f42ef
update docs and crd validation
cpgo Jan 11, 2021
a51c9f6
dont update status on hook
cpgo Jan 11, 2021
01a899c
fix initial circle crd
cpgo Jan 11, 2021
b9d6c55
fix routes crd format
cpgo Jan 13, 2021
a790540
Merge branch 'main' into butler-operator-hooks
cpgo Jan 13, 2021
6ee2b6d
create deployment with active true and set circle deployments active …
cpgo Jan 14, 2021
a2387e3
cleanup comments
cpgo Jan 14, 2021
426a162
remove simultaneous deployment validation
cpgo Jan 14, 2021
dfcdfe4
dont start pgboss
cpgo Jan 14, 2021
8d02a1b
enable sourcemaps on docker image
cpgo Jan 15, 2021
a5b40a6
update tsconfig target version
cpgo Jan 15, 2021
0470692
add previous_deployment_id column on deployment entity
cpgo Jan 15, 2021
a590ead
fix k8s services interface
cpgo Jan 15, 2021
10e341c
add deployment_id to crd
cpgo Jan 15, 2021
39cda30
extract logic to class
cpgo Jan 18, 2021
f6d5396
Create routes hook reconcile
leandroleo02 Jan 18, 2021
c7c518c
fix circle deployment override to keep deployments until all news are…
cpgo Jan 18, 2021
f245fc4
Create UseCase for rote manifest creation
leandroleo02 Jan 18, 2021
b76130e
rename active column to current
cpgo Jan 19, 2021
70a5fce
change update strategy of crd children
cpgo Jan 19, 2021
8cb372c
remove comment
cpgo Jan 19, 2021
6bbd859
fix update query, was overriding where clause
cpgo Jan 19, 2021
45e064e
Create unit tests and fixtures for routes manifests creation
leandroleo02 Jan 19, 2021
571babb
Create unit tests for errors
leandroleo02 Jan 20, 2021
fecc5c1
remove redundant conditions
cpgo Jan 20, 2021
82ccd9a
Merge branch 'butler-operator' into butler-operator-hooks
cpgo Jan 20, 2021
4060305
Merge branch 'butler-operator' into butler-operator-hooks
leandroleo02 Jan 20, 2021
4e65783
Merge branch 'butler-operator' into butler-operator-routes
leandroleo02 Jan 20, 2021
d88fc21
Merge branch 'butler-operator-hooks' of https://github.com/ZupIT/char…
leandroleo02 Jan 20, 2021
0df9a91
Merge branch 'butler-operator-hooks' into butler-operator-routes
leandroleo02 Jan 20, 2021
b866c1b
Fix hardcoded mistake
leandroleo02 Jan 21, 2021
0120cd1
Merge pull request #820 from ZupIT/butler-operator-routes
cpgo Jan 27, 2021
a08562e
change istio resource version
cpgo Jan 28, 2021
20fa448
Fix integration tests
leandrorodrigueszup Feb 3, 2021
7706f0d
Cleanup simultaneuos deployment control
leandrorodrigueszup Feb 3, 2021
fddc697
delete unused code
cpgo Feb 4, 2021
ae29f7a
Cleanup PgBossWorker
leandrorodrigueszup Feb 4, 2021
ae0d84a
Cleanup notification endpoint
leandrorodrigueszup Feb 4, 2021
1a60ec9
Code gardening
leandrorodrigueszup Feb 4, 2021
22d8f5f
WIP: check observed routes
cpgo Feb 5, 2021
9bca99b
Remove spinnaker integration
leandrorodrigueszup Feb 5, 2021
3c471f1
Remove octopipe integration
leandrorodrigueszup Feb 5, 2021
e2d1d83
Remove octopipe and spinnaker internal URLs
leandrorodrigueszup Feb 5, 2021
9442c97
Merge pull request #889 from ZupIT/butler-operator-cleanup
leandrorodrigueszup Feb 8, 2021
5255cf3
add routed status field to deployments table
cpgo Feb 9, 2021
99ae000
Merge branch 'butler-operator-hooks' of github.com:ZupIT/charlescd in…
cpgo Feb 9, 2021
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
2 changes: 2 additions & 0 deletions butler/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
13 changes: 5 additions & 8 deletions butler/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
FROM node:12.17.0-alpine3.9

ENV NODE_ENV qa

ENV CONSUL_HOST consul-server

ENV APP_PATH /opt/darwin-deploy

RUN apk upgrade --update-cache --available && \
Expand All @@ -16,10 +12,11 @@ RUN helm version

RUN mkdir -p $APP_PATH
WORKDIR $APP_PATH
COPY . $APP_PATH

ADD package.json $APP_PATH
RUN npm install
RUN npm ci
RUN npm run build

ADD ./dist $APP_PATH
ENV NODE_OPTIONS --enable-source-maps

ENTRYPOINT node main.js
ENTRYPOINT node dist/main.js
20 changes: 16 additions & 4 deletions butler/doc/adr/0001-operator-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,26 @@ spec:

Routes example
```yaml
api: k8s.charles.io
apiVersion: charlescd.io/v1
kind: CharlesRoutes
metadata:
name: default-routes
spec:
circles:
- id: <id-circle>
- id: first-circle
default: true
components:
- name: quiz-app-backend
tag: v1
- name: quiz-app-frontend
tag: v1
- id: second-circle
default: false
components:
- quiz-app-backend
- quiz-app-frontend
- name: quiz-app-backend
tag: v2
- name: quiz-app-frontend
tag: v2
```

Butler will only directly apply the CRDs to the cluster.
Expand Down
11 changes: 4 additions & 7 deletions butler/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ services:
- ./src/resources/stubby/integrations.yml:/usr/local/stubby.yml

app:
image: node:12.17.0-alpine3.9
build:
context: ./
dockerfile: Dockerfile
depends_on:
- stubby4j
volumes:
- ./:/app
working_dir: /app
command: sh -c 'while sleep 3600; do :; done'
entrypoint: sh -c 'while sleep 3600; do :; done'
environment:
TZ: America/Sao_Paulo
DEPLOYMENT_EXPIRE_TIME: 25
Expand All @@ -40,7 +39,5 @@ services:
DARWIN_UNDEPLOYMENT_CALLBACK: http://stubby4j:8883/deploy/notifications/undeployment
DARWIN_DEPLOYMENT_CALLBACK: http://stubby4j:8883/deploy/notifications/deployment
DARWIN_ISTIO_DEPLOYMENT_CALLBACK: http://stubby4j:8883/deploy/notifications/istio-deployment
SPINNAKER_URL: http://stubby4j:8883/spinnaker
HELM_TEMPLATE_URL: http://stubby4j:8883/helm
HELM_PREFIX_URL: http://stubby4j:8883/helm
OCTOPIPE_URL: http://stubby4j:8883/octopipe
2 changes: 2 additions & 0 deletions butler/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Configuration } from './v2/core/config/configurations'
import { AppConstants } from './v2/core/constants'
import { IoCTokensConstants } from './v2/core/constants/ioc'
import { CoreModule } from './v2/core/core.module'
import { OperatorModule } from './v2/operator/operator.module'

@Global()
@Module({})
Expand All @@ -40,6 +41,7 @@ export class AppModule {
imports: [
CoreModule,
ApiModuleV2,
OperatorModule,
TypeOrmModule.forRootAsync({
useFactory: () => (
DatabasesService.getPostgresConnectionOptions(envConfiguration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { validate as uuidValidate } from 'uuid'
import { CreateDeploymentRequestDto } from '../dto/create-deployment-request.dto'
import { ReadDeploymentDto } from '../dto/read-deployment.dto'
import { ReadUndeploymentDto } from '../dto/read-undeployment.dto'
import { CdConfigurationExistencePipe, SimultaneousDeploymentValidationPipe } from '../pipes'
import { CdConfigurationExistencePipe } from '../pipes'
import { CreateDeploymentUseCase } from '../use-cases/create-deployment.usecase'
import { CreateUndeploymentUseCase } from '../use-cases/create-undeployment.usecase'
import { DeploymentUniquenessPipe } from '../pipes/deployment-uniqueness.pipe'
Expand All @@ -34,7 +34,6 @@ export class DeploymentsController {
) { }

@Post('/')
@UsePipes(SimultaneousDeploymentValidationPipe)
@UsePipes(CdConfigurationExistencePipe)
@UsePipes(DeploymentUniquenessPipe)
@UsePipes(new ValidationPipe({ transform: true }))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { Body, Controller, Get, Param, Post, Query, UsePipes, ValidationPipe } from '@nestjs/common'
import { DeploymentNotificationRequestDto } from '../dto/deployment-notification-request.dto'
import { Controller, Get, Query, UsePipes, ValidationPipe } from '@nestjs/common'
import { ExecutionQuery } from '../dto/execution/paginated-execution-query.dto'
import { PaginatedExecutions } from '../dto/execution/paginated-executions.dto'
import { Execution } from '../entity/execution.entity'
import { PaginatedExecutionsUseCase } from '../use-cases/paginated-executions.usecase'
import { ReceiveNotificationUseCase } from '../use-cases/receive-notification.usecase'

@Controller('v2/executions')
export class ExecutionsController {
constructor(
private receiveNotificationUseCase: ReceiveNotificationUseCase,
private paginatedExecutionsUseCase: PaginatedExecutionsUseCase
) { }

Expand All @@ -20,13 +16,4 @@ export class ExecutionsController {
): Promise<PaginatedExecutions> {
return await this.paginatedExecutionsUseCase.execute(params)
}

@Post('/:id/notify')
@UsePipes(new ValidationPipe({ transform: true }))
public async receiveNotification(
@Param('id') executionId: string,
@Body() deploymentNotification: DeploymentNotificationRequestDto,
): Promise<Execution> {
return await this.receiveNotificationUseCase.execute(executionId, deploymentNotification)
}
}
16 changes: 0 additions & 16 deletions butler/src/app/v2/api/deployments/deployments.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,18 @@ import { HttpModule, Module } from '@nestjs/common'
import { TypeOrmModule } from '@nestjs/typeorm'
import { CdConfigurationEntity } from '../configurations/entity'
import { CdConfigurationsRepository } from '../configurations/repository'
import { SpinnakerApiService } from '../../core/integrations/spinnaker/spinnaker-api.service'
import { MooveService } from '../../core/integrations/moove'
import { DeploymentsController } from './controller/deployments.controller'
import { DeploymentEntityV2 as DeploymentEntity } from './entity/deployment.entity'
import { Execution } from './entity/execution.entity'
import { PgBossWorker } from './jobs/pgboss.worker'
import { DeploymentCleanupHandler } from './use-cases/deployment-cleanup-handler'
import { DeploymentHandlerUseCase } from './use-cases/deployment-handler.usecase'
import { ReceiveNotificationUseCase } from './use-cases/receive-notification.usecase'
import { SpinnakerConnector } from '../../core/integrations/spinnaker/connector'
import { ComponentsRepositoryV2 } from './repository'
import { CreateDeploymentUseCase } from './use-cases/create-deployment.usecase'
import { CreateUndeploymentUseCase } from './use-cases/create-undeployment.usecase'
import { DeploymentRepositoryV2 } from './repository/deployment.repository'
import { ExecutionRepository } from './repository/execution.repository'
import { ExecutionsController } from './controller/executions.controller'
import { PaginatedExecutionsUseCase } from './use-cases/paginated-executions.usecase'
import { CdStrategyFactory } from '../../core/integrations/cd-strategy-factory'
import { OctopipeConnector } from '../../core/integrations/octopipe/connector'
import { OctopipeApi } from '../../core/integrations/octopipe/octopipe-api'
import { HelmManifest } from '../../core/manifests/helm/helm-manifest'
import { GitHubRepository } from '../../core/integrations/github/github-repository'
import { GitLabRepository } from '../../core/integrations/gitlab/gitlab-repository'
Expand All @@ -63,20 +55,12 @@ import { ConsoleLoggerService } from '../../core/logs/console/console-logger.ser
ExecutionsController
],
providers: [
PgBossWorker,
CreateDeploymentUseCase,
CreateUndeploymentUseCase,
ReceiveNotificationUseCase,
DeploymentHandlerUseCase,
PaginatedExecutionsUseCase,
MooveService,
DeploymentCleanupHandler,
ConsoleLoggerService,
SpinnakerConnector,
SpinnakerApiService,
CdStrategyFactory,
OctopipeConnector,
OctopipeApi,
GitHubRepository,
GitLabRepository,
RepositoryStrategyFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export class ExecutionQuery {

@ApiProperty()
@IsBooleanString()
public active: boolean
public current: boolean

constructor(size: number, page: number, active: boolean) {
constructor(size: number, page: number, current: boolean) {
this.size = size
this.page = page
this.active = active
this.current = current
}
}
13 changes: 11 additions & 2 deletions butler/src/app/v2/api/deployments/entity/deployment.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ export class DeploymentEntityV2 implements Deployment {
@Column({ name: 'circle_id', nullable: false, type: 'varchar' })
public circleId!: string

@Column({ name: 'previous_deployment_id', nullable: false, type: 'varchar' })
public previousDeploymentId!: string | null

@Column({ name: 'active' })
public active!: boolean

@Column({ name: 'current' })
public current!: boolean

@Column({ name: 'healthy' })
public healthy!: boolean

@Column({ name: 'routed' })
public routed!: boolean

@OneToMany(() => ComponentEntity, component => component.deployment, { cascade: ['insert', 'update'] })
public components!: ComponentEntity[]
Expand Down
86 changes: 0 additions & 86 deletions butler/src/app/v2/api/deployments/jobs/pgboss.worker.ts

This file was deleted.

4 changes: 1 addition & 3 deletions butler/src/app/v2/api/deployments/pipes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
*/

import { CdConfigurationExistencePipe } from './cd-configuration-existence-pipe'
import { SimultaneousDeploymentValidationPipe } from './simultaneous-deployment-validation.pipe'

export {
CdConfigurationExistencePipe,
SimultaneousDeploymentValidationPipe
CdConfigurationExistencePipe
}

This file was deleted.

Loading