Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Use errgroup instead of counting goroutines #3387

Merged
merged 1 commit into from
Jul 2, 2018
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
8 changes: 6 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ import:
version: 0841753fc26e934b715ca7a83dced5bcb721245a
- package: k8s.io/client-go
version: ~7.0.0
# This is the same version client-go is pinned to
- package: k8s.io/api
version: 73d903622b7391f3312dcbac6483fed484e185f8
- package: github.com/Jeffail/gabs
version: 1.0
version: "1.0"
- package: github.com/rjtsdl/conform
version: 1.2.1
- package: github.com/etgryphon/stringUp
- package: golang.org/x/sync
subpackages:
- errgroup
testImport:
# glide isn't able to mutually reconcile pinned versions of these deps
- package: github.com/onsi/gomega
- package: github.com/onsi/ginkgo
- package: github.com/kelseyhightower/envconfig
Expand All @@ -77,4 +78,6 @@ testImport:
version: ~7.0.0
- package: k8s.io/api
version: 73d903622b7391f3312dcbac6483fed484e185f8
- package: github.com/influxdata/influxdb/client/v2
- package: github.com/influxdata/influxdb
subpackages:
- client/v2
55 changes: 24 additions & 31 deletions pkg/acsengine/pki.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"net"
"time"

"golang.org/x/sync/errgroup"

log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -58,7 +60,7 @@ func CreatePki(extraFQDNs []string, extraIPs []net.IP, clusterDomain string, caP
etcdClientPrivateKey *rsa.PrivateKey
etcdPeerCertPairs []*PkiKeyCertPair
)
errors := make(chan error)
var group errgroup.Group

var err error
caCertificate, err = pemToCertificate(caPair.CertificatePem)
Expand All @@ -70,62 +72,53 @@ func CreatePki(extraFQDNs []string, extraIPs []net.IP, clusterDomain string, caP
return nil, nil, nil, nil, nil, nil, err
}

go func() {
var err error
group.Go(func() (err error) {
apiServerCertificate, apiServerPrivateKey, err = createCertificate("apiserver", caCertificate, caPrivateKey, false, true, extraFQDNs, extraIPs, nil)
errors <- err
}()
return err
})

go func() {
var err error
group.Go(func() (err error) {
organization := make([]string, 1)
organization[0] = "system:masters"
clientCertificate, clientPrivateKey, err = createCertificate("client", caCertificate, caPrivateKey, false, false, nil, nil, organization)
errors <- err
}()
return err
})

go func() {
var err error
group.Go(func() (err error) {
organization := make([]string, 1)
organization[0] = "system:masters"
kubeConfigCertificate, kubeConfigPrivateKey, err = createCertificate("client", caCertificate, caPrivateKey, false, false, nil, nil, organization)
errors <- err
}()
return err
})

go func() {
var err error
group.Go(func() (err error) {
ip := net.ParseIP("127.0.0.1").To4()
peerIPs := append(extraIPs, ip)
etcdServerCertificate, etcdServerPrivateKey, err = createCertificate("etcdserver", caCertificate, caPrivateKey, true, true, nil, peerIPs, nil)
errors <- err
}()
return err
})

go func() {
var err error
group.Go(func() (err error) {
ip := net.ParseIP("127.0.0.1").To4()
peerIPs := append(extraIPs, ip)
etcdClientCertificate, etcdClientPrivateKey, err = createCertificate("etcdclient", caCertificate, caPrivateKey, true, false, nil, peerIPs, nil)
errors <- err
}()
return err
})

etcdPeerCertPairs = make([]*PkiKeyCertPair, masterCount)
for i := 0; i < masterCount; i++ {
go func(i int) {
var err error
i := i
group.Go(func() (err error) {
ip := net.ParseIP("127.0.0.1").To4()
peerIPs := append(extraIPs, ip)
etcdPeerCertificate, etcdPeerPrivateKey, err := createCertificate("etcdpeer", caCertificate, caPrivateKey, true, false, nil, peerIPs, nil)
etcdPeerCertPairs[i] = &PkiKeyCertPair{CertificatePem: string(certificateToPem(etcdPeerCertificate.Raw)), PrivateKeyPem: string(privateKeyToPem(etcdPeerPrivateKey))}
errors <- err
}(i)
return err
})
}

e := make([]error, (masterCount + 5))
for i := 0; i < len(e); i++ {
e[i] = <-errors
if e[i] != nil {
return nil, nil, nil, nil, nil, nil, e[i]
}
if err := group.Wait(); err != nil {
return nil, nil, nil, nil, nil, nil, err
}

return &PkiKeyCertPair{CertificatePem: string(certificateToPem(apiServerCertificate.Raw)), PrivateKeyPem: string(privateKeyToPem(apiServerPrivateKey))},
Expand Down
3 changes: 3 additions & 0 deletions vendor/golang.org/x/sync/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions vendor/golang.org/x/sync/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/golang.org/x/sync/CONTRIBUTORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/golang.org/x/sync/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/golang.org/x/sync/PATENTS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions vendor/golang.org/x/sync/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/golang.org/x/sync/codereview.cfg

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions vendor/golang.org/x/sync/errgroup/errgroup.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading