Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
257c3ad7
Commit
257c3ad7
authored
Feb 06, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20153 from sky-uk/fix-sg-comparison
Auto commit by PR queue bot
parents
c6a4f848
c3383b34
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
18 deletions
+95
-18
aws.go
pkg/cloudprovider/providers/aws/aws.go
+31
-18
aws_test.go
pkg/cloudprovider/providers/aws/aws_test.go
+64
-0
No files found.
pkg/cloudprovider/providers/aws/aws.go
View file @
257c3ad7
...
@@ -1427,6 +1427,7 @@ func isEqualIntPointer(l, r *int64) bool {
...
@@ -1427,6 +1427,7 @@ func isEqualIntPointer(l, r *int64) bool {
}
}
return
*
l
==
*
r
return
*
l
==
*
r
}
}
func
isEqualStringPointer
(
l
,
r
*
string
)
bool
{
func
isEqualStringPointer
(
l
,
r
*
string
)
bool
{
if
l
==
nil
{
if
l
==
nil
{
return
r
==
nil
return
r
==
nil
...
@@ -1437,40 +1438,50 @@ func isEqualStringPointer(l, r *string) bool {
...
@@ -1437,40 +1438,50 @@ func isEqualStringPointer(l, r *string) bool {
return
*
l
==
*
r
return
*
l
==
*
r
}
}
func
i
sEqualIPPermission
(
l
,
r
*
ec2
.
IpPermission
,
compareGroupUserIDs
bool
)
bool
{
func
i
pPermissionExists
(
newPermission
,
existing
*
ec2
.
IpPermission
,
compareGroupUserIDs
bool
)
bool
{
if
!
isEqualIntPointer
(
l
.
FromPort
,
r
.
FromPort
)
{
if
!
isEqualIntPointer
(
newPermission
.
FromPort
,
existing
.
FromPort
)
{
return
false
return
false
}
}
if
!
isEqualIntPointer
(
l
.
ToPort
,
r
.
ToPort
)
{
if
!
isEqualIntPointer
(
newPermission
.
ToPort
,
existing
.
ToPort
)
{
return
false
return
false
}
}
if
!
isEqualStringPointer
(
l
.
IpProtocol
,
r
.
IpProtocol
)
{
if
!
isEqualStringPointer
(
newPermission
.
IpProtocol
,
existing
.
IpProtocol
)
{
return
false
return
false
}
}
if
len
(
l
.
IpRanges
)
!=
len
(
r
.
IpRanges
)
{
if
len
(
newPermission
.
IpRanges
)
!=
len
(
existing
.
IpRanges
)
{
return
false
return
false
}
}
for
j
:=
range
l
.
IpRanges
{
for
j
:=
range
newPermission
.
IpRanges
{
if
!
isEqualStringPointer
(
l
.
IpRanges
[
j
]
.
CidrIp
,
r
.
IpRanges
[
j
]
.
CidrIp
)
{
if
!
isEqualStringPointer
(
newPermission
.
IpRanges
[
j
]
.
CidrIp
,
existing
.
IpRanges
[
j
]
.
CidrIp
)
{
return
false
return
false
}
}
}
}
if
len
(
l
.
UserIdGroupPairs
)
!=
len
(
r
.
UserIdGroupPairs
)
{
for
_
,
leftPair
:=
range
newPermission
.
UserIdGroupPairs
{
for
_
,
rightPair
:=
range
existing
.
UserIdGroupPairs
{
if
isEqualUserGroupPair
(
leftPair
,
rightPair
,
compareGroupUserIDs
)
{
return
true
}
}
return
false
return
false
}
}
for
j
:=
range
l
.
UserIdGroupPairs
{
if
!
isEqualStringPointer
(
l
.
UserIdGroupPairs
[
j
]
.
GroupId
,
r
.
UserIdGroupPairs
[
j
]
.
GroupId
)
{
return
true
return
false
}
}
func
isEqualUserGroupPair
(
l
,
r
*
ec2
.
UserIdGroupPair
,
compareGroupUserIDs
bool
)
bool
{
glog
.
V
(
2
)
.
Infof
(
"Comparing %v to %v"
,
*
l
.
GroupId
,
*
r
.
GroupId
)
if
isEqualStringPointer
(
l
.
GroupId
,
r
.
GroupId
)
{
if
compareGroupUserIDs
{
if
compareGroupUserIDs
{
if
!
isEqualStringPointer
(
l
.
UserIdGroupPairs
[
j
]
.
UserId
,
r
.
UserIdGroupPairs
[
j
]
.
UserId
)
{
if
isEqualStringPointer
(
l
.
UserId
,
r
.
UserId
)
{
return
fals
e
return
tru
e
}
}
}
else
{
return
true
}
}
}
}
return
tru
e
return
fals
e
}
}
// Makes sure the security group includes the specified permissions
// Makes sure the security group includes the specified permissions
...
@@ -1487,6 +1498,8 @@ func (s *AWSCloud) ensureSecurityGroupIngress(securityGroupId string, addPermiss
...
@@ -1487,6 +1498,8 @@ func (s *AWSCloud) ensureSecurityGroupIngress(securityGroupId string, addPermiss
return
false
,
fmt
.
Errorf
(
"security group not found: %s"
,
securityGroupId
)
return
false
,
fmt
.
Errorf
(
"security group not found: %s"
,
securityGroupId
)
}
}
glog
.
V
(
2
)
.
Infof
(
"Existing security group ingress: %s %v"
,
securityGroupId
,
group
.
IpPermissions
)
changes
:=
[]
*
ec2
.
IpPermission
{}
changes
:=
[]
*
ec2
.
IpPermission
{}
for
_
,
addPermission
:=
range
addPermissions
{
for
_
,
addPermission
:=
range
addPermissions
{
hasUserID
:=
false
hasUserID
:=
false
...
@@ -1498,7 +1511,7 @@ func (s *AWSCloud) ensureSecurityGroupIngress(securityGroupId string, addPermiss
...
@@ -1498,7 +1511,7 @@ func (s *AWSCloud) ensureSecurityGroupIngress(securityGroupId string, addPermiss
found
:=
false
found
:=
false
for
_
,
groupPermission
:=
range
group
.
IpPermissions
{
for
_
,
groupPermission
:=
range
group
.
IpPermissions
{
if
i
sEqualIPPermission
(
addPermission
,
groupPermission
,
hasUserID
)
{
if
i
pPermissionExists
(
addPermission
,
groupPermission
,
hasUserID
)
{
found
=
true
found
=
true
break
break
}
}
...
@@ -1553,8 +1566,8 @@ func (s *AWSCloud) removeSecurityGroupIngress(securityGroupId string, removePerm
...
@@ -1553,8 +1566,8 @@ func (s *AWSCloud) removeSecurityGroupIngress(securityGroupId string, removePerm
var
found
*
ec2
.
IpPermission
var
found
*
ec2
.
IpPermission
for
_
,
groupPermission
:=
range
group
.
IpPermissions
{
for
_
,
groupPermission
:=
range
group
.
IpPermissions
{
if
i
sEqualIPPermission
(
groupPermission
,
remove
Permission
,
hasUserID
)
{
if
i
pPermissionExists
(
removePermission
,
group
Permission
,
hasUserID
)
{
found
=
group
Permission
found
=
remove
Permission
break
break
}
}
}
}
...
...
pkg/cloudprovider/providers/aws/aws_test.go
View file @
257c3ad7
...
@@ -799,3 +799,67 @@ func TestSubnetIDsinVPC(t *testing.T) {
...
@@ -799,3 +799,67 @@ func TestSubnetIDsinVPC(t *testing.T) {
}
}
}
}
func
TestIpPermissionExistsHandlesMultipleGroupIds
(
t
*
testing
.
T
)
{
oldIpPermission
:=
ec2
.
IpPermission
{
UserIdGroupPairs
:
[]
*
ec2
.
UserIdGroupPair
{
{
GroupId
:
aws
.
String
(
"firstGroupId"
)},
{
GroupId
:
aws
.
String
(
"secondGroupId"
)},
{
GroupId
:
aws
.
String
(
"thirdGroupId"
)},
},
}
existingIpPermission
:=
ec2
.
IpPermission
{
UserIdGroupPairs
:
[]
*
ec2
.
UserIdGroupPair
{
{
GroupId
:
aws
.
String
(
"secondGroupId"
)},
},
}
newIpPermission
:=
ec2
.
IpPermission
{
UserIdGroupPairs
:
[]
*
ec2
.
UserIdGroupPair
{
{
GroupId
:
aws
.
String
(
"fourthGroupId"
)},
},
}
equals
:=
ipPermissionExists
(
&
existingIpPermission
,
&
oldIpPermission
,
false
)
if
!
equals
{
t
.
Errorf
(
"Should have been considered equal since first is in the second array of groups"
)
}
equals
=
ipPermissionExists
(
&
newIpPermission
,
&
oldIpPermission
,
false
)
if
equals
{
t
.
Errorf
(
"Should have not been considered equal since first is not in the second array of groups"
)
}
}
func
TestIpPermissionExistsHandlesMultipleGroupIdsWithUserIds
(
t
*
testing
.
T
)
{
oldIpPermission
:=
ec2
.
IpPermission
{
UserIdGroupPairs
:
[]
*
ec2
.
UserIdGroupPair
{
{
GroupId
:
aws
.
String
(
"firstGroupId"
),
UserId
:
aws
.
String
(
"firstUserId"
)},
{
GroupId
:
aws
.
String
(
"secondGroupId"
),
UserId
:
aws
.
String
(
"secondUserId"
)},
{
GroupId
:
aws
.
String
(
"thirdGroupId"
),
UserId
:
aws
.
String
(
"thirdUserId"
)},
},
}
existingIpPermission
:=
ec2
.
IpPermission
{
UserIdGroupPairs
:
[]
*
ec2
.
UserIdGroupPair
{
{
GroupId
:
aws
.
String
(
"secondGroupId"
),
UserId
:
aws
.
String
(
"secondUserId"
)},
},
}
newIpPermission
:=
ec2
.
IpPermission
{
UserIdGroupPairs
:
[]
*
ec2
.
UserIdGroupPair
{
{
GroupId
:
aws
.
String
(
"secondGroupId"
),
UserId
:
aws
.
String
(
"anotherUserId"
)},
},
}
equals
:=
ipPermissionExists
(
&
existingIpPermission
,
&
oldIpPermission
,
true
)
if
!
equals
{
t
.
Errorf
(
"Should have been considered equal since first is in the second array of groups"
)
}
equals
=
ipPermissionExists
(
&
newIpPermission
,
&
oldIpPermission
,
true
)
if
equals
{
t
.
Errorf
(
"Should have not been considered equal since first is not in the second array of groups"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment