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
88e4be7c
Commit
88e4be7c
authored
Feb 15, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #20790 from Clarifai/ip-permission-iprange
Auto commit by PR queue bot
parents
a7818ac3
da4ba612
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
3 deletions
+70
-3
aws.go
pkg/cloudprovider/providers/aws/aws.go
+13
-3
aws_test.go
pkg/cloudprovider/providers/aws/aws_test.go
+57
-0
No files found.
pkg/cloudprovider/providers/aws/aws.go
View file @
88e4be7c
...
@@ -1525,15 +1525,25 @@ func ipPermissionExists(newPermission, existing *ec2.IpPermission, compareGroupU
...
@@ -1525,15 +1525,25 @@ func ipPermissionExists(newPermission, existing *ec2.IpPermission, compareGroupU
if
!
isEqualStringPointer
(
newPermission
.
IpProtocol
,
existing
.
IpProtocol
)
{
if
!
isEqualStringPointer
(
newPermission
.
IpProtocol
,
existing
.
IpProtocol
)
{
return
false
return
false
}
}
if
len
(
newPermission
.
IpRanges
)
!=
len
(
existing
.
IpRanges
)
{
// Check only if newPermission is a subset of existing. Usually it has zero or one elements.
// Not doing actual CIDR math yet; not clear it's needed, either.
glog
.
V
(
4
)
.
Infof
(
"Comparing %v to %v"
,
newPermission
,
existing
)
if
len
(
newPermission
.
IpRanges
)
>
len
(
existing
.
IpRanges
)
{
return
false
return
false
}
}
for
j
:=
range
newPermission
.
IpRanges
{
for
j
:=
range
newPermission
.
IpRanges
{
if
!
isEqualStringPointer
(
newPermission
.
IpRanges
[
j
]
.
CidrIp
,
existing
.
IpRanges
[
j
]
.
CidrIp
)
{
found
:=
false
for
k
:=
range
existing
.
IpRanges
{
if
isEqualStringPointer
(
newPermission
.
IpRanges
[
j
]
.
CidrIp
,
existing
.
IpRanges
[
k
]
.
CidrIp
)
{
found
=
true
break
}
}
if
found
==
false
{
return
false
return
false
}
}
}
}
for
_
,
leftPair
:=
range
newPermission
.
UserIdGroupPairs
{
for
_
,
leftPair
:=
range
newPermission
.
UserIdGroupPairs
{
for
_
,
rightPair
:=
range
existing
.
UserIdGroupPairs
{
for
_
,
rightPair
:=
range
existing
.
UserIdGroupPairs
{
if
isEqualUserGroupPair
(
leftPair
,
rightPair
,
compareGroupUserIDs
)
{
if
isEqualUserGroupPair
(
leftPair
,
rightPair
,
compareGroupUserIDs
)
{
...
...
pkg/cloudprovider/providers/aws/aws_test.go
View file @
88e4be7c
...
@@ -849,6 +849,63 @@ func TestIpPermissionExistsHandlesMultipleGroupIds(t *testing.T) {
...
@@ -849,6 +849,63 @@ func TestIpPermissionExistsHandlesMultipleGroupIds(t *testing.T) {
}
}
}
}
func
TestIpPermissionExistsHandlesRangeSubsets
(
t
*
testing
.
T
)
{
// Two existing scenarios we'll test against
emptyIpPermission
:=
ec2
.
IpPermission
{}
oldIpPermission
:=
ec2
.
IpPermission
{
IpRanges
:
[]
*
ec2
.
IpRange
{
{
CidrIp
:
aws
.
String
(
"10.0.0.0/8"
)},
{
CidrIp
:
aws
.
String
(
"192.168.1.0/24"
)},
},
}
// Two already existing ranges and a new one
existingIpPermission
:=
ec2
.
IpPermission
{
IpRanges
:
[]
*
ec2
.
IpRange
{
{
CidrIp
:
aws
.
String
(
"10.0.0.0/8"
)},
},
}
existingIpPermission2
:=
ec2
.
IpPermission
{
IpRanges
:
[]
*
ec2
.
IpRange
{
{
CidrIp
:
aws
.
String
(
"192.168.1.0/24"
)},
},
}
newIpPermission
:=
ec2
.
IpPermission
{
IpRanges
:
[]
*
ec2
.
IpRange
{
{
CidrIp
:
aws
.
String
(
"172.16.0.0/16"
)},
},
}
exists
:=
ipPermissionExists
(
&
emptyIpPermission
,
&
emptyIpPermission
,
false
)
if
!
exists
{
t
.
Errorf
(
"Should have been considered existing since we're comparing a range array against itself"
)
}
exists
=
ipPermissionExists
(
&
oldIpPermission
,
&
oldIpPermission
,
false
)
if
!
exists
{
t
.
Errorf
(
"Should have been considered existing since we're comparing a range array against itself"
)
}
exists
=
ipPermissionExists
(
&
existingIpPermission
,
&
oldIpPermission
,
false
)
if
!
exists
{
t
.
Errorf
(
"Should have been considered existing since 10.* is in oldIpPermission's array of ranges"
)
}
exists
=
ipPermissionExists
(
&
existingIpPermission2
,
&
oldIpPermission
,
false
)
if
!
exists
{
t
.
Errorf
(
"Should have been considered existing since 192.* is in oldIpPermission2's array of ranges"
)
}
exists
=
ipPermissionExists
(
&
newIpPermission
,
&
emptyIpPermission
,
false
)
if
exists
{
t
.
Errorf
(
"Should have not been considered existing since we compared against a missing array of ranges"
)
}
exists
=
ipPermissionExists
(
&
newIpPermission
,
&
oldIpPermission
,
false
)
if
exists
{
t
.
Errorf
(
"Should have not been considered existing since 172.* is not in oldIpPermission's array of ranges"
)
}
}
func
TestIpPermissionExistsHandlesMultipleGroupIdsWithUserIds
(
t
*
testing
.
T
)
{
func
TestIpPermissionExistsHandlesMultipleGroupIdsWithUserIds
(
t
*
testing
.
T
)
{
oldIpPermission
:=
ec2
.
IpPermission
{
oldIpPermission
:=
ec2
.
IpPermission
{
UserIdGroupPairs
:
[]
*
ec2
.
UserIdGroupPair
{
UserIdGroupPairs
:
[]
*
ec2
.
UserIdGroupPair
{
...
...
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