Skip to content

Commit 4b9127a

Browse files
authoredMar 4, 2025··
feat(harness): add dry run support to harness and drop outputs when stack run is in dry run mode (#380)
1 parent f5e179d commit 4b9127a

File tree

4 files changed

+39
-28
lines changed

4 files changed

+39
-28
lines changed
 

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ require (
3535
github.com/opencost/opencost/core v0.0.0-20241216191657-30e5d9a27f41
3636
github.com/orcaman/concurrent-map/v2 v2.0.1
3737
github.com/pkg/errors v0.9.1
38-
github.com/pluralsh/console/go/client v1.31.0
38+
github.com/pluralsh/console/go/client v1.32.0
3939
github.com/pluralsh/controller-reconcile-helper v0.1.0
4040
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34
4141
github.com/pluralsh/polly v0.1.10

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1736,8 +1736,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
17361736
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
17371737
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo=
17381738
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
1739-
github.com/pluralsh/console/go/client v1.31.0 h1:rmuPcJdJQetg5c0n7rv1cyd0l107vsGqEKBrt2oatKw=
1740-
github.com/pluralsh/console/go/client v1.31.0/go.mod h1:ZDRhjfDzbFLrHCfP3k6SaLlTDcjALCL8KIKQCYIHSJM=
1739+
github.com/pluralsh/console/go/client v1.32.0 h1:V/VoiohHmhdwmPxQBDoF167yoau8jGWV+sxXV90dCgk=
1740+
github.com/pluralsh/console/go/client v1.32.0/go.mod h1:ZDRhjfDzbFLrHCfP3k6SaLlTDcjALCL8KIKQCYIHSJM=
17411741
github.com/pluralsh/controller-reconcile-helper v0.1.0 h1:BV3dYZFH5rn8ZvZjtpkACSv/GmLEtRftNQj/Y4ddHEo=
17421742
github.com/pluralsh/controller-reconcile-helper v0.1.0/go.mod h1:RxAbvSB4/jkvx616krCdNQXPbpGJXW3J1L3rASxeFOA=
17431743
github.com/pluralsh/gophoenix v0.1.3-0.20231201014135-dff1b4309e34 h1:ab2PN+6if/Aq3/sJM0AVdy1SYuMAnq4g20VaKhTm/Bw=

‎pkg/harness/controller/controller.go

+19-15
Original file line numberDiff line numberDiff line change
@@ -150,30 +150,34 @@ func (in *stackRunController) completeStackRun(status gqlclient.StackStatus, sta
150150
var output []*gqlclient.StackOutputAttributes
151151
var err error
152152

153-
if in.tool != nil {
154-
state, err = in.tool.State()
155-
if err != nil {
156-
klog.ErrorS(err, "could not prepare state attributes")
157-
}
153+
serviceErrorAttributes := make([]*gqlclient.ServiceErrorAttributes, 0)
154+
if stackRunErr != nil {
155+
serviceErrorAttributes = append(serviceErrorAttributes, &gqlclient.ServiceErrorAttributes{
156+
Source: "harness",
157+
Message: stackRunErr.Error(),
158+
})
159+
}
158160

159-
klog.V(log.LogLevelTrace).InfoS("generated console state", "state", state)
161+
if in.tool == nil {
162+
return stackrun.CompleteStackRun(in.consoleClient, in.stackRunID, &gqlclient.StackRunAttributes{
163+
Errors: serviceErrorAttributes,
164+
})
165+
}
160166

167+
state, err = in.tool.State()
168+
if err != nil {
169+
klog.ErrorS(err, "could not prepare state attributes")
170+
}
171+
klog.V(log.LogLevelTrace).InfoS("generated console state", "state", state)
172+
173+
if !in.stackRun.DryRun {
161174
output, err = in.tool.Output()
162175
if err != nil {
163176
klog.ErrorS(err, "could not prepare output attributes")
164177
}
165-
166178
klog.V(log.LogLevelTrace).InfoS("generated console output", "output", output)
167179
}
168180

169-
serviceErrorAttributes := make([]*gqlclient.ServiceErrorAttributes, 0)
170-
if stackRunErr != nil {
171-
serviceErrorAttributes = append(serviceErrorAttributes, &gqlclient.ServiceErrorAttributes{
172-
Source: "harness",
173-
Message: stackRunErr.Error(),
174-
})
175-
}
176-
177181
return stackrun.CompleteStackRun(in.consoleClient, in.stackRunID, &gqlclient.StackRunAttributes{
178182
Errors: serviceErrorAttributes,
179183
Output: output,

‎pkg/harness/stackrun/v1/types.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@ import (
1111
)
1212

1313
type StackRun struct {
14-
ID string
14+
ID string
15+
Tarball string
16+
17+
ExecWorkDir *string
18+
ApprovedAt *string
19+
20+
Approval bool
21+
ManageState bool
22+
DryRun bool
23+
24+
Variables map[string]interface{}
25+
1526
Status gqlclient.StackStatus
1627
Type gqlclient.StackType
17-
Tarball string
18-
Steps []*gqlclient.RunStepFragment
19-
Files []*gqlclient.StackFileFragment
20-
Environment []*gqlclient.StackEnvironmentFragment
21-
ExecWorkDir *string
22-
Approval bool
23-
ApprovedAt *string
24-
ManageState bool
2528
Creds *gqlclient.StackRunBaseFragment_PluralCreds
2629
StateUrls *gqlclient.StackRunBaseFragment_StateUrls
27-
Variables map[string]interface{}
2830
PolicyEngine *gqlclient.PolicyEngineFragment
31+
32+
Steps []*gqlclient.RunStepFragment
33+
Files []*gqlclient.StackFileFragment
34+
Environment []*gqlclient.StackEnvironmentFragment
2935
}
3036

3137
func (in *StackRun) MaxSeverity() int {
@@ -53,6 +59,7 @@ func (in *StackRun) FromStackRunBaseFragment(fragment *gqlclient.StackRunBaseFra
5359
StateUrls: fragment.StateUrls,
5460
Variables: fragment.Variables,
5561
PolicyEngine: fragment.PolicyEngine,
62+
DryRun: fragment.DryRun,
5663
}
5764
}
5865

0 commit comments

Comments
 (0)
Please sign in to comment.