Skip to content

Commit

Permalink
Simplify CaptureResource function
Browse files Browse the repository at this point in the history
The function now only takes Deployments into account.
  • Loading branch information
Roberto Bruggemann committed Jan 4, 2018
1 parent cf6e0ff commit 9f42e1c
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions probe/kubernetes/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,21 @@ func (r *Reporter) CapturePod(f func(xfer.Request, string, string) xfer.Response
func (r *Reporter) CaptureResource(f func(xfer.Request, string, string, string) xfer.Response) func(xfer.Request) xfer.Response {
return func(req xfer.Request) xfer.Response {
var resource, uid string
for _, parser := range []struct {
res string
f func(string) (string, bool)
}{
{report.Deployment, report.ParseDeploymentNodeID},
} {
if u, ok := parser.f(req.NodeID); ok {
resource, uid = parser.res, u
break
}
if u, ok := report.ParseDeploymentNodeID(req.NodeID); ok {
resource, uid = report.Deployment, u
}
if resource == "" {
return xfer.ResponseErrorf("Invalid ID: %s", req.NodeID)
}

switch resource {
case report.Deployment:
var deployment Deployment
r.client.WalkDeployments(func(d Deployment) error {
if d.UID() == uid {
deployment = d
}
return nil
})
if deployment != nil {
return f(req, "deployment", deployment.Namespace(), deployment.Name())
var deployment Deployment
r.client.WalkDeployments(func(d Deployment) error {
if d.UID() == uid {
deployment = d
}
return nil
})
if deployment != nil {
return f(req, "deployment", deployment.Namespace(), deployment.Name())
}
return xfer.ResponseErrorf("%s not found: %s", resource, uid)
}
Expand Down

0 comments on commit 9f42e1c

Please sign in to comment.