Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CloudMap Integration tests #343

Merged
merged 2 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions pkg/cloudmap/instances_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
"service-A": {
instanceAttrsByID: map[string]instanceAttributes{
"192.168.1.1": {
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
},
lastUpdatedTimeByID: map[string]time.Time{
Expand All @@ -95,7 +95,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
serviceID: "service-A",
instanceID: "192.168.1.1",
attrs: instanceAttributes{
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
"k": "v",
},
operation: &servicediscovery.Operation{
Expand All @@ -105,7 +105,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
wantInstanceAttrsByService: map[string]map[string]instanceAttributes{
"service-A": {
"192.168.1.1": instanceAttributes{
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
"k": "v",
},
},
Expand All @@ -118,7 +118,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
"service-A": {
instanceAttrsByID: map[string]instanceAttributes{
"192.168.1.1": {
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
},
lastUpdatedTimeByID: make(map[string]time.Time),
Expand All @@ -129,7 +129,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
serviceID: "service-A",
instanceID: "192.168.1.1",
attrs: instanceAttributes{
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
"k": "v",
},
operation: &servicediscovery.Operation{
Expand All @@ -139,7 +139,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
wantInstanceAttrsByService: map[string]map[string]instanceAttributes{
"service-A": {
"192.168.1.1": instanceAttributes{
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
"k": "v",
},
},
Expand All @@ -152,7 +152,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
"service-A": {
instanceAttrsByID: map[string]instanceAttributes{
"192.168.1.1": {
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
},
lastUpdatedTimeByID: map[string]time.Time{
Expand All @@ -165,7 +165,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
serviceID: "service-A",
instanceID: "192.168.1.1",
attrs: instanceAttributes{
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
"k": "v",
},
operation: &servicediscovery.Operation{
Expand All @@ -175,7 +175,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
wantInstanceAttrsByService: map[string]map[string]instanceAttributes{
"service-A": {
"192.168.1.1": instanceAttributes{
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
},
},
Expand All @@ -187,7 +187,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
"service-A": {
instanceAttrsByID: map[string]instanceAttributes{
"192.168.1.1": {
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
},
lastUpdatedTimeByID: map[string]time.Time{
Expand All @@ -200,7 +200,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
serviceID: "service-A",
instanceID: "192.168.1.2",
attrs: instanceAttributes{
attrAWSInstanceIPV4: "192.168.1.2",
AttrAWSInstanceIPV4: "192.168.1.2",
},
operation: &servicediscovery.Operation{
UpdateDate: &oneSecAfterNow,
Expand All @@ -209,10 +209,10 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
wantInstanceAttrsByService: map[string]map[string]instanceAttributes{
"service-A": {
"192.168.1.1": instanceAttributes{
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
"192.168.1.2": instanceAttributes{
attrAWSInstanceIPV4: "192.168.1.2",
AttrAWSInstanceIPV4: "192.168.1.2",
},
},
},
Expand All @@ -224,7 +224,7 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
"service-A": {
instanceAttrsByID: map[string]instanceAttributes{
"192.168.1.1": {
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
},
},
Expand All @@ -234,15 +234,15 @@ func Test_defaultInstancesCache_recordSuccessfulRegisterInstanceOperation(t *tes
serviceID: "service-B",
instanceID: "192.168.1.1",
attrs: instanceAttributes{
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
"k": "v",
},
operation: nil,
},
wantInstanceAttrsByService: map[string]map[string]instanceAttributes{
"service-A": {
"192.168.1.1": instanceAttributes{
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
},
},
Expand Down Expand Up @@ -292,10 +292,10 @@ func Test_defaultInstancesCache_recordSuccessfulDeregisterInstanceOperation(t *t
"service-A": {
instanceAttrsByID: map[string]instanceAttributes{
"192.168.1.1": {
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
"192.168.1.2": {
attrAWSInstanceIPV4: "192.168.1.2",
AttrAWSInstanceIPV4: "192.168.1.2",
},
},
lastUpdatedTimeByID: map[string]time.Time{
Expand All @@ -315,7 +315,7 @@ func Test_defaultInstancesCache_recordSuccessfulDeregisterInstanceOperation(t *t
wantInstanceAttrsByService: map[string]map[string]instanceAttributes{
"service-A": {
"192.168.1.2": {
attrAWSInstanceIPV4: "192.168.1.2",
AttrAWSInstanceIPV4: "192.168.1.2",
},
},
},
Expand All @@ -327,10 +327,10 @@ func Test_defaultInstancesCache_recordSuccessfulDeregisterInstanceOperation(t *t
"service-A": {
instanceAttrsByID: map[string]instanceAttributes{
"192.168.1.1": {
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
"192.168.1.2": {
attrAWSInstanceIPV4: "192.168.1.2",
AttrAWSInstanceIPV4: "192.168.1.2",
},
},
lastUpdatedTimeByID: map[string]time.Time{
Expand All @@ -350,10 +350,10 @@ func Test_defaultInstancesCache_recordSuccessfulDeregisterInstanceOperation(t *t
wantInstanceAttrsByService: map[string]map[string]instanceAttributes{
"service-A": {
"192.168.1.1": {
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
"192.168.1.2": {
attrAWSInstanceIPV4: "192.168.1.2",
AttrAWSInstanceIPV4: "192.168.1.2",
},
},
},
Expand All @@ -365,10 +365,10 @@ func Test_defaultInstancesCache_recordSuccessfulDeregisterInstanceOperation(t *t
"service-A": {
instanceAttrsByID: map[string]instanceAttributes{
"192.168.1.1": {
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
"192.168.1.2": {
attrAWSInstanceIPV4: "192.168.1.2",
AttrAWSInstanceIPV4: "192.168.1.2",
},
},
lastUpdatedTimeByID: map[string]time.Time{
Expand All @@ -388,10 +388,10 @@ func Test_defaultInstancesCache_recordSuccessfulDeregisterInstanceOperation(t *t
wantInstanceAttrsByService: map[string]map[string]instanceAttributes{
"service-A": {
"192.168.1.1": {
attrAWSInstanceIPV4: "192.168.1.1",
AttrAWSInstanceIPV4: "192.168.1.1",
},
"192.168.1.2": {
attrAWSInstanceIPV4: "192.168.1.2",
AttrAWSInstanceIPV4: "192.168.1.2",
},
},
},
Expand Down
28 changes: 14 additions & 14 deletions pkg/cloudmap/instances_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ import (
const (
// attrAWSInstanceIPV4 is a special attribute expected by CloudMap.
// See https://github.com/aws/aws-sdk-go/blob/fd304fe4cb2ea1027e7fc7e21062beb768915fcc/service/servicediscovery/api.go#L5161
attrAWSInstanceIPV4 = "AWS_INSTANCE_IPV4"
AttrAWSInstanceIPV4 = "AWS_INSTANCE_IPV4"

// attrK8sPod is a custom attribute injected by app-mesh controller
attrK8sPod = "k8s.io/pod"
AttrK8sPod = "k8s.io/pod"
// AttrK8sNamespace is a custom attribute injected by app-mesh controller
attrK8sNamespace = "k8s.io/namespace"
AttrK8sNamespace = "k8s.io/namespace"
// AttrK8sPodRegion is a custom attribute injected by app-mesh controller
attrK8sPodRegion = "REGION"
AttrK8sPodRegion = "REGION"
// AttrK8sPodAZ is a custom attribute injected by app-mesh controller
attrK8sPodAZ = "AVAILABILITY_ZONE"
AttrK8sPodAZ = "AVAILABILITY_ZONE"

attrAppMeshMesh = "appmesh.k8s.aws/mesh"
attrAppMeshVirtualNode = "appmesh.k8s.aws/virtualNode"
AttrAppMeshMesh = "appmesh.k8s.aws/mesh"
AttrAppMeshVirtualNode = "appmesh.k8s.aws/virtualNode"

// how long to synchronously wait for instances reconcile operation
defaultInstancesReconcileWaitTimeout = 5 * time.Second
Expand Down Expand Up @@ -150,17 +150,17 @@ func (r *defaultInstancesReconciler) buildInstanceAttributes(ms *appmesh.Mesh, v
attr[cmAttr.Key] = cmAttr.Value
}
podsNodeName := pod.Spec.NodeName
attr[attrAWSInstanceIPV4] = pod.Status.PodIP
attr[attrK8sPod] = pod.Name
attr[attrK8sNamespace] = pod.Namespace
attr[attrAppMeshMesh] = aws.StringValue(ms.Spec.AWSName)
attr[attrAppMeshVirtualNode] = aws.StringValue(vn.Spec.AWSName)
attr[AttrAWSInstanceIPV4] = pod.Status.PodIP
attr[AttrK8sPod] = pod.Name
attr[AttrK8sNamespace] = pod.Namespace
attr[AttrAppMeshMesh] = aws.StringValue(ms.Spec.AWSName)
attr[AttrAppMeshVirtualNode] = aws.StringValue(vn.Spec.AWSName)
if nodeInfo, ok := nodeInfoByName[podsNodeName]; ok {
if nodeInfo.region != "" {
attr[attrK8sPodRegion] = nodeInfo.region
attr[AttrK8sPodRegion] = nodeInfo.region
}
if nodeInfo.availabilityZone != "" {
attr[attrK8sPodAZ] = nodeInfo.availabilityZone
attr[AttrK8sPodAZ] = nodeInfo.availabilityZone
}
}
return attr
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudmap/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ func (s *virtualNodeServiceSubset) SubsetID() string {
}

func (s *virtualNodeServiceSubset) Contains(instanceID string, attrs instanceAttributes) bool {
return attrs[attrAppMeshMesh] == aws.StringValue(s.ms.Spec.AWSName) && attrs[attrAppMeshVirtualNode] == aws.StringValue(s.vn.Spec.AWSName)
return attrs[AttrAppMeshMesh] == aws.StringValue(s.ms.Spec.AWSName) && attrs[AttrAppMeshVirtualNode] == aws.StringValue(s.vn.Spec.AWSName)
}
2 changes: 1 addition & 1 deletion test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func New(options Options) *Framework {
NSManager: namespace.NewManager(k8sClient),
DPManager: deployment.NewManager(k8sClient),
MeshManager: mesh.NewManager(k8sClient, cloud.AppMesh()),
VNManager: virtualnode.NewManager(k8sClient, cloud.AppMesh()),
VNManager: virtualnode.NewManager(k8sClient, cloud.AppMesh(), cloud.CloudMap()),
VSManager: virtualservice.NewManager(k8sClient, cloud.AppMesh()),
VRManager: virtualrouter.NewManager(k8sClient, cloud.AppMesh()),
VGManager: virtualgateway.NewManager(k8sClient, cloud.AppMesh()),
Expand Down
Loading