Skip to content

Commit d75b11c

Browse files
author
Luiz Filho
committed
Setting lastest revision to pipeline status
1 parent 136b757 commit d75b11c

File tree

7 files changed

+58
-2
lines changed

7 files changed

+58
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ build: generate fmt vet ## Build manager binary.
113113

114114
.PHONY: run
115115
run: manifests generate fmt vet ## Run a controller from your host.
116-
go run ./main.go --log-level debug
116+
go run ./main.go --enable-level-triggered true --log-level debug
117117

118118
.PHONY: docker-build
119119
docker-build: ## Build docker image with the manager.

api/v1alpha1/pipeline_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ type PipelineStatus struct {
137137
// +optional
138138
Conditions []metav1.Condition `json:"conditions,omitempty"`
139139

140+
// LatestRevision is the latest revision that's been promoted to the environments.
141+
// +optional
142+
LatestRevision string `json:"latestRevision,omitempty"`
143+
140144
// Environments holds environment statuses.
141145
// +optional
142146
Environments map[string]*EnvironmentStatus `json:"environments"`

charts/pipeline-controller/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ apiVersion: v2
22
name: pipeline-controller
33
description: Pipeline-controller Helm chart for Weave GitOps Enterprise
44
type: application
5-
version: "0.22.0"
5+
version: "0.23.0"
66
appVersion: "v0.0.31"

charts/pipeline-controller/crds/pipelines.weave.works_pipelines.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ spec:
432432
type: object
433433
description: Environments holds environment statuses.
434434
type: object
435+
latestRevision:
436+
description: LatestRevision is the latest revision that's been promoted
437+
to the environments.
438+
type: string
435439
observedGeneration:
436440
description: ObservedGeneration is the last observed generation.
437441
format: int64

config/crd/bases/pipelines.weave.works_pipelines.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ spec:
432432
type: object
433433
description: Environments holds environment statuses.
434434
type: object
435+
latestRevision:
436+
description: LatestRevision is the latest revision that's been promoted
437+
to the environments.
438+
type: string
435439
observedGeneration:
436440
description: ObservedGeneration is the last observed generation.
437441
format: int64

controllers/leveltriggered/controller.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ func (r *PipelineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
232232
return ctrl.Result{}, fmt.Errorf("error removing pending condition: %w", err)
233233
}
234234

235+
if err := r.setLatestRevision(ctx, pipeline, latestRevision); err != nil {
236+
return ctrl.Result{}, fmt.Errorf("error setting latest revision: %w", err)
237+
}
238+
235239
for _, env := range pipeline.Spec.Environments[1:] {
236240
// if all targets run the latest revision and are ready, we can skip this environment
237241
if checkAllTargetsRunRevision(pipeline.Status.Environments[env.Name], latestRevision) && checkAllTargetsAreReady(pipeline.Status.Environments[env.Name]) {
@@ -253,6 +257,24 @@ func (r *PipelineReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
253257
return ctrl.Result{}, nil
254258
}
255259

260+
func (r *PipelineReconciler) setLatestRevision(ctx context.Context, pipeline v1alpha1.Pipeline, revision string) error {
261+
pipeline.Status.LatestRevision = revision
262+
263+
fmt.Println("setting latest revision to", revision)
264+
if err := r.patchStatus(ctx, client.ObjectKeyFromObject(&pipeline), pipeline.Status); err != nil {
265+
r.emitEventf(
266+
&pipeline,
267+
corev1.EventTypeWarning,
268+
"SetStatus", "Failed to set LatestRevision status for pipeline %s/%s: %s",
269+
pipeline.GetNamespace(), pipeline.GetName(),
270+
err,
271+
)
272+
return err
273+
}
274+
275+
return nil
276+
}
277+
256278
func (r *PipelineReconciler) setPendingCondition(ctx context.Context, pipeline v1alpha1.Pipeline, reason, message string) error {
257279
condition := metav1.Condition{
258280
Type: conditions.PromotionPendingCondition,

controllers/leveltriggered/controller_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,28 @@ func TestReconcile(t *testing.T) {
122122
g.Expect(targetStatus.Revision).To(Equal(appRevision))
123123
})
124124

125+
t.Run("sets the lastestRevision status field", func(t *testing.T) {
126+
g := testingutils.NewGomegaWithT(t)
127+
name := "pipeline-" + rand.String(5)
128+
ns := testingutils.NewNamespace(ctx, g, k8sClient)
129+
t.Cleanup(deleteObjectCleanup(ctx, g, ns))
130+
131+
const appRevision = "v1.0.1"
132+
133+
hr := createApp(ctx, k8sClient, g, name, ns.Name)
134+
setAppRevisionAndReadyStatus(ctx, g, hr, appRevision)
135+
136+
pipeline := newPipeline(name, ns.Name, nil)
137+
g.Expect(k8sClient.Create(ctx, pipeline)).To(Succeed())
138+
139+
checkCondition(ctx, g, client.ObjectKeyFromObject(pipeline), meta.ReadyCondition, metav1.ConditionTrue, v1alpha1.ReconciliationSucceededReason)
140+
141+
g.Eventually(func() string {
142+
p := getPipeline(ctx, g, client.ObjectKeyFromObject(pipeline))
143+
return p.Status.LatestRevision
144+
}, "5s", "0.2s").Should(Equal(appRevision))
145+
})
146+
125147
t.Run("promotes revision to all environments", func(t *testing.T) {
126148
g := testingutils.NewGomegaWithT(t)
127149
mockStrategy := setStrategyRegistry(t, pipelineReconciler)

0 commit comments

Comments
 (0)