Skip to content

Commit

Permalink
test: support ApisixRoute v2 and split suit-plugins (#1103)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlinsRan authored Jul 1, 2022
1 parent 810f1a1 commit 4aa2ca5
Show file tree
Hide file tree
Showing 64 changed files with 5,524 additions and 5,357 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
- name: List test suites and set the matrix
id: set-matrix
run: |
SUITES=($(find test/e2e -type d -iname 'suite-*' | grep -E -o '(\w|\-)*' | grep -v 'test' | grep -v 'e2e'))
SUITES=($(find test/e2e -type d -iname 'suite-*' | grep -E -o '(\w|\-)*' | grep -v 'test' | grep -v 'e2e' | sort | uniq))
echo $SUITES
echo "::set-output name=matrix::$(jq --compact-output --null-input '$ARGS.positional' --args "${SUITES[@]}")"
outputs:
Expand Down
17 changes: 17 additions & 0 deletions pkg/ingress/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ func (c *Controller) recordStatus(at interface{}, reason string, err error, stat
)
}
}
case *configv2.ApisixRoute:
// set to status
if v.Status.Conditions == nil {
conditions := make([]metav1.Condition, 0)
v.Status.Conditions = conditions
}
if c.verifyGeneration(&v.Status.Conditions, condition) {
meta.SetStatusCondition(&v.Status.Conditions, condition)
if _, errRecord := client.ApisixV2().ApisixRoutes(v.Namespace).
UpdateStatus(context.TODO(), v, metav1.UpdateOptions{}); errRecord != nil {
log.Errorw("failed to record status change for ApisixRoute",
zap.Error(errRecord),
zap.String("name", v.Name),
zap.String("namespace", v.Namespace),
)
}
}
case *configv2beta2.ApisixRoute:
// set to status
if v.Status.Conditions == nil {
Expand Down
12 changes: 12 additions & 0 deletions samples/deploy/crd/v1/ApisixRoute.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,23 @@ spec:
enum:
- "basicAuth"
- "keyAuth"
- "jwtAuth"
- "wolfRBAC"
- "hmacAuth"
keyAuth:
type: object
properties:
header:
type: string
jwtAuth:
type: object
properties:
header:
type: string
query:
type: string
cookie:
type: string
required:
- enable
stream:
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import (
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-features"
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-gateway"
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-ingress"
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins"
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins-all/suite-plugins-general"
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins-all/suite-plugins-other"
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins-all/suite-plugins-security"
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins-all/suite-plugins-traffic"
_ "github.com/apache/apisix-ingress-controller/test/e2e/suite-plugins-all/suite-plugins-transformation"
)

func runE2E() {}
19 changes: 4 additions & 15 deletions test/e2e/scaffold/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
package scaffold

import (
"errors"
"fmt"
"strings"
)

var (
Expand Down Expand Up @@ -70,29 +68,20 @@ spec:

func (s *Scaffold) ApisixConsumerBasicAuthCreated(name, username, password string) error {
ac := fmt.Sprintf(_apisixConsumerBasicAuth, s.opts.APISIXConsumerVersion, name, username, password)
return s.CreateResourceFromString(ac)
return s.CreateVersionedApisixResource(ac)
}

func (s *Scaffold) ApisixConsumerBasicAuthSecretCreated(name, secret string) error {
ac := fmt.Sprintf(_apisixConsumerBasicAuthSecret, s.opts.APISIXConsumerVersion, name, secret)
return s.CreateResourceFromString(ac)
return s.CreateVersionedApisixResource(ac)
}

func (s *Scaffold) ApisixConsumerKeyAuthCreated(name, key string) error {
ac := fmt.Sprintf(_apisixConsumerKeyAuth, s.opts.APISIXConsumerVersion, name, key)
return s.CreateResourceFromString(ac)
return s.CreateVersionedApisixResource(ac)
}

func (s *Scaffold) ApisixConsumerKeyAuthSecretCreated(name, secret string) error {
ac := fmt.Sprintf(_apisixConsumerKeyAuthSecret, s.opts.APISIXConsumerVersion, name, secret)
return s.CreateResourceFromString(ac)
}

func (s *Scaffold) CreateVersionedApisixConsumer(yml string) error {
if !strings.Contains(yml, "kind: ApisixConsumer") {
return errors.New("not a ApisixConsumer")
}

ac := s.replaceApiVersion(yml, s.opts.APISIXConsumerVersion)
return s.CreateResourceFromString(ac)
return s.CreateVersionedApisixResource(ac)
}
3 changes: 2 additions & 1 deletion test/e2e/scaffold/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ spec:
initContainers:
- name: wait-apisix-admin
image: localhost:5000/busybox:1.28
imagePullPolicy: IfNotPresent
command: ['sh', '-c', "until nc -z apisix-service-e2e-test.%s.svc.cluster.local 9180 ; do echo waiting for apisix-admin; sleep 2; done;"]
containers:
- livenessProbe:
Expand Down Expand Up @@ -263,7 +264,7 @@ spec:
fieldRef:
fieldPath: metadata.name
image: "localhost:5000/apache/apisix-ingress-controller:dev"
imagePullPolicy: Always
imagePullPolicy: IfNotPresent
name: ingress-apisix-controller-deployment-e2e-test
ports:
- containerPort: 8080
Expand Down
153 changes: 106 additions & 47 deletions test/e2e/scaffold/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Options struct {
disableNamespaceSelector bool
ApisixResourceSyncInterval string
EnableGatewayAPI bool
ApisixResourceVersion string
}

type Scaffold struct {
Expand All @@ -89,6 +90,18 @@ type Scaffold struct {
EtcdServiceFQDN string
}

type apisixResourceVersionInfo struct {
V2 string
V2beta3 string
}

var (
apisixResourceVersion = &apisixResourceVersionInfo{
V2: "apisix.apache.org/v2",
V2beta3: "apisix.apache.org/v2beta3",
}
)

// GetKubeconfig returns the kubeconfig file path.
// Order:
// env KUBECONFIG;
Expand All @@ -111,20 +124,38 @@ func GetKubeconfig() string {

// NewScaffold creates an e2e test scaffold.
func NewScaffold(o *Options) *Scaffold {
if o.APISIXRouteVersion == "" {
o.APISIXRouteVersion = kube.ApisixRouteV2beta3
}
if o.APISIXTlsVersion == "" {
o.APISIXTlsVersion = config.ApisixV2beta3
}
if o.APISIXConsumerVersion == "" {
o.APISIXConsumerVersion = config.ApisixV2beta3
}
if o.ApisixPluginConfigVersion == "" {
o.ApisixPluginConfigVersion = config.ApisixV2beta3
}
if o.APISIXClusterConfigVersion == "" {
o.APISIXClusterConfigVersion = config.ApisixV2beta3
if o.ApisixResourceVersion == ApisixResourceVersion().V2 {
if o.APISIXRouteVersion == "" {
o.APISIXRouteVersion = kube.ApisixRouteV2
}
if o.APISIXTlsVersion == "" {
o.APISIXTlsVersion = config.ApisixV2
}
if o.APISIXConsumerVersion == "" {
o.APISIXConsumerVersion = config.ApisixV2
}
if o.ApisixPluginConfigVersion == "" {
o.ApisixPluginConfigVersion = config.ApisixV2
}
if o.APISIXClusterConfigVersion == "" {
o.APISIXClusterConfigVersion = config.ApisixV2
}
} else {
if o.APISIXRouteVersion == "" {
o.APISIXRouteVersion = kube.ApisixRouteV2beta3
}
if o.APISIXTlsVersion == "" {
o.APISIXTlsVersion = config.ApisixV2beta3
}
if o.APISIXConsumerVersion == "" {
o.APISIXConsumerVersion = config.ApisixV2beta3
}
if o.ApisixPluginConfigVersion == "" {
o.ApisixPluginConfigVersion = config.ApisixV2beta3
}
if o.APISIXClusterConfigVersion == "" {
o.APISIXClusterConfigVersion = config.ApisixV2beta3
}
}
if o.APISIXAdminAPIKey == "" {
o.APISIXAdminAPIKey = "edd1c9f034335f136f87ad84b625c8f1"
Expand All @@ -148,39 +179,31 @@ func NewScaffold(o *Options) *Scaffold {
// NewDefaultScaffold creates a scaffold with some default options.
func NewDefaultScaffold() *Scaffold {
opts := &Options{
Name: "default",
Kubeconfig: GetKubeconfig(),
APISIXConfigPath: "testdata/apisix-gw-config.yaml",
IngressAPISIXReplicas: 1,
HTTPBinServicePort: 80,
APISIXRouteVersion: kube.ApisixRouteV2beta3,
APISIXTlsVersion: config.ApisixV2beta3,
APISIXConsumerVersion: config.ApisixV2beta3,
ApisixPluginConfigVersion: config.ApisixV2beta3,
APISIXClusterConfigVersion: config.ApisixV2beta3,
EnableWebhooks: false,
APISIXPublishAddress: "",
EnableGatewayAPI: true,
Name: "default",
Kubeconfig: GetKubeconfig(),
APISIXConfigPath: "testdata/apisix-gw-config.yaml",
IngressAPISIXReplicas: 1,
HTTPBinServicePort: 80,
ApisixResourceVersion: ApisixResourceVersion().V2beta3,
EnableWebhooks: false,
APISIXPublishAddress: "",
EnableGatewayAPI: true,
}
return NewScaffold(opts)
}

// NewDefaultV2Scaffold creates a scaffold with some default options.
func NewDefaultV2Scaffold() *Scaffold {
opts := &Options{
Name: "default",
Kubeconfig: GetKubeconfig(),
APISIXConfigPath: "testdata/apisix-gw-config.yaml",
IngressAPISIXReplicas: 1,
HTTPBinServicePort: 80,
APISIXRouteVersion: kube.ApisixRouteV2,
APISIXTlsVersion: config.ApisixV2,
APISIXConsumerVersion: config.ApisixV2,
ApisixPluginConfigVersion: config.ApisixV2,
APISIXClusterConfigVersion: config.ApisixV2,
EnableWebhooks: false,
APISIXPublishAddress: "",
EnableGatewayAPI: true,
Name: "default",
Kubeconfig: GetKubeconfig(),
APISIXConfigPath: "testdata/apisix-gw-config.yaml",
IngressAPISIXReplicas: 1,
HTTPBinServicePort: 80,
ApisixResourceVersion: ApisixResourceVersion().V2,
EnableWebhooks: false,
APISIXPublishAddress: "",
EnableGatewayAPI: true,
}
return NewScaffold(opts)
}
Expand Down Expand Up @@ -541,12 +564,19 @@ func (s *Scaffold) FormatNamespaceLabel(label string) string {

var (
versionRegex = regexp.MustCompile(`apiVersion: apisix.apache.org/v.*?\n`)
kindRegex = regexp.MustCompile(`kind: .*?\n`)
)

func (s *Scaffold) replaceApiVersion(yml, ver string) string {
return versionRegex.ReplaceAllString(yml, "apiVersion: "+ver+"\n")
}

func (s *Scaffold) getKindValue(yml string) string {
kind := strings.Replace(kindRegex.FindString(yml), "\n", "", -1)
kindValue := strings.Replace(kind, "kind: ", "", -1)
return kindValue
}

func (s *Scaffold) DisableNamespaceSelector() {
s.opts.disableNamespaceSelector = true
}
Expand Down Expand Up @@ -583,11 +613,40 @@ func (s *Scaffold) CreateVersionedApisixPluginConfig(yml string) error {
return s.CreateResourceFromString(ac)
}

func (s *Scaffold) CreateVersionedApisixRoute(yml string) error {
if !strings.Contains(yml, "kind: ApisixRoute") {
return errors.New("not a ApisixRoute")
}

ac := s.replaceApiVersion(yml, s.opts.APISIXRouteVersion)
return s.CreateResourceFromString(ac)
func (s *Scaffold) CreateVersionedApisixResource(yml string) error {
kindValue := s.getKindValue(yml)
switch kindValue {
case "ApisixRoute":
ar := s.replaceApiVersion(yml, s.opts.APISIXRouteVersion)
return s.CreateResourceFromString(ar)
case "ApisixConsumer":
ac := s.replaceApiVersion(yml, s.opts.APISIXConsumerVersion)
return s.CreateResourceFromString(ac)
case "ApisixPluginConfig":
apc := s.replaceApiVersion(yml, s.opts.ApisixPluginConfigVersion)
return s.CreateResourceFromString(apc)
}
errString := fmt.Sprint("the resource ", kindValue, " does not support")
return errors.New(errString)
}

func (s *Scaffold) CreateVersionedApisixResourceWithNamespace(yml, namespace string) error {
kindValue := s.getKindValue(yml)
switch kindValue {
case "ApisixRoute":
ar := s.replaceApiVersion(yml, s.opts.APISIXRouteVersion)
return s.CreateResourceFromStringWithNamespace(ar, namespace)
case "ApisixConsumer":
ac := s.replaceApiVersion(yml, s.opts.APISIXConsumerVersion)
return s.CreateResourceFromStringWithNamespace(ac, namespace)
case "ApisixPluginConfig":
apc := s.replaceApiVersion(yml, s.opts.ApisixPluginConfigVersion)
return s.CreateResourceFromStringWithNamespace(apc, namespace)
}
errString := fmt.Sprint("the resource ", kindValue, " does not support")
return errors.New(errString)
}

func ApisixResourceVersion() *apisixResourceVersionInfo {
return apisixResourceVersion
}
Loading

0 comments on commit 4aa2ca5

Please sign in to comment.