Skip to content

Commit

Permalink
Merge pull request #115075 from aojea/ipaddress
Browse files Browse the repository at this point in the history
IPAddress allocator

Kubernetes-commit: f44d561c1f8c327bdf2ff3bff175bd10d161454c
  • Loading branch information
k8s-publishing-bot committed Mar 15, 2023
2 parents 5de08c8 + 9be7ad1 commit 67016c7
Show file tree
Hide file tree
Showing 4 changed files with 97 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.1
golang.org/x/sys v0.6.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.0.0-20230315055831-abe66f57fdb1
k8s.io/api v0.0.0-20230315055832-c79498c4e63b
k8s.io/apimachinery v0.0.0-20230315054728-8d1258da8f38
k8s.io/cli-runtime v0.0.0-20230315090346-9185a9dd0ead
k8s.io/client-go v0.0.0-20230315061845-84ae514115bd
k8s.io/client-go v0.0.0-20230315061852-9ff2627505a4
k8s.io/component-base v0.0.0-20230315065615-6b9bb8ecc3d0
k8s.io/component-helpers v0.0.0-20230315070331-853a1039365a
k8s.io/klog/v2 v2.90.1
Expand Down Expand Up @@ -94,10 +94,10 @@ require (
)

replace (
k8s.io/api => k8s.io/api v0.0.0-20230315055831-abe66f57fdb1
k8s.io/api => k8s.io/api v0.0.0-20230315055832-c79498c4e63b
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20230315054728-8d1258da8f38
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20230315090346-9185a9dd0ead
k8s.io/client-go => k8s.io/client-go v0.0.0-20230315061845-84ae514115bd
k8s.io/client-go => k8s.io/client-go v0.0.0-20230315061852-9ff2627505a4
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20230315053024-8fead9f64de8
k8s.io/component-base => k8s.io/component-base v0.0.0-20230315065615-6b9bb8ecc3d0
k8s.io/component-helpers => k8s.io/component-helpers v0.0.0-20230315070331-853a1039365a
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,14 @@ 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-20230315055831-abe66f57fdb1 h1:XQ9kk+GySLR6UE0w0oqxpzP5QrcsELjK2R7rD7hnWsI=
k8s.io/api v0.0.0-20230315055831-abe66f57fdb1/go.mod h1:aZ6MBt4NMLXSxkSKFkoDaP4hTutnZIvH5dCSpOis9g4=
k8s.io/api v0.0.0-20230315055832-c79498c4e63b h1:+XtheLjvEgurlWvtf13tutNwmW6WUHGezbiapc4s6EM=
k8s.io/api v0.0.0-20230315055832-c79498c4e63b/go.mod h1:aZ6MBt4NMLXSxkSKFkoDaP4hTutnZIvH5dCSpOis9g4=
k8s.io/apimachinery v0.0.0-20230315054728-8d1258da8f38 h1:n1qDRCTPAXwyXYg7eSpWDO9FdW79lwAQ9dAr1vETpn4=
k8s.io/apimachinery v0.0.0-20230315054728-8d1258da8f38/go.mod h1:5ikh59fK3AJ287GUvpUsryoMFtH9zj/ARfWCo3AyXTM=
k8s.io/cli-runtime v0.0.0-20230315090346-9185a9dd0ead h1:HYtR8a33cxjM2XGQvAZaDXXjhY3nz9uWvbeYJSz6yl0=
k8s.io/cli-runtime v0.0.0-20230315090346-9185a9dd0ead/go.mod h1:wg6/UJ9wwfEEAXnyuuajHSr+YnMXL1K0yUrRHjXz3Do=
k8s.io/client-go v0.0.0-20230315061845-84ae514115bd h1:dilBefJQ4PnyI4xt/dH3EUQfGx5+tjwQMWL92ICsKoQ=
k8s.io/client-go v0.0.0-20230315061845-84ae514115bd/go.mod h1:Np+Pk6S0Rgul2HDFTuxJLmr5pdZNE9rDxwdzBoxpOF4=
k8s.io/client-go v0.0.0-20230315061852-9ff2627505a4 h1:mjPYL7mzIzB9PHI4ttnYkGY5zat6ObsndQNh7Gx12OQ=
k8s.io/client-go v0.0.0-20230315061852-9ff2627505a4/go.mod h1:daDXfDBtiJdqKrqqFL0WtQ6hHzsDxP1lCEdTt3+kijU=
k8s.io/component-base v0.0.0-20230315065615-6b9bb8ecc3d0 h1:IjneP02MOB07PIP9+PQjKrOIZEZ5T7umR+GIZkU4h0U=
k8s.io/component-base v0.0.0-20230315065615-6b9bb8ecc3d0/go.mod h1:kTuptveA6tUMLMKnaq4AbIAAk7IcdhwkbljAV3JZRpM=
k8s.io/component-helpers v0.0.0-20230315070331-853a1039365a h1:PIKao3YG7ZMiE+CtdM09YDcowRhGTdvCeEgWj3J9DKI=
Expand Down
41 changes: 41 additions & 0 deletions pkg/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func describerMap(clientConfig *rest.Config) (map[schema.GroupKind]ResourceDescr
{Group: networkingv1.GroupName, Kind: "Ingress"}: &IngressDescriber{c},
{Group: networkingv1.GroupName, Kind: "IngressClass"}: &IngressClassDescriber{c},
{Group: networkingv1alpha1.GroupName, Kind: "ClusterCIDR"}: &ClusterCIDRDescriber{c},
{Group: networkingv1alpha1.GroupName, Kind: "IPAddress"}: &IPAddressDescriber{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,46 @@ func (c *ClusterCIDRDescriber) describeClusterCIDRV1alpha1(cc *networkingv1alpha
})
}

// IPAddressDescriber generates information about an IPAddress.
type IPAddressDescriber struct {
client clientset.Interface
}

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

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

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

if ip.Spec.ParentRef != nil {
w.Write(LEVEL_0, "Parent Reference:\n")
w.Write(LEVEL_1, "Group:\t%v\n", ip.Spec.ParentRef.Group)
w.Write(LEVEL_1, "Resource:\t%v\n", ip.Spec.ParentRef.Resource)
w.Write(LEVEL_1, "Namespace:\t%v\n", ip.Spec.ParentRef.Namespace)
w.Write(LEVEL_1, "Name:\t%v\n", ip.Spec.ParentRef.Name)
}

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

// ServiceDescriber generates information about a service.
type ServiceDescriber struct {
clientset.Interface
Expand Down
48 changes: 48 additions & 0 deletions pkg/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5686,6 +5686,54 @@ Events: <none>` + "\n",
}
}

func TestDescribeIPAddress(t *testing.T) {

testcases := map[string]struct {
input *fake.Clientset
output string
}{
"IPAddress v1alpha1": {
input: fake.NewSimpleClientset(&networkingv1alpha1.IPAddress{
ObjectMeta: metav1.ObjectMeta{
Name: "foo.123",
},
Spec: networkingv1alpha1.IPAddressSpec{
ParentRef: &networkingv1alpha1.ParentReference{
Group: "mygroup",
Resource: "myresource",
Namespace: "mynamespace",
Name: "myname",
},
},
}),

output: `Name: foo.123
Labels: <none>
Annotations: <none>
Parent Reference:
Group: mygroup
Resource: myresource
Namespace: mynamespace
Name: myname
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 := IPAddressDescriber{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 67016c7

Please sign in to comment.