Skip to content

Commit 8d2bd1a

Browse files
authored
Merge pull request #71 from davidz627/feature/e2eOverTCP
Redid test framework to bring up driver on instance and expose TCP socket with SSH Tunneling
2 parents 1c0e451 + 6934153 commit 8d2bd1a

18 files changed

+1139
-1348
lines changed

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ all: gce-pd-driver
2323
gce-pd-driver:
2424
mkdir -p bin
2525
go build -ldflags "-X main.vendorVersion=${STAGINGVERSION}" -o bin/gce-pd-csi-driver ./cmd/
26-
go test -c sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/test/e2e -o bin/e2e.test
2726

2827
build-container:
2928
docker build --build-arg TAG=$(STAGINGVERSION) -t $(STAGINGIMAGE):$(STAGINGVERSION) .

pkg/gce-pd-csi-driver/server.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ func (s *nonBlockingGRPCServer) ForceStop() {
7070
}
7171

7272
func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer) {
73+
opts := []grpc.ServerOption{
74+
grpc.UnaryInterceptor(logGRPC),
75+
}
7376

7477
u, err := url.Parse(endpoint)
7578

@@ -83,6 +86,8 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c
8386
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
8487
glog.Fatalf("Failed to remove %s, error: %s", addr, err.Error())
8588
}
89+
} else if u.Scheme == "tcp" {
90+
addr = u.Host
8691
} else {
8792
glog.Fatalf("%v endpoint scheme not supported", u.Scheme)
8893
}
@@ -93,9 +98,6 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c
9398
glog.Fatalf("Failed to listen: %v", err)
9499
}
95100

96-
opts := []grpc.ServerOption{
97-
grpc.UnaryInterceptor(logGRPC),
98-
}
99101
server := grpc.NewServer(opts...)
100102
s.server = server
101103

@@ -111,6 +113,8 @@ func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, c
111113

112114
glog.Infof("Listening for connections on address: %#v", listener.Addr())
113115

114-
server.Serve(listener)
116+
if err := server.Serve(listener); err != nil {
117+
glog.Fatalf("Failed to serve: %v", err)
118+
}
115119

116120
}

test/binremote/archiver.go

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package binremote
18+
19+
import (
20+
"fmt"
21+
"io/ioutil"
22+
"os"
23+
"os/exec"
24+
"path/filepath"
25+
26+
"github.com/golang/glog"
27+
)
28+
29+
func CreateDriverArchive(archiveName, pkgPath, binPath string) (string, error) {
30+
glog.V(2).Infof("Building archive...")
31+
tarDir, err := ioutil.TempDir("", "driver-temp-archive")
32+
if err != nil {
33+
return "", fmt.Errorf("failed to create temporary directory %v", err)
34+
}
35+
defer os.RemoveAll(tarDir)
36+
37+
// Call the suite function to setup the test package.
38+
err = setupBinaries(tarDir, pkgPath, binPath)
39+
if err != nil {
40+
return "", fmt.Errorf("failed to setup test package %q: %v", tarDir, err)
41+
}
42+
43+
// Build the tar
44+
out, err := exec.Command("tar", "-zcvf", archiveName, "-C", tarDir, ".").CombinedOutput()
45+
if err != nil {
46+
return "", fmt.Errorf("failed to build tar %v. Output:\n%s", err, out)
47+
}
48+
49+
dir, err := os.Getwd()
50+
if err != nil {
51+
return "", fmt.Errorf("failed to get working directory %v", err)
52+
}
53+
return filepath.Join(dir, archiveName), nil
54+
}
55+
56+
func setupBinaries(tarDir, pkgPath, binPath string) error {
57+
glog.V(4).Infof("Making binaries and copying to temp dir...")
58+
out, err := exec.Command("make", "-C", pkgPath).CombinedOutput()
59+
if err != nil {
60+
return fmt.Errorf("Failed to make at %s: %v: %v", pkgPath, string(out), err)
61+
}
62+
63+
// Copy binaries
64+
if _, err := os.Stat(binPath); err != nil {
65+
return fmt.Errorf("failed to locate test binary %s: %v", binPath, err)
66+
}
67+
out, err = exec.Command("cp", binPath, tarDir).CombinedOutput()
68+
if err != nil {
69+
return fmt.Errorf("failed to copy %q: %v Output: %q", binPath, err, out)
70+
}
71+
72+
return nil
73+
}

0 commit comments

Comments
 (0)