Skip to content

Commit f537f7e

Browse files
chore: init force deploy
1 parent 9a41850 commit f537f7e

File tree

9 files changed

+76
-3
lines changed

9 files changed

+76
-3
lines changed

apps/workspace-engine/oapi/openapi.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,21 @@
11721172
],
11731173
"type": "object"
11741174
},
1175+
"ReleaseTargetForceDeployEvent": {
1176+
"properties": {
1177+
"releaseTarget": {
1178+
"$ref": "#/components/schemas/ReleaseTarget"
1179+
},
1180+
"version": {
1181+
"$ref": "#/components/schemas/DeploymentVersion"
1182+
}
1183+
},
1184+
"required": [
1185+
"releaseTarget",
1186+
"version"
1187+
],
1188+
"type": "object"
1189+
},
11751190
"ReleaseTargetState": {
11761191
"properties": {
11771192
"currentRelease": {

apps/workspace-engine/oapi/spec/main.jsonnet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
(import 'schemas/relationship.jsonnet') +
3838
(import 'schemas/jobs.jsonnet') +
3939
(import 'schemas/deployments.jsonnet') +
40-
(import 'schemas/verification.jsonnet'),
40+
(import 'schemas/verification.jsonnet') +
41+
(import 'schemas/release-targets.jsonnet'),
4142
},
4243
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
local openapi = import '../lib/openapi.libsonnet';
2+
3+
{
4+
ReleaseTargetForceDeployEvent: {
5+
type: 'object',
6+
required: ['releaseTarget', 'version'],
7+
properties: {
8+
releaseTarget: openapi.schemaRef('ReleaseTarget'),
9+
version: openapi.schemaRef('DeploymentVersion'),
10+
},
11+
},
12+
}

apps/workspace-engine/pkg/events/handler/redeploy/redeploy.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@ func HandleReleaseTargetDeploy(ctx context.Context, ws *workspace.Workspace, eve
2727

2828
return nil
2929
}
30+
31+
func HandleReleaseTargetForceDeploy(ctx context.Context, ws *workspace.Workspace, event handler.RawEvent) error {
32+
releaseTargetForceDeployEvent := &oapi.ReleaseTargetForceDeployEvent{}
33+
if err := json.Unmarshal(event.Data, releaseTargetForceDeployEvent); err != nil {
34+
return err
35+
}
36+
37+
return ws.ReleaseManager().ForceDeploy(ctx, &releaseTargetForceDeployEvent.ReleaseTarget, &releaseTargetForceDeployEvent.Version)
38+
}

apps/workspace-engine/pkg/oapi/oapi.gen.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/workspace-engine/pkg/workspace/releasemanager/deployment/planner.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type planDeploymentConfig struct {
5858
resourceRelatedEntities map[string][]*oapi.EntityRelation
5959
recorder *trace.ReconcileTarget
6060
earliestVersionForEvaluation *oapi.DeploymentVersion
61+
forceDeployVersion *oapi.DeploymentVersion
6162
}
6263

6364
func WithResourceRelatedEntities(entities map[string][]*oapi.EntityRelation) planDeploymentOptions {
@@ -78,6 +79,12 @@ func WithVersionAndNewer(version *oapi.DeploymentVersion) planDeploymentOptions
7879
}
7980
}
8081

82+
func WithForceDeployVersion(version *oapi.DeploymentVersion) planDeploymentOptions {
83+
return func(cfg *planDeploymentConfig) {
84+
cfg.forceDeployVersion = version
85+
}
86+
}
87+
8188
// Returns:
8289
// - *oapi.Release: The desired release to deploy
8390
// - nil: No deployable release (no versions or all blocked by policies)
@@ -126,9 +133,14 @@ func (p *Planner) PlanDeployment(ctx context.Context, releaseTarget *oapi.Releas
126133
return nil, nil
127134
}
128135

136+
deployableVersion := cfg.forceDeployVersion
137+
129138
// Step 2: Find first version that passes user-defined policies
130-
span.AddEvent("Step 2: Finding deployable version")
131-
deployableVersion := p.findDeployableVersion(ctx, candidateVersions, releaseTarget, planning)
139+
if deployableVersion == nil {
140+
span.AddEvent("Step 2: Finding deployable version")
141+
deployableVersion = p.findDeployableVersion(ctx, candidateVersions, releaseTarget, planning)
142+
}
143+
132144
if deployableVersion == nil {
133145
span.AddEvent("No deployable version found (blocked by policies)")
134146
span.SetAttributes(

apps/workspace-engine/pkg/workspace/releasemanager/deployment_orchestrator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func (o *DeploymentOrchestrator) Reconcile(
9494
deployment.WithResourceRelatedEntities(options.resourceRelationships),
9595
deployment.WithTraceRecorder(recorder),
9696
deployment.WithVersionAndNewer(options.earliestVersionForEvaluation),
97+
deployment.WithForceDeployVersion(options.forceDeployVersion),
9798
)
9899
if err != nil {
99100
span.RecordError(err)

apps/workspace-engine/pkg/workspace/releasemanager/manager.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,16 @@ func (m *Manager) Redeploy(ctx context.Context, releaseTarget *oapi.ReleaseTarge
285285
WithTrigger(trace.TriggerManual))
286286
}
287287

288+
func (m *Manager) ForceDeploy(ctx context.Context, releaseTarget *oapi.ReleaseTarget, version *oapi.DeploymentVersion) error {
289+
ctx, span := tracer.Start(ctx, "ForceDeploy")
290+
defer span.End()
291+
292+
return m.ReconcileTarget(ctx, releaseTarget,
293+
WithSkipEligibilityCheck(true),
294+
WithTrigger(trace.TriggerManual),
295+
WithForceDeployVersion(version))
296+
}
297+
288298
// reconcileTargetWithRelationships is like ReconcileTarget but accepts pre-computed resource relationships.
289299
// This is an optimization to avoid recomputing relationships for multiple release targets that share the same resource.
290300
// After reconciliation completes, it caches the computed state for use by other APIs.

apps/workspace-engine/pkg/workspace/releasemanager/opts.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type options struct {
1212
trigger trace.TriggerReason
1313
resourceRelationships map[string][]*oapi.EntityRelation
1414
earliestVersionForEvaluation *oapi.DeploymentVersion
15+
forceDeployVersion *oapi.DeploymentVersion
1516

1617
// StateCache options
1718
bypassCache bool
@@ -42,6 +43,12 @@ func WithVersionAndNewer(version *oapi.DeploymentVersion) Option {
4243
}
4344
}
4445

46+
func WithForceDeployVersion(version *oapi.DeploymentVersion) Option {
47+
return func(opts *options) {
48+
opts.forceDeployVersion = version
49+
}
50+
}
51+
4552
// StateCache options
4653

4754
func WithResourceRelationships(relationships map[string][]*oapi.EntityRelation) Option {

0 commit comments

Comments
 (0)