Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteb1143f

Browse files
Initialize OS type detailed attribute during container instance registration (#4724)
* Initialize OS type detailed attribute during container instance registration* Fix imports and formatting* add test case for empty detailed OS attribute validation
1 parent6e9b8f3 commiteb1143f

File tree

5 files changed

+58
-13
lines changed

5 files changed

+58
-13
lines changed

‎agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/api/ecs/client/ecs_client.go‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface/networkinterface.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎ecs-agent/api/ecs/client/ecs_client.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const (
5454
cpuArchAttrName="ecs.cpu-architecture"
5555
osTypeAttrName="ecs.os-type"
5656
osFamilyAttrName="ecs.os-family"
57+
osTypeDetailedAttrName="ecs.os-type-detailed"
5758
// RoundtripTimeout should only time out after dial and TLS handshake timeouts have elapsed.
5859
// Add additional 2 seconds to the sum of these 2 timeouts to be extra sure of this.
5960
RoundtripTimeout=httpclient.DefaultDialTimeout+httpclient.DefaultTLSHandshakeTimeout+2*time.Second
@@ -565,6 +566,17 @@ func (client *ecsClient) getAdditionalAttributes() []types.Attribute {
565566
Value:aws.String(client.configAccessor.OSFamily()),
566567
})
567568
}
569+
570+
// OSFamilyDetailed should be treated as an optional field as it is not applicable for all agents
571+
// using ecs client shared library. Add a check to ensure only non-empty values are added
572+
// to API call.
573+
ifclient.configAccessor.OSFamilyDetailed()!="" {
574+
attrs=append(attrs, types.Attribute{
575+
Name:aws.String(osTypeDetailedAttrName),
576+
Value:aws.String(client.configAccessor.OSFamilyDetailed()),
577+
})
578+
}
579+
568580
// Send CPU arch attribute directly when running on external capacity. When running on EC2 or Fargate launch type,
569581
// this is not needed since the CPU arch is reported via instance identity document in those cases.
570582
ifclient.configAccessor.External() {

‎ecs-agent/api/ecs/client/ecs_client_test.go‎

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"time"
2727

2828
"github.com/aws/aws-sdk-go-v2/aws"
29+
ecsservice"github.com/aws/aws-sdk-go-v2/service/ecs"
30+
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
2931
"github.com/golang/mock/gomock"
3032
"github.com/stretchr/testify/assert"
3133
"github.com/stretchr/testify/require"
@@ -44,8 +46,6 @@ import (
4446
mock_ec2"github.com/aws/amazon-ecs-agent/ecs-agent/ec2/mocks"
4547
ni"github.com/aws/amazon-ecs-agent/ecs-agent/netlib/model/networkinterface"
4648
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/retry"
47-
ecsservice"github.com/aws/aws-sdk-go-v2/service/ecs"
48-
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
4949
)
5050

5151
const (
@@ -480,6 +480,12 @@ func TestRegisterContainerInstance(t *testing.T) {
480480
cfgAccessor.EXPECT().External().Return(true).AnyTimes()
481481
},
482482
},
483+
{
484+
name:"empty os detailed attribute",
485+
mockCfgAccessorOverride:func(cfgAccessor*mock_config.MockAgentConfigAccessor) {
486+
cfgAccessor.EXPECT().OSFamilyDetailed().Return("").AnyTimes()
487+
},
488+
},
483489
}
484490

485491
for_,tc:=rangetestCases {
@@ -508,6 +514,10 @@ func TestRegisterContainerInstance(t *testing.T) {
508514
"ecs.outpost-arn":outpostARN,
509515
cpuArchAttrName:getCPUArch(),
510516
}
517+
// Add ecs.os-type-detailed only if OSFamilyDetailed() returns a non-empty value
518+
iftester.mockCfgAccessor.OSFamilyDetailed()!="" {
519+
expectedAttributes["ecs.os-type-detailed"]=tester.mockCfgAccessor.OSFamilyDetailed()
520+
}
511521
capabilities:=buildAttributeList(fakeCapabilities,nil)
512522
platformDevices:= []types.PlatformDevice{
513523
{
@@ -553,12 +563,18 @@ func TestRegisterContainerInstance(t *testing.T) {
553563
varexpectedNumOfAttributesint
554564
if!tester.mockCfgAccessor.External() {
555565
// 2 capability attributes: capability1, capability2
556-
// and 5 other attributes:
557-
// ecs.os-type, ecs.os-family, ecs.outpost-arn, my_custom_attribute, my_other_custom_attribute.
558-
expectedNumOfAttributes=7
566+
// Base attributes: ecs.os-type, ecs.os-family, ecs.outpost-arn, my_custom_attribute, my_other_custom_attribute (5)
567+
// Plus ecs.os-type-detailed if OSFamilyDetailed() is not empty
568+
expectedNumOfAttributes=7// 2 capabilities + 5 base attributes
569+
iftester.mockCfgAccessor.OSFamilyDetailed()!="" {
570+
expectedNumOfAttributes=8
571+
}
559572
}else {
560573
// One more attribute for external case: ecs.cpu-architecture.
561574
expectedNumOfAttributes=8
575+
iftester.mockCfgAccessor.OSFamilyDetailed()!="" {
576+
expectedNumOfAttributes=9
577+
}
562578
}
563579

564580
gomock.InOrder(
@@ -630,6 +646,7 @@ func TestRegisterContainerInstanceWithRetryNonTerminalError(t *testing.T) {
630646
expectedAttributes:=map[string]string{
631647
"ecs.os-type":tester.mockCfgAccessor.OSType(),
632648
"ecs.os-family":tester.mockCfgAccessor.OSFamily(),
649+
"ecs.os-type-detailed":tester.mockCfgAccessor.OSFamilyDetailed(),
633650
"my_custom_attribute":"Custom_Value1",
634651
"my_other_custom_attribute":"Custom_Value2",
635652
"ecs.availability-zone":availabilityZone,
@@ -725,6 +742,7 @@ func TestReRegisterContainerInstance(t *testing.T) {
725742
expectedAttributes:=map[string]string{
726743
"ecs.os-type":tester.mockCfgAccessor.OSType(),
727744
"ecs.os-family":tester.mockCfgAccessor.OSFamily(),
745+
"ecs.os-type-detailed":tester.mockCfgAccessor.OSFamilyDetailed(),
728746
"ecs.availability-zone":availabilityZone,
729747
"ecs.outpost-arn":outpostARN,
730748
}
@@ -749,8 +767,8 @@ func TestReRegisterContainerInstance(t *testing.T) {
749767
resource,ok:=findResource(req.TotalResources,"PORTS_UDP")
750768
assert.True(t,ok,`Could not find resource "PORTS_UDP"`)
751769
assert.Equal(t,"STRINGSET",*resource.Type,`Wrong type for resource "PORTS_UDP"`)
752-
// "ecs.os-type", ecs.os-family, ecs.outpost-arn and the 2 that we specified as additionalAttributes.
753-
assert.Equal(t,5,len(req.Attributes),"Wrong number of Attributes")
770+
// "ecs.os-type", ecs.os-family, ecs.os-type-detailed, ecs.outpost-arn and the 2 that we specified as additionalAttributes.
771+
assert.Equal(t,6,len(req.Attributes),"Wrong number of Attributes")
754772
reqAttributes:=func()map[string]string {
755773
rv:=make(map[string]string,len(req.Attributes))
756774
fori:=rangereq.Attributes {
@@ -821,6 +839,7 @@ func TestRegisterContainerInstanceWithEmptyTags(t *testing.T) {
821839
expectedAttributes:=map[string]string{
822840
"ecs.os-type":tester.mockCfgAccessor.OSType(),
823841
"ecs.os-family":tester.mockCfgAccessor.OSFamily(),
842+
"ecs.os-type-detailed":tester.mockCfgAccessor.OSFamilyDetailed(),
824843
"my_custom_attribute":"Custom_Value1",
825844
"my_other_custom_attribute":"Custom_Value2",
826845
}
@@ -886,8 +905,9 @@ func TestRegisterBlankCluster(t *testing.T) {
886905
tester:=setup(t,ctrl,mockEC2Metadata,cfgAccessorOverrideFunc)
887906

888907
expectedAttributes:=map[string]string{
889-
"ecs.os-type":tester.mockCfgAccessor.OSType(),
890-
"ecs.os-family":tester.mockCfgAccessor.OSFamily(),
908+
"ecs.os-type":tester.mockCfgAccessor.OSType(),
909+
"ecs.os-family":tester.mockCfgAccessor.OSFamily(),
910+
"ecs.os-type-detailed":tester.mockCfgAccessor.OSFamilyDetailed(),
891911
}
892912
defaultCluster:=tester.mockCfgAccessor.DefaultClusterName()
893913
gomock.InOrder(
@@ -935,8 +955,9 @@ func TestRegisterBlankClusterNotCreatingClusterWhenErrorNotClusterNotFound(t *te
935955
tester:=setup(t,ctrl,mockEC2Metadata,cfgAccessorOverrideFunc)
936956

937957
expectedAttributes:=map[string]string{
938-
"ecs.os-type":tester.mockCfgAccessor.OSType(),
939-
"ecs.os-family":tester.mockCfgAccessor.OSFamily(),
958+
"ecs.os-type":tester.mockCfgAccessor.OSType(),
959+
"ecs.os-family":tester.mockCfgAccessor.OSFamily(),
960+
"ecs.os-type-detailed":tester.mockCfgAccessor.OSFamilyDetailed(),
940961
}
941962

942963
defaultCluster:=tester.mockCfgAccessor.DefaultClusterName()

‎ecs-agent/netlib/model/networkinterface/networkinterface.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type NetworkInterface struct {
4646
// SubnetGatewayIPV4Address is the IPv4 address of the subnet gateway of the NetworkInterface
4747
SubnetGatewayIPV4Addressstring`json:",omitempty"`
4848
// SubnetGatewayIPV6Address is the IPv6 address of the subnet gateway of the NetworkInterface
49-
SubnetGatewayIPV6Addressstring`json:",omitempty`
49+
SubnetGatewayIPV6Addressstring`json:",omitempty"`
5050
// DomainNameServers specifies the nameserver IP addresses for the eni
5151
DomainNameServers []string`json:",omitempty"`
5252
// DomainNameSearchList specifies the search list for the domain

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp