Skip to content

Commit

Permalink
write pull image progress
Browse files Browse the repository at this point in the history
  • Loading branch information
aylei committed Dec 22, 2018
1 parent 8296c53 commit f6c8e68
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
!debug-agent
*
!debug-agent

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ before_deploy:

deploy:
- provider: script
script: bash docker_push.sh
script: bash ./scripts/docker_push.sh
on:
tags: true
13 changes: 7 additions & 6 deletions pkg/agent/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (a *DebugAttacher) AttachContainer(name string, uid kubetype.UID, container

// GetAttacher returns an implementation of Attacher
func (m *RuntimeManager) GetAttacher(image string, command []string) kubeletremote.Attacher {
return &DebugAttacher{runtime: m, image: image}
return &DebugAttacher{runtime: m, image: image, command: command}
}

// DebugContainer executes the main debug flow
Expand All @@ -59,7 +59,7 @@ func (m *RuntimeManager) DebugContainer(container, image string, command []strin

// step 1: pull image
stdout.Write([]byte(fmt.Sprintf("pulling image %s ...\n\r", image)))
err := m.PullImage(image)
err := m.PullImage(image, stdout)
if err != nil {
return err
}
Expand Down Expand Up @@ -128,16 +128,17 @@ func (m *RuntimeManager) CreateContainer(targetId string, image string, command
return &body, nil
}

func (m *RuntimeManager) PullImage(image string) error {
func (m *RuntimeManager) PullImage(image string, stdout io.WriteCloser) error {
ctx, cancel := m.getTimeoutContext()
defer cancel()
resp, err := m.client.ImagePull(ctx, image, types.ImagePullOptions{})
out, err := m.client.ImagePull(ctx, image, types.ImagePullOptions{})
if err != nil {
return err
}
defer resp.Close()
defer out.Close()
// write pull progress to user
io.Copy(stdout, out)
return nil

}

func (m *RuntimeManager) CleanContainer(id string) {
Expand Down
1 change: 0 additions & 1 deletion pkg/agent/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ func (s *Server) ServeDebug(w http.ResponseWriter, req *http.Request) {
TTY: true,
}

log.Printf("start serve attach, id: %s, image: %s, command: %v \n", containerId, image, commandSlice)
// replace Attacher implementation to hook the ServeAttach procedure
kubeletremote.ServeAttach(
w,
Expand Down
46 changes: 46 additions & 0 deletions scripts/agent_daemonset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
labels:
app: debug-agent
name: debug-agent
spec:
selector:
matchLabels:
app: debug-agent
template:
metadata:
labels:
app: debug-agent
spec:
containers:
- image: aylei/debug-agent:latest
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 10027
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
name: debug-agent
ports:
- containerPort: 10027
hostPort: 10027
name: http
protocol: TCP
volumeMounts:
- name: docker
mountPath: "/var/run/docker.sock"
hostNetwork: true
volumes:
- name: docker
hostPath:
path: /var/run/docker.sock
updateStrategy:
rollingUpdate:
maxUnavailable: 5
type: RollingUpdate
File renamed without changes.

0 comments on commit f6c8e68

Please sign in to comment.