mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-01 07:47:56 +00:00
findSecurityRule returns true when it matches most of characteristics.
This commit is contained in:
parent
e201d34296
commit
d39b517ad3
@ -1207,9 +1207,33 @@ func findRule(rules []network.LoadBalancingRule, rule network.LoadBalancingRule)
|
||||
|
||||
func findSecurityRule(rules []network.SecurityRule, rule network.SecurityRule) bool {
|
||||
for _, existingRule := range rules {
|
||||
if strings.EqualFold(*existingRule.Name, *rule.Name) {
|
||||
return true
|
||||
if !strings.EqualFold(*existingRule.Name, *rule.Name) {
|
||||
continue
|
||||
}
|
||||
if existingRule.Protocol != rule.Protocol {
|
||||
continue
|
||||
}
|
||||
if !strings.EqualFold(*existingRule.SourcePortRange, *rule.SourcePortRange) {
|
||||
continue
|
||||
}
|
||||
if !strings.EqualFold(*existingRule.DestinationPortRange, *rule.DestinationPortRange) {
|
||||
continue
|
||||
}
|
||||
if !strings.EqualFold(*existingRule.SourceAddressPrefix, *rule.SourceAddressPrefix) {
|
||||
continue
|
||||
}
|
||||
if !allowsConsolidation(existingRule) && !allowsConsolidation(rule) {
|
||||
if !strings.EqualFold(*existingRule.DestinationAddressPrefix, *rule.DestinationAddressPrefix) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if existingRule.Access != rule.Access {
|
||||
continue
|
||||
}
|
||||
if existingRule.Direction != rule.Direction {
|
||||
continue
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -392,6 +392,36 @@ func TestReconcileLoadBalancerAddServiceOnInternalSubnet(t *testing.T) {
|
||||
validateLoadBalancer(t, lb, svc)
|
||||
}
|
||||
|
||||
func TestReconcileSecurityGroupFromAnyDestinationAddressPrefixToLoadBalancerIP(t *testing.T) {
|
||||
az := getTestCloud()
|
||||
svc1 := getTestService("serviceea", v1.ProtocolTCP, 80)
|
||||
svc1.Spec.LoadBalancerIP = "192.168.0.0"
|
||||
sg := getTestSecurityGroup(az)
|
||||
// Simulate a pre-Kubernetes 1.8 NSG, where we do not specify the destination address prefix
|
||||
sg,err := az.reconcileSecurityGroup(testClusterName, &svc1, to.StringPtr(""), true)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %q", err)
|
||||
}
|
||||
sg, err = az.reconcileSecurityGroup(testClusterName, &svc1, to.StringPtr(svc1.Spec.LoadBalancerIP), true)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %q", err)
|
||||
}
|
||||
validateSecurityGroup(t, sg, svc1)
|
||||
}
|
||||
|
||||
func TestReconcileSecurityGroupDynamicLoadBalancerIP(t *testing.T) {
|
||||
az := getTestCloud()
|
||||
svc1 := getTestService("servicea", v1.ProtocolTCP, 80)
|
||||
svc1.Spec.LoadBalancerIP = ""
|
||||
sg := getTestSecurityGroup(az)
|
||||
dynamicallyAssignedIP := "192.168.0.0"
|
||||
sg, err := az.reconcileSecurityGroup(testClusterName, &svc1, to.StringPtr(dynamicallyAssignedIP), true)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %q", err)
|
||||
}
|
||||
validateSecurityGroup(t, sg, svc1)
|
||||
}
|
||||
|
||||
// Test addition of services on an internal LB using both default and explicit subnets.
|
||||
func TestReconcileLoadBalancerAddServicesOnMultipleSubnets(t *testing.T) {
|
||||
az := getTestCloud()
|
||||
|
Loading…
Reference in New Issue
Block a user