func buildSingleArchContainers()

in gke-windows-builder/builder/main.go [169:196]


func buildSingleArchContainers(pickedVersionMap map[string]string, bss *[]builderServerStatus) error {
	ch := make(chan builderServerStatus, len(pickedVersionMap))
	wg := sync.WaitGroup{}
	for ver, imageFamily := range pickedVersionMap {
		wg.Add(1)
		go func(ver string, imageFamily string) {
			defer wg.Done()
			ctx := context.Background()
			ch <- buildSingleArchContainer(ctx, ver, imageFamily)
		}(ver, imageFamily)
	}
	// Wait until all builder server statuses returned.
	wg.Wait()
	chLen := len(ch)
	if chLen != len(pickedVersionMap) {
		return fmt.Errorf("Unexpected discrepancy happened, the number of builder server statuses in channel is not equal to length of pickedVersionMap")
	}
	for i := 0; i < chLen; i++ {
		*bss = append(*bss, <-ch)
	}
	// If any fatal error happens, exit the process
	for _, bs := range *bss {
		if bs.err != nil {
			return fmt.Errorf("Error happened when building single-arch containers: %+v", bs.err)
		}
	}
	return nil
}