Skip to content

Commit 74e75dc

Browse files
rakebMazhar Islam
andauthored
Backendgroup bug fix (#652)
* Added primary changes to fix the clienpolicy missing in VN spec * Bug fix: clientPolicy now can be added under backends, which previously does not get converted to AppMesh SDK spec * Bug fix: clientPolicy now can be added under backends, which previously does not get converted to AppMesh SDK spec * Bug fix: clientPolicy now can be added under backends, which previously does not get converted to AppMesh SDK spec Co-authored-by: Mazhar Islam <[email protected]>
1 parent ab15370 commit 74e75dc

File tree

2 files changed

+151
-48
lines changed

2 files changed

+151
-48
lines changed

pkg/virtualnode/resource_manager.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,10 @@ func BuildSDKVirtualNodeSpec(vn *appmesh.VirtualNode, vsByKey map[types.Namespac
345345
backendMap := make(map[types.NamespacedName]bool)
346346

347347
for _, backend := range tempSpec.Backends {
348-
vsKey := references.ObjectKeyForVirtualServiceReference(vn, *backend.VirtualService.VirtualServiceRef)
349-
backendMap[vsKey] = true
348+
if backend.VirtualService.VirtualServiceRef != nil {
349+
vsKey := references.ObjectKeyForVirtualServiceReference(vn, *backend.VirtualService.VirtualServiceRef)
350+
backendMap[vsKey] = true
351+
}
350352
}
351353

352354
for vsKey, vs := range vsByKey {

pkg/virtualnode/resource_manager_test.go

Lines changed: 147 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func Test_defaultResourceManager_findVirtualServiceDependencies(t *testing.T) {
505505
},
506506
},
507507
want: map[types.NamespacedName]*appmesh.VirtualService{types.NamespacedName{
508-
Namespace: "ns-1", Name: "vs-1"}: &appmesh.VirtualService{
508+
Namespace: "ns-1", Name: "vs-1"}: {
509509
ObjectMeta: metav1.ObjectMeta{
510510
Namespace: "ns-1",
511511
Name: "vs-1",
@@ -548,7 +548,7 @@ func Test_defaultResourceManager_findVirtualServiceDependencies(t *testing.T) {
548548
},
549549
},
550550
want: map[types.NamespacedName]*appmesh.VirtualService{types.NamespacedName{
551-
Namespace: "ns-1", Name: "vs-1"}: &appmesh.VirtualService{
551+
Namespace: "ns-1", Name: "vs-1"}: {
552552
ObjectMeta: metav1.ObjectMeta{
553553
Namespace: "ns-1",
554554
Name: "vs-1",
@@ -601,56 +601,157 @@ The reason behind that, the BuildSDKVirtualNodeSpec function will not modify the
601601
Backends. However, VirtualRouterServiceProvider will get wiped out because it is under key (ns-2/vs-2) and will be treated as flexible backend.
602602
*/
603603
func Test_BuildSDKVirtualNodeSpec(t *testing.T) {
604-
vn := &appmesh.VirtualNode{
605-
ObjectMeta: metav1.ObjectMeta{
606-
Name: "vn-1",
607-
},
608-
Spec: appmesh.VirtualNodeSpec{
609-
AWSName: aws.String("app1"),
610-
Backends: []appmesh.Backend{
611-
{
612-
VirtualService: appmesh.VirtualServiceBackend{
613-
VirtualServiceRef: &appmesh.VirtualServiceReference{
614-
Namespace: aws.String("ns-1"),
615-
Name: "vs-1",
604+
type args struct {
605+
vn *appmesh.VirtualNode
606+
vsByKey map[types.NamespacedName]*appmesh.VirtualService
607+
}
608+
tests := []struct {
609+
name string
610+
args args
611+
wantSDKObj *appmeshsdk.ClientPolicy
612+
wantErr error
613+
}{
614+
{
615+
name: "non nil TLS from vn backends spec having VirtualServiceRef",
616+
args: args{
617+
vn: &appmesh.VirtualNode{
618+
ObjectMeta: metav1.ObjectMeta{
619+
Name: "vn-1",
620+
},
621+
Spec: appmesh.VirtualNodeSpec{
622+
AWSName: aws.String("app1"),
623+
Backends: []appmesh.Backend{
624+
{
625+
VirtualService: appmesh.VirtualServiceBackend{
626+
VirtualServiceRef: &appmesh.VirtualServiceReference{
627+
Namespace: aws.String("ns-1"),
628+
Name: "vs-1",
629+
},
630+
ClientPolicy: &appmesh.ClientPolicy{
631+
TLS: &appmesh.ClientPolicyTLS{
632+
Enforce: aws.Bool(true),
633+
Ports: []appmesh.PortNumber{80, 443},
634+
Validation: appmesh.TLSValidationContext{
635+
Trust: appmesh.TLSValidationContextTrust{
636+
ACM: &appmesh.TLSValidationContextACMTrust{
637+
CertificateAuthorityARNs: []string{"arn-1", "arn-2"},
638+
},
639+
},
640+
},
641+
},
642+
},
643+
}}},
644+
},
645+
},
646+
vsByKey: map[types.NamespacedName]*appmesh.VirtualService{
647+
types.NamespacedName{Namespace: "ns-2", Name: "vs-2"}: {
648+
ObjectMeta: metav1.ObjectMeta{
649+
Namespace: "ns-2",
650+
Name: "vs-2",
616651
},
617-
ClientPolicy: &appmesh.ClientPolicy{
618-
TLS: &appmesh.ClientPolicyTLS{
619-
Enforce: aws.Bool(true),
652+
Spec: appmesh.VirtualServiceSpec{
653+
AWSName: aws.String("app2"),
654+
Provider: &appmesh.VirtualServiceProvider{
655+
VirtualRouter: &appmesh.VirtualRouterServiceProvider{
656+
VirtualRouterRef: &appmesh.VirtualRouterReference{
657+
Namespace: aws.String("ns-2"),
658+
Name: "vr-2",
659+
},
660+
},
661+
},
662+
}},
663+
types.NamespacedName{Namespace: "ns-1", Name: "vs-1"}: {},
664+
},
665+
},
666+
wantSDKObj: &appmeshsdk.ClientPolicy{
667+
Tls: &appmeshsdk.ClientPolicyTls{
668+
Enforce: aws.Bool(true),
669+
Ports: []*int64{aws.Int64(80), aws.Int64(443)},
670+
Validation: &appmeshsdk.TlsValidationContext{
671+
Trust: &appmeshsdk.TlsValidationContextTrust{
672+
Acm: &appmeshsdk.TlsValidationContextAcmTrust{
673+
CertificateAuthorityArns: []*string{aws.String("arn-1"), aws.String("arn-2")},
620674
},
621675
},
622-
}}},
623-
},
624-
}
625-
626-
vsByKey := map[types.NamespacedName]*appmesh.VirtualService{types.NamespacedName{
627-
Namespace: "ns-2", Name: "vs-2"}: &appmesh.VirtualService{
628-
ObjectMeta: metav1.ObjectMeta{
629-
Namespace: "ns-2",
630-
Name: "vs-2",
676+
},
677+
},
678+
},
679+
wantErr: nil,
631680
},
632-
Spec: appmesh.VirtualServiceSpec{
633-
AWSName: aws.String("app2"),
634-
Provider: &appmesh.VirtualServiceProvider{
635-
VirtualRouter: &appmesh.VirtualRouterServiceProvider{
636-
VirtualRouterRef: &appmesh.VirtualRouterReference{
637-
Namespace: aws.String("ns-2"),
638-
Name: "vr-2",
681+
{
682+
name: "non nil TLS from vn backends spec having VirtualServiceARN instead of VirtualServiceRef",
683+
args: args{
684+
vn: &appmesh.VirtualNode{
685+
ObjectMeta: metav1.ObjectMeta{
686+
Name: "vn-1",
687+
},
688+
Spec: appmesh.VirtualNodeSpec{
689+
AWSName: aws.String("app1"),
690+
Backends: []appmesh.Backend{
691+
{
692+
VirtualService: appmesh.VirtualServiceBackend{
693+
VirtualServiceARN: aws.String("arn:aws:appmesh:us-west-2:233846545377:mesh/howto-k8s-http2/virtualService/color.howto-k8s-http2.svc.cluster.local"),
694+
ClientPolicy: &appmesh.ClientPolicy{
695+
TLS: &appmesh.ClientPolicyTLS{
696+
Enforce: aws.Bool(true),
697+
Ports: []appmesh.PortNumber{80, 443},
698+
Validation: appmesh.TLSValidationContext{
699+
Trust: appmesh.TLSValidationContextTrust{
700+
ACM: &appmesh.TLSValidationContextACMTrust{
701+
CertificateAuthorityARNs: []string{"arn-1", "arn-2"},
702+
},
703+
},
704+
},
705+
},
706+
},
707+
}}},
708+
},
709+
},
710+
vsByKey: map[types.NamespacedName]*appmesh.VirtualService{
711+
types.NamespacedName{Namespace: "ns-2", Name: "vs-2"}: {
712+
ObjectMeta: metav1.ObjectMeta{
713+
Namespace: "ns-2",
714+
Name: "vs-2",
715+
},
716+
Spec: appmesh.VirtualServiceSpec{
717+
AWSName: aws.String("app2"),
718+
Provider: &appmesh.VirtualServiceProvider{
719+
VirtualRouter: &appmesh.VirtualRouterServiceProvider{
720+
VirtualRouterRef: &appmesh.VirtualRouterReference{
721+
Namespace: aws.String("ns-2"),
722+
Name: "vr-2",
723+
},
724+
},
725+
},
726+
}},
727+
},
728+
},
729+
wantSDKObj: &appmeshsdk.ClientPolicy{
730+
Tls: &appmeshsdk.ClientPolicyTls{
731+
Enforce: aws.Bool(true),
732+
Ports: []*int64{aws.Int64(80), aws.Int64(443)},
733+
Validation: &appmeshsdk.TlsValidationContext{
734+
Trust: &appmeshsdk.TlsValidationContextTrust{
735+
Acm: &appmeshsdk.TlsValidationContextAcmTrust{
736+
CertificateAuthorityArns: []*string{aws.String("arn-1"), aws.String("arn-2")},
737+
},
738+
},
639739
},
640740
},
641741
},
642-
}}}
643-
644-
vsByKey[types.NamespacedName{Namespace: "ns-1", Name: "vs-1"}] = &appmesh.VirtualService{}
645-
646-
ctrl := gomock.NewController(t)
647-
defer ctrl.Finish()
648-
649-
sdkVnSpec, err := BuildSDKVirtualNodeSpec(vn, vsByKey)
650-
if err != nil {
651-
assert.Fail(t, "Could not convert to sdkVn spec", err)
652-
} else {
653-
assert.NotNil(t, sdkVnSpec.Backends[0].VirtualService.ClientPolicy)
654-
assert.Nil(t, sdkVnSpec.Backends[1].VirtualService.ClientPolicy)
742+
wantErr: nil,
743+
},
744+
}
745+
for _, tt := range tests {
746+
t.Run(tt.name, func(t *testing.T) {
747+
sdkVnSpec, err := BuildSDKVirtualNodeSpec(tt.args.vn, tt.args.vsByKey)
748+
if tt.wantErr != nil {
749+
assert.EqualError(t, err, tt.wantErr.Error())
750+
} else {
751+
assert.NoError(t, err)
752+
assert.Equal(t, tt.wantSDKObj, sdkVnSpec.Backends[0].VirtualService.ClientPolicy)
753+
assert.Nil(t, sdkVnSpec.Backends[1].VirtualService.ClientPolicy)
754+
}
755+
})
655756
}
656757
}

0 commit comments

Comments
 (0)