From dddd5b2e430baab4ca9f8a3340ca0a6aa35bd2a9 Mon Sep 17 00:00:00 2001 From: bakito Date: Sat, 23 Jul 2022 11:05:11 +0200 Subject: [PATCH] evaluate equality on clone - do not sort original - fixes #84 --- Makefile | 11 ++++++- pkg/types/deepcopy_generated.go | 51 +++++++++++++++++++++++++++++++++ pkg/types/dns.go | 11 ++++--- 3 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 pkg/types/deepcopy_generated.go diff --git a/Makefile b/Makefile index 4ec943a..fe5a925 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -35,6 +39,11 @@ ifeq (, $(shell which mockgen)) $(shell go install github.com/golang/mock/mockgen@v1.6.0) 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 diff --git a/pkg/types/deepcopy_generated.go b/pkg/types/deepcopy_generated.go new file mode 100644 index 0000000..06a8f27 --- /dev/null +++ b/pkg/types/deepcopy_generated.go @@ -0,0 +1,51 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package types + +import ( + net "net" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DNSConfig) DeepCopyInto(out *DNSConfig) { + *out = *in + if in.Upstreams != nil { + in, out := &in.Upstreams, &out.Upstreams + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Bootstraps != nil { + in, out := &in.Bootstraps, &out.Bootstraps + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.BlockingIPv4 != nil { + in, out := &in.BlockingIPv4, &out.BlockingIPv4 + *out = make(net.IP, len(*in)) + copy(*out, *in) + } + if in.BlockingIPv6 != nil { + in, out := &in.BlockingIPv6, &out.BlockingIPv6 + *out = make(net.IP, len(*in)) + copy(*out, *in) + } + if in.LocalPTRUpstreams != nil { + in, out := &in.LocalPTRUpstreams, &out.LocalPTRUpstreams + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DNSConfig. +func (in *DNSConfig) DeepCopy() *DNSConfig { + if in == nil { + return nil + } + out := new(DNSConfig) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/types/dns.go b/pkg/types/dns.go index 443b970..29422e8 100644 --- a/pkg/types/dns.go +++ b/pkg/types/dns.go @@ -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"` @@ -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) }