Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/event/parsers/parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func ParsePullDockerImage(e partybus.Event) (string, *docker.PullStatus, error)
return "", nil, newPayloadErr(e.Type, "Source", e.Source)
}

prog, ok := e.Value.(*docker.PullStatus)
pullStatus, ok := e.Value.(*docker.PullStatus)
if !ok {
return "", nil, newPayloadErr(e.Type, "Value", e.Value)
}

return imgName, prog, nil
return imgName, pullStatus, nil
}

func ParseFetchImage(e partybus.Event) (string, progress.StagedProgressable, error) {
Expand Down
39 changes: 16 additions & 23 deletions pkg/image/docker/pull_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ const (
PullCompletePhase
)

var phaseLookup = map[string]PullPhase{
"Waiting": WaitingPhase,
"Pulling fs layer": PullingFsPhase,
"Downloading": DownloadingPhase,
"Download complete": DownloadCompletePhase,
"Extracting": ExtractingPhase,
"Verifying Checksum": VerifyingChecksumPhase,
"Already exists": AlreadyExistsPhase,
"Pull complete": PullCompletePhase,
}

type PullPhase int
type LayerID string

Expand Down Expand Up @@ -100,7 +111,11 @@ func (p *PullStatus) onEvent(event *pullEvent) {
}

// capture latest event info
currentPhase := parsePhase(event.Status)
currentPhase, ok := phaseLookup[event.Status]
if !ok {
currentPhase = UnknownPhase
}

p.phase[layer] = currentPhase
phaseProgress := p.phaseProgress[layer]

Expand All @@ -121,25 +136,3 @@ func (p *PullStatus) onEvent(event *pullEvent) {
dl.SetCompleted()
}
}

func parsePhase(inputStr string) PullPhase {
switch inputStr {
case "Waiting":
return WaitingPhase
case "Pulling fs layer":
return PullingFsPhase
case "Downloading":
return DownloadingPhase
case "Download complete":
return DownloadCompletePhase
case "Extracting":
return ExtractingPhase
case "Verifying Checksum":
return VerifyingChecksumPhase
case "Already exists":
return AlreadyExistsPhase
case "Pull complete":
return PullCompletePhase
}
return UnknownPhase
}