diff options
author | 2021-11-12 08:22:34 -0800 | |
---|---|---|
committer | 2021-11-12 11:22:34 -0500 | |
commit | 2e6953c7dbd1d6b359911e1ce92e2567df07ca8c (patch) | |
tree | d91514ca867bb5b000bec3ea219e6a2ab0a0c244 /plugin/forwardcrd/fakes_test.go | |
parent | 6953ab2b4f23f916a08b68ba51b9a26e41e9a748 (diff) | |
download | coredns-2e6953c7dbd1d6b359911e1ce92e2567df07ca8c.tar.gz coredns-2e6953c7dbd1d6b359911e1ce92e2567df07ca8c.tar.zst coredns-2e6953c7dbd1d6b359911e1ce92e2567df07ca8c.zip |
Initial implementation of ForwardCRD plugin (#4512)
* Add forwardcrd plugin README.md
Co-authored-by: Aidan Obley <aobley@vmware.com>
Signed-off-by: Christian Ang <angc@vmware.com>
* Create forwardcrd plugin
- Place forwardcrd before forward plugin in plugin list. This will avoid
forward from preventing the forwardcrd plugin from handling any queries
in the case of having a default upstream forwarder in a server block (as
is the case in the default kubernetes Corefile).
Co-authored-by: Aidan Obley <aobley@vmware.com>
Signed-off-by: Christian Ang <angc@vmware.com>
* Add Forward CRD
Signed-off-by: Christian Ang <angc@vmware.com>
* Add NewWithConfig to forward plugin
- allows external packages to instanciate forward plugins
Co-authored-by: Aidan Obley <aobley@vmware.com>
Signed-off-by: Christian Ang <angc@vmware.com>
* ForwardCRD plugin handles requests for Forward CRs
- add a Kubernetes controller that can read Forward CRs
- instances of the forward plugin are created based on Forward CRs from
the Kubernetes controller
- DNS requests are handled by calling matching Forward plugin instances
based on zone name
- Defaults to the kube-system namespace to align with Corefile RBAC
Signed-off-by: Christian Ang <angc@vmware.com>
Use klog v2 in forwardcrd plugin
* Refactor forward setup to use NewWithConfig
Co-authored-by: Christian Ang <angc@vmware.com>
Signed-off-by: Edwin Xie <exie@vmware.com>
* Use ParseInt instead of Atoi
- to ensure that the bitsize is 32 for later casting to uint32
Signed-off-by: Christian Ang <angc@vmware.com>
* Add @christianang to CODEOWNERS for forwardcrd
Signed-off-by: Christian Ang <angc@vmware.com>
Co-authored-by: Edwin Xie <exie@vmware.com>
Diffstat (limited to 'plugin/forwardcrd/fakes_test.go')
-rw-r--r-- | plugin/forwardcrd/fakes_test.go | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/plugin/forwardcrd/fakes_test.go b/plugin/forwardcrd/fakes_test.go new file mode 100644 index 000000000..9b6cb0bcf --- /dev/null +++ b/plugin/forwardcrd/fakes_test.go @@ -0,0 +1,86 @@ +package forwardcrd + +import ( + "context" + "sync" + + "github.com/coredns/coredns/plugin/forward" + + "github.com/miekg/dns" +) + +type TestPluginHandler struct { + mutex sync.Mutex + ReceivedConfig forward.ForwardConfig + onStartupCallCount int + onShutdownCallCount int +} + +func (t *TestPluginHandler) ServeDNS(context.Context, dns.ResponseWriter, *dns.Msg) (int, error) { + return 0, nil +} + +func (t *TestPluginHandler) Name() string { return "" } + +func (t *TestPluginHandler) OnStartup() error { + t.mutex.Lock() + defer t.mutex.Unlock() + t.onStartupCallCount++ + return nil +} + +func (t *TestPluginHandler) OnShutdown() error { + t.mutex.Lock() + defer t.mutex.Unlock() + t.onShutdownCallCount++ + return nil +} + +func (t *TestPluginHandler) OnStartupCallCount() int { + t.mutex.Lock() + defer t.mutex.Unlock() + return t.onStartupCallCount +} + +func (t *TestPluginHandler) OnShutdownCallCount() int { + t.mutex.Lock() + defer t.mutex.Unlock() + return t.onShutdownCallCount +} + +type TestPluginInstancer struct { + mutex sync.Mutex + testPluginHandlers []*TestPluginHandler +} + +func (t *TestPluginInstancer) NewWithConfig(config forward.ForwardConfig) (lifecyclePluginHandler, error) { + t.mutex.Lock() + defer t.mutex.Unlock() + + testPluginHandler := &TestPluginHandler{ + ReceivedConfig: config, + } + t.testPluginHandlers = append(t.testPluginHandlers, testPluginHandler) + return testPluginHandler, nil +} + +func (t *TestPluginInstancer) NewWithConfigArgsForCall(index int) *TestPluginHandler { + t.mutex.Lock() + defer t.mutex.Unlock() + + return t.testPluginHandlers[index] +} + +func (t *TestPluginInstancer) NewWithConfigCallCount() int { + t.mutex.Lock() + defer t.mutex.Unlock() + + return len(t.testPluginHandlers) +} + +type TestController struct { +} + +func (t *TestController) Run(threads int) {} +func (t *TestController) HasSynced() bool { return true } +func (t *TestController) Stop() error { return nil } |