Skip to content

Commit

Permalink
Merge pull request #272 from prameshj/nodecache-followup
Browse files Browse the repository at this point in the history
Follow up changes to node-cache PR
  • Loading branch information
k8s-ci-robot authored Nov 8, 2018
2 parents 06d95eb + 2623e1a commit abffff0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
9 changes: 4 additions & 5 deletions Dockerfile.node-cache
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
# limitations under the License.

FROM debian:stable-slim

MAINTAINER Pavithra Ramesh <[email protected]>

RUN apt-get update
RUN apt-get -y install iproute2 iptables
RUN apt-get update && apt-get install -y \
iproute2 \
iptables \
&& rm -rf /var/lib/apt/lists/*
ADD bin/ARG_ARCH/ARG_BIN /ARG_BIN
EXPOSE 53 53/udp
EXPOSE 53 53/tcp
Expand Down
1 change: 1 addition & 0 deletions cmd/node-cache/Corefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
cache 30
reload
loop
log
bind 1.2.3.4
forward . 8.8.8.8 {
force_tcp
Expand Down
56 changes: 27 additions & 29 deletions cmd/node-cache/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,48 +173,46 @@ func (c *cacheApp) parseAndValidateFlags() error {
return nil
}

func (c *cacheApp) Run() {
func (c *cacheApp) run() {
c.params.exitChan = make(chan bool, 1)
go func(ch chan bool) {
tick := time.NewTicker(c.params.interval * time.Second)
for {
select {
case <-tick.C:
for _, rule := range c.iptablesRules {
exists, err := c.iptables.EnsureRule(utiliptables.Prepend, rule.table, rule.chain, rule.args...)
if !exists {
if err != nil {
cache.teardownNetworking()
clog.Fatalf("Failed to add back non-existent rule %v", rule)
}
clog.Infof("Added back nonexistent rule - %v", rule)
}
if err != nil {
clog.Errorf("Failed to check rule %v - %s", rule, err)
}
}

exists, err := c.netifHandle.EnsureDummyDevice(c.params.intfName)
tick := time.NewTicker(c.params.interval * time.Second)
for {
select {
case <-tick.C:
for _, rule := range c.iptablesRules {
exists, err := c.iptables.EnsureRule(utiliptables.Prepend, rule.table, rule.chain, rule.args...)
if !exists {
if err != nil {
cache.teardownNetworking()
clog.Fatalf("Failed to add back non-existent interface %s", c.params.intfName)
clog.Fatalf("Failed to add back non-existent rule %v", rule)
}
clog.Infof("Added back nonexistent interface - %s", c.params.intfName)
clog.Infof("Added back nonexistent rule - %v", rule)
}
if err != nil {
clog.Errorf("Failed to check dummy device %s - %s", c.params.intfName, err)
clog.Errorf("Failed to check rule %v - %s", rule, err)
}
case <-ch:
clog.Warningf("Exiting iptables check goroutine")
return
}

exists, err := c.netifHandle.EnsureDummyDevice(c.params.intfName)
if !exists {
if err != nil {
cache.teardownNetworking()
clog.Fatalf("Failed to add back non-existent interface %s", c.params.intfName)
}
clog.Infof("Added back nonexistent interface - %s", c.params.intfName)
}
if err != nil {
clog.Errorf("Failed to check dummy device %s - %s", c.params.intfName, err)
}
case <-c.params.exitChan:
clog.Warningf("Exiting iptables check goroutine")
return
}
}(c.params.exitChan)
}
}

func main() {
cache.Run()
go cache.run()
coremain.Run()
// Unlikely to reach here, if we did it is because coremain exited and the signal was not trapped.
clog.Errorf("Untrapped signal, tearing down")
Expand Down

0 comments on commit abffff0

Please sign in to comment.