Skip to content

Commit d232150

Browse files
support set chaos in config file (#11)
1 parent 799b00d commit d232150

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

handler.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
2828
}
2929

3030
if k.IsNameError(err) {
31+
if len(zone) == 0 {
32+
return plugin.NextOrFailure(k.Name(), k.Next, ctx, w, r)
33+
}
34+
3135
if k.Fall.Through(state.Name()) {
3236
return plugin.NextOrFailure(k.Name(), k.Next, ctx, w, r)
3337
}

kubernetes.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,25 @@ func (k *Kubernetes) InitKubeCache(ctx context.Context) (err error) {
278278
k.opts.endpointNameMode = k.endpointNameMode
279279
k.APIConn = newdnsController(ctx, kubeClient, k.opts)
280280

281+
// get IP for chaos Pod
282+
for _, pods := range k.podMap {
283+
for name := range pods {
284+
podInfo := pods[name]
285+
pod, err := k.getPodFromCluster(podInfo.Namespace, podInfo.Name)
286+
if err != nil {
287+
return err
288+
}
289+
podInfo.IP = pod.Status.PodIP
290+
podInfo.LastUpdateTime = time.Now()
291+
k.ipPodMap[pod.Status.PodIP] = podInfo
292+
}
293+
}
294+
281295
return err
282296
}
283297

284298
// Records looks up services in kubernetes.
285299
func (k *Kubernetes) Records(ctx context.Context, state request.Request, exact bool) ([]msg.Service, error) {
286-
log.Infof("k8s Records, sourceIP: %s", state.IP())
287300
r, e := parseRequest(state.Name(), state.Zone)
288301
if e != nil {
289302
return nil, e

setup.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,34 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
288288
}
289289
k8s.grpcPort = port
290290
}
291+
case "chaos":
292+
/*
293+
the sample config:
294+
chaos error outer busybox.busybox-0 busybox.busybox-1
295+
chaos random inner busybox.busybox-2 busybox.busybox-3
296+
*/
297+
args := c.RemainingArgs()
298+
if len(args) >= 3 {
299+
for i := 2; i < len(args); i++ {
300+
items := strings.SplitN(args[i], ".", 2)
301+
if len(items) != 2 {
302+
return nil, c.ArgErr()
303+
}
304+
305+
if _, ok := k8s.podMap[items[0]]; !ok {
306+
k8s.podMap[items[0]] = make(map[string]*PodInfo)
307+
}
308+
k8s.podMap[items[0]][items[1]] = &PodInfo{
309+
Namespace: items[0],
310+
Name: items[1],
311+
Action: args[0],
312+
Scope: args[1],
313+
}
314+
}
315+
} else {
316+
return nil, c.ArgErr()
317+
}
318+
291319
default:
292320
return nil, c.Errf("unknown property '%s'", c.Val())
293321
}

0 commit comments

Comments
 (0)