Custom resource definition
Co-authored-by: Mathieu Lonjaret <mathieu.lonjaret@gmail.com>
This commit is contained in:
parent
cfaf47c8a2
commit
4c060a78cc
1348 changed files with 92364 additions and 55766 deletions
28
integration/fixtures/k8s/01-crd.yml
Normal file
28
integration/fixtures/k8s/01-crd.yml
Normal file
|
@ -0,0 +1,28 @@
|
|||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
name: ingressroutes.traefik.containo.us
|
||||
|
||||
spec:
|
||||
group: traefik.containo.us
|
||||
version: v1alpha1
|
||||
names:
|
||||
kind: IngressRoute
|
||||
plural: ingressroutes
|
||||
singular: ingressroute
|
||||
scope: Namespaced
|
||||
|
||||
---
|
||||
apiVersion: apiextensions.k8s.io/v1beta1
|
||||
kind: CustomResourceDefinition
|
||||
metadata:
|
||||
name: middlewares.traefik.containo.us
|
||||
|
||||
spec:
|
||||
group: traefik.containo.us
|
||||
version: v1alpha1
|
||||
names:
|
||||
kind: Middleware
|
||||
plural: middlewares
|
||||
singular: middleware
|
||||
scope: Namespaced
|
|
@ -1,11 +1,12 @@
|
|||
---
|
||||
kind: Deployment
|
||||
apiVersion: extensions/v1beta1
|
||||
metadata:
|
||||
name: whoami
|
||||
namespace: default
|
||||
labels:
|
||||
app: containous
|
||||
name: whoami
|
||||
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
|
@ -23,11 +24,14 @@ spec:
|
|||
image: containous/whoami
|
||||
ports:
|
||||
- containerPort: 80
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: whoami
|
||||
namespace: default
|
||||
|
||||
spec:
|
||||
ports:
|
||||
- name: http
|
||||
|
@ -35,17 +39,3 @@ spec:
|
|||
selector:
|
||||
app: containous
|
||||
task: whoami
|
||||
---
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: cheeses
|
||||
spec:
|
||||
rules:
|
||||
- host: whoami.test
|
||||
http:
|
||||
paths:
|
||||
- path: /whoami
|
||||
backend:
|
||||
serviceName: whoami
|
||||
servicePort: http
|
15
integration/fixtures/k8s/03-ingress.yml
Normal file
15
integration/fixtures/k8s/03-ingress.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
apiVersion: extensions/v1beta1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: test.ingress
|
||||
namespace: default
|
||||
|
||||
spec:
|
||||
rules:
|
||||
- host: whoami.test
|
||||
http:
|
||||
paths:
|
||||
- path: /whoami
|
||||
backend:
|
||||
serviceName: whoami
|
||||
servicePort: http
|
18
integration/fixtures/k8s/03-ingressroute.yml
Normal file
18
integration/fixtures/k8s/03-ingressroute.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: test.crd
|
||||
namespace: default
|
||||
|
||||
spec:
|
||||
entrypoints:
|
||||
- web
|
||||
|
||||
routes:
|
||||
- match: Host(`foo.com`) && PathPrefix(`/bar`)
|
||||
kind: Rule
|
||||
priority: 12
|
||||
services:
|
||||
- name: whoami
|
||||
port: 80
|
||||
|
29
integration/fixtures/k8s/04-ingressroute.yml
Normal file
29
integration/fixtures/k8s/04-ingressroute.yml
Normal file
|
@ -0,0 +1,29 @@
|
|||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: Middleware
|
||||
metadata:
|
||||
name: stripprefix
|
||||
namespace: default
|
||||
|
||||
spec:
|
||||
stripprefix:
|
||||
prefixes:
|
||||
- /tobestripped
|
||||
|
||||
---
|
||||
apiVersion: traefik.containo.us/v1alpha1
|
||||
kind: IngressRoute
|
||||
metadata:
|
||||
name: test2.crd
|
||||
namespace: default
|
||||
|
||||
spec:
|
||||
entrypoints:
|
||||
- web
|
||||
routes:
|
||||
- match: Host(`foo.com`) && PathPrefix(`/tobestripped`)
|
||||
kind: Rule
|
||||
services:
|
||||
- name: whoami
|
||||
port: 80
|
||||
middlewares:
|
||||
- name: stripprefix
|
11
integration/fixtures/k8s_crd.toml
Normal file
11
integration/fixtures/k8s_crd.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[global]
|
||||
debug=true
|
||||
|
||||
[entryPoints]
|
||||
[entryPoints.web]
|
||||
address = ":8000"
|
||||
|
||||
[api]
|
||||
|
||||
[Providers]
|
||||
[Providers.KubernetesCRD]
|
|
@ -2,7 +2,7 @@
|
|||
debug=true
|
||||
|
||||
[entryPoints]
|
||||
[entryPoints.http]
|
||||
[entryPoints.web]
|
||||
address = ":8000"
|
||||
|
||||
[api]
|
||||
|
|
|
@ -73,7 +73,7 @@ func init() {
|
|||
}
|
||||
if *host {
|
||||
// tests launched from the host
|
||||
// check.Suite(&K8sSuite{})
|
||||
check.Suite(&K8sSuite{})
|
||||
check.Suite(&ProxyProtocolSuite{})
|
||||
check.Suite(&TCPSuite{})
|
||||
// FIXME Provider tests
|
||||
|
|
|
@ -1,81 +1,27 @@
|
|||
package integration
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containous/traefik/integration/try"
|
||||
"github.com/containous/traefik/log"
|
||||
"github.com/containous/traefik/testhelpers"
|
||||
"github.com/go-check/check"
|
||||
checker "github.com/vdemeester/shakers"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
v1beta12 "k8s.io/api/extensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
// K8sSuite
|
||||
type K8sSuite struct{ BaseSuite }
|
||||
|
||||
const (
|
||||
kubeServer = "https://127.0.0.1:6443"
|
||||
namespace = "default"
|
||||
)
|
||||
|
||||
func (s *K8sSuite) SetUpSuite(c *check.C) {
|
||||
s.createComposeProject(c, "k8s")
|
||||
s.composeProject.Start(c)
|
||||
}
|
||||
|
||||
func (s *K8sSuite) TearDownSuite(c *check.C) {
|
||||
s.composeProject.Stop(c)
|
||||
os.Remove("./resources/compose/output/kubeconfig.yaml")
|
||||
}
|
||||
|
||||
func parseK8sYaml(fileR []byte) []runtime.Object {
|
||||
acceptedK8sTypes := regexp.MustCompile(`(Deployment|Service|Ingress)`)
|
||||
sepYamlfiles := strings.Split(string(fileR), "---")
|
||||
retVal := make([]runtime.Object, 0, len(sepYamlfiles))
|
||||
for _, f := range sepYamlfiles {
|
||||
if f == "\n" || f == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
decode := scheme.Codecs.UniversalDeserializer().Decode
|
||||
obj, groupVersionKind, err := decode([]byte(f), nil, nil)
|
||||
|
||||
if err != nil {
|
||||
log.WithoutContext().Debugf("Error while decoding YAML object. Err was: %s", err)
|
||||
continue
|
||||
}
|
||||
|
||||
if !acceptedK8sTypes.MatchString(groupVersionKind.Kind) {
|
||||
log.WithoutContext().Debugf("The custom-roles configMap contained K8s object types which are not supported! Skipping object with type: %s", groupVersionKind.Kind)
|
||||
} else {
|
||||
retVal = append(retVal, obj)
|
||||
}
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
func (s *K8sSuite) TestSimpleDefaultConfig(c *check.C) {
|
||||
req := testhelpers.MustNewRequest(http.MethodGet, kubeServer, nil)
|
||||
err := try.RequestWithTransport(req, time.Second*60, &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}, try.StatusCodeIs(http.StatusUnauthorized))
|
||||
abs, err := filepath.Abs("./fixtures/k8s/kubeconfig.yaml")
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
abs, err := filepath.Abs("./resources/compose/output/kubeconfig.yaml")
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.Do(time.Second*60, try.DoCondition(func() error {
|
||||
err = try.Do(60*time.Second, try.DoCondition(func() error {
|
||||
_, err := os.Stat(abs)
|
||||
return err
|
||||
}))
|
||||
|
@ -83,41 +29,54 @@ func (s *K8sSuite) TestSimpleDefaultConfig(c *check.C) {
|
|||
|
||||
err = os.Setenv("KUBECONFIG", abs)
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
||||
func (s *K8sSuite) TearDownSuite(c *check.C) {
|
||||
s.composeProject.Stop(c)
|
||||
|
||||
err := os.Remove("./fixtures/k8s/kubeconfig.yaml")
|
||||
if err != nil {
|
||||
c.Log(err)
|
||||
}
|
||||
err = os.Remove("./fixtures/k8s/coredns.yaml")
|
||||
if err != nil {
|
||||
c.Log(err)
|
||||
}
|
||||
err = os.Remove("./fixtures/k8s/traefik.yaml")
|
||||
if err != nil {
|
||||
c.Log(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *K8sSuite) TestIngressSimple(c *check.C) {
|
||||
cmd, display := s.traefikCmd(withConfigFile("fixtures/k8s_default.toml"))
|
||||
defer display(c)
|
||||
|
||||
err = cmd.Start()
|
||||
err := cmd.Start()
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
config, err := clientcmd.BuildConfigFromFlags("", abs)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
clientset, err := kubernetes.NewForConfig(config)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
yamlContent, err := ioutil.ReadFile("./fixtures/k8s/test.yml")
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
k8sObjects := parseK8sYaml(yamlContent)
|
||||
for _, obj := range k8sObjects {
|
||||
switch o := obj.(type) {
|
||||
case *v1beta12.Deployment:
|
||||
_, err := clientset.ExtensionsV1beta1().Deployments(namespace).Create(o)
|
||||
c.Assert(err, checker.IsNil)
|
||||
case *v1.Service:
|
||||
_, err := clientset.CoreV1().Services(namespace).Create(o)
|
||||
c.Assert(err, checker.IsNil)
|
||||
case *v1beta12.Ingress:
|
||||
_, err := clientset.ExtensionsV1beta1().Ingresses(namespace).Create(o)
|
||||
c.Assert(err, checker.IsNil)
|
||||
default:
|
||||
log.WithoutContext().Errorf("Unknown runtime object %+v %T", o, o)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8080/api/providers/kubernetes/routers", 60*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("Host(`whoami.test`)"))
|
||||
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 60*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("Host(`whoami.test`)"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
||||
func (s *K8sSuite) TestCRDSimple(c *check.C) {
|
||||
cmd, display := s.traefikCmd(withConfigFile("fixtures/k8s_crd.toml"))
|
||||
defer display(c)
|
||||
|
||||
err := cmd.Start()
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 60*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("Host(`foo.com`)"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 1*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("PathPrefix(`/tobestripped`)"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8080/api/providers/kubernetescrd/routers", 1*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("default/stripprefix"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.GetRequest("http://127.0.0.1:8080/api/providers/kubernetescrd/middlewares", 1*time.Second, try.StatusCodeIs(http.StatusOK), try.BodyContains("stripprefix"))
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
|
1
integration/resources/compose/.gitignore
vendored
Normal file
1
integration/resources/compose/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
output/
|
|
@ -1,17 +1,18 @@
|
|||
server:
|
||||
image: rancher/k3s:v0.2.0-rc4
|
||||
command: server --disable-agent
|
||||
image: rancher/k3s:v0.2.0
|
||||
command: server --disable-agent --no-deploy traefik
|
||||
environment:
|
||||
- K3S_CLUSTER_SECRET=somethingtotallyrandom
|
||||
- K3S_KUBECONFIG_OUTPUT=/output/kubeconfig.yaml
|
||||
- K3S_KUBECONFIG_MODE=666
|
||||
volumes:
|
||||
- ./output:/output
|
||||
- ../../fixtures/k8s:/output
|
||||
- ../../fixtures/k8s:/var/lib/rancher/k3s/server/manifests
|
||||
ports:
|
||||
- 6443:6443
|
||||
|
||||
node:
|
||||
image: rancher/k3s:v0.2.0-rc4
|
||||
image: rancher/k3s:v0.2.0
|
||||
privileged: true
|
||||
links:
|
||||
- server
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue