From 98191e2b07a618415dfa2604d060e059f25e8182 Mon Sep 17 00:00:00 2001 From: Lukasz Zajaczkowski Date: Wed, 29 May 2024 12:02:07 +0200 Subject: [PATCH] feat: set jobRef on stack run (#201) * set jobRef on stack run * fix linter --- go.mod | 2 +- go.sum | 6 ++---- pkg/controller/stacks/job.go | 11 +++++++++++ pkg/controller/stacks/reconciler_test.go | 3 +++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 17faa76b..ba8eaae9 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/open-policy-agent/gatekeeper/v3 v3.15.1 github.com/orcaman/concurrent-map/v2 v2.0.1 github.com/pkg/errors v0.9.1 - github.com/pluralsh/console-client-go v0.5.9 + github.com/pluralsh/console-client-go v0.5.10 github.com/pluralsh/controller-reconcile-helper v0.0.4 github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 github.com/pluralsh/polly v0.1.10 diff --git a/go.sum b/go.sum index 423b6859..3c2fe096 100644 --- a/go.sum +++ b/go.sum @@ -526,10 +526,8 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= -github.com/pluralsh/console-client-go v0.5.8 h1:Qm7vS+gCbmWqy5i4saLPc5/SUZaW6RCzxWF+uxyPA+Y= -github.com/pluralsh/console-client-go v0.5.8/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo= -github.com/pluralsh/console-client-go v0.5.9 h1:r5YMD4dU2zWiDApWtqu45l/02X4RnsNeVEFzuuyehEA= -github.com/pluralsh/console-client-go v0.5.9/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo= +github.com/pluralsh/console-client-go v0.5.10 h1:2BnzzJ6w8bkDX/k55GaRykPTVOy66k/vojfhBAof5G8= +github.com/pluralsh/console-client-go v0.5.10/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo= github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E= github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s= github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 h1:ab2PN+6if/Aq3/sJM0AVdy1SYuMAnq4g20VaKhTm/Bw= diff --git a/pkg/controller/stacks/job.go b/pkg/controller/stacks/job.go index 91b06257..ec03b264 100644 --- a/pkg/controller/stacks/job.go +++ b/pkg/controller/stacks/job.go @@ -64,6 +64,17 @@ func (r *StackReconciler) reconcileRunJob(ctx context.Context, run *console.Stac logger.Error(err, "unable to create job") return nil, err } + + if err := r.ConsoleClient.UpdateStackRun(run.ID, console.StackRunAttributes{ + Status: run.Status, + JobRef: &console.NamespacedName{ + Name: job.Name, + Namespace: job.Namespace, + }, + }); err != nil { + return nil, err + } + return job, nil } return foundJob, nil diff --git a/pkg/controller/stacks/reconciler_test.go b/pkg/controller/stacks/reconciler_test.go index 9ca7ace8..04b37ed0 100644 --- a/pkg/controller/stacks/reconciler_test.go +++ b/pkg/controller/stacks/reconciler_test.go @@ -115,6 +115,7 @@ var _ = Describe("Reconciler", Ordered, func() { fakeConsoleClient := mocks.NewClientMock(mocks.TestingT) fakeConsoleClient.On("GetStackRun", mock.Anything).Return(stackRun, nil) + fakeConsoleClient.On("UpdateStackRun", mock.Anything, mock.Anything).Return(nil) reconciler := stacks.NewStackReconciler(fakeConsoleClient, kClient, time.Minute, namespace, "", "") @@ -153,6 +154,7 @@ var _ = Describe("Reconciler", Ordered, func() { fakeConsoleClient := mocks.NewClientMock(mocks.TestingT) fakeConsoleClient.On("GetStackRun", mock.Anything).Return(stackRun, nil) + fakeConsoleClient.On("UpdateStackRun", mock.Anything, mock.Anything).Return(nil) reconciler := stacks.NewStackReconciler(fakeConsoleClient, kClient, time.Minute, namespace, "", "") @@ -208,6 +210,7 @@ var _ = Describe("Reconciler", Ordered, func() { fakeConsoleClient := mocks.NewClientMock(mocks.TestingT) fakeConsoleClient.On("GetStackRun", mock.Anything).Return(stackRun, nil) + fakeConsoleClient.On("UpdateStackRun", mock.Anything, mock.Anything).Return(nil) reconciler := stacks.NewStackReconciler(fakeConsoleClient, kClient, time.Minute, namespace, "", "")