Skip to content

Commit

Permalink
Extra test
Browse files Browse the repository at this point in the history
Signed-off-by: lubronzhan <[email protected]>
  • Loading branch information
lubronzhan committed Jun 24, 2024
1 parent f089a81 commit e1b35fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The `kube-vip-cloud-provider` will only implement the `loadBalancer` functionali
- Support loadbalancerClass `kube-vip.io/kube-vip-class`
- Support assigning multiple services on single VIP (IPv4 only, optional)
- Support specifying service interface per namespace or at global level
- Support exlucding first and last ip from cidr
- Support excluding first and last ip from cidr

## Installing the `kube-vip-cloud-provider`

Expand Down
22 changes: 14 additions & 8 deletions pkg/provider/loadbalancerclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func newSmallIPPoolConfigMap() *corev1.ConfigMap {
Namespace: KubeVipClientConfigNamespace,
},
Data: map[string]string{
"cidr-global": "10.0.0.0/30,2001::0/48",
"cidr-global": "10.0.0.2/31,2001::0/48",
"allow-share-global": "true",
},
}
Expand All @@ -160,21 +160,21 @@ func TestSyncLoadBalancerIfNeededWithMultipleIpUse(t *testing.T) {
{
desc: "udp service that wants LB",
service: tu.NewService("udp-service", tu.TweakDualStack(), tu.TweakAddPorts(corev1.ProtocolUDP, 123, 123), tu.TweakAddLBClass(ptr.To(LoadbalancerClass))),
expectIP: "10.0.0.1,2001::",
expectIP: "10.0.0.2,2001::",
expectNumOfUpdate: 1,
expectNumOfPatch: 1,
},
{
desc: "tcp service that wants LB",
service: tu.NewService("basic-service1", tu.TweakDualStack(), tu.TweakAddPorts(corev1.ProtocolTCP, 345, 345), tu.TweakAddLBClass(ptr.To(LoadbalancerClass))),
expectIP: "10.0.0.1,2001::1",
expectIP: "10.0.0.2,2001::1",
expectNumOfUpdate: 1,
expectNumOfPatch: 1,
},
{
desc: "sctp service that wants LB",
service: tu.NewService("sctp-service", tu.TweakAddPorts(corev1.ProtocolSCTP, 1234, 1234), tu.TweakAddLBClass(ptr.To(LoadbalancerClass))),
expectIP: "10.0.0.1",
expectIP: "10.0.0.2",
expectNumOfUpdate: 1,
expectNumOfPatch: 1,
},
Expand All @@ -186,31 +186,37 @@ func TestSyncLoadBalancerIfNeededWithMultipleIpUse(t *testing.T) {
{
desc: "service with finalizer that wants LB",
service: tu.NewService("basic-service3", tu.TweakAddFinalizers(servicehelper.LoadBalancerCleanupFinalizer), tu.TweakAddLBClass(ptr.To(LoadbalancerClass))),
expectIP: "10.0.0.1",
expectIP: "10.0.0.2",
expectNumOfUpdate: 1,
},
{
desc: "now there is not enough ip, another tcp service that wants LB, but still could share ip with existing service",
service: tu.NewService("basic-service4", tu.TweakAddPorts(corev1.ProtocolTCP, 8080, 8080), tu.TweakAddLBClass(ptr.To(LoadbalancerClass))),
expectNumOfUpdate: 1,
expectNumOfPatch: 1,
expectIP: "10.0.0.1",
expectIP: "10.0.0.2",
expectError: true,
},
{
desc: "another service who wants same port, get a new IP address",
service: tu.NewService("basic-service5", tu.TweakAddPorts(corev1.ProtocolTCP, 80, 80), tu.TweakAddLBClass(ptr.To(LoadbalancerClass))),
expectNumOfUpdate: 1,
expectNumOfPatch: 1,
expectIP: "10.0.0.2",
expectIP: "10.0.0.3",
expectError: true,
},
{
desc: "another service who wants same port, no ip left, get no ip",
service: tu.NewService("basic-service6", tu.TweakAddPorts(corev1.ProtocolTCP, 80, 80), tu.TweakAddLBClass(ptr.To(LoadbalancerClass))),
expectNumOfPatch: 1,
expectError: true,
},
}

// create ip pool for service to use
client := fake.NewSimpleClientset()
ctx := context.Background()
// This pool has 4 ipv4 addresses and 8 ipv6 address
// This pool has 2 ipv4 addresses and 8 ipv6 address
cm := newSmallIPPoolConfigMap()
if _, err := client.CoreV1().ConfigMaps(cm.Namespace).Create(ctx, cm, metav1.CreateOptions{}); err != nil {
t.Errorf("Failed to prepare configmap %s for testing: %v", cm.Name, err)
Expand Down

0 comments on commit e1b35fc

Please sign in to comment.