Skip to content

Commit

Permalink
Merge pull request #109090 from sarveshr7/multicidr-rangeallocator
Browse files Browse the repository at this point in the history
Enhance NodeIPAM to support multiple ClusterCIDRs

Kubernetes-commit: 759785ea147bc13945d521eaba4a6592cbc0675f
  • Loading branch information
k8s-publishing-bot committed Aug 10, 2022
2 parents efd055b + 4cb46af commit 372aa8c
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 30 deletions.
30 changes: 15 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ require (
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.0.0-20220804201334-3be517c25d08
k8s.io/apimachinery v0.0.0-20220804201133-74deb3dbf6fd
k8s.io/cli-runtime v0.0.0-20220804203856-b48c51ece852
k8s.io/client-go v0.0.0-20220804201634-3300752b6159
k8s.io/component-base v0.0.0-20220804202306-bd3841ae5bd6
k8s.io/component-helpers v0.0.0-20220804202405-ad3109323577
k8s.io/api v0.0.0-20220807235320-860821164923
k8s.io/apimachinery v0.0.0-20220805001719-117bd9b56ec3
k8s.io/cli-runtime v0.0.0-20220810191336-a7c40597df6d
k8s.io/client-go v0.0.0-20220807235612-a890e7bc14d5
k8s.io/component-base v0.0.0-20220810184732-a3ff0a6aeab5
k8s.io/component-helpers v0.0.0-20220810184904-28f37af09947
k8s.io/klog/v2 v2.70.1
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1
k8s.io/metrics v0.0.0-20220804203745-0bf1725b4b86
k8s.io/metrics v0.0.0-20220810191141-ffc1ec435f51
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2
sigs.k8s.io/kustomize/kustomize/v4 v4.5.7
Expand Down Expand Up @@ -94,12 +94,12 @@ require (
)

replace (
k8s.io/api => k8s.io/api v0.0.0-20220804201334-3be517c25d08
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20220804201133-74deb3dbf6fd
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20220804203856-b48c51ece852
k8s.io/client-go => k8s.io/client-go v0.0.0-20220804201634-3300752b6159
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20220804200942-97fa351e57d3
k8s.io/component-base => k8s.io/component-base v0.0.0-20220804202306-bd3841ae5bd6
k8s.io/component-helpers => k8s.io/component-helpers v0.0.0-20220804202405-ad3109323577
k8s.io/metrics => k8s.io/metrics v0.0.0-20220804203745-0bf1725b4b86
k8s.io/api => k8s.io/api v0.0.0-20220807235320-860821164923
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20220805001719-117bd9b56ec3
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20220810191336-a7c40597df6d
k8s.io/client-go => k8s.io/client-go v0.0.0-20220807235612-a890e7bc14d5
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20220810182828-7a6b27b949b5
k8s.io/component-base => k8s.io/component-base v0.0.0-20220810184732-a3ff0a6aeab5
k8s.io/component-helpers => k8s.io/component-helpers v0.0.0-20220810184904-28f37af09947
k8s.io/metrics => k8s.io/metrics v0.0.0-20220810191141-ffc1ec435f51
)
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -541,25 +541,25 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.0.0-20220804201334-3be517c25d08 h1:GhSb7UiWlJLG12FUUz3PwSpT2FVZCbYtls4p4+3HSeQ=
k8s.io/api v0.0.0-20220804201334-3be517c25d08/go.mod h1:a3GfmLd04jiJgn/o0eLXPVt1neCVuUVj/RJzEEWOMJU=
k8s.io/apimachinery v0.0.0-20220804201133-74deb3dbf6fd h1:bTjsTSrHSYBuovT0kZTwfLlTGHzHL9POhWK2ci83fOg=
k8s.io/apimachinery v0.0.0-20220804201133-74deb3dbf6fd/go.mod h1:qMx9eAk0sZQGsXGu86fab8tZdffHbwUfsvzqKn4mfB0=
k8s.io/cli-runtime v0.0.0-20220804203856-b48c51ece852 h1:jIB0rKV6fdXuN/fttQa5T0JCTHuOaT/1rWhiMccorL4=
k8s.io/cli-runtime v0.0.0-20220804203856-b48c51ece852/go.mod h1:Tvpth9pLpTuGtIJRXkHyiRV1aySWB4fkzO/eISsDbk4=
k8s.io/client-go v0.0.0-20220804201634-3300752b6159 h1:zhOzoFXSKarof7EuFdrhhcGa6ZXKTdCKM3J+CzCOJjA=
k8s.io/client-go v0.0.0-20220804201634-3300752b6159/go.mod h1:Qlh6X9VIv4nlzpVedbEUUpMY2HeNgGPNPr3+SQOtDAQ=
k8s.io/component-base v0.0.0-20220804202306-bd3841ae5bd6 h1:FHz479e22/WLD6+Tr3G+YWh5IVaJYocmPjizCb7chDU=
k8s.io/component-base v0.0.0-20220804202306-bd3841ae5bd6/go.mod h1:ij1d8OKrbGbeL3b7tnrEKOuN2itnGAl4CSinffjTRko=
k8s.io/component-helpers v0.0.0-20220804202405-ad3109323577 h1:r0ySqBj26jCSuvu55gA2r4RgtW16DteTm2AlKxA7+0M=
k8s.io/component-helpers v0.0.0-20220804202405-ad3109323577/go.mod h1:R0VxXCZmw73I91z817R+rKB5TQlMrxnMWvexBnhZmIE=
k8s.io/api v0.0.0-20220807235320-860821164923 h1:nDGbaAze/PQhS5Br0Q506rBEBVOlniVO7Mzjq1h9eOY=
k8s.io/api v0.0.0-20220807235320-860821164923/go.mod h1:cuE2+aKfcxEMeHx/NuUKIL3aRJhth7/K9wlCf+3Q3+s=
k8s.io/apimachinery v0.0.0-20220805001719-117bd9b56ec3 h1:Ru2oqar5qMV68dM0G6OEZs2C7qtydpReZ2dHsXpu/Kw=
k8s.io/apimachinery v0.0.0-20220805001719-117bd9b56ec3/go.mod h1:qMx9eAk0sZQGsXGu86fab8tZdffHbwUfsvzqKn4mfB0=
k8s.io/cli-runtime v0.0.0-20220810191336-a7c40597df6d h1:IRToqMteYht2e5RnZkx8ZlhFNcsW1hixmQEbOS2J5iw=
k8s.io/cli-runtime v0.0.0-20220810191336-a7c40597df6d/go.mod h1:Tvpth9pLpTuGtIJRXkHyiRV1aySWB4fkzO/eISsDbk4=
k8s.io/client-go v0.0.0-20220807235612-a890e7bc14d5 h1:BqsFtQcyMLlMSB4i+MKiQryECg6KwyLpNAoURVMbVe0=
k8s.io/client-go v0.0.0-20220807235612-a890e7bc14d5/go.mod h1:pPOa0mPr0yaIJIxznPOjENyC7fxgTWAR5VKGjQvNx70=
k8s.io/component-base v0.0.0-20220810184732-a3ff0a6aeab5 h1:qw7krbnZuTUZssW4V4V4h+pvLsnWNz5ZhfglrEIoNLI=
k8s.io/component-base v0.0.0-20220810184732-a3ff0a6aeab5/go.mod h1:ij1d8OKrbGbeL3b7tnrEKOuN2itnGAl4CSinffjTRko=
k8s.io/component-helpers v0.0.0-20220810184904-28f37af09947 h1:J91pDxCYAqAoTdjg6LuzFa3MXin/ZEpwapp/bVOidPU=
k8s.io/component-helpers v0.0.0-20220810184904-28f37af09947/go.mod h1:R0VxXCZmw73I91z817R+rKB5TQlMrxnMWvexBnhZmIE=
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
k8s.io/klog/v2 v2.70.1 h1:7aaoSdahviPmR+XkS7FyxlkkXs6tHISSG03RxleQAVQ=
k8s.io/klog/v2 v2.70.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 h1:MQ8BAZPZlWk3S9K4a9NCkIFQtZShWqoha7snGixVgEA=
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1/go.mod h1:C/N6wCaBHeBHkHUesQOQy2/MZqGgMAFPqGsGQLdbZBU=
k8s.io/metrics v0.0.0-20220804203745-0bf1725b4b86 h1:TMl6dJxngVSNxgdWRrVrb7gf+bYsiU0kZjZC9NLqZWU=
k8s.io/metrics v0.0.0-20220804203745-0bf1725b4b86/go.mod h1:ytk8irWR9C+e1rP4a2d1VS3T2yn8QKNMlMslESHUF+s=
k8s.io/metrics v0.0.0-20220810191141-ffc1ec435f51 h1:eLBee5nezvmPnT3ErJ5tCpKmFuDTdNR7I+nEAnxA1b8=
k8s.io/metrics v0.0.0-20220810191141-ffc1ec435f51/go.mod h1:OZtyc11+TayJnMu7L/Cd8dDrxPdrXJ6Ef5gTDy0VWQg=
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed h1:jAne/RjBTyawwAy0utX5eqigAwz/lQhTmy+Hr/Cpue4=
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
60 changes: 59 additions & 1 deletion pkg/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"unicode"

"github.com/fatih/camelcase"

appsv1 "k8s.io/api/apps/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
Expand All @@ -46,6 +45,7 @@ import (
discoveryv1beta1 "k8s.io/api/discovery/v1beta1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
networkingv1alpha1 "k8s.io/api/networking/v1alpha1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
policyv1 "k8s.io/api/policy/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
Expand Down Expand Up @@ -213,6 +213,7 @@ func describerMap(clientConfig *rest.Config) (map[schema.GroupKind]ResourceDescr
{Group: networkingv1beta1.GroupName, Kind: "IngressClass"}: &IngressClassDescriber{c},
{Group: networkingv1.GroupName, Kind: "Ingress"}: &IngressDescriber{c},
{Group: networkingv1.GroupName, Kind: "IngressClass"}: &IngressClassDescriber{c},
{Group: networkingv1alpha1.GroupName, Kind: "ClusterCIDR"}: &ClusterCIDRDescriber{c},
{Group: batchv1.GroupName, Kind: "Job"}: &JobDescriber{c},
{Group: batchv1.GroupName, Kind: "CronJob"}: &CronJobDescriber{c},
{Group: batchv1beta1.GroupName, Kind: "CronJob"}: &CronJobDescriber{c},
Expand Down Expand Up @@ -2853,6 +2854,63 @@ func (i *IngressClassDescriber) describeIngressClassV1(ic *networkingv1.IngressC
})
}

// ClusterCIDRDescriber generates information about a ClusterCIDR.
type ClusterCIDRDescriber struct {
client clientset.Interface
}

func (c *ClusterCIDRDescriber) Describe(namespace, name string, describerSettings DescriberSettings) (string, error) {
var events *corev1.EventList

ccV1alpha1, err := c.client.NetworkingV1alpha1().ClusterCIDRs().Get(context.TODO(), name, metav1.GetOptions{})
if err == nil {
if describerSettings.ShowEvents {
events, _ = searchEvents(c.client.CoreV1(), ccV1alpha1, describerSettings.ChunkSize)
}
return c.describeClusterCIDRV1alpha1(ccV1alpha1, events)
}
return "", err
}

func (c *ClusterCIDRDescriber) describeClusterCIDRV1alpha1(cc *networkingv1alpha1.ClusterCIDR, events *corev1.EventList) (string, error) {
return tabbedString(func(out io.Writer) error {
w := NewPrefixWriter(out)
w.Write(LEVEL_0, "Name:\t%v\n", cc.Name)
printLabelsMultiline(w, "Labels", cc.Labels)
printAnnotationsMultiline(w, "Annotations", cc.Annotations)

w.Write(LEVEL_0, "NodeSelector:\n")
if cc.Spec.NodeSelector != nil {
w.Write(LEVEL_1, "NodeSelector Terms:")
if len(cc.Spec.NodeSelector.NodeSelectorTerms) == 0 {
w.WriteLine("<none>")
} else {
w.WriteLine("")
for i, term := range cc.Spec.NodeSelector.NodeSelectorTerms {
printNodeSelectorTermsMultilineWithIndent(w, LEVEL_2, fmt.Sprintf("Term %v", i), "\t", term.MatchExpressions)
}
}
}

if cc.Spec.PerNodeHostBits != 0 {
w.Write(LEVEL_0, "PerNodeHostBits:\t%s\n", fmt.Sprint(cc.Spec.PerNodeHostBits))
}

if cc.Spec.IPv4 != "" {
w.Write(LEVEL_0, "IPv4:\t%s\n", cc.Spec.IPv4)
}

if cc.Spec.IPv6 != "" {
w.Write(LEVEL_0, "IPv6:\t%s\n", cc.Spec.IPv6)
}

if events != nil {
DescribeEvents(events, w)
}
return nil
})
}

// ServiceDescriber generates information about a service.
type ServiceDescriber struct {
clientset.Interface
Expand Down
60 changes: 60 additions & 0 deletions pkg/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"testing"
"time"

"github.com/google/go-cmp/cmp"
appsv1 "k8s.io/api/apps/v1"
autoscalingv1 "k8s.io/api/autoscaling/v1"
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
Expand All @@ -34,6 +35,7 @@ import (
discoveryv1 "k8s.io/api/discovery/v1"
discoveryv1beta1 "k8s.io/api/discovery/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
networkingv1alpha1 "k8s.io/api/networking/v1alpha1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
policyv1 "k8s.io/api/policy/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
Expand Down Expand Up @@ -5371,6 +5373,64 @@ Events: <none>` + "\n",
}
}

func TestDescribeClusterCIDR(t *testing.T) {

testcases := map[string]struct {
input *fake.Clientset
output string
}{
"ClusterCIDR v1alpha1": {
input: fake.NewSimpleClientset(&networkingv1alpha1.ClusterCIDR{
ObjectMeta: metav1.ObjectMeta{
Name: "foo.123",
},
Spec: networkingv1alpha1.ClusterCIDRSpec{
PerNodeHostBits: int32(8),
IPv4: "10.1.0.0/16",
IPv6: "fd00:1:1::/64",
NodeSelector: &corev1.NodeSelector{
NodeSelectorTerms: []corev1.NodeSelectorTerm{
{
MatchExpressions: []corev1.NodeSelectorRequirement{
{
Key: "foo",
Operator: "In",
Values: []string{"bar"}},
},
},
},
},
},
}),

output: `Name: foo.123
Labels: <none>
Annotations: <none>
NodeSelector:
NodeSelector Terms:
Term 0: foo in [bar]
PerNodeHostBits: 8
IPv4: 10.1.0.0/16
IPv6: fd00:1:1::/64
Events: <none>` + "\n",
},
}

for name, tc := range testcases {
t.Run(name, func(t *testing.T) {
c := &describeClient{T: t, Namespace: "foo", Interface: tc.input}
d := ClusterCIDRDescriber{c}
out, err := d.Describe("bar", "foo.123", DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if out != tc.output {
t.Errorf("expected :\n%s\nbut got output:\n%s diff:\n%s", tc.output, out, cmp.Diff(tc.output, out))
}
})
}
}

func TestControllerRef(t *testing.T) {
var replicas int32 = 1
f := fake.NewSimpleClientset(
Expand Down

0 comments on commit 372aa8c

Please sign in to comment.