cmd/coordinator: pull out kubeCluster variable, update to new Cloud Storage API

Change-Id: If0ebe24c1359c4a4c4f3fdb0f214994605e2e887
Reviewed-on: https://go-review.googlesource.com/17313
Reviewed-by: Evan Brown <evanbrown@google.com>
This commit is contained in:
Brad Fitzpatrick 2015-12-02 22:39:00 +00:00
Родитель c274d96d25
Коммит 350b42fe78
3 изменённых файлов: 15 добавлений и 9 удалений

Просмотреть файл

@ -161,7 +161,7 @@ func readGCSFile(name string) ([]byte, error) {
return []byte(b), nil
}
r, err := storage.NewReader(serviceCtx, stagingPrefix()+"go-builder-data", name)
r, err := storageClient.Bucket(stagingPrefix() + "go-builder-data").Object(name).NewReader(serviceCtx)
if err != nil {
return nil, err
}
@ -978,7 +978,7 @@ func (ts *trySet) noteBuildComplete(bconf dashboard.BuildConfig, bs *buildStatus
s1 := sha1.New()
io.WriteString(s1, buildLog)
objName := fmt.Sprintf("%s/%s_%x.log", bs.rev[:8], bs.name, s1.Sum(nil)[:4])
wr := storage.NewWriter(serviceCtx, buildLogBucket(), objName)
wr := storageClient.Bucket(buildLogBucket()).Object(objName).NewWriter(serviceCtx)
wr.ContentType = "text/plain; charset=utf-8"
wr.ACL = append(wr.ACL, storage.ACLRule{Entity: storage.AllUsers, Role: storage.RoleReader})
if _, err := io.WriteString(wr, buildLog); err != nil {
@ -1591,7 +1591,7 @@ func (st *buildStatus) writeSnapshot() error {
}
defer tgz.Close()
wr := storage.NewWriter(serviceCtx, snapBucket(), st.snapshotObjectName())
wr := storageClient.Bucket(snapBucket()).Object(st.snapshotObjectName()).NewWriter(serviceCtx)
wr.ContentType = "application/octet-stream"
wr.ACL = append(wr.ACL, storage.ACLRule{Entity: storage.AllUsers, Role: storage.RoleReader})
if _, err := io.Copy(wr, tgz); err != nil {

Просмотреть файл

@ -63,6 +63,7 @@ var (
serviceCtx context.Context
errTryDeps error // non-nil if try bots are disabled
gerritClient *gerrit.Client
storageClient *storage.Client
inStaging bool // are we running in the staging project? (named -dev)
initGCECalled bool
@ -112,6 +113,10 @@ func initGCE() error {
tokenSource, _ = google.DefaultTokenSource(oauth2.NoContext)
httpClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
serviceCtx = cloud.NewContext(projectID, httpClient)
storageClient, err = storage.NewClient(serviceCtx, cloud.WithBaseHTTP(httpClient))
if err != nil {
log.Fatalf("storage.NewClient: %v", err)
}
externalIP, err = metadata.ExternalIP()
if err != nil {
@ -133,7 +138,7 @@ func checkTryBuildDeps() error {
if !hasStorageScope() {
return errors.New("coordinator's GCE instance lacks the storage service scope")
}
wr := storage.NewWriter(serviceCtx, buildLogBucket(), "hello.txt")
wr := storageClient.Bucket(buildLogBucket()).Object("hello.txt").NewWriter(serviceCtx)
fmt.Fprintf(wr, "Hello, world! Coordinator start-up at %v", time.Now())
if err := wr.Close(); err != nil {
return fmt.Errorf("test write of a GCS object to bucket %q failed: %v", buildLogBucket(), err)

Просмотреть файл

@ -39,6 +39,7 @@ var (
kubeErr error
initKubeCalled bool
registryPrefix = "gcr.io"
kubeCluster *container.Cluster
)
const (
@ -61,7 +62,7 @@ func initKube() error {
return fmt.Errorf("could not create client for Google Container Engine: %v", err)
}
cluster, err := containerService.Projects.Zones.Clusters.Get(projectID, projectZone, clusterName).Do()
kubeCluster, err = containerService.Projects.Zones.Clusters.Get(projectID, projectZone, clusterName).Do()
if err != nil {
return fmt.Errorf("cluster %q could not be found in project %q, zone %q: %v", clusterName, projectID, projectZone, err)
}
@ -77,9 +78,9 @@ func initKube() error {
}
return []byte(s)
}
clientCert := decode("client cert", cluster.MasterAuth.ClientCertificate)
clientKey := decode("client key", cluster.MasterAuth.ClientKey)
caCert := decode("cluster cert", cluster.MasterAuth.ClusterCaCertificate)
clientCert := decode("client cert", kubeCluster.MasterAuth.ClientCertificate)
clientKey := decode("client key", kubeCluster.MasterAuth.ClientKey)
caCert := decode("cluster cert", kubeCluster.MasterAuth.ClusterCaCertificate)
if err != nil {
return err
}
@ -107,7 +108,7 @@ func initKube() error {
},
}
kubeClient, err = kubernetes.NewClient("https://"+cluster.Endpoint, kubeHTTPClient)
kubeClient, err = kubernetes.NewClient("https://"+kubeCluster.Endpoint, kubeHTTPClient)
if err != nil {
return fmt.Errorf("kubernetes HTTP client could not be created: %v", err)
}