Skip to content

Commit

Permalink
Support preallocate continuous IPs for StatefulSet
Browse files Browse the repository at this point in the history
In order to provide better user experience, AtreamIPAM will try to
preallocate continuous IP range for StatefulSet. If unsuccesful,
IPs for the StatfulSet will be allocated on the fly, as before.

Signed-off-by: Anna Khmelnitsky <[email protected]>
  • Loading branch information
annakhm committed Feb 14, 2022
1 parent 12f20a7 commit bfe3f41
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 170 deletions.
1 change: 1 addition & 0 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3867,6 +3867,7 @@ rules:
- get
- list
- watch
- create
- apiGroups:
- clusterinformation.antrea.tanzu.vmware.com
resources:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3867,6 +3867,7 @@ rules:
- get
- list
- watch
- create
- apiGroups:
- clusterinformation.antrea.tanzu.vmware.com
resources:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3867,6 +3867,7 @@ rules:
- get
- list
- watch
- create
- apiGroups:
- clusterinformation.antrea.tanzu.vmware.com
resources:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3867,6 +3867,7 @@ rules:
- get
- list
- watch
- create
- apiGroups:
- clusterinformation.antrea.tanzu.vmware.com
resources:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/antrea-kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3867,6 +3867,7 @@ rules:
- get
- list
- watch
- create
- apiGroups:
- clusterinformation.antrea.tanzu.vmware.com
resources:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3867,6 +3867,7 @@ rules:
- get
- list
- watch
- create
- apiGroups:
- clusterinformation.antrea.tanzu.vmware.com
resources:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/base/controller-rbac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ rules:
- get
- list
- watch
- create
# Deprecated in v1.0.0.
- apiGroups:
- clusterinformation.antrea.tanzu.vmware.com
Expand Down
13 changes: 7 additions & 6 deletions pkg/agent/cniserver/ipam/antrea_ipam_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"antrea.io/antrea/pkg/client/informers/externalversions"
crdinformers "antrea.io/antrea/pkg/client/informers/externalversions/crd/v1alpha2"
crdlisters "antrea.io/antrea/pkg/client/listers/crd/v1alpha2"
annotation "antrea.io/antrea/pkg/ipam"
"antrea.io/antrea/pkg/ipam/poolallocator"
"antrea.io/antrea/pkg/util/k8s"
)
Expand Down Expand Up @@ -149,11 +150,11 @@ func (c *AntreaIPAMController) getIPPoolsByPod(namespace, name string) ([]string
return nil, nil, nil, err
}
// Collect specified IPs if exist
ipStrings, _ := pod.Annotations[AntreaIPAMPodIPAnnotationKey]
ipStrings, _ := pod.Annotations[annotation.AntreaIPAMPodIPAnnotationKey]
ipStrings = strings.ReplaceAll(ipStrings, " ", "")
var ipErr error
if ipStrings != "" {
splittedIPStrings := strings.Split(ipStrings, AntreaIPAMAnnotationDelimiter)
splittedIPStrings := strings.Split(ipStrings, annotation.AntreaIPAMAnnotationDelimiter)
for _, ipString := range splittedIPStrings {
ip := net.ParseIP(ipString)
if ipString != "" && ip == nil {
Expand Down Expand Up @@ -187,21 +188,21 @@ ownerReferenceLoop:
}
}

annotations, exists := pod.Annotations[AntreaIPAMAnnotationKey]
annotations, exists := pod.Annotations[annotation.AntreaIPAMAnnotationKey]
if exists {
return strings.Split(annotations, AntreaIPAMAnnotationDelimiter), ips, reservedOwner, ipErr
return strings.Split(annotations, annotation.AntreaIPAMAnnotationDelimiter), ips, reservedOwner, ipErr
}

// Find IPPool by Namespace
ns, err := c.namespaceLister.Get(namespace)
if err != nil {
return nil, nil, nil, nil
}
annotations, exists = ns.Annotations[AntreaIPAMAnnotationKey]
annotations, exists = ns.Annotations[annotation.AntreaIPAMAnnotationKey]
if !exists {
return nil, nil, nil, nil
}
return strings.Split(annotations, AntreaIPAMAnnotationDelimiter), ips, reservedOwner, ipErr
return strings.Split(annotations, annotation.AntreaIPAMAnnotationDelimiter), ips, reservedOwner, ipErr
}

func (c *AntreaIPAMController) getPoolAllocatorByPod(namespace, podName string) (*poolallocator.IPPoolAllocator, []net.IP, *crdv1a2.IPAddressOwner, error) {
Expand Down
23 changes: 12 additions & 11 deletions pkg/agent/cniserver/ipam/antrea_ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
argtypes "antrea.io/antrea/pkg/agent/cniserver/types"
crdv1a2 "antrea.io/antrea/pkg/apis/crd/v1alpha2"
crdinformers "antrea.io/antrea/pkg/client/informers/externalversions"
annotations "antrea.io/antrea/pkg/ipam"
fakepoolclient "antrea.io/antrea/pkg/ipam/poolallocator/testing"
)

Expand Down Expand Up @@ -153,13 +154,13 @@ func initTestClients() (*fake.Clientset, *fakepoolclient.IPPoolClientset) {
&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testApple,
Annotations: map[string]string{AntreaIPAMAnnotationKey: testApple, "junk": "garbage"},
Annotations: map[string]string{annotations.AntreaIPAMAnnotationKey: testApple, "junk": "garbage"},
},
},
&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testOrange,
Annotations: map[string]string{"junk": "garbage", AntreaIPAMAnnotationKey: testOrange},
Annotations: map[string]string{"junk": "garbage", annotations.AntreaIPAMAnnotationKey: testOrange},
},
},
&corev1.Namespace{
Expand All @@ -171,7 +172,7 @@ func initTestClients() (*fake.Clientset, *fakepoolclient.IPPoolClientset) {
&corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testJunkAnnotation,
Annotations: map[string]string{AntreaIPAMAnnotationKey: testJunkAnnotation},
Annotations: map[string]string{annotations.AntreaIPAMAnnotationKey: testJunkAnnotation},
},
},
&corev1.Namespace{
Expand Down Expand Up @@ -219,23 +220,23 @@ func initTestClients() (*fake.Clientset, *fakepoolclient.IPPoolClientset) {
ObjectMeta: metav1.ObjectMeta{
Name: "pear1",
Namespace: testPear,
Annotations: map[string]string{"junk": "garbage", AntreaIPAMAnnotationKey: testPear},
Annotations: map[string]string{"junk": "garbage", annotations.AntreaIPAMAnnotationKey: testPear},
},
Spec: corev1.PodSpec{NodeName: "fakeNode"},
},
&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pear2",
Namespace: testPear,
Annotations: map[string]string{"junk": "garbage", AntreaIPAMAnnotationKey: testPear, AntreaIPAMPodIPAnnotationKey: " "},
Annotations: map[string]string{"junk": "garbage", annotations.AntreaIPAMAnnotationKey: testPear, annotations.AntreaIPAMPodIPAnnotationKey: " "},
},
Spec: corev1.PodSpec{NodeName: "fakeNode"},
},
&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pear3",
Namespace: testPear,
Annotations: map[string]string{"junk": "garbage", AntreaIPAMAnnotationKey: testPear, AntreaIPAMPodIPAnnotationKey: "10.2.3.199"},
Annotations: map[string]string{"junk": "garbage", annotations.AntreaIPAMAnnotationKey: testPear, annotations.AntreaIPAMPodIPAnnotationKey: "10.2.3.199"},
},
Spec: corev1.PodSpec{NodeName: "fakeNode"},
},
Expand All @@ -244,7 +245,7 @@ func initTestClients() (*fake.Clientset, *fakepoolclient.IPPoolClientset) {
// conflict
Name: "pear4",
Namespace: testPear,
Annotations: map[string]string{"junk": "garbage", AntreaIPAMAnnotationKey: testPear, AntreaIPAMPodIPAnnotationKey: "10.2.3.199"},
Annotations: map[string]string{"junk": "garbage", annotations.AntreaIPAMAnnotationKey: testPear, annotations.AntreaIPAMPodIPAnnotationKey: "10.2.3.199"},
},
Spec: corev1.PodSpec{NodeName: "fakeNode"},
},
Expand All @@ -253,7 +254,7 @@ func initTestClients() (*fake.Clientset, *fakepoolclient.IPPoolClientset) {
// out of range
Name: "pear5",
Namespace: testPear,
Annotations: map[string]string{"junk": "garbage", AntreaIPAMAnnotationKey: testPear, AntreaIPAMPodIPAnnotationKey: "10.2.4.199"},
Annotations: map[string]string{"junk": "garbage", annotations.AntreaIPAMAnnotationKey: testPear, annotations.AntreaIPAMPodIPAnnotationKey: "10.2.4.199"},
},
Spec: corev1.PodSpec{NodeName: "fakeNode"},
},
Expand All @@ -262,7 +263,7 @@ func initTestClients() (*fake.Clientset, *fakepoolclient.IPPoolClientset) {
// invalid IP
Name: "pear6",
Namespace: testPear,
Annotations: map[string]string{"junk": "garbage", AntreaIPAMAnnotationKey: testPear, AntreaIPAMPodIPAnnotationKey: "junk"},
Annotations: map[string]string{"junk": "garbage", annotations.AntreaIPAMAnnotationKey: testPear, annotations.AntreaIPAMPodIPAnnotationKey: "junk"},
},
Spec: corev1.PodSpec{NodeName: "fakeNode"},
},
Expand All @@ -271,15 +272,15 @@ func initTestClients() (*fake.Clientset, *fakepoolclient.IPPoolClientset) {
// invalid IPPool
Name: "pear7",
Namespace: testPear,
Annotations: map[string]string{"junk": "garbage", AntreaIPAMAnnotationKey: testJunkAnnotation},
Annotations: map[string]string{"junk": "garbage", annotations.AntreaIPAMAnnotationKey: testJunkAnnotation},
},
Spec: corev1.PodSpec{NodeName: "fakeNode"},
},
&corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "pear-sts-8",
Namespace: testPear,
Annotations: map[string]string{AntreaIPAMAnnotationKey: testPear},
Annotations: map[string]string{annotations.AntreaIPAMAnnotationKey: testPear},
OwnerReferences: []metav1.OwnerReference{{Controller: &bTrue, Kind: "StatefulSet"}},
},
Spec: corev1.PodSpec{NodeName: "fakeNode"},
Expand Down
Loading

0 comments on commit bfe3f41

Please sign in to comment.