mirror of
https://github.com/fluxcd/flagger.git
synced 2026-04-15 06:57:34 +00:00
Add AppMesh timeout unit test
This commit is contained in:
@@ -452,6 +452,19 @@ func (ar *AppMeshv1beta2Router) SetRoutes(
|
||||
return nil
|
||||
}
|
||||
|
||||
// getTimeout converts the Canary.Service.Timeout to AppMesh Duration
|
||||
func (ar *AppMeshv1beta2Router) getTimeout(canary *flaggerv1.Canary) *appmeshv1.Duration {
|
||||
if canary.Spec.Service.Timeout != "" {
|
||||
if d, err := time.ParseDuration(canary.Spec.Service.Timeout); err == nil {
|
||||
return &appmeshv1.Duration{
|
||||
Unit: appmeshv1.DurationUnitMS,
|
||||
Value: d.Milliseconds(),
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// makeRouteTimeout creates an AppMesh HTTPTimeout from the Canary.Service.Timeout
|
||||
func (ar *AppMeshv1beta2Router) makeRouteTimeout(canary *flaggerv1.Canary) *appmeshv1.HTTPTimeout {
|
||||
if timeout := ar.getTimeout(canary); timeout != nil {
|
||||
@@ -543,24 +556,6 @@ func (ar *AppMeshv1beta2Router) getContainerPort(canary *flaggerv1.Canary) appme
|
||||
return appmeshv1.PortNumber(containerPort)
|
||||
}
|
||||
|
||||
// getTimeout converts the Canary.Service.Timeout to AppMesh Duration
|
||||
func (ar *AppMeshv1beta2Router) getTimeout(canary *flaggerv1.Canary) *appmeshv1.Duration {
|
||||
if canary.Spec.Service.Timeout != "" {
|
||||
timeout := int64(1500)
|
||||
if d, err := time.ParseDuration(canary.Spec.Service.Retries.PerTryTimeout); err == nil {
|
||||
timeout = d.Milliseconds()
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &appmeshv1.Duration{
|
||||
Unit: appmeshv1.DurationUnitMS,
|
||||
Value: timeout,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ar *AppMeshv1beta2Router) gatewayAnnotations(canary *flaggerv1.Canary) map[string]string {
|
||||
a := make(map[string]string)
|
||||
domains := ""
|
||||
|
||||
@@ -52,9 +52,14 @@ func TestAppmeshv1beta2Router_Reconcile(t *testing.T) {
|
||||
vnPrimary, err := router.appmeshClient.AppmeshV1beta2().VirtualNodes("default").Get(context.TODO(), primaryName, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
// check FQDN
|
||||
primaryDNS := fmt.Sprintf("%s.%s.svc.cluster.local.", primaryName, mocks.appmeshCanary.Namespace)
|
||||
assert.Equal(t, primaryDNS, vnPrimary.Spec.ServiceDiscovery.DNS.Hostname)
|
||||
|
||||
// check timeout
|
||||
assert.Equal(t, int64(30000), vrApex.Spec.Routes[0].HTTPRoute.Timeout.PerRequest.Value)
|
||||
assert.Equal(t, int64(30000), vnPrimary.Spec.Listeners[0].Timeout.HTTP.PerRequest.Value)
|
||||
|
||||
// test backends update
|
||||
cd, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Get(context.TODO(), mocks.appmeshCanary.Name, metav1.GetOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -152,7 +152,7 @@ func newTestCanaryAppMesh() *flaggerv1.Canary {
|
||||
MeshName: "global",
|
||||
Hosts: []string{"*"},
|
||||
Backends: []string{"backend.default"},
|
||||
Timeout: "25",
|
||||
Timeout: "30s",
|
||||
Retries: &istiov1alpha3.HTTPRetry{
|
||||
Attempts: 5,
|
||||
PerTryTimeout: "gateway-error",
|
||||
|
||||
Reference in New Issue
Block a user