Skip to content

Commit

Permalink
Let pre/post upgrade hook use extended watch
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiu Yu committed Apr 27, 2018
1 parent bfa37bc commit cbd2b63
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 127 deletions.
3 changes: 2 additions & 1 deletion _proto/hapi/services/tiller.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ service ReleaseService {
}

// UpdateRelease updates release content.
rpc UpdateRelease(UpdateReleaseRequest) returns (UpdateReleaseResponse) {
rpc UpdateRelease(UpdateReleaseRequest) returns (stream UpdateReleaseResponse) { // TODO: backward compatibility
}

// InstallRelease requests installation of a chart as a new release.
Expand Down Expand Up @@ -215,6 +215,7 @@ message UpdateReleaseRequest {
// UpdateReleaseResponse is the response to an update request.
message UpdateReleaseResponse {
hapi.release.Release release = 1;
hapi.release.WatchFeed watch_feed = 2; // TODO: think about compatibility
}

message RollbackReleaseRequest {
Expand Down
47 changes: 46 additions & 1 deletion pkg/helm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,52 @@ func (h *Client) update(ctx context.Context, req *rls.UpdateReleaseRequest) (*rl
defer c.Close()

rlc := rls.NewReleaseServiceClient(c)
return rlc.UpdateRelease(ctx, req)

var finalResp *rls.UpdateReleaseResponse

currentLogHeader := ""
setLogHeader := func(logHeader string) {
if currentLogHeader != logHeader {
if currentLogHeader != "" {
fmt.Println()
}
fmt.Printf("%s\n", logHeader)
currentLogHeader = logHeader
}
}
formatJobHeader := func(jobName string, podName string, containerName string) string {
// tail -f on multiple files prints similar headers
return fmt.Sprintf("==> Job \"%s\", Pod \"%s\", Container \"%s\" <==", jobName, podName, containerName)
}

stream, err := rlc.UpdateRelease(ctx, req)
for {
resp, err := stream.Recv()
if err == io.EOF {
return finalResp, nil
}
if err != nil {
return resp, err
}

if resp.WatchFeed.GetJobLogChunk() != nil {
chunk := resp.WatchFeed.GetJobLogChunk()

setLogHeader(formatJobHeader(chunk.JobName, chunk.PodName, chunk.ContainerName))

for _, line := range chunk.LogLines {
fmt.Println(line.Data)
}
} else if resp.WatchFeed.GetJobPodError() != nil {
jobPodError := resp.WatchFeed.GetJobPodError()

setLogHeader(formatJobHeader(jobPodError.JobName, jobPodError.PodName, jobPodError.ContainerName))

fmt.Fprintf(os.Stderr, "Error: %s\n", jobPodError.Message)
} else {
finalResp = resp // TODO verify/debug this code
}
}
}

// Executes tiller.RollbackRelease RPC.
Expand Down
Loading

0 comments on commit cbd2b63

Please sign in to comment.