Skip to content

Commit

Permalink
Merge pull request #116516 from aojea/servicecidr
Browse files Browse the repository at this point in the history
KEP-1880 Multiple ServiceCIDR ( and IPAddress allocation)

Kubernetes-commit: 6abff7457e3a722fd217a0a58d1992b4002d496d
  • Loading branch information
k8s-publishing-bot committed Nov 1, 2023
2 parents cebf241 + 931e867 commit 57a70fb
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 8 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ require (
github.com/stretchr/testify v1.8.4
golang.org/x/sys v0.13.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.0.0-20231101011356-6106c48f363d
k8s.io/api v0.0.0-20231101051301-a4966a65096d
k8s.io/apimachinery v0.0.0-20231101011123-96ae302100a8
k8s.io/cli-runtime v0.0.0-20231101014603-a832cfbf22f6
k8s.io/client-go v0.0.0-20231101011735-7523a344f785
k8s.io/client-go v0.0.0-20231101051607-c13269dd6b3c
k8s.io/component-base v0.0.0-20231101012453-36eaf6a3a115
k8s.io/component-helpers v0.0.0-20231101012613-d6e059a1d44d
k8s.io/klog/v2 v2.100.1
Expand Down Expand Up @@ -96,10 +96,10 @@ require (
)

replace (
k8s.io/api => k8s.io/api v0.0.0-20231101011356-6106c48f363d
k8s.io/api => k8s.io/api v0.0.0-20231101051301-a4966a65096d
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20231101011123-96ae302100a8
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20231101014603-a832cfbf22f6
k8s.io/client-go => k8s.io/client-go v0.0.0-20231101011735-7523a344f785
k8s.io/client-go => k8s.io/client-go v0.0.0-20231101051607-c13269dd6b3c
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20231101010903-a0b3d34de476
k8s.io/component-base => k8s.io/component-base v0.0.0-20231101012453-36eaf6a3a115
k8s.io/component-helpers => k8s.io/component-helpers v0.0.0-20231101012613-d6e059a1d44d
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.0.0-20231101011356-6106c48f363d h1:UGmDzNqOmVt+OcwK8zqQY+Rt7jex0EqP8teb11hhVNo=
k8s.io/api v0.0.0-20231101011356-6106c48f363d/go.mod h1:lBfRF4cZnQAE1dC8eo5d+GYNg4AVK8XhcdF7OeZP3vw=
k8s.io/api v0.0.0-20231101051301-a4966a65096d h1:/t04G7UGfOOY0/lS0ZHySBd7mqaWOc1ljcgSnz6oy4Y=
k8s.io/api v0.0.0-20231101051301-a4966a65096d/go.mod h1:lBfRF4cZnQAE1dC8eo5d+GYNg4AVK8XhcdF7OeZP3vw=
k8s.io/apimachinery v0.0.0-20231101011123-96ae302100a8 h1:ZmtmO/iO+jAzN4d6CitAv4GcBeoL900OIyD8hQH+BOY=
k8s.io/apimachinery v0.0.0-20231101011123-96ae302100a8/go.mod h1:Jstex+Vd1bLMOri3JGwKux2G++hIIH+6+/Gbrq+DhOQ=
k8s.io/cli-runtime v0.0.0-20231101014603-a832cfbf22f6 h1:TW8JEOuz4BRPDMrE7jq0KQj+fdtFOGs639JuRvKU8cA=
k8s.io/cli-runtime v0.0.0-20231101014603-a832cfbf22f6/go.mod h1:ZMSud1gJWvbEtQWvf51G4pPRh2bWIF8AMgpVw2pKfNQ=
k8s.io/client-go v0.0.0-20231101011735-7523a344f785 h1:RCG2X8THR9tj0NKW3r7e6WuC4O9PZTw0RVKBntWjVUw=
k8s.io/client-go v0.0.0-20231101011735-7523a344f785/go.mod h1:cTK5cDp0KQpzCXVivM3YixBMwcJdet4JFzdnwWQfgKk=
k8s.io/client-go v0.0.0-20231101051607-c13269dd6b3c h1:0rqa6SI8FEFjKmy4ha0aWVEEh6cP1p1QWoIh2gfAc84=
k8s.io/client-go v0.0.0-20231101051607-c13269dd6b3c/go.mod h1:vT22kLeqES8awNEXSqpxwxlX4Etwv6Xyb7JYntCOeag=
k8s.io/component-base v0.0.0-20231101012453-36eaf6a3a115 h1:hSeGKNDD82ZZX9xSla8OH02UzwNXDLfxIaYtTFbAmNg=
k8s.io/component-base v0.0.0-20231101012453-36eaf6a3a115/go.mod h1:NSugshDiYqn5/1FWEweKICkcNSIwfNS+4n4nVM1kBk8=
k8s.io/component-helpers v0.0.0-20231101012613-d6e059a1d44d h1:AuN2dg4wNd9l7j4Iayzx6ZlxIJ6I1nsdOndK+uYLSmc=
Expand Down
50 changes: 50 additions & 0 deletions pkg/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,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: "ServiceCIDR"}: &ServiceCIDRDescriber{c},
{Group: networkingv1alpha1.GroupName, Kind: "IPAddress"}: &IPAddressDescriber{c},
{Group: batchv1.GroupName, Kind: "Job"}: &JobDescriber{c},
{Group: batchv1.GroupName, Kind: "CronJob"}: &CronJobDescriber{c},
Expand Down Expand Up @@ -2844,6 +2845,55 @@ func (i *IngressClassDescriber) describeIngressClassV1(ic *networkingv1.IngressC
})
}

// ServiceCIDRDescriber generates information about a ServiceCIDR.
type ServiceCIDRDescriber struct {
client clientset.Interface
}

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

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

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

w.Write(LEVEL_0, "CIDRs:\t%v\n", strings.Join(svc.Spec.CIDRs, ", "))

if len(svc.Status.Conditions) > 0 {
w.Write(LEVEL_0, "Status:\n")
w.Write(LEVEL_0, "Conditions:\n")
w.Write(LEVEL_1, "Type\tStatus\tLastTransitionTime\tReason\tMessage\n")
w.Write(LEVEL_1, "----\t------\t------------------\t------\t-------\n")
for _, c := range svc.Status.Conditions {
w.Write(LEVEL_1, "%v\t%v\t%s\t%v\t%v\n",
c.Type,
c.Status,
c.LastTransitionTime.Time.Format(time.RFC1123Z),
c.Reason,
c.Message)
}
}

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

// IPAddressDescriber generates information about an IPAddress.
type IPAddressDescriber struct {
client clientset.Interface
Expand Down
71 changes: 71 additions & 0 deletions pkg/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5932,6 +5932,77 @@ Events: <none>` + "\n",
}
}

func TestDescribeServiceCIDR(t *testing.T) {

testcases := map[string]struct {
input *fake.Clientset
output string
}{
"ServiceCIDR v1alpha1": {
input: fake.NewSimpleClientset(&networkingv1alpha1.ServiceCIDR{
ObjectMeta: metav1.ObjectMeta{
Name: "foo.123",
},
Spec: networkingv1alpha1.ServiceCIDRSpec{
CIDRs: []string{"10.1.0.0/16", "fd00:1:1::/64"},
},
}),

output: `Name: foo.123
Labels: <none>
Annotations: <none>
CIDRs: 10.1.0.0/16, fd00:1:1::/64
Events: <none>` + "\n",
},
"ServiceCIDR v1alpha1 IPv4": {
input: fake.NewSimpleClientset(&networkingv1alpha1.ServiceCIDR{
ObjectMeta: metav1.ObjectMeta{
Name: "foo.123",
},
Spec: networkingv1alpha1.ServiceCIDRSpec{
CIDRs: []string{"10.1.0.0/16"},
},
}),

output: `Name: foo.123
Labels: <none>
Annotations: <none>
CIDRs: 10.1.0.0/16
Events: <none>` + "\n",
},
"ServiceCIDR v1alpha1 IPv6": {
input: fake.NewSimpleClientset(&networkingv1alpha1.ServiceCIDR{
ObjectMeta: metav1.ObjectMeta{
Name: "foo.123",
},
Spec: networkingv1alpha1.ServiceCIDRSpec{
CIDRs: []string{"fd00:1:1::/64"},
},
}),

output: `Name: foo.123
Labels: <none>
Annotations: <none>
CIDRs: 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 := ServiceCIDRDescriber{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 TestDescribeIPAddress(t *testing.T) {

testcases := map[string]struct {
Expand Down

0 comments on commit 57a70fb

Please sign in to comment.