-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add --imagePullSecret flag to support agent images in private registries * Add Ruby support Co-authored-by: Ashley Lowde <[email protected]>
- Loading branch information
Showing
17 changed files
with
229 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM golang:1.14-buster as agentbuild | ||
WORKDIR /go/src/github.com/VerizonMedia/kubectl-flame | ||
ADD . /go/src/github.com/VerizonMedia/kubectl-flame | ||
RUN go get -d -v ./... | ||
RUN cd agent && go build -o /go/bin/agent | ||
|
||
FROM rust:1.50 AS rbspybuild | ||
WORKDIR / | ||
RUN git clone https://github.com/rbspy/rbspy | ||
RUN cd rbspy && cargo build --release | ||
|
||
FROM bitnami/minideb:stretch | ||
RUN mkdir /app | ||
COPY --from=agentbuild /go/bin/agent /app/agent | ||
COPY --from=rbspybuild /rbspy/target/release/rbspy /app/rbspy | ||
|
||
CMD [ "/app/agent" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package profiler | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"os/exec" | ||
"strconv" | ||
|
||
"github.com/VerizonMedia/kubectl-flame/agent/details" | ||
"github.com/VerizonMedia/kubectl-flame/agent/utils" | ||
) | ||
|
||
const ( | ||
rbspyLocation = "/app/rbspy" | ||
rbspyOutputFileName = "/tmp/rbspy" | ||
) | ||
|
||
type RubyProfiler struct{} | ||
|
||
func (r *RubyProfiler) SetUp(job *details.ProfilingJob) error { | ||
return nil | ||
} | ||
|
||
func (r *RubyProfiler) Invoke(job *details.ProfilingJob) error { | ||
pid, err := utils.FindRootProcessId(job) | ||
if err != nil { | ||
return fmt.Errorf("could not find root process ID: %w", err) | ||
} | ||
|
||
duration := strconv.Itoa(int(job.Duration.Seconds())) | ||
cmd := exec.Command(rbspyLocation, "record", "--pid", pid, "--file", rbspyOutputFileName, "--duration", duration, "--format", "flamegraph") | ||
var out bytes.Buffer | ||
var stderr bytes.Buffer | ||
cmd.Stdout = &out | ||
cmd.Stderr = &stderr | ||
err = cmd.Run() | ||
if err != nil { | ||
return fmt.Errorf("could not launch profiler: %w", err) | ||
} | ||
|
||
return utils.PublishFlameGraph(rbspyOutputFileName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package job | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/VerizonMedia/kubectl-flame/cli/cmd/data" | ||
"github.com/VerizonMedia/kubectl-flame/cli/cmd/version" | ||
batchv1 "k8s.io/api/batch/v1" | ||
apiv1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/uuid" | ||
) | ||
|
||
type rubyCreator struct{} | ||
|
||
func (r *rubyCreator) create(targetPod *apiv1.Pod, cfg *data.FlameConfig) (string, *batchv1.Job, error) { | ||
id := string(uuid.NewUUID()) | ||
var imageName string | ||
var imagePullSecret []apiv1.LocalObjectReference | ||
args := []string{ | ||
id, | ||
string(targetPod.UID), | ||
cfg.TargetConfig.ContainerName, | ||
cfg.TargetConfig.ContainerId, | ||
cfg.TargetConfig.Duration.String(), | ||
string(cfg.TargetConfig.Language), | ||
cfg.TargetConfig.Pgrep, | ||
} | ||
|
||
if cfg.TargetConfig.Image != "" { | ||
imageName = cfg.TargetConfig.Image | ||
} else { | ||
imageName = fmt.Sprintf("%s:%s-ruby", baseImageName, version.GetCurrent()) | ||
} | ||
|
||
if cfg.TargetConfig.ImagePullSecret != "" { | ||
imagePullSecret = []apiv1.LocalObjectReference{{Name: cfg.TargetConfig.ImagePullSecret}} | ||
} | ||
|
||
commonMeta := metav1.ObjectMeta{ | ||
Name: fmt.Sprintf("kubectl-flame-%s", id), | ||
Namespace: cfg.TargetConfig.Namespace, | ||
Labels: map[string]string{ | ||
"kubectl-flame/id": id, | ||
}, | ||
Annotations: map[string]string{ | ||
"sidecar.istio.io/inject": "false", | ||
}, | ||
} | ||
|
||
resources, err := cfg.JobConfig.ToResourceRequirements() | ||
if err != nil { | ||
return "", nil, fmt.Errorf("unable to generate resource requirements: %w", err) | ||
} | ||
|
||
job := &batchv1.Job{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "Job", | ||
APIVersion: "batch/v1", | ||
}, | ||
ObjectMeta: commonMeta, | ||
Spec: batchv1.JobSpec{ | ||
Parallelism: int32Ptr(1), | ||
Completions: int32Ptr(1), | ||
TTLSecondsAfterFinished: int32Ptr(5), | ||
Template: apiv1.PodTemplateSpec{ | ||
ObjectMeta: commonMeta, | ||
Spec: apiv1.PodSpec{ | ||
HostPID: true, | ||
Volumes: []apiv1.Volume{ | ||
{ | ||
Name: "target-filesystem", | ||
VolumeSource: apiv1.VolumeSource{ | ||
HostPath: &apiv1.HostPathVolumeSource{ | ||
Path: cfg.TargetConfig.DockerPath, | ||
}, | ||
}, | ||
}, | ||
}, | ||
ImagePullSecrets: imagePullSecret, | ||
InitContainers: nil, | ||
Containers: []apiv1.Container{ | ||
{ | ||
ImagePullPolicy: apiv1.PullAlways, | ||
Name: ContainerName, | ||
Image: imageName, | ||
Command: []string{"/app/agent"}, | ||
Args: args, | ||
VolumeMounts: []apiv1.VolumeMount{ | ||
{ | ||
Name: "target-filesystem", | ||
MountPath: "/var/lib/docker", | ||
}, | ||
}, | ||
SecurityContext: &apiv1.SecurityContext{ | ||
Privileged: boolPtr(true), | ||
Capabilities: &apiv1.Capabilities{ | ||
Add: []apiv1.Capability{"SYS_PTRACE"}, | ||
}, | ||
}, | ||
Resources: resources, | ||
}, | ||
}, | ||
RestartPolicy: "Never", | ||
NodeName: targetPod.Spec.NodeName, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
return id, job, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.