Skip to content

Commit

Permalink
raft updates and many other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bubbajoe committed Jun 8, 2024
1 parent ea3e447 commit 7be75b7
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 36 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/discord.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
release:
types: [published]

jobs:
github-releases-to-discord:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Github Releases To Discord
uses: SethCohen/[email protected]
with:
webhook_url: ${{ secrets.DISCORD_WEBHOOK_URL }}
color: "2105893"
username: "Release Changelog"
avatar_url: "https://github.com/dgate-io.png"
content: "||@everyone||"
footer_title: "Changelog"
footer_icon_url: "https://cdn.discordapp.com/avatars/487431320314576937/bd64361e4ba6313d561d54e78c9e7171.png"
footer_timestamp: true
2 changes: 1 addition & 1 deletion functional-tests/raft_tests/raft_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dgate-cli -f domain create name=dm-$id \

dgate-cli -f service create \
name=svc-$id namespace=ns-$id \
urls="http://localhost:8888/$RANDOM"
urls="http://localhost:8081/$RANDOM"

dgate-cli -f route create \
name=rt-$id \
Expand Down
2 changes: 1 addition & 1 deletion functional-tests/raft_tests/test1.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: v1
debug: true
log_level: info
log_level: debug

tags:
- "dev"
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ require (
github.com/dop251/goja v0.0.0-20240220182346-e401ed450204
github.com/dop251/goja_nodejs v0.0.0-20231122114759-e84d9a924c5c
github.com/google/uuid v1.3.1
github.com/hashicorp/go-hclog v1.6.2
github.com/hashicorp/raft v1.6.0
github.com/hashicorp/go-hclog v1.6.3
github.com/hashicorp/raft v1.7.0
github.com/knadh/koanf/parsers/json v0.1.0
github.com/knadh/koanf/parsers/toml v0.1.0
github.com/knadh/koanf/parsers/yaml v0.1.0
Expand Down Expand Up @@ -46,7 +46,7 @@ require (
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/dop251/base64dec v0.0.0-20231022112746-c6c9f9a96217 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand All @@ -59,12 +59,12 @@ require (
github.com/google/flatbuffers v1.12.1 // indirect
github.com/google/pprof v0.0.0-20230926050212-f7f687d19a98 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-msgpack/v2 v2.1.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/go-msgpack/v2 v2.1.2 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
Expand All @@ -82,7 +82,7 @@ require (
go.opentelemetry.io/otel/trace v1.26.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
Expand Down Expand Up @@ -125,19 +127,27 @@ github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v1.6.2 h1:NOtoftovWkDheyUM/8JW3QMiXyxJK3uHRK7wV04nD2I=
github.com/hashicorp/go-hclog v1.6.2/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc=
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-msgpack/v2 v2.1.1 h1:xQEY9yB2wnHitoSzk/B9UjXWRQ67QKu5AOm8aFp8N3I=
github.com/hashicorp/go-msgpack/v2 v2.1.1/go.mod h1:upybraOAblm4S7rx0+jeNy+CWWhzywQsSRV5033mMu4=
github.com/hashicorp/go-msgpack/v2 v2.1.2 h1:4Ee8FTp834e+ewB71RDrQ0VKpyFdrKOjvYtnQ/ltVj0=
github.com/hashicorp/go-msgpack/v2 v2.1.2/go.mod h1:upybraOAblm4S7rx0+jeNy+CWWhzywQsSRV5033mMu4=
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/raft v1.6.0 h1:tkIAORZy2GbJ2Trp5eUSggLXDPOJLXC+JJLNMMqtgtM=
github.com/hashicorp/raft v1.6.0/go.mod h1:Xil5pDgeGwRWuX4uPUmwa+7Vagg4N804dz6mhNi6S7o=
github.com/hashicorp/raft v1.7.0 h1:4u24Qn6lQ6uwziM++UgsyiT64Q8GyRn43CV41qPiz1o=
github.com/hashicorp/raft v1.7.0/go.mod h1:N1sKh6Vn47mrWvEArQgILTyng8GoDRNYlgKyK7PMjs0=
github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand Down Expand Up @@ -182,6 +192,8 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
Expand Down Expand Up @@ -343,6 +355,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
Expand Down
2 changes: 1 addition & 1 deletion internal/admin/changestate/change_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type ChangeState interface {
// Change state
ApplyChangeLog(cl *spec.ChangeLog) error
ProcessChangeLog(*spec.ChangeLog, bool) error
ProcessChangeLog(cl *spec.ChangeLog, reload bool) error
WaitForChanges() error
ReloadState(bool, ...*spec.ChangeLog) error
ChangeHash() uint32
Expand Down
17 changes: 11 additions & 6 deletions internal/proxy/change_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
)

// processChangeLog - processes a change log and applies the change to the proxy state
func (ps *ProxyState) processChangeLog(cl *spec.ChangeLog, reload, store bool) (err error) {
func (ps *ProxyState) processChangeLog(cl *spec.ChangeLog, reload, store bool) error {
if cl == nil {
cl = &spec.ChangeLog{
Cmd: spec.NoopCommand,
}
} else if !cl.Cmd.IsNoop() {
var err error
switch cl.Cmd.Resource() {
case spec.Namespaces:
var item spec.Namespace
Expand Down Expand Up @@ -82,16 +83,16 @@ func (ps *ProxyState) processChangeLog(cl *spec.ChangeLog, reload, store bool) (
}
if err != nil {
ps.logger.Error("error processing change log", zap.Error(err))
return
return err

Check warning on line 86 in internal/proxy/change_log.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/change_log.go#L85-L86

Added lines #L85 - L86 were not covered by tests
}
}
if reload {
if cl.Cmd.IsNoop() || cl.Cmd.Resource().IsRelatedTo(spec.Routes) {
ps.logger.Debug("Registering change log", zap.Stringer("cmd", cl.Cmd))
err = ps.reconfigureState(false, cl)
err := ps.reconfigureState(false, cl)

Check warning on line 92 in internal/proxy/change_log.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/change_log.go#L92

Added line #L92 was not covered by tests
if err != nil {
ps.logger.Error("Error registering change log", zap.Error(err))
return
return err

Check warning on line 95 in internal/proxy/change_log.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/change_log.go#L95

Added line #L95 was not covered by tests
}
// update change log hash only when the change is successfully applied
// even if the change is a noop, we still need to update the hash
Expand All @@ -105,11 +106,15 @@ func (ps *ProxyState) processChangeLog(cl *spec.ChangeLog, reload, store bool) (
}
}
if store {
if err = ps.store.StoreChangeLog(cl); err != nil {
if cl.Cmd.IsNoop() {
ps.logger.Debug("Noop change log, skipping storage")
return nil

Check warning on line 111 in internal/proxy/change_log.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/change_log.go#L110-L111

Added lines #L110 - L111 were not covered by tests
}
if err := ps.store.StoreChangeLog(cl); err != nil {
// TODO: find a way to revert the change and reload the state
// TODO: OR add flag in config to ignore storage errors
ps.logger.Error("Error storing change log", zap.Error(err))
return
return err

Check warning on line 117 in internal/proxy/change_log.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/change_log.go#L117

Added line #L117 was not covered by tests
}
}

Expand Down
8 changes: 7 additions & 1 deletion internal/proxy/proxy_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func handleServiceProxy(ps *ProxyState, reqCtx *RequestContext, modExt ModuleExt
}).
ErrorHandler(func(w http.ResponseWriter, r *http.Request, reqErr error) {
upstreamErr = reqErr
ps.logger.Debug("Error proxying request",
ps.logger.Error("Error proxying request",
zap.String("error", reqErr.Error()),
zap.String("route", reqCtx.route.Name),
zap.String("service", reqCtx.route.Service.Name),
Expand Down Expand Up @@ -197,6 +197,12 @@ func handleServiceProxy(ps *ProxyState, reqCtx *RequestContext, modExt ModuleExt
}
}
if !reqCtx.rw.HeadersSent() && reqCtx.rw.BytesWritten() == 0 {
ps.logger.Error("Writing error response",
zap.String("error", reqErr.Error()),
zap.String("route", reqCtx.route.Name),
zap.String("service", reqCtx.route.Service.Name),
zap.String("namespace", reqCtx.route.Namespace.Name),
)
util.WriteStatusCodeError(reqCtx.rw, http.StatusInternalServerError)
}
})
Expand Down
67 changes: 48 additions & 19 deletions internal/proxy/proxy_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,28 +205,52 @@ func (ps *ProxyState) WaitForChanges() error {
}

func (ps *ProxyState) ApplyChangeLog(log *spec.ChangeLog) error {
ps.logger.Debug("applying change log",
zap.Bool("replication", ps.replicationEnabled),
)

Check warning on line 210 in internal/proxy/proxy_state.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/proxy_state.go#L208-L210

Added lines #L208 - L210 were not covered by tests
if ps.replicationEnabled {
if log.Cmd.IsNoop() {
return ps.processChangeLog(log, true, false)
}
r := ps.replicationSettings.raft
r := ps.Raft()

Check warning on line 212 in internal/proxy/proxy_state.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/proxy_state.go#L212

Added line #L212 was not covered by tests
if r.State() != raft.Leader {
return raft.ErrNotLeader
}
encodedCL, err := json.Marshal(log)
if err != nil {
if ecl, err := json.Marshal(log); err != nil {

Check warning on line 216 in internal/proxy/proxy_state.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/proxy_state.go#L216

Added line #L216 was not covered by tests
return err
} else {
restartCallback := func(err error) {
if err != nil {
ps.logger.Error("Error restarting state", zap.Error(err))
go ps.Stop()
} else {
ps.logger.Info("State successfully restarted")

Check warning on line 224 in internal/proxy/proxy_state.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/proxy_state.go#L218-L224

Added lines #L218 - L224 were not covered by tests
}
}
raftLog := raft.Log{Data: ecl}
future := r.ApplyLog(raftLog, time.Second*15)
if err := future.Error(); err != nil {
ps.restartState(restartCallback)
return err

Check warning on line 231 in internal/proxy/proxy_state.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/proxy_state.go#L227-L231

Added lines #L227 - L231 were not covered by tests
}
resp := future.Response()
if resp != nil {
ps.restartState(restartCallback)
switch val := resp.(type) {
case error:
return val
default:
ps.logger.Error("unexpected response from raft",
zap.Any("response", val),
)
return errors.New("unexpected response from raft")

Check warning on line 243 in internal/proxy/proxy_state.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/proxy_state.go#L233-L243

Added lines #L233 - L243 were not covered by tests
}
}
ps.logger.With().
Info("waiting for reply from raft",
zap.String("id", log.ID),
zap.Stringer("command", log.Cmd),
zap.Error(err),
)
return nil

Check warning on line 252 in internal/proxy/proxy_state.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/proxy_state.go#L246-L252

Added lines #L246 - L252 were not covered by tests
}
raftLog := raft.Log{
Data: encodedCL,
}
future := r.ApplyLog(raftLog, time.Second*15)
ps.logger.With().
Debug("waiting for reply from raft",
zap.String("id", log.ID),
zap.Stringer("command", log.Cmd),
)
return future.Error()
} else {
return ps.processChangeLog(log, true, true)
}
Expand Down Expand Up @@ -291,7 +315,7 @@ func (ps *ProxyState) ReloadState(check bool, logs ...*spec.ChangeLog) error {
}
}
if reload {
return ps.processChangeLog(nil, true, true)
return ps.processChangeLog(nil, true, false)

Check warning on line 318 in internal/proxy/proxy_state.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/proxy_state.go#L318

Added line #L318 was not covered by tests
}
return nil
}
Expand All @@ -300,8 +324,9 @@ func (ps *ProxyState) ProcessChangeLog(log *spec.ChangeLog, reload bool) error {
err := ps.processChangeLog(log, reload, !ps.replicationEnabled)
if err != nil {
ps.logger.Error("processing error", zap.Error(err))
return err

Check warning on line 327 in internal/proxy/proxy_state.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/proxy_state.go#L327

Added line #L327 was not covered by tests
}
return err
return nil
}

func (ps *ProxyState) DynamicTLSConfig(certFile, keyFile string) *tls.Config {
Expand Down Expand Up @@ -399,7 +424,11 @@ func (ps *ProxyState) initConfigResources(resources *config.DGateResources) erro
return err
}
if numChanges > 0 {
defer ps.processChangeLog(nil, false, false)
defer func() {
if err != nil {
err = ps.processChangeLog(nil, false, false)

Check warning on line 429 in internal/proxy/proxy_state.go

View check run for this annotation

Codecov / codecov/patch

internal/proxy/proxy_state.go#L429

Added line #L429 was not covered by tests
}
}()
}
ps.logger.Info("Initializing resources")
for _, ns := range resources.Namespaces {
Expand Down
13 changes: 13 additions & 0 deletions pkg/spec/change_log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package spec

import (
"encoding/json"
"strconv"
"strings"
"time"
Expand All @@ -16,6 +17,14 @@ type ChangeLog struct {
errChan chan error
}

func NewNoopChangeLog() *ChangeLog {
return &ChangeLog{
Version: 1,
ID: strconv.FormatInt(time.Now().UnixNano(), 36),
Cmd: NoopCommand,

Check warning on line 24 in pkg/spec/change_log.go

View check run for this annotation

Codecov / codecov/patch

pkg/spec/change_log.go#L20-L24

Added lines #L20 - L24 were not covered by tests
}
}

func NewChangeLog(item Named, namespace string, cmd Command) *ChangeLog {
if item == nil {
panic("item cannot be nil")
Expand Down Expand Up @@ -49,6 +58,10 @@ func (cl *ChangeLog) PushError(err error) {
}
}

func (cl *ChangeLog) JSONBytes() ([]byte, error) {
return json.Marshal(cl)

Check warning on line 62 in pkg/spec/change_log.go

View check run for this annotation

Codecov / codecov/patch

pkg/spec/change_log.go#L61-L62

Added lines #L61 - L62 were not covered by tests
}

type Command string

type Action string
Expand Down

0 comments on commit 7be75b7

Please sign in to comment.