Skip to content

Commit 47a708e

Browse files
rawkodedanielnelson
authored andcommitted
Remove usage of deprecated v1beta API endpoints (#6543)
1 parent 988e036 commit 47a708e

File tree

11 files changed

+107
-96
lines changed

11 files changed

+107
-96
lines changed

Gopkg.lock

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/inputs/kube_inventory/README.md

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
# Kube_Inventory Plugin
2+
23
This plugin generates metrics derived from the state of the following Kubernetes resources:
3-
- daemonsets
4-
- deployments
5-
- nodes
6-
- persistentvolumes
7-
- persistentvolumeclaims
8-
- pods (containers)
9-
- statefulsets
4+
5+
- daemonsets
6+
- deployments
7+
- nodes
8+
- persistentvolumes
9+
- persistentvolumeclaims
10+
- pods (containers)
11+
- statefulsets
12+
13+
Kubernetes is a fast moving project, with a new minor release every 3 months. As
14+
such, we will aim to maintain support only for versions that are supported by
15+
the major cloud providers; this is roughly 4 release / 2 years.
16+
17+
**This plugin supports Kubernetes 1.11 and later.**
1018

1119
#### Series Cardinality Warning
1220

1321
This plugin may produce a high number of series which, when not controlled
14-
for, will cause high load on your database. Use the following techniques to
22+
for, will cause high load on your database. Use the following techniques to
1523
avoid cardinality issues:
1624

1725
- Use [metric filtering][] options to exclude unneeded measurements and tags.
@@ -61,6 +69,7 @@ avoid cardinality issues:
6169
#### Kubernetes Permissions
6270

6371
If using [RBAC authorization](https://kubernetes.io/docs/reference/access-authn-authz/rbac/), you will need to create a cluster role to list "persistentvolumes" and "nodes". You will then need to make an [aggregated ClusterRole](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#aggregated-clusterroles) that will eventually be bound to a user or group.
72+
6473
```yaml
6574
---
6675
kind: ClusterRole
@@ -70,9 +79,9 @@ metadata:
7079
labels:
7180
rbac.authorization.k8s.io/aggregate-view-telegraf: "true"
7281
rules:
73-
- apiGroups: [""]
74-
resources: ["persistentvolumes","nodes"]
75-
verbs: ["get","list"]
82+
- apiGroups: [""]
83+
resources: ["persistentvolumes", "nodes"]
84+
verbs: ["get", "list"]
7685

7786
---
7887
kind: ClusterRole
@@ -81,14 +90,15 @@ metadata:
8190
name: influx:telegraf
8291
aggregationRule:
8392
clusterRoleSelectors:
84-
- matchLabels:
85-
rbac.authorization.k8s.io/aggregate-view-telegraf: "true"
86-
- matchLabels:
87-
rbac.authorization.k8s.io/aggregate-to-view: "true"
93+
- matchLabels:
94+
rbac.authorization.k8s.io/aggregate-view-telegraf: "true"
95+
- matchLabels:
96+
rbac.authorization.k8s.io/aggregate-to-view: "true"
8897
rules: [] # Rules are automatically filled in by the controller manager.
8998
```
9099
91100
Bind the newly created aggregated ClusterRole with the following config file, updating the subjects as needed.
101+
92102
```yaml
93103
---
94104
apiVersion: rbac.authorization.k8s.io/v1
@@ -100,15 +110,14 @@ roleRef:
100110
kind: ClusterRole
101111
name: influx:telegraf
102112
subjects:
103-
- kind: ServiceAccount
104-
name: telegraf
105-
namespace: default
113+
- kind: ServiceAccount
114+
name: telegraf
115+
namespace: default
106116
```
107117
108-
109118
### Metrics:
110119
111-
+ kubernetes_daemonset
120+
- kubernetes_daemonset
112121
- tags:
113122
- daemonset_name
114123
- namespace
@@ -122,7 +131,7 @@ subjects:
122131
- number_unavailable
123132
- updated_number_scheduled
124133
125-
- kubernetes_deployment
134+
* kubernetes_deployment
126135
- tags:
127136
- deployment_name
128137
- namespace
@@ -131,22 +140,22 @@ subjects:
131140
- replicas_unavailable
132141
- created
133142
134-
+ kubernetes_endpoints
143+
- kubernetes_endpoints
135144
- tags:
136145
- endpoint_name
137146
- namespace
138147
- hostname
139148
- node_name
140149
- port_name
141150
- port_protocol
142-
- kind (*varies)
151+
- kind (\*varies)
143152
- fields:
144153
- created
145154
- generation
146155
- ready
147156
- port
148157
149-
- kubernetes_ingress
158+
* kubernetes_ingress
150159
- tags:
151160
- ingress_name
152161
- namespace
@@ -161,7 +170,7 @@ subjects:
161170
- backend_service_port
162171
- tls
163172
164-
+ kubernetes_node
173+
- kubernetes_node
165174
- tags:
166175
- node_name
167176
- fields:
@@ -172,15 +181,15 @@ subjects:
172181
- allocatable_memory_bytes
173182
- allocatable_pods
174183
175-
- kubernetes_persistentvolume
184+
* kubernetes_persistentvolume
176185
- tags:
177186
- pv_name
178187
- phase
179188
- storageclass
180189
- fields:
181190
- phase_type (int, [see below](#pv-phase_type))
182191
183-
+ kubernetes_persistentvolumeclaim
192+
- kubernetes_persistentvolumeclaim
184193
- tags:
185194
- pvc_name
186195
- namespace
@@ -189,7 +198,7 @@ subjects:
189198
- fields:
190199
- phase_type (int, [see below](#pvc-phase_type))
191200
192-
- kubernetes_pod_container
201+
* kubernetes_pod_container
193202
- tags:
194203
- container_name
195204
- namespace
@@ -204,7 +213,7 @@ subjects:
204213
- resource_limits_cpu_units
205214
- resource_limits_memory_bytes
206215
207-
+ kubernetes_service
216+
- kubernetes_service
208217
- tags:
209218
- service_name
210219
- namespace
@@ -218,7 +227,7 @@ subjects:
218227
- port
219228
- target_port
220229
221-
- kubernetes_statefulset
230+
* kubernetes_statefulset
222231
- tags:
223232
- statefulset_name
224233
- namespace
@@ -236,26 +245,25 @@ subjects:
236245

237246
The persistentvolume "phase" is saved in the `phase` tag with a correlated numeric field called `phase_type` corresponding with that tag value.
238247

239-
|Tag value |Corresponding field value|
240-
-----------|-------------------------|
241-
|bound | 0 |
242-
|failed | 1 |
243-
|pending | 2 |
244-
|released | 3 |
245-
|available | 4 |
246-
|unknown | 5 |
248+
| Tag value | Corresponding field value |
249+
| --------- | ------------------------- |
250+
| bound | 0 |
251+
| failed | 1 |
252+
| pending | 2 |
253+
| released | 3 |
254+
| available | 4 |
255+
| unknown | 5 |
247256

248257
#### pvc `phase_type`
249258

250259
The persistentvolumeclaim "phase" is saved in the `phase` tag with a correlated numeric field called `phase_type` corresponding with that tag value.
251260

252-
|Tag value |Corresponding field value|
253-
-----------|-------------------------|
254-
|bound | 0 |
255-
|lost | 1 |
256-
|pending | 2 |
257-
|unknown | 3 |
258-
261+
| Tag value | Corresponding field value |
262+
| --------- | ------------------------- |
263+
| bound | 0 |
264+
| lost | 1 |
265+
| pending | 2 |
266+
| unknown | 3 |
259267

260268
### Example Output:
261269

@@ -271,7 +279,6 @@ kubernetes_pod_container,container_name=telegraf,namespace=default,node_name=ip-
271279
kubernetes_statefulset,namespace=default,statefulset_name=etcd replicas_updated=3i,spec_replicas=3i,observed_generation=1i,created=1544101669000000000i,generation=1i,replicas=3i,replicas_current=3i,replicas_ready=3i 1547597616000000000
272280
```
273281
274-
275282
[metric filtering]: https://github.com/influxdata/telegraf/blob/master/docs/CONFIGURATION.md#metric-filtering
276283
[retention policy]: https://docs.influxdata.com/influxdb/latest/guides/downsampling_and_retention/
277284
[max-series-per-database]: https://docs.influxdata.com/influxdb/latest/administration/config/#max-series-per-database-1000000

plugins/inputs/kube_inventory/client.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import (
55
"time"
66

77
"github.com/ericchiang/k8s"
8-
"github.com/ericchiang/k8s/apis/apps/v1beta1"
9-
"github.com/ericchiang/k8s/apis/apps/v1beta2"
10-
"github.com/ericchiang/k8s/apis/core/v1"
8+
v1APPS "github.com/ericchiang/k8s/apis/apps/v1"
9+
v1 "github.com/ericchiang/k8s/apis/core/v1"
1110
v1beta1EXT "github.com/ericchiang/k8s/apis/extensions/v1beta1"
1211

1312
"github.com/influxdata/telegraf/internal/tls"
@@ -48,15 +47,15 @@ func newClient(baseURL, namespace, bearerToken string, timeout time.Duration, tl
4847
}, nil
4948
}
5049

51-
func (c *client) getDaemonSets(ctx context.Context) (*v1beta2.DaemonSetList, error) {
52-
list := new(v1beta2.DaemonSetList)
50+
func (c *client) getDaemonSets(ctx context.Context) (*v1APPS.DaemonSetList, error) {
51+
list := new(v1APPS.DaemonSetList)
5352
ctx, cancel := context.WithTimeout(ctx, c.timeout)
5453
defer cancel()
5554
return list, c.List(ctx, c.namespace, list)
5655
}
5756

58-
func (c *client) getDeployments(ctx context.Context) (*v1beta1.DeploymentList, error) {
59-
list := &v1beta1.DeploymentList{}
57+
func (c *client) getDeployments(ctx context.Context) (*v1APPS.DeploymentList, error) {
58+
list := &v1APPS.DeploymentList{}
6059
ctx, cancel := context.WithTimeout(ctx, c.timeout)
6160
defer cancel()
6261
return list, c.List(ctx, c.namespace, list)
@@ -111,8 +110,8 @@ func (c *client) getServices(ctx context.Context) (*v1.ServiceList, error) {
111110
return list, c.List(ctx, c.namespace, list)
112111
}
113112

114-
func (c *client) getStatefulSets(ctx context.Context) (*v1beta1.StatefulSetList, error) {
115-
list := new(v1beta1.StatefulSetList)
113+
func (c *client) getStatefulSets(ctx context.Context) (*v1APPS.StatefulSetList, error) {
114+
list := new(v1APPS.StatefulSetList)
116115
ctx, cancel := context.WithTimeout(ctx, c.timeout)
117116
defer cancel()
118117
return list, c.List(ctx, c.namespace, list)

plugins/inputs/kube_inventory/daemonset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55
"time"
66

7-
"github.com/ericchiang/k8s/apis/apps/v1beta2"
7+
"github.com/ericchiang/k8s/apis/apps/v1"
88

99
"github.com/influxdata/telegraf"
1010
)
@@ -23,7 +23,7 @@ func collectDaemonSets(ctx context.Context, acc telegraf.Accumulator, ki *Kubern
2323
}
2424
}
2525

26-
func (ki *KubernetesInventory) gatherDaemonSet(d v1beta2.DaemonSet, acc telegraf.Accumulator) error {
26+
func (ki *KubernetesInventory) gatherDaemonSet(d v1.DaemonSet, acc telegraf.Accumulator) error {
2727
fields := map[string]interface{}{
2828
"generation": d.Metadata.GetGeneration(),
2929
"current_number_scheduled": d.Status.GetCurrentNumberScheduled(),

plugins/inputs/kube_inventory/daemonset_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55
"time"
66

7-
"github.com/ericchiang/k8s/apis/apps/v1beta2"
7+
"github.com/ericchiang/k8s/apis/apps/v1"
88
metav1 "github.com/ericchiang/k8s/apis/meta/v1"
99

1010
"github.com/influxdata/telegraf/testutil"
@@ -24,7 +24,7 @@ func TestDaemonSet(t *testing.T) {
2424
name: "no daemon set",
2525
handler: &mockHandler{
2626
responseMap: map[string]interface{}{
27-
"/daemonsets/": &v1beta2.DaemonSetList{},
27+
"/daemonsets/": &v1.DaemonSetList{},
2828
},
2929
},
3030
hasError: false,
@@ -33,10 +33,10 @@ func TestDaemonSet(t *testing.T) {
3333
name: "collect daemonsets",
3434
handler: &mockHandler{
3535
responseMap: map[string]interface{}{
36-
"/daemonsets/": &v1beta2.DaemonSetList{
37-
Items: []*v1beta2.DaemonSet{
36+
"/daemonsets/": &v1.DaemonSetList{
37+
Items: []*v1.DaemonSet{
3838
{
39-
Status: &v1beta2.DaemonSetStatus{
39+
Status: &v1.DaemonSetStatus{
4040
CurrentNumberScheduled: toInt32Ptr(3),
4141
DesiredNumberScheduled: toInt32Ptr(5),
4242
NumberAvailable: toInt32Ptr(2),
@@ -90,7 +90,7 @@ func TestDaemonSet(t *testing.T) {
9090
client: cli,
9191
}
9292
acc := new(testutil.Accumulator)
93-
for _, dset := range ((v.handler.responseMap["/daemonsets/"]).(*v1beta2.DaemonSetList)).Items {
93+
for _, dset := range ((v.handler.responseMap["/daemonsets/"]).(*v1.DaemonSetList)).Items {
9494
err := ks.gatherDaemonSet(*dset, acc)
9595
if err != nil {
9696
t.Errorf("Failed to gather daemonset - %s", err.Error())

plugins/inputs/kube_inventory/deployment.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import (
44
"context"
55
"time"
66

7-
"github.com/ericchiang/k8s/apis/apps/v1beta1"
8-
7+
v1 "github.com/ericchiang/k8s/apis/apps/v1"
98
"github.com/influxdata/telegraf"
109
)
1110

@@ -23,7 +22,7 @@ func collectDeployments(ctx context.Context, acc telegraf.Accumulator, ki *Kuber
2322
}
2423
}
2524

26-
func (ki *KubernetesInventory) gatherDeployment(d v1beta1.Deployment, acc telegraf.Accumulator) error {
25+
func (ki *KubernetesInventory) gatherDeployment(d v1.Deployment, acc telegraf.Accumulator) error {
2726
fields := map[string]interface{}{
2827
"replicas_available": d.Status.GetAvailableReplicas(),
2928
"replicas_unavailable": d.Status.GetUnavailableReplicas(),

0 commit comments

Comments
 (0)