diff --git a/docs/LICENSE_OF_DEPENDENCIES.md b/docs/LICENSE_OF_DEPENDENCIES.md index dbb5758c5..0670cc967 100644 --- a/docs/LICENSE_OF_DEPENDENCIES.md +++ b/docs/LICENSE_OF_DEPENDENCIES.md @@ -189,7 +189,6 @@ following works: - github.com/google/go-github [BSD 3-Clause "New" or "Revised" License](https://github.com/google/go-github/blob/master/LICENSE) - github.com/google/go-querystring [BSD 3-Clause "New" or "Revised" License](https://github.com/google/go-querystring/blob/master/LICENSE) - github.com/google/go-tpm [Apache License 2.0](https://github.com/google/go-tpm/blob/main/LICENSE) -- github.com/google/gofuzz [Apache License 2.0](https://github.com/google/gofuzz/blob/master/LICENSE) - github.com/google/s2a-go [Apache License 2.0](https://github.com/google/s2a-go/blob/main/LICENSE.md) - github.com/google/uuid [BSD 3-Clause "New" or "Revised" License](https://github.com/google/uuid/blob/master/LICENSE) - github.com/googleapis/enterprise-certificate-proxy [Apache License 2.0](https://github.com/googleapis/enterprise-certificate-proxy/blob/main/LICENSE) @@ -485,6 +484,7 @@ following works: - modernc.org/memory [BSD 3-Clause "New" or "Revised" License](https://gitlab.com/cznic/memory/-/blob/master/LICENSE) - modernc.org/sqlite [BSD 3-Clause "New" or "Revised" License](https://gitlab.com/cznic/sqlite/-/blob/master/LICENSE) - sigs.k8s.io/json [Apache License 2.0](https://github.com/kubernetes/client-go/blob/master/LICENSE) +- sigs.k8s.io/randfill [Apache License 2.0](https://github.com/kubernetes-sigs/randfill/blob/main/LICENSE) - sigs.k8s.io/structured-merge-diff [Apache License 2.0](https://github.com/kubernetes/client-go/blob/master/LICENSE) - sigs.k8s.io/yaml [Apache License 2.0](https://github.com/kubernetes/client-go/blob/master/LICENSE) - software.sslmate.com/src/go-pkcs12 [BSD 3-Clause "New" or "Revised" License](https://github.com/SSLMate/go-pkcs12/blob/master/LICENSE) diff --git a/go.mod b/go.mod index 90d00915d..5f87f1731 100644 --- a/go.mod +++ b/go.mod @@ -110,7 +110,7 @@ require ( github.com/gophercloud/gophercloud/v2 v2.7.0 github.com/gorcon/rcon v1.4.0 github.com/gorilla/mux v1.8.1 - github.com/gorilla/websocket v1.5.3 + github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 github.com/gosnmp/gosnmp v1.40.0 github.com/grid-x/modbus v0.0.0-20240503115206-582f2ab60a18 github.com/gwos/tcg/sdk v0.0.0-20240830123415-f8a34bba6358 @@ -239,9 +239,9 @@ require ( gopkg.in/olivere/elastic.v5 v5.0.86 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 gopkg.in/yaml.v2 v2.4.0 - k8s.io/api v0.32.3 - k8s.io/apimachinery v0.32.3 - k8s.io/client-go v0.32.3 + k8s.io/api v0.33.0 + k8s.io/apimachinery v0.33.0 + k8s.io/client-go v0.33.0 layeh.com/radius v0.0.0-20221205141417-e7fbddd11d68 modernc.org/sqlite v1.37.0 software.sslmate.com/src/go-pkcs12 v0.5.0 @@ -367,10 +367,9 @@ require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/flatbuffers v25.2.10+incompatible // indirect - github.com/google/gnostic-models v0.6.8 // indirect + github.com/google/gnostic-models v0.6.9 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/go-tpm v0.9.3 // indirect - github.com/google/gofuzz v1.2.0 // indirect github.com/google/s2a-go v0.1.9 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect github.com/googleapis/gax-go/v2 v2.14.1 // indirect @@ -552,12 +551,13 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect honnef.co/go/tools v0.2.2 // indirect k8s.io/klog/v2 v2.130.1 // indirect - k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect + k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e // indirect modernc.org/libc v1.62.1 // indirect modernc.org/mathutil v1.7.1 // indirect modernc.org/memory v1.9.1 // indirect sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect + sigs.k8s.io/randfill v1.0.0 // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) diff --git a/go.sum b/go.sum index ac07e6687..8b6e95b59 100644 --- a/go.sum +++ b/go.sum @@ -1375,16 +1375,16 @@ github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= -github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= +github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg= +github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= github.com/google/cel-go v0.25.0 h1:jsFw9Fhn+3y2kBbltZR4VEz5xKkcIFRPDnuEzAGv5GY= github.com/google/cel-go v0.25.0/go.mod h1:hjEb6r5SuOSlhCHmFoLzu8HGCERvIsDAbxDAyNU/MmI= github.com/google/flatbuffers v1.12.0/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= github.com/google/flatbuffers v2.0.8+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= github.com/google/flatbuffers v25.2.10+incompatible h1:F3vclr7C3HpB1k9mxCGRMXq6FdUalZ6H/pNX4FP1v0Q= github.com/google/flatbuffers v25.2.10+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= -github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= -github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= +github.com/google/gnostic-models v0.6.9 h1:MU/8wDLif2qCXZmzncUQ/BOfxWfthHi63KqpoNbWqVw= +github.com/google/gnostic-models v0.6.9/go.mod h1:CiWsm0s6BSQd1hRn8/QmxqB6BesYcbSZxsz9b0KuDBw= github.com/google/gnxi v0.0.0-20231026134436-d82d9936af15 h1:EETGSLGKBReUUYZdztSp45EzTE6CHw2qMKIfyPrgp6c= github.com/google/gnxi v0.0.0-20231026134436-d82d9936af15/go.mod h1:w8XuCWhpJuVsGdFLU9bLN9CBLROXSDp9tO1SFgg2l+4= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -1494,8 +1494,8 @@ github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pw github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= -github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5THxAzdVpqr6/geYxZytqFMBCOtn/ujyeo= +github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA= github.com/gosnmp/gosnmp v1.40.0 h1:MvSqHZaNnhMKdn5IVhyYzCsVfXV1lgg6ZgLRku7FVcM= github.com/gosnmp/gosnmp v1.40.0/go.mod h1:CxVS6bXqmWZlafUj9pZUnQX5e4fAltqPcijxWpCitDo= github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc h1:GN2Lv3MGO7AS6PrRoT6yV5+wkrOpcszoIsO4+4ds248= @@ -3415,16 +3415,16 @@ honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= honnef.co/go/tools v0.2.1/go.mod h1:lPVVZ2BS5TfnjLyizF7o7hv7j9/L+8cZY2hLyjP9cGY= honnef.co/go/tools v0.2.2 h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk= honnef.co/go/tools v0.2.2/go.mod h1:lPVVZ2BS5TfnjLyizF7o7hv7j9/L+8cZY2hLyjP9cGY= -k8s.io/api v0.32.3 h1:Hw7KqxRusq+6QSplE3NYG4MBxZw1BZnq4aP4cJVINls= -k8s.io/api v0.32.3/go.mod h1:2wEDTXADtm/HA7CCMD8D8bK4yuBUptzaRhYcYEEYA3k= -k8s.io/apimachinery v0.32.3 h1:JmDuDarhDmA/Li7j3aPrwhpNBA94Nvk5zLeOge9HH1U= -k8s.io/apimachinery v0.32.3/go.mod h1:GpHVgxoKlTxClKcteaeuF1Ul/lDVb74KpZcxcmLDElE= -k8s.io/client-go v0.32.3 h1:RKPVltzopkSgHS7aS98QdscAgtgah/+zmpAogooIqVU= -k8s.io/client-go v0.32.3/go.mod h1:3v0+3k4IcT9bXTc4V2rt+d2ZPPG700Xy6Oi0Gdl2PaY= +k8s.io/api v0.33.0 h1:yTgZVn1XEe6opVpP1FylmNrIFWuDqe2H0V8CT5gxfIU= +k8s.io/api v0.33.0/go.mod h1:CTO61ECK/KU7haa3qq8sarQ0biLq2ju405IZAd9zsiM= +k8s.io/apimachinery v0.33.0 h1:1a6kHrJxb2hs4t8EE5wuR/WxKDwGN1FKH3JvDtA0CIQ= +k8s.io/apimachinery v0.33.0/go.mod h1:BHW0YOu7n22fFv/JkYOEfkUYNRN0fj0BlvMFWA7b+SM= +k8s.io/client-go v0.33.0 h1:UASR0sAYVUzs2kYuKn/ZakZlcs2bEHaizrrHUZg0G98= +k8s.io/client-go v0.33.0/go.mod h1:kGkd+l/gNGg8GYWAPr0xF1rRKvVWvzh9vmZAMXtaKOg= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f h1:GA7//TjRY9yWGy1poLzYYJJ4JRdzg3+O6e8I+e+8T5Y= -k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f/go.mod h1:R/HEjbvWI0qdfb8viZUeVZm0X6IZnxAydC7YU42CMw4= +k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff h1:/usPimJzUKKu+m+TE36gUyGcf03XZEP0ZIKgKj35LS4= +k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff/go.mod h1:5jIi+8yX4RIb8wk3XwBo5Pq2ccx4FP10ohkbSKCZoK8= k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e h1:KqK5c/ghOm8xkHYhlodbp6i6+r+ChV2vuAuVRdFbLro= k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= layeh.com/radius v0.0.0-20221205141417-e7fbddd11d68 h1:2NDro2Jzkrqfngy/sA5GVnChs7fx8EzcQKFi/lI2cfg= @@ -3497,8 +3497,11 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 h1:/Rv+M11QRah1itp8VhT6HoVx1Ray9eB4DBr+K+/sCJ8= sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3/go.mod h1:18nIHnGi6636UCz6m8i4DhaJ65T6EruyzmoQqI2BVDo= -sigs.k8s.io/structured-merge-diff/v4 v4.4.2 h1:MdmvkGuXi/8io6ixD5wud3vOLwc1rj0aNqRlpuvjmwA= -sigs.k8s.io/structured-merge-diff/v4 v4.4.2/go.mod h1:N8f93tFZh9U6vpxwRArLiikrE5/2tiu1w1AGfACIGE4= +sigs.k8s.io/randfill v0.0.0-20250304075658-069ef1bbf016/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= +sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU= +sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= +sigs.k8s.io/structured-merge-diff/v4 v4.6.0 h1:IUA9nvMmnKWcj5jl84xn+T5MnlZKThmUW1TdblaLVAc= +sigs.k8s.io/structured-merge-diff/v4 v4.6.0/go.mod h1:dDy58f92j70zLsuZVuUX5Wp9vtxXpaZnkPGWeqDfCps= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= software.sslmate.com/src/go-pkcs12 v0.5.0 h1:EC6R394xgENTpZ4RltKydeDUjtlM5drOYIG9c6TVj2M= diff --git a/plugins/inputs/kube_inventory/client.go b/plugins/inputs/kube_inventory/client.go index 20eb6faab..e13cd45fc 100644 --- a/plugins/inputs/kube_inventory/client.go +++ b/plugins/inputs/kube_inventory/client.go @@ -7,6 +7,7 @@ import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + discoveryv1 "k8s.io/api/discovery/v1" netv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" @@ -91,10 +92,10 @@ func (c *client) getDeployments(ctx context.Context) (*appsv1.DeploymentList, er return c.AppsV1().Deployments(c.namespace).List(ctx, metav1.ListOptions{}) } -func (c *client) getEndpoints(ctx context.Context) (*corev1.EndpointsList, error) { +func (c *client) getEndpoints(ctx context.Context) (*discoveryv1.EndpointSliceList, error) { ctx, cancel := context.WithTimeout(ctx, c.timeout) defer cancel() - return c.CoreV1().Endpoints(c.namespace).List(ctx, metav1.ListOptions{}) + return c.DiscoveryV1().EndpointSlices(c.namespace).List(ctx, metav1.ListOptions{}) } func (c *client) getIngress(ctx context.Context) (*netv1.IngressList, error) { diff --git a/plugins/inputs/kube_inventory/client_test.go b/plugins/inputs/kube_inventory/client_test.go index 8444ef072..2b3145221 100644 --- a/plugins/inputs/kube_inventory/client_test.go +++ b/plugins/inputs/kube_inventory/client_test.go @@ -13,16 +13,8 @@ type mockHandler struct { responseMap map[string]interface{} } -func toStrPtr(s string) *string { - return &s -} - -func toInt32Ptr(i int32) *int32 { - return &i -} - -func toBoolPtr(b bool) *bool { - return &b +func toPtr[T any](v T) *T { + return &v } func TestNewClient(t *testing.T) { diff --git a/plugins/inputs/kube_inventory/deployment_test.go b/plugins/inputs/kube_inventory/deployment_test.go index 239387916..f13948b69 100644 --- a/plugins/inputs/kube_inventory/deployment_test.go +++ b/plugins/inputs/kube_inventory/deployment_test.go @@ -59,7 +59,7 @@ func TestDeployment(t *testing.T) { }, }, }, - Replicas: toInt32Ptr(4), + Replicas: toPtr(int32(4)), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "select1": "s1", @@ -155,7 +155,7 @@ func TestDeploymentSelectorFilter(t *testing.T) { }, }, }, - Replicas: toInt32Ptr(4), + Replicas: toPtr(int32(4)), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "select1": "s1", diff --git a/plugins/inputs/kube_inventory/endpoint.go b/plugins/inputs/kube_inventory/endpoint.go index ea82a62a5..a009ae33c 100644 --- a/plugins/inputs/kube_inventory/endpoint.go +++ b/plugins/inputs/kube_inventory/endpoint.go @@ -4,7 +4,7 @@ import ( "context" "strings" - corev1 "k8s.io/api/core/v1" + discoveryv1 "k8s.io/api/discovery/v1" "github.com/influxdata/telegraf" ) @@ -20,7 +20,7 @@ func collectEndpoints(ctx context.Context, acc telegraf.Accumulator, ki *Kuberne } } -func gatherEndpoint(e corev1.Endpoints, acc telegraf.Accumulator) { +func gatherEndpoint(e discoveryv1.EndpointSlice, acc telegraf.Accumulator) { creationTS := e.GetCreationTimestamp() if creationTS.IsZero() { return @@ -36,46 +36,28 @@ func gatherEndpoint(e corev1.Endpoints, acc telegraf.Accumulator) { "namespace": e.Namespace, } - for _, endpoint := range e.Subsets { - for _, readyAddr := range endpoint.Addresses { - fields["ready"] = true + for _, endpoint := range e.Endpoints { + fields["ready"] = *endpoint.Conditions.Ready - tags["hostname"] = readyAddr.Hostname - if readyAddr.NodeName != nil { - tags["node_name"] = *readyAddr.NodeName - } - if readyAddr.TargetRef != nil { - tags[strings.ToLower(readyAddr.TargetRef.Kind)] = readyAddr.TargetRef.Name - } - - for _, port := range endpoint.Ports { - fields["port"] = port.Port - - tags["port_name"] = port.Name - tags["port_protocol"] = string(port.Protocol) - - acc.AddFields(endpointMeasurement, fields, tags) - } + if endpoint.Hostname != nil { + tags["hostname"] = *endpoint.Hostname + } + if endpoint.NodeName != nil { + tags["node_name"] = *endpoint.NodeName + } + if endpoint.TargetRef != nil { + tags[strings.ToLower(endpoint.TargetRef.Kind)] = endpoint.TargetRef.Name } - for _, notReadyAddr := range endpoint.NotReadyAddresses { - fields["ready"] = false - tags["hostname"] = notReadyAddr.Hostname - if notReadyAddr.NodeName != nil { - tags["node_name"] = *notReadyAddr.NodeName - } - if notReadyAddr.TargetRef != nil { - tags[strings.ToLower(notReadyAddr.TargetRef.Kind)] = notReadyAddr.TargetRef.Name + for _, port := range e.Ports { + if port.Port != nil { + fields["port"] = *port.Port } - for _, port := range endpoint.Ports { - fields["port"] = port.Port + tags["port_name"] = *port.Name + tags["port_protocol"] = string(*port.Protocol) - tags["port_name"] = port.Name - tags["port_protocol"] = string(port.Protocol) - - acc.AddFields(endpointMeasurement, fields, tags) - } + acc.AddFields(endpointMeasurement, fields, tags) } } } diff --git a/plugins/inputs/kube_inventory/endpoint_test.go b/plugins/inputs/kube_inventory/endpoint_test.go index 97bf85077..fd095905f 100644 --- a/plugins/inputs/kube_inventory/endpoint_test.go +++ b/plugins/inputs/kube_inventory/endpoint_test.go @@ -5,7 +5,8 @@ import ( "time" "github.com/stretchr/testify/require" - "k8s.io/api/core/v1" + corev1 "k8s.io/api/core/v1" + discoveryv1 "k8s.io/api/discovery/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/influxdata/telegraf" @@ -26,7 +27,7 @@ func TestEndpoint(t *testing.T) { name: "no endpoints", handler: &mockHandler{ responseMap: map[string]interface{}{ - "/endpoints/": &v1.EndpointsList{}, + "/endpoints/": &discoveryv1.EndpointSliceList{}, }, }, hasError: false, @@ -35,30 +36,29 @@ func TestEndpoint(t *testing.T) { name: "collect ready endpoints", handler: &mockHandler{ responseMap: map[string]interface{}{ - "/endpoints/": &v1.EndpointsList{ - Items: []v1.Endpoints{ + "/endpoints/": &discoveryv1.EndpointSliceList{ + Items: []discoveryv1.EndpointSlice{ { - Subsets: []v1.EndpointSubset{ + Endpoints: []discoveryv1.Endpoint{ { - Addresses: []v1.EndpointAddress{ - { - Hostname: "storage-6", - NodeName: toStrPtr("b.storage.internal"), - TargetRef: &v1.ObjectReference{ - Kind: "pod", - Name: "storage-6", - }, - }, + Hostname: toPtr("storage-6"), + NodeName: toPtr("b.storage.internal"), + TargetRef: &corev1.ObjectReference{ + Kind: "pod", + Name: "storage-6", }, - Ports: []v1.EndpointPort{ - { - Name: "server", - Protocol: "TCP", - Port: 8080, - }, + Conditions: discoveryv1.EndpointConditions{ + Ready: toPtr(true), }, }, }, + Ports: []discoveryv1.EndpointPort{ + { + Name: toPtr("server"), + Protocol: toPtr(corev1.Protocol("TCP")), + Port: toPtr(int32(8080)), + }, + }, ObjectMeta: metav1.ObjectMeta{ Generation: 12, Namespace: "ns1", @@ -97,27 +97,19 @@ func TestEndpoint(t *testing.T) { name: "collect notready endpoints", handler: &mockHandler{ responseMap: map[string]interface{}{ - "/endpoints/": &v1.EndpointsList{ - Items: []v1.Endpoints{ + "/endpoints/": &discoveryv1.EndpointSliceList{ + Items: []discoveryv1.EndpointSlice{ { - Subsets: []v1.EndpointSubset{ + Endpoints: []discoveryv1.Endpoint{ { - NotReadyAddresses: []v1.EndpointAddress{ - { - Hostname: "storage-6", - NodeName: toStrPtr("b.storage.internal"), - TargetRef: &v1.ObjectReference{ - Kind: "pod", - Name: "storage-6", - }, - }, + Hostname: toPtr("storage-6"), + NodeName: toPtr("b.storage.internal"), + TargetRef: &corev1.ObjectReference{ + Kind: "pod", + Name: "storage-6", }, - Ports: []v1.EndpointPort{ - { - Name: "server", - Protocol: "TCP", - Port: 8080, - }, + Conditions: discoveryv1.EndpointConditions{ + Ready: toPtr(false), }, }, }, @@ -127,6 +119,13 @@ func TestEndpoint(t *testing.T) { Name: "storage", CreationTimestamp: metav1.Time{Time: now}, }, + Ports: []discoveryv1.EndpointPort{ + { + Name: toPtr("server"), + Protocol: toPtr(corev1.Protocol("TCP")), + Port: toPtr(int32(8080)), + }, + }, }, }, }, @@ -159,44 +158,28 @@ func TestEndpoint(t *testing.T) { name: "endpoints missing node_name", handler: &mockHandler{ responseMap: map[string]interface{}{ - "/endpoints/": &v1.EndpointsList{ - Items: []v1.Endpoints{ + "/endpoints/": &discoveryv1.EndpointSliceList{ + Items: []discoveryv1.EndpointSlice{ { - Subsets: []v1.EndpointSubset{ + Endpoints: []discoveryv1.Endpoint{ { - NotReadyAddresses: []v1.EndpointAddress{ - { - Hostname: "storage-6", - TargetRef: &v1.ObjectReference{ - Kind: "pod", - Name: "storage-6", - }, - }, + Hostname: toPtr("storage-6"), + TargetRef: &corev1.ObjectReference{ + Kind: "pod", + Name: "storage-6", }, - Ports: []v1.EndpointPort{ - { - Name: "server", - Protocol: "TCP", - Port: 8080, - }, + Conditions: discoveryv1.EndpointConditions{ + Ready: toPtr(false), }, }, { - Addresses: []v1.EndpointAddress{ - { - Hostname: "storage-12", - TargetRef: &v1.ObjectReference{ - Kind: "pod", - Name: "storage-12", - }, - }, + Hostname: toPtr("storage-12"), + TargetRef: &corev1.ObjectReference{ + Kind: "pod", + Name: "storage-12", }, - Ports: []v1.EndpointPort{ - { - Name: "server", - Protocol: "TCP", - Port: 8080, - }, + Conditions: discoveryv1.EndpointConditions{ + Ready: toPtr(true), }, }, }, @@ -206,6 +189,13 @@ func TestEndpoint(t *testing.T) { Name: "storage", CreationTimestamp: metav1.Time{Time: now}, }, + Ports: []discoveryv1.EndpointPort{ + { + Name: toPtr("server"), + Protocol: toPtr(corev1.Protocol("TCP")), + Port: toPtr(int32(8080)), + }, + }, }, }, }, @@ -255,7 +245,7 @@ func TestEndpoint(t *testing.T) { for _, v := range tests { acc := new(testutil.Accumulator) - for _, endpoint := range ((v.handler.responseMap["/endpoints/"]).(*v1.EndpointsList)).Items { + for _, endpoint := range ((v.handler.responseMap["/endpoints/"]).(*discoveryv1.EndpointSliceList)).Items { gatherEndpoint(endpoint, acc) } diff --git a/plugins/inputs/kube_inventory/persistentvolumeclaim_test.go b/plugins/inputs/kube_inventory/persistentvolumeclaim_test.go index 8e91b3383..39c9c624b 100644 --- a/plugins/inputs/kube_inventory/persistentvolumeclaim_test.go +++ b/plugins/inputs/kube_inventory/persistentvolumeclaim_test.go @@ -45,7 +45,7 @@ func TestPersistentVolumeClaim(t *testing.T) { }, Spec: corev1.PersistentVolumeClaimSpec{ VolumeName: "pvc-dc870fd6-1e08-11e8-b226-02aa4bc06eb8", - StorageClassName: toStrPtr("ebs-1"), + StorageClassName: toPtr("ebs-1"), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "select1": "s1", @@ -99,7 +99,7 @@ func TestPersistentVolumeClaim(t *testing.T) { }, Spec: corev1.PersistentVolumeClaimSpec{ VolumeName: "pvc-dc870fd6-1e08-11e8-b226-02aa4bc06eb8", - StorageClassName: toStrPtr("ebs-1"), + StorageClassName: toPtr("ebs-1"), Selector: nil, }, ObjectMeta: metav1.ObjectMeta{ @@ -224,7 +224,7 @@ func TestPersistentVolumeClaimSelectorFilter(t *testing.T) { }, Spec: corev1.PersistentVolumeClaimSpec{ VolumeName: "pvc-dc870fd6-1e08-11e8-b226-02aa4bc06eb8", - StorageClassName: toStrPtr("ebs-1"), + StorageClassName: toPtr("ebs-1"), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "select1": "s1", diff --git a/plugins/inputs/kube_inventory/pod_test.go b/plugins/inputs/kube_inventory/pod_test.go index d76e6a2c1..7490b6965 100644 --- a/plugins/inputs/kube_inventory/pod_test.go +++ b/plugins/inputs/kube_inventory/pod_test.go @@ -193,7 +193,7 @@ func TestPod(t *testing.T) { APIVersion: "apps/v1", Kind: "DaemonSet", Name: "forwarder", - Controller: toBoolPtr(true), + Controller: toPtr(true), }, }, Generation: 11232, @@ -559,7 +559,7 @@ func TestPodSelectorFilter(t *testing.T) { APIVersion: "apps/v1", Kind: "DaemonSet", Name: "forwarder", - Controller: toBoolPtr(true), + Controller: toPtr(true), }, }, Generation: 11232, @@ -802,7 +802,7 @@ func TestPodPendingContainers(t *testing.T) { APIVersion: "apps/v1", Kind: "DaemonSet", Name: "forwarder", - Controller: toBoolPtr(true), + Controller: toPtr(true), }, }, Generation: 11232, diff --git a/plugins/inputs/kube_inventory/statefulset_test.go b/plugins/inputs/kube_inventory/statefulset_test.go index 03b5586d8..dc48315bb 100644 --- a/plugins/inputs/kube_inventory/statefulset_test.go +++ b/plugins/inputs/kube_inventory/statefulset_test.go @@ -47,7 +47,7 @@ func TestStatefulSet(t *testing.T) { ObservedGeneration: 119, }, Spec: v1.StatefulSetSpec{ - Replicas: toInt32Ptr(3), + Replicas: toPtr(int32(3)), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "select1": "s1", @@ -105,7 +105,7 @@ func TestStatefulSet(t *testing.T) { ObservedGeneration: 119, }, Spec: v1.StatefulSetSpec{ - Replicas: toInt32Ptr(3), + Replicas: toPtr(int32(3)), Selector: nil, }, ObjectMeta: metav1.ObjectMeta{ @@ -242,7 +242,7 @@ func TestStatefulSetSelectorFilter(t *testing.T) { ObservedGeneration: 119, }, Spec: v1.StatefulSetSpec{ - Replicas: toInt32Ptr(3), + Replicas: toPtr(int32(3)), Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ "select1": "s1",