Skip to content

Commit

Permalink
add --image flag
Browse files Browse the repository at this point in the history
  • Loading branch information
edeNFed committed Aug 29, 2020
1 parent af94968 commit 74ccef8
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 30 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Release
on:
pull_request:
push:
tags:
- 'v*.*.*'
jobs:
goreleaser:
runs-on: ubuntu-latest
Expand All @@ -17,12 +19,25 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: verizondigital/kubectl-flame
tags: test
tags: ${{ steps.vars.outputs.tag }}-jvm
- name: Build JVM Alpine Docker Image
uses: docker/build-push-action@v1
with:
dockerfile: 'agent/Dockerfile.alpine'
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: verizondigital/kubectl-flame
tags: test-jvm-alpine
tags: ${{ steps.vars.outputs.tag }}-jvm-alpine
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.14
- name: GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update new version in krew-index
uses: rajatjindal/[email protected]
6 changes: 4 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ builds:
- arm64
- ppc64le
goarm: [6, 7]
ldflags:
- -s -w -X version.semver={{.Tag}} -X version.date={{.Date}} -X version.commit={{.Commit}}
ldflags: |
-X github.com/VerizonMedia/kubectl-flame/cli/cmd/version.semver={{ .Tag }}
-X github.com/VerizonMedia/kubectl-flame/cli/cmd/version.date={{ .Date }}
-X github.com/VerizonMedia/kubectl-flame/cli/cmd/version.commit={{ .Commit }}
archives:
- id: kubectl-flame-archive
name_template: |
Expand Down
11 changes: 8 additions & 3 deletions agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
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 openjdk:8 as asyncprofiler
RUN echo deb http://deb.debian.org/debian stretch-backports main > /etc/apt/sources.list.d/stretch-backports.list && \
apt-get update && \
Expand All @@ -7,8 +13,7 @@ RUN cd async-profiler && make

FROM bitnami/minideb:stretch
RUN mkdir -p /app/async-profiler/build
ADD agent /app
COPY --from=agentbuild /go/bin/agent /app
COPY --from=asyncprofiler /async-profiler/build /app/async-profiler/build
COPY --from=asyncprofiler /async-profiler/profiler.sh /app/async-profiler
CMD [ "/app/agent" ]

CMD [ "/app/agent" ]
11 changes: 8 additions & 3 deletions agent/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,12 +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 openjdk:8-alpine as asyncprofiler
RUN apk add build-base git linux-headers
RUN git clone https://github.com/edeNFed/async-profiler.git
RUN cd async-profiler && make

FROM alpine
RUN mkdir -p /app/async-profiler/build
ADD agent /app
COPY --from=agentbuild /go/bin/agent /app
COPY --from=asyncprofiler /async-profiler/build /app/async-profiler/build
COPY --from=asyncprofiler /async-profiler/profiler.sh /app/async-profiler
CMD [ "/app/agent" ]

CMD [ "/app/agent" ]
1 change: 1 addition & 0 deletions cli/cmd/data/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ type TargetDetails struct {
FileName string
Alpine bool
DryRun bool
Image string
}
21 changes: 17 additions & 4 deletions cli/cmd/kubernetes/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package kubernetes
import (
"context"
"fmt"
"github.com/VerizonMedia/kubectl-flame/cli/cmd/version"
"os"

"github.com/VerizonMedia/kubectl-flame/cli/cmd/data"
Expand All @@ -16,12 +17,11 @@ import (
"k8s.io/apimachinery/pkg/util/uuid"
)

const imageName = "verizondigital/kubectl-flame"

func LaunchFlameJob(targetPod *v1.Pod, targetDetails *data.TargetDetails, ctx context.Context) (string, *batchv1.Job, error) {
id := string(uuid.NewUUID())
imageName := "edenfed/kubectl-flame:latest"
if targetDetails.Alpine {
imageName += "-alpine"
}
imageName := getAgentImage(targetDetails)

commonMeta := metav1.ObjectMeta{
Name: fmt.Sprintf("kubectl-flame-%s", id),
Expand Down Expand Up @@ -108,6 +108,19 @@ func printJob(job *batchv1.Job) error {
return encoder.Encode(job, os.Stdout)
}

func getAgentImage(targetDetails *data.TargetDetails) string {
if targetDetails.Image != "" {
return targetDetails.Image
}

tag := fmt.Sprintf("%s-jvm", version.GetCurrent())
if targetDetails.Alpine {
tag = fmt.Sprintf("%s-alpine", tag)
}

return fmt.Sprintf("%s:%s", imageName, tag)
}

func DeleteProfilingJob(job *batchv1.Job, targetDetails *data.TargetDetails, ctx context.Context) error {
deleteStrategy := metav1.DeletePropagationForeground
return clientSet.
Expand Down
24 changes: 10 additions & 14 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ These commands help you identify application performance issues.
)

var targetDetails data.TargetDetails
var showVersion bool

type FlameOptions struct {
configFlags *genericclioptions.ConfigFlags
Expand All @@ -55,6 +56,11 @@ func NewFlameCommand(streams genericclioptions.IOStreams) *cobra.Command {
c.SetOutput(streams.ErrOut)
},
Run: func(cmd *cobra.Command, args []string) {
if showVersion {
fmt.Fprintln(streams.Out, version.String())
return
}

if len(args) == 0 {
cmd.Help()
return
Expand All @@ -69,23 +75,13 @@ func NewFlameCommand(streams genericclioptions.IOStreams) *cobra.Command {
},
}

cmd.AddCommand(newVersionCommand(streams))
cmd.Flags().DurationVarP(&targetDetails.Duration, "time", "t", defaultDuration, "Enter max scan Duration")
cmd.Flags().BoolVar(&showVersion, "version", false, "Print version info")
cmd.Flags().DurationVarP(&targetDetails.Duration, "time", "t", defaultDuration, "Max scan Duration")
cmd.Flags().StringVarP(&targetDetails.FileName, "file", "f", "flamegraph.svg", "Optional file location")
cmd.Flags().BoolVar(&targetDetails.Alpine, "alpine", false, "Target image is based on Alpine")
cmd.Flags().BoolVar(&targetDetails.DryRun, "dry-run", false, "simulate profiling")
cmd.Flags().BoolVar(&targetDetails.DryRun, "dry-run", false, "Simulate profiling")
cmd.Flags().StringVar(&targetDetails.Image, "image", "", "Manually choose agent docker image")
options.configFlags.AddFlags(cmd.Flags())

return cmd
}
func newVersionCommand(streams genericclioptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Short: "Print the version information for kubectl flame",
RunE: func(c *cobra.Command, args []string) error {
fmt.Fprintln(streams.Out, version.String())
return nil
},
}
return cmd
}
2 changes: 1 addition & 1 deletion cli/cmd/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var (
)

func String() string {
return fmt.Sprintf("kubectl flame version: %s\ncommit: %s\nbuild date: %s", semver, commit, date)
return fmt.Sprintf("Version: %s, Commit: %s, Build Date: %s", semver, commit, date)
}

func GetCurrent() string {
Expand Down

0 comments on commit 74ccef8

Please sign in to comment.