Skip to content

Commit

Permalink
add e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonig committed Feb 18, 2023
1 parent e68014c commit 91c3564
Show file tree
Hide file tree
Showing 6 changed files with 485 additions and 7 deletions.
51 changes: 51 additions & 0 deletions examples/global-external-auth/01-authserver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: testserver
labels:
app.kubernetes.io/name: testserver
spec:
selector:
matchLabels:
app.kubernetes.io/name: testserver
replicas: 1
template:
metadata:
labels:
app.kubernetes.io/name: testserver
spec:
containers:
- name: testserver
image: docker.io/projectcontour/contour-authserver:v2
imagePullPolicy: IfNotPresent
command:
- /contour-authserver
args:
- testserver
- --address=:9443
ports:
- name: auth
containerPort: 9443
protocol: TCP
resources:
limits:
cpu: 100m
memory: 30Mi

---

apiVersion: v1
kind: Service
metadata:
name: testserver
labels:
app.kubernetes.io/name: testserver
spec:
ports:
- name: auth
protocol: TCP
port: 9443
targetPort: 9443
selector:
app.kubernetes.io/name: testserver
type: ClusterIP
12 changes: 12 additions & 0 deletions examples/global-external-auth/02-globalextauth-extsvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: projectcontour.io/v1alpha1
kind: ExtensionService
metadata:
namespace: projectcontour
name: testserver
spec:
protocol: h2c
services:
- name: testserver
port: 9443
timeoutPolicy:
response: 100ms
11 changes: 11 additions & 0 deletions examples/global-external-auth/03-contour-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: contour
namespace: projectcontour
data:
contour.yaml: |
rateLimitService:
extensionService: projectcontour/ratelimit
domain: contour
failOpen: false
67 changes: 63 additions & 4 deletions test/e2e/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build e2e
// +build e2e

package e2e

import (
Expand Down Expand Up @@ -108,6 +105,11 @@ type Deployment struct {
RateLimitDeployment *apps_v1.Deployment
RateLimitService *v1.Service
RateLimitExtensionService *contour_api_v1alpha1.ExtensionService

// // Global External Authorization deployment.
GlobalExtAuthDeployment *apps_v1.Deployment
GlobalExtAuthService *v1.Service
GlobalExtAuthExtensionService *contour_api_v1alpha1.ExtensionService
}

// UnmarshalResources unmarshals resources from rendered Contour manifest in
Expand Down Expand Up @@ -197,6 +199,7 @@ func (d *Deployment) UnmarshalResources() error {
}
}

// ratelimit
rateLimitExamplePath := filepath.Join(filepath.Dir(thisFile), "..", "..", "examples", "ratelimit")
rateLimitDeploymentFile := filepath.Join(rateLimitExamplePath, "02-ratelimit.yaml")
rateLimitExtSvcFile := filepath.Join(rateLimitExamplePath, "03-ratelimit-extsvc.yaml")
Expand Down Expand Up @@ -224,7 +227,39 @@ func (d *Deployment) UnmarshalResources() error {
decoder = apimachinery_util_yaml.NewYAMLToJSONDecoder(rLESFile)
d.RateLimitExtensionService = new(contour_api_v1alpha1.ExtensionService)

return decoder.Decode(d.RateLimitExtensionService)
if err := decoder.Decode(d.RateLimitExtensionService); err != nil {
return err
}

// // Global external auth
globalExtAuthExamplePath := filepath.Join(filepath.Dir(thisFile), "..", "..", "examples", "global-external-auth")
globalExtAuthServerDeploymentFile := filepath.Join(globalExtAuthExamplePath, "01-authserver.yaml")
globalExtAuthExtSvcFile := filepath.Join(globalExtAuthExamplePath, "02-globalextauth-extsvc.yaml")

rGlobalExtAuthDeploymentFile, err := os.Open(globalExtAuthServerDeploymentFile)
if err != nil {
return err
}
defer rGlobalExtAuthDeploymentFile.Close()
decoder = apimachinery_util_yaml.NewYAMLToJSONDecoder(rGlobalExtAuthDeploymentFile)
d.GlobalExtAuthDeployment = new(apps_v1.Deployment)
if err := decoder.Decode(d.GlobalExtAuthDeployment); err != nil {
return err
}
d.GlobalExtAuthService = new(v1.Service)
if err := decoder.Decode(d.GlobalExtAuthService); err != nil {
return err
}

rGlobalExtAuthExtSvcFile, err := os.Open(globalExtAuthExtSvcFile)
if err != nil {
return err
}
defer rGlobalExtAuthExtSvcFile.Close()
decoder = apimachinery_util_yaml.NewYAMLToJSONDecoder(rGlobalExtAuthExtSvcFile)
d.GlobalExtAuthExtensionService = new(contour_api_v1alpha1.ExtensionService)

return decoder.Decode(d.GlobalExtAuthExtensionService)
}

// Common case of updating object if exists, create otherwise.
Expand Down Expand Up @@ -467,6 +502,30 @@ func (d *Deployment) EnsureRateLimitResources(namespace string, configContents s
return d.ensureResource(extSvc, new(contour_api_v1alpha1.ExtensionService))
}

func (d *Deployment) EnsureGlobalExternalAuthResources(namespace string) error {
setNamespace := d.Namespace.Name
if len(namespace) > 0 {
setNamespace = namespace
}

deployment := d.GlobalExtAuthDeployment.DeepCopy()
deployment.Namespace = setNamespace
if err := d.ensureResource(deployment, new(apps_v1.Deployment)); err != nil {
return err
}

service := d.GlobalExtAuthService.DeepCopy()
service.Namespace = setNamespace
if err := d.ensureResource(service, new(v1.Service)); err != nil {
return err
}

extSvc := d.GlobalExtAuthExtensionService.DeepCopy()
extSvc.Namespace = setNamespace

return d.ensureResource(extSvc, new(contour_api_v1alpha1.ExtensionService))
}

// Convenience method for deploying the pieces of the deployment needed for
// testing Contour running locally, out of cluster.
// Includes:
Expand Down
Loading

0 comments on commit 91c3564

Please sign in to comment.