validate if its an ARN

This commit is contained in:
João Carreira
2020-11-19 16:19:16 +00:00
parent 9667664853
commit e149125eaa
3 changed files with 21 additions and 8 deletions
+3 -1
View File
@@ -57,7 +57,9 @@ type VirtualServiceReference struct {
// +optional
Namespace *string `json:"namespace,omitempty"`
// Name is the name of VirtualService CR
Name string `json:"name"`
Name string `json:"name,omitempty"`
// ARN of the AWS VirtualService CR
ARN string `json:"virtualServiceARN,omitempty"`
}
// VirtualRouterReference holds a reference to VirtualRouter.appmesh.k8s.aws
+16 -5
View File
@@ -104,12 +104,23 @@ func (ar *AppMeshv1beta2Router) reconcileVirtualNode(canary *flaggerv1.Canary, n
backends := make([]appmeshv1.Backend, 0)
for _, b := range canary.Spec.Service.Backends {
bk := appmeshv1.Backend{
VirtualService: appmeshv1.VirtualServiceBackend{
VirtualServiceRef: appmeshv1.VirtualServiceReference{
Name: b,
var bk appmeshv1.Backend
if b[:6] == "arn:aws" {
bk = appmeshv1.Backend{
VirtualService: appmeshv1.VirtualServiceBackend{
VirtualServiceRef: appmeshv1.VirtualServiceReference{
ARN: b,
},
},
},
}
} else {
bk = appmeshv1.Backend{
VirtualService: appmeshv1.VirtualServiceBackend{
VirtualServiceRef: appmeshv1.VirtualServiceReference{
Name: b,
},
},
}
}
backends = append(backends, bk)
}
+2 -2
View File
@@ -66,7 +66,7 @@ func TestAppmeshv1beta2Router_Reconcile(t *testing.T) {
cdClone := cd.DeepCopy()
backends := cdClone.Spec.Service.Backends
backends = append(backends, "test.example.com")
backends = append(backends, "test.example.com", "arn:aws:appmesh:eu-west-1:12345678910:mesh/my-mesh/virtualService/mytestservice")
cdClone.Spec.Service.Backends = backends
canary, err := mocks.flaggerClient.FlaggerV1beta1().Canaries("default").Update(context.TODO(), cdClone, metav1.UpdateOptions{})
require.NoError(t, err)
@@ -78,7 +78,7 @@ func TestAppmeshv1beta2Router_Reconcile(t *testing.T) {
// verify
vnPrimary, err = router.appmeshClient.AppmeshV1beta2().VirtualNodes("default").Get(context.TODO(), primaryName, metav1.GetOptions{})
require.NoError(t, err)
require.Len(t, vnPrimary.Spec.Backends, 2)
require.Len(t, vnPrimary.Spec.Backends, 3)
// update URI
vrClone := vrApex.DeepCopy()