chore: test Kubernetes storage with KinD

Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
This commit is contained in:
m.nabokikh 2021-04-19 16:45:12 +04:00
parent 6384af06e4
commit 5a48d8a82d
4 changed files with 24 additions and 54 deletions

View file

@ -57,6 +57,12 @@ jobs:
- name: Start services - name: Start services
run: docker-compose -f docker-compose.test.yaml up -d run: docker-compose -f docker-compose.test.yaml up -d
- name: Create kind cluster
uses: helm/kind-action@v1.0.0
with:
version: v0.10.0
node_image: kindest/node:v1.19.7@sha256:a70639454e97a4b733f9d9b67e12c01f6b0297449d5b9cbbef87473458e26dca
- name: Test - name: Test
run: make testall run: make testall
env: env:
@ -78,6 +84,7 @@ jobs:
DEX_KEYSTONE_ADMIN_URL: http://localhost:${{ job.services.keystone.ports[35357] }} DEX_KEYSTONE_ADMIN_URL: http://localhost:${{ job.services.keystone.ports[35357] }}
DEX_KEYSTONE_ADMIN_USER: demo DEX_KEYSTONE_ADMIN_USER: demo
DEX_KEYSTONE_ADMIN_PASS: DEMO_PASS DEX_KEYSTONE_ADMIN_PASS: DEMO_PASS
DEX_KUBERNETES_CONFIG_PATH: ~/.kube/config
- name: Lint - name: Lint
run: make lint run: make lint

View file

@ -61,25 +61,12 @@ up: docker-compose.override.yaml ## Launch the development environment
down: clear ## Destroy the development environment down: clear ## Destroy the development environment
docker-compose down --volumes --remove-orphans --rmi local docker-compose down --volumes --remove-orphans --rmi local
test: bin/test/kube-apiserver bin/test/etcd test:
@go test -v ./... @go test -v ./...
testrace: bin/test/kube-apiserver bin/test/etcd testrace:
@go test -v --race ./... @go test -v --race ./...
export TEST_ASSET_KUBE_APISERVER=$(abspath bin/test/kube-apiserver)
export TEST_ASSET_ETCD=$(abspath bin/test/etcd)
bin/test/kube-apiserver:
@mkdir -p bin/test
curl -L https://storage.googleapis.com/k8s-c10s-test-binaries/kube-apiserver-$(shell uname)-x86_64 > bin/test/kube-apiserver
chmod +x bin/test/kube-apiserver
bin/test/etcd:
@mkdir -p bin/test
curl -L https://storage.googleapis.com/k8s-c10s-test-binaries/etcd-$(shell uname)-x86_64 > bin/test/etcd
chmod +x bin/test/etcd
bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}
@ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint @ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
bin/golangci-lint-${GOLANGCI_VERSION}: bin/golangci-lint-${GOLANGCI_VERSION}:

1
go.mod
View file

@ -35,7 +35,6 @@ require (
google.golang.org/grpc v1.38.0 google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.26.0 google.golang.org/protobuf v1.26.0
gopkg.in/square/go-jose.v2 v2.5.1 gopkg.in/square/go-jose.v2 v2.5.1
sigs.k8s.io/testing_frameworks v0.1.2
) )
replace github.com/dexidp/dex/api/v2 => ./api/v2 replace github.com/dexidp/dex/api/v2 => ./api/v2

View file

@ -5,40 +5,26 @@ import (
"crypto/tls" "crypto/tls"
"errors" "errors"
"fmt" "fmt"
"io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
"path/filepath"
"strings" "strings"
"testing" "testing"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"sigs.k8s.io/testing_frameworks/integration"
"github.com/dexidp/dex/storage" "github.com/dexidp/dex/storage"
"github.com/dexidp/dex/storage/conformance" "github.com/dexidp/dex/storage/conformance"
) )
const kubeconfigTemplate = `apiVersion: v1 const kubeconfigPathVariableName = "DEX_KUBERNETES_CONFIG_PATH"
kind: Config
clusters:
- name: local
cluster:
server: SERVERURL
users:
- name: local
user:
contexts:
- context:
cluster: local
user: local
`
func TestStorage(t *testing.T) { func TestStorage(t *testing.T) {
if os.Getenv("TEST_ASSET_KUBE_APISERVER") == "" || os.Getenv("TEST_ASSET_ETCD") == "" { if os.Getenv(kubeconfigPathVariableName) == "" {
t.Skip("control plane binaries are missing") t.Skip(fmt.Sprintf("variable %q not set, skipping kubernetes storage tests\n", kubeconfigPathVariableName))
} }
suite.Run(t, new(StorageTestSuite)) suite.Run(t, new(StorageTestSuite))
@ -46,33 +32,24 @@ func TestStorage(t *testing.T) {
type StorageTestSuite struct { type StorageTestSuite struct {
suite.Suite suite.Suite
controlPlane *integration.ControlPlane
client *client client *client
} }
func (s *StorageTestSuite) SetupSuite() { func (s *StorageTestSuite) expandDir(dir string) string {
s.controlPlane = &integration.ControlPlane{} if strings.HasPrefix(dir, "~/") {
homedir, err := os.UserHomeDir()
s.Require().NoError(err)
err := s.controlPlane.Start() dir = filepath.Join(homedir, strings.TrimPrefix(dir, "~/"))
s.Require().NoError(err) }
} return dir
func (s *StorageTestSuite) TearDownSuite() {
s.controlPlane.Stop()
} }
func (s *StorageTestSuite) SetupTest() { func (s *StorageTestSuite) SetupTest() {
f, err := ioutil.TempFile("", "dex-kubeconfig-*") kubeconfigPath := s.expandDir(os.Getenv(kubeconfigPathVariableName))
s.Require().NoError(err)
defer f.Close()
_, err = f.WriteString(strings.ReplaceAll(kubeconfigTemplate, "SERVERURL", s.controlPlane.APIURL().String()))
s.Require().NoError(err)
config := Config{ config := Config{
KubeConfigFile: f.Name(), KubeConfigFile: kubeconfigPath,
} }
logger := &logrus.Logger{ logger := &logrus.Logger{
@ -81,10 +58,10 @@ func (s *StorageTestSuite) SetupTest() {
Level: logrus.DebugLevel, Level: logrus.DebugLevel,
} }
client, err := config.open(logger, true) kubeClient, err := config.open(logger, true)
s.Require().NoError(err) s.Require().NoError(err)
s.client = client s.client = kubeClient
} }
func (s *StorageTestSuite) TestStorage() { func (s *StorageTestSuite) TestStorage() {