Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Add Ambassador Preview (#524)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneutt authored Oct 2, 2020
1 parent baf124f commit 4622b26
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 10 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ addons/kibana/* @mesosphere/sig-ksphere-observability @mesosphere/sig-ksphere-ca
# Networking
addons/metallb/* @mesosphere/sig-ksphere-networking @mesosphere/sig-ksphere-catalog
addons/istio/* @mesosphere/sig-ksphere-networking @mesosphere/sig-ksphere-catalog
addons/ambassador/* @mesosphere/sig-ksphere-networking @mesosphere/sig-ksphere-catalog
49 changes: 49 additions & 0 deletions addons/ambassador/preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# ------------------------------------------------------------------------------
# PREVIEW: this addon is in preview mode and only intended for use in testing environments.
# ------------------------------------------------------------------------------
apiVersion: kubeaddons.mesosphere.io/v1beta2
kind: ClusterAddon
metadata:
name: ambassador
labels:
kubeaddons.mesosphere.io/name: ambassador
kubeaddons.mesosphere.io/provides: ingresscontroller
annotations:
catalog.kubeaddons.mesosphere.io/addon-revision: "6.5.6-1"
appversion.kubeaddons.mesosphere.io/ambassador: "1.7.2"
docs.kubeaddons.mesosphere.io/ambassador: "https://www.getambassador.io/docs/1.7/"
values.chart.helm.kubeaddons.mesosphere.io/ambassador: "https://raw.githubusercontent.com/datawire/ambassador-chart/d082fc2f2bc563726f5a940ad48b1b005fb85ef9/values.yaml"
spec:
kubernetes:
minSupportedVersion: v1.17.11
cloudProvider:
- name: aws
enabled: false
- name: gcp
enabled: false
- name: azure
enabled: false
- name: docker
enabled: false
- name: vsphere
enabled: false
# TODO: at the time of writing there are several changes in flight for our cert-manager addon and we're holding on cert-manager integration until a follow-up iteration
# requires:
# - matchLabels:
# kubeaddons.mesosphere.io/name: cert-manager
chartReference:
chart: ambassador
repo: https://getambassador.io
version: 6.5.6
values: |
enableAES: false # use the OSS features
image:
repository: "datawire/ambassador" # use the OSS image
tag: 1.7.2
rbac:
create: true
resources:
limits:
cpu: 1000m
requests:
cpu: 500m
16 changes: 11 additions & 5 deletions test/addons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
"testing"

"github.com/blang/semver"
"github.com/mesosphere/ksphere-testing-framework/pkg/cluster/kind"
"sigs.k8s.io/kind/pkg/cluster"

volumetypes "github.com/docker/docker/api/types/volume"
docker "github.com/docker/docker/client"
"github.com/google/uuid"
testcluster "github.com/mesosphere/ksphere-testing-framework/pkg/cluster"
"github.com/mesosphere/ksphere-testing-framework/pkg/cluster/kind"
"github.com/mesosphere/ksphere-testing-framework/pkg/cluster/konvoy"
"github.com/mesosphere/ksphere-testing-framework/pkg/experimental"
testgroups "github.com/mesosphere/ksphere-testing-framework/pkg/groups"
testharness "github.com/mesosphere/ksphere-testing-framework/pkg/harness"
"github.com/mesosphere/kubeaddons/pkg/api/v1beta2"
"github.com/mesosphere/kubeaddons/pkg/catalog"
Expand All @@ -31,6 +30,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
"k8s.io/helm/pkg/chartutil"
"sigs.k8s.io/kind/pkg/apis/config/v1alpha4"
"sigs.k8s.io/kind/pkg/cluster"
)

const (
Expand Down Expand Up @@ -74,7 +74,7 @@ func init() {
}

fmt.Println("finding addon test groups...")
groups, err = experimental.AddonsForGroupsFile("groups.yaml", cat)
groups, err = testgroups.AddonsForGroupsFile("groups.yaml", cat)
if err != nil {
panic(err)
}
Expand All @@ -101,6 +101,12 @@ func TestGeneralGroup(t *testing.T) {
}
}

func TestAmbassadorGroup(t *testing.T) {
if err := testgroup(t, "ambassador", defaultKindestNodeImage, ambassadorChecker); err != nil {
t.Fatal(err)
}
}

func TestBackupsGroup(t *testing.T) {
if err := testgroup(t, "backups", defaultKindestNodeImage); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -306,7 +312,7 @@ func testgroup(t *testing.T, groupname string, version string, jobs ...clusterTe
return fmt.Errorf("revisions for addon %s are broken, previous revision %s is newer than current %s", newAddon.GetName(), oldVersion, newVersion)
}
if !newVersion.GT(oldVersion) {
t.Logf("skipping upgrade test for addon %s, it has not be updated", newAddon.GetName())
t.Logf("skipping upgrade test for addon %s, it has not been updated", newAddon.GetName())
continue
}

Expand Down
153 changes: 153 additions & 0 deletions test/ambassador_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package test

import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"testing"
"time"

ambassadorv2 "github.com/datawire/ambassador/pkg/api/getambassador.io/v2"
testcluster "github.com/mesosphere/ksphere-testing-framework/pkg/cluster"
testharness "github.com/mesosphere/ksphere-testing-framework/pkg/harness"
"github.com/mesosphere/kubeaddons/pkg/api/v1beta2"
"github.com/mesosphere/kubeaddons/pkg/constants"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
kscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
)

const waitForAmbassador = time.Minute * 1

func ambassadorChecker(t *testing.T, cluster testcluster.Cluster) testharness.Job {
return func(t *testing.T) error {
app := "quote"
ns := "default"

// create a test application to ensure proper connectivity
testDeployment := appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: app,
Namespace: ns,
},
Spec: appsv1.DeploymentSpec{
Replicas: pointer.Int32Ptr(1),
Selector: &metav1.LabelSelector{MatchLabels: map[string]string{"app": app}},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"app": app},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: "backend",
Image: "docker.io/datawire/quote:0.4.1",
Ports: []corev1.ContainerPort{{
Name: "http",
ContainerPort: 8080,
}}}}}}}}
deployment, err := cluster.Client().AppsV1().Deployments(ns).Create(context.TODO(), &testDeployment, metav1.CreateOptions{})
if err != nil {
t.Fatal(err)
}

// create the svc for the
testService := corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: app,
Namespace: ns,
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{{
Name: "http",
Port: 80,
TargetPort: intstr.FromInt(8080),
}},
Selector: map[string]string{
"app": deployment.Name,
}}}
svc, err := cluster.Client().CoreV1().Services(ns).Create(context.TODO(), &testService, metav1.CreateOptions{})
if err != nil {
t.Fatal(err)
}

// create a dynamic client for ambassador's API
scheme := k8sruntime.NewScheme()
if err := kscheme.AddToScheme(scheme); err != nil {
t.Fatal(err)
}
if err := ambassadorv2.AddToScheme(scheme); err != nil {
t.Fatal(err)
}
if err := v1beta2.AddToScheme(scheme); err != nil {
t.Fatal(err)
}
mapper, err := apiutil.NewDynamicRESTMapper(cluster.Config())
if err != nil {
t.Fatal(err)
}
c, err := client.New(cluster.Config(), client.Options{Scheme: scheme, Mapper: mapper})
if err != nil {
t.Fatal(err)
}

// create a mapping for traffic to the service
apptestMapping := ambassadorv2.Mapping{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-backend", app),
Namespace: ns,
},
Spec: ambassadorv2.MappingSpec{
Prefix: "/backend/",
Service: svc.Name,
}}
if err := c.Create(context.TODO(), &apptestMapping); err != nil {
t.Fatal(err)
}

// I've checked with upstream, even though there's a status available in the Mapping API, they don't use it since several
// versions ago, so for the time being we just give the mapping a reasonable amount of time to resolve.
time.Sleep(time.Second * 10)

// get the svc IP for ambassador
localport, stop, err := portForwardPodWithPrefix(cluster, constants.DefaultAddonNamespace, "ambassador", "8080")
if err != nil {
return fmt.Errorf("could not forward port to elasticsearch client pod: %s", err)
}
defer close(stop)

// make sure requests to the test application are successful
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/backend/", localport))
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Fatalf("expected 200 OK from ambassador backend, got %s", resp.Status)
}

// check the contents of the response
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
data := make(map[string]string)
if err := json.Unmarshal(b, &data); err != nil {
t.Fatal(err)
}
qotd, ok := data["quote"]
if !ok {
t.Fatalf("structure of output from test app did not include \"quote\" key: %+v", data)
}

t.Logf("INFO: ambassador tests complete, mapping connectivity verified! quote of the day is: %s", qotd)
return nil
}
}
5 changes: 4 additions & 1 deletion test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ replace (

require (
github.com/blang/semver v3.5.1+incompatible
github.com/datawire/ambassador v1.7.2
github.com/docker/docker v1.4.2-0.20200203170920-46ec8731fbce
github.com/google/uuid v1.1.2
github.com/mesosphere/ksphere-testing-framework v0.2.0
github.com/mesosphere/ksphere-testing-framework v0.2.1
github.com/mesosphere/kubeaddons v0.22.2
k8s.io/api v0.19.2
k8s.io/apimachinery v0.19.2
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/helm v2.16.12+incompatible
k8s.io/utils v0.0.0-20200729134348-d5654de09c73
sigs.k8s.io/controller-runtime v0.6.3
sigs.k8s.io/kind v0.9.0
)
Loading

0 comments on commit 4622b26

Please sign in to comment.