Skip to content

Commit

Permalink
evaluate equality on clone - do not sort original - fixes #84
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Jul 23, 2022
1 parent ff8e2d6 commit dddd5b2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ fmt:
tidy:
go mod tidy

generate: deepcopy-gen
touch ./tmp/deepcopy-gen-boilerplate.go.txt
deepcopy-gen -h ./tmp/deepcopy-gen-boilerplate.go.txt -i ./pkg/types

# Run tests
test: test-ci fmt
test: generate test-ci fmt

# Run ci tests
test-ci: mocks tidy
Expand Down Expand Up @@ -35,6 +39,11 @@ ifeq (, $(shell which mockgen))
$(shell go install github.com/golang/mock/[email protected])
endif

deepcopy-gen:
ifeq (, $(shell which deepcopy-gen))
$(shell go install k8s.io/code-generator/cmd/deepcopy-gen@latest)
endif

start-replica:
podman run --pull always --rm -it -p 9090:80 -p 9091:3000 adguard/adguardhome

Expand Down
51 changes: 51 additions & 0 deletions pkg/types/deepcopy_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions pkg/types/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

// DNSConfig dns config
// +k8s:deepcopy-gen=true
type DNSConfig struct {
Upstreams []string `json:"upstream_dns,omitempty"`
UpstreamsFile string `json:"upstream_dns_file"`
Expand All @@ -31,11 +32,13 @@ type DNSConfig struct {

// Equals dns config equal check
func (c *DNSConfig) Equals(o *DNSConfig) bool {
c.Sort()
o.Sort()
cc := c.DeepCopy()
oo := o.DeepCopy()
cc.Sort()
oo.Sort()

a, _ := json.Marshal(c)
b, _ := json.Marshal(o)
a, _ := json.Marshal(cc)
b, _ := json.Marshal(oo)
return string(a) == string(b)
}

Expand Down

0 comments on commit dddd5b2

Please sign in to comment.