Skip to content

Commit

Permalink
lint and refine for ci
Browse files Browse the repository at this point in the history
  • Loading branch information
aylei committed Dec 22, 2018
1 parent ed3d6e5 commit 8296c53
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
sudo: required
services:
- docker
language: go

go:
- "1.10.x"

env:
- DEP_VERSION="0.4.1"

Expand All @@ -15,14 +16,20 @@ install:

before_script:
- GO_FILES=$(find . -iname '*.go' -type f | grep -v /vendor/) # All the .go files, excluding vendor/
- go get github.com/golang/lint/golint
- go get honnef.co/go/tools/cmd/megacheck

script:
- test -z $(gofmt -s -l $GO_FILES) # Fail if a .go file hasn't been formatted with gofmt
- go test -v -race ./... # Run all the tests with the race detector enabled
- go vet ./... # go vet is the official Go static analyzer
- megacheck ./... # "go vet on steroids" + linter
- golint -set_exit_status $(go list ./...) # one last linter

before_deploy:
- GOOS=linux GARCH=amd64 go build -o debug-agent ./cmd/agent
- docker build . -t aylei/debug-agent:$TRAVIS_TAG

deploy:
- provider: script
script: bash docker_push.sh
on:
tags: true
3 changes: 3 additions & 0 deletions docker_push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
docker push aylei/debug-agent:$TRAVIS_TAG
2 changes: 1 addition & 1 deletion pkg/agent/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (m *RuntimeManager) CleanContainer(id string) {
if rmErr != nil {
log.Printf("error remove container: %s \n", id)
} else {
log.Printf("Debug session end, debug container %s removed")
log.Printf("Debug session end, debug container %s removed", id)
}
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/agent/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (s *Server) Run() error {

log.Println("shutting done server...")

ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
server.Shutdown(ctx)

return nil
Expand Down
9 changes: 3 additions & 6 deletions pkg/plugin/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@ const (
kubectl debug POD_NAME --image aylei/debug-jvm /bin/bash
`
defaultImage = "aylei/troubleshoot:latest"
defaultRetain = false
defaultAgentPort = 10027
)

var (
errNoContext = fmt.Errorf("no context is currently set, use %q to select a new one", "kubectl config use-context <context>")
)

// DebugOptions specify how to run debug container in a running pod
type DebugOptions struct {

Expand Down Expand Up @@ -86,7 +81,6 @@ func NewDebugCmd(streams genericclioptions.IOStreams) *cobra.Command {
if err := opts.Run(); err != nil {
fmt.Println(err)
}
return
},
}
//cmd.Flags().BoolVarP(&opts.RetainContainer, "retain", "r", defaultRetain,
Expand Down Expand Up @@ -212,6 +206,9 @@ func (o *DebugOptions) Run() error {

func (o *DebugOptions) getContainerIdByName(pod *corev1.Pod, containerName string) (string, error) {
for _, containerStatus := range pod.Status.ContainerStatuses {
if containerStatus.Name != containerName {
continue
}
if !containerStatus.Ready {
return "", fmt.Errorf("container %s id not ready", containerName)
}
Expand Down

0 comments on commit 8296c53

Please sign in to comment.