add gateway tests and change provider aname

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
This commit is contained in:
Sanskar Jaiswal
2022-03-10 16:54:36 +05:30
committed by Sanskar Jaiswal
parent 174e9fdc93
commit 00d54d268c
6 changed files with 154 additions and 5 deletions
+1 -1
View File
@@ -11,5 +11,5 @@ spec:
args:
- -log-level=debug
- -include-label-prefix=app.kubernetes.io
- -mesh-provider=gatewayapi
- -mesh-provider=gatewayapi:v1alpha2
- -metrics-server=http://flagger-prometheus:9090
+1 -1
View File
@@ -177,7 +177,7 @@ func (factory *Factory) MeshRouter(provider string, labelSelector string) Interf
kubeClient: factory.kubeClient,
kumaClient: factory.meshClient,
}
case provider == flaggerv1.GatewayAPIProvider:
case strings.HasPrefix(provider, flaggerv1.GatewayAPIProvider):
return &GatewayAPIRouter{
logger: factory.logger,
kubeClient: factory.kubeClient,
+72
View File
@@ -0,0 +1,72 @@
/*
Copyright 2020 The Flux authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package router
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestGatewayAPIRouter_Reconcile(t *testing.T) {
canary := newTestGatewayAPICanary()
mocks := newFixture(canary)
router := &GatewayAPIRouter{
gatewayAPIClient: mocks.meshClient,
kubeClient: mocks.kubeClient,
logger: mocks.logger,
}
err := router.Reconcile(canary)
require.NoError(t, err)
httpRoute, err := router.gatewayAPIClient.GatewayapiV1alpha2().HTTPRoutes("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})
require.NoError(t, err)
routeRules := httpRoute.Spec.Rules
require.Equal(t, len(routeRules), 1)
backendRefs := routeRules[0].BackendRefs
require.Equal(t, len(backendRefs), 2)
assert.Equal(t, int32(100), *backendRefs[0].Weight)
assert.Equal(t, int32(0), *backendRefs[1].Weight)
}
func TestGatewayAPIRouter_Routes(t *testing.T) {
canary := newTestGatewayAPICanary()
mocks := newFixture(canary)
router := &GatewayAPIRouter{
gatewayAPIClient: mocks.meshClient,
kubeClient: mocks.kubeClient,
logger: mocks.logger,
}
err := router.Reconcile(canary)
require.NoError(t, err)
err = router.SetRoutes(canary, 50, 50, false)
require.NoError(t, err)
httpRoute, err := router.gatewayAPIClient.GatewayapiV1alpha2().HTTPRoutes("default").Get(context.TODO(), "podinfo", metav1.GetOptions{})
require.NoError(t, err)
primary := httpRoute.Spec.Rules[0].BackendRefs[0]
assert.Equal(t, int32(50), *primary.Weight)
}
+74
View File
@@ -27,6 +27,7 @@ import (
"k8s.io/client-go/kubernetes/fake"
flaggerv1 "github.com/fluxcd/flagger/pkg/apis/flagger/v1beta1"
"github.com/fluxcd/flagger/pkg/apis/gatewayapi/v1alpha2"
istiov1alpha1 "github.com/fluxcd/flagger/pkg/apis/istio/common/v1alpha1"
istiov1alpha3 "github.com/fluxcd/flagger/pkg/apis/istio/v1alpha3"
clientset "github.com/fluxcd/flagger/pkg/client/clientset/versioned"
@@ -65,6 +66,7 @@ func newFixture(c *flaggerv1.Canary) fixture {
newTestDeployment(),
newTestABTestDeployment(),
newTestIngress(),
newTestGateway(),
)
meshClient := fakeFlagger.NewSimpleClientset()
@@ -477,3 +479,75 @@ func newTestIngress() *netv1.Ingress {
},
}
}
func newTestGatewayAPICanary() *flaggerv1.Canary {
cd := &flaggerv1.Canary{
TypeMeta: metav1.TypeMeta{APIVersion: flaggerv1.SchemeGroupVersion.String()},
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "podinfo",
},
Spec: flaggerv1.CanarySpec{
TargetRef: flaggerv1.CrossNamespaceObjectReference{
Name: "podinfo",
APIVersion: "apps/v1",
Kind: "Deployment",
},
Service: flaggerv1.CanaryService{
Name: "podinfo",
Port: 80,
PortName: "http",
TargetPort: intstr.IntOrString{
Type: 0,
IntVal: 9898,
},
PortDiscovery: true,
GatewayRefs: []v1alpha2.ParentReference{
{
Name: "podinfo",
},
},
},
Analysis: &flaggerv1.CanaryAnalysis{
Threshold: 10,
StepWeight: 10,
MaxWeight: 50,
Metrics: []flaggerv1.CanaryMetric{
{
Name: "request-success-rate",
Threshold: 99,
Interval: "1m",
},
{
Name: "request-duration",
Threshold: 500,
Interval: "1m",
},
},
},
},
}
return cd
}
func newTestGateway() *v1alpha2.Gateway {
hostName := v1alpha2.Hostname("app.example.com")
gw := &v1alpha2.Gateway{
TypeMeta: metav1.TypeMeta{APIVersion: v1alpha2.SchemeGroupVersion.String()},
ObjectMeta: metav1.ObjectMeta{
Namespace: "default",
Name: "podinfo",
},
Spec: v1alpha2.GatewaySpec{
GatewayClassName: "example",
Listeners: []v1alpha2.Listener{
{
Hostname: &hostName,
Name: "http",
Port: 80,
},
},
},
}
return gw
}
+5 -2
View File
@@ -12,8 +12,11 @@ ARCH=$(arch)
mkdir -p ${REPO_ROOT}/bin
echo ">>> Installing Contour ${CONTOUR_VER}, Gateway API components ${GATEWAY_API_VER}"
cd ${REPO_ROOT}/bin && \
kubectl apply -f https://raw.githubusercontent.com/projectcontour/contour/${CONTOUR_VER}/examples/render/contour-gateway.yaml
# retry if it fails, creating a gateway object is flaky sometimes
until cd ${REPO_ROOT}/bin && kubectl apply -f \
https://raw.githubusercontent.com/projectcontour/contour/${CONTOUR_VER}/examples/render/contour-gateway.yaml; do
sleep 1
done
kubectl -n projectcontour rollout status deployment/contour
kubectl -n projectcontour get all
+1 -1
View File
@@ -11,5 +11,5 @@ spec:
args:
- -log-level=debug
- -include-label-prefix=app.kubernetes.io
- -mesh-provider=gatewayapi
- -mesh-provider=gatewayapi:v1alpha2
- -metrics-server=http://flagger-prometheus:9090