Skip to content

Commit

Permalink
Add build for the e2e tests
Browse files Browse the repository at this point in the history
To run the e2e tests, RUN_INGRESS_E2E must be set. Otherwise, the
tests will be skipped.
  • Loading branch information
bowei committed Jun 5, 2018
1 parent 2a805f5 commit 778b0c0
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 9 deletions.
18 changes: 18 additions & 0 deletions Dockerfile.e2e-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2018 The Kubernetes Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM debian:9

ADD bin/ARG_ARCH/ARG_BIN /ARG_BIN
ENTRYPOINT ["/ARG_BIN"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ PKG := k8s.io/ingress-gce

# List of binaries to build. You must have a matching Dockerfile.BINARY
# for each BINARY.
CONTAINER_BINARIES := glbc
CONTAINER_BINARIES := glbc e2e-test

# Latest commit hash for current branch.
GIT_COMMIT := $(shell git rev-parse HEAD)
Expand Down
12 changes: 8 additions & 4 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ if [ $GOARCH == "amd64" ]; then
export GOBIN="$GOPATH/bin/linux_amd64"
fi

go install \
-installsuffix "static" \
-ldflags "-X ${PKG}/pkg/version.Version=${VERSION} -X ${PKG}/pkg/version.GitCommit=${GIT_COMMIT}" \
./...
if echo "${TARGET}" | grep '.*-test$'; then
go test -c -o "${TARGET}" "$PKG/cmd/$(basename ${TARGET})"
else
go install \
-installsuffix "static" \
-ldflags "-X ${PKG}/pkg/version.Version=${VERSION} -X ${PKG}/pkg/version.GitCommit=${GIT_COMMIT}" \
./...
fi
8 changes: 4 additions & 4 deletions build/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ifeq ($(VERBOSE), 1)
VERBOSE_OUTPUT := >&1
else
DOCKER_BUILD_FLAGS := -q
VERBOSE_OUTPUT := >/dev/null
VERBOSE_OUTPUT := >/dev/null 2>/dev/null
endif

# This MUST appear as the first rule in a Makefile
Expand Down Expand Up @@ -106,7 +106,7 @@ build: $(GO_BINARIES) images-build
# Rule for all bin/$(ARCH)/bin/$(BINARY)
$(GO_BINARIES): build-dirs
@echo "building : $@"
@docker pull $(BUILD_IMAGE)
@docker pull $(BUILD_IMAGE) $(VERBOSE_OUTPUT)
@docker run \
--rm \
--sig-proxy=true \
Expand All @@ -122,11 +122,11 @@ $(GO_BINARIES): build-dirs
ARCH=$(ARCH) \
VERSION=$(VERSION) \
PKG=$(PKG) \
GIT_COMMIT=$(GIT_COMMIT) \
TARGET=$@ \
GIT_COMMIT=$(GIT_COMMIT) \
./build/build.sh \
"


# Rules for dockerfiles.
define DOCKERFILE_RULE
.$(BINARY)-$(ARCH)-dockerfile: Dockerfile.$(BINARY)
Expand Down
84 changes: 84 additions & 0 deletions cmd/e2e-test/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"flag"
"fmt"
"os"
"path/filepath"
"testing"

"github.com/golang/glog"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/ingress-gce/pkg/e2e"
// Pull in the auth library for GCP.
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)

var (
flags struct {
inCluster bool
kubeconfig string
}

Framework *e2e.Framework
)

func init() {
home := os.Getenv("HOME")
if home != "" {
flag.StringVar(&flags.kubeconfig, "kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
flag.StringVar(&flags.kubeconfig, "kubeconfig", "", "absolute path to the kubeconfig file")
}
flag.BoolVar(&flags.inCluster, "inCluster", false, "set to true if running in the cluster")
}

// TestMain is the entrypoint for the end-to-end test suite. This is where
// global resource setup should be done.
func TestMain(m *testing.M) {
flag.Parse()

if os.Getenv("RUN_INGRESS_E2E") != "true" {
fmt.Fprintln(os.Stderr, "You must set the RUN_INGRESS_E2E environment variable to 'true' run the tests.")
return
}

var err error
var kubeconfig *rest.Config

if flags.inCluster {
kubeconfig, err = rest.InClusterConfig()
if err != nil {
glog.Fatalf("Error creating InClusterConfig(): %v", err)
}
} else {
kubeconfig, err = clientcmd.BuildConfigFromFlags("", flags.kubeconfig)
if err != nil {
glog.Fatalf("Error creating kubernetes clientset from %q: %v", flags.kubeconfig, err)
}
}

Framework = e2e.NewFramework(kubeconfig)
if err := Framework.SanityCheck(); err != nil {
glog.Fatalf("Framework sanity check failed: %v", err)
}

os.Exit(m.Run())
}
24 changes: 24 additions & 0 deletions cmd/e2e-test/nothing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"testing"
)

func TestNothing(t *testing.T) {
}
20 changes: 20 additions & 0 deletions cmd/e2e-test/placeholder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

// This is a placeholder file to keep the Golang build happy.
func main() {}
19 changes: 19 additions & 0 deletions pkg/e2e/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package e2e contains supporting infrastructure for end-to-end integration
// testing driven by the tests in cmd/e2e-test.
package e2e
46 changes: 46 additions & 0 deletions pkg/e2e/framework.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"github.com/golang/glog"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)

// NewFramework returns a new test framework to run.
func NewFramework(config *rest.Config) *Framework {
return &Framework{
Clientset: kubernetes.NewForConfigOrDie(config),
}
}

// Framework is the ent-to-end test framework.
type Framework struct {
Clientset *kubernetes.Clientset
}

// SanityCheck the test environment before proceeding.
func (f *Framework) SanityCheck() error {
if _, err := f.Clientset.Core().Pods("default").List(metav1.ListOptions{}); err != nil {
glog.Errorf("Error talking to the Kubernetes master: %v", err)
return err
}
// TODO: check connectivity etc.
return nil
}

0 comments on commit 778b0c0

Please sign in to comment.