Skip to content

Commit

Permalink
Rename CaptureResource -> CaptureDeployment
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 8, 2018
1 parent cf6e0ff commit b14cb95
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions probe/kubernetes/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,39 +74,24 @@ func (r *Reporter) CapturePod(f func(xfer.Request, string, string) xfer.Response
}
}

// CaptureResource is exported for testing
func (r *Reporter) CaptureResource(f func(xfer.Request, string, string, string) xfer.Response) func(xfer.Request) xfer.Response {
// CaptureDeployment is exported for testing
func (r *Reporter) CaptureDeployment(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 resource == "" {
uid, ok := report.ParseDeploymentNodeID(req.NodeID)
if !ok {
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 xfer.ResponseErrorf("Deployment not found: %s", uid)
}
return xfer.ResponseErrorf("%s not found: %s", resource, uid)
return f(req, "deployment", deployment.Namespace(), deployment.Name())
}
}

Expand All @@ -124,8 +109,8 @@ func (r *Reporter) registerControls() {
controls := map[string]xfer.ControlHandlerFunc{
GetLogs: r.CapturePod(r.GetLogs),
DeletePod: r.CapturePod(r.deletePod),
ScaleUp: r.CaptureResource(r.ScaleUp),
ScaleDown: r.CaptureResource(r.ScaleDown),
ScaleUp: r.CaptureDeployment(r.ScaleUp),
ScaleDown: r.CaptureDeployment(r.ScaleDown),
}
r.handlerRegistry.Batch(nil, controls)
}
Expand Down

0 comments on commit b14cb95

Please sign in to comment.