Skip to content

Commit

Permalink
fix(enhance_k8s_metadata): remove API group unavailable in k8s 1.22
Browse files Browse the repository at this point in the history
The `extensions/v1beta1` API group has been unneeded for some time now,
since all the resources supported by this plugin - DaemonSet, Deployment, ReplicaSet,
StatefulSet - have been moved to `apps/v1` API group.
The API group has ben ultimately removed in Kubernetes 1.22, causing errors
when trying to create a client for it.
  • Loading branch information
andrzej-stencel committed Nov 19, 2021
1 parent c41af2e commit f3fee12
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class EnhanceK8sMetadataFilter < Fluent::Plugin::Filter
# Need different clients to access different API groups/versions
# https://github.com/abonas/kubeclient/issues/208
config_param :core_api_versions, :array, default: ['v1']
config_param :api_groups, :array, default: ["apps/v1", "extensions/v1beta1"]
config_param :api_groups, :array, default: ["apps/v1"]
# if `ca_file` is for an intermediate CA, or otherwise we do not have the
# root CA and want to trust the intermediate CA certs we do have, set this
# to `true` - this corresponds to the openssl s_client -partial_chain flag
Expand Down
16 changes: 7 additions & 9 deletions fluent-plugin-enhance-k8s-metadata/test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,26 @@ def stub_apis
stub_request(:any, %r{/apis$})
.to_return(
'body' => {
'versions' => ['apps/v1', 'extensions/v1beta1']
'versions' => ['apps/v1']
}.to_json
)
stub_request(:get, %r{/api/v1$})
.to_return(body: test_resource('api_list_core_v1.json'), status: 200)
stub_request(:get, %r{/apis/apps$})
.to_return(body: test_resource('api_list_apps.json'), status: 200)
stub_request(:get, %r{/apis/extensions$})
.to_return(body: test_resource('api_list_extensions.json'), status: 200)
stub_request(:get, %r{/api/v1/endpoints$})
.to_return(body: test_resource('endpoints_list.json'), status: 200)
stub_request(:get, %r{/api/v1/namespaces/sumologic/pods})
.to_return(body: test_resource('pod_sumologic.json'), status: 200)
stub_request(:get, %r{/apis/extensions/v1beta1/namespaces/sumologic/replicasets})
stub_request(:get, %r{/apis/apps/v1/namespaces/sumologic/replicasets})
.to_return(body: test_resource('rs_sumologic.json'), status: 200)
stub_request(:get, %r{/apis/extensions/v1beta1/namespaces/sumologic/deployments})
stub_request(:get, %r{/apis/apps/v1/namespaces/sumologic/deployments})
.to_return(body: test_resource('deploy_sumologic.json'), status: 200)
stub_request(:get, %r{/api/v1/namespaces/kube-system/pods})
.to_return(body: test_resource('pod_kube-system.json'), status: 200)
stub_request(:get, %r{/apis/extensions/v1beta1/namespaces/kube-system/replicasets})
stub_request(:get, %r{/apis/apps/v1/namespaces/kube-system/replicasets})
.to_return(body: test_resource('rs_kube-system.json'), status: 200)
stub_request(:get, %r{/apis/extensions/v1beta1/namespaces/kube-system/deployments})
stub_request(:get, %r{/apis/apps/v1/namespaces/kube-system/deployments})
.to_return(body: test_resource('deploy_kube-system.json'), status: 200)
stub_request(:get, %r{/api/v1/namespaces/non-exist/pods})
.to_raise(Kubeclient::ResourceNotFoundError.new(404, nil, nil))
Expand All @@ -55,7 +53,7 @@ def stub_apis
def stub_pod_with_nonexistent_owner
stub_request(:get, %r{/api/v1/namespaces/sumologic/pods/pod-with-nonexistent-owner})
.to_return(body: test_resource('pod_with_nonexistent_owner.json'), status: 200)
stub_request(:get, %r{/apis/extensions/v1beta1/namespaces/sumologic/replicasets/non-existent-replicaset})
stub_request(:get, %r{/apis/apps/v1/namespaces/sumologic/replicasets/non-existent-replicaset})
.to_return(status: 404)
end

Expand All @@ -70,5 +68,5 @@ def init_globals
@cache_size = 1000
@cache_ttl = 60 * 60
@core_api_versions = ['v1']
@api_groups = ['apps/v1', 'extensions/v1beta1']
@api_groups = ['apps/v1']
end

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"annotations": {
"deployment.kubernetes.io/revision": "1",
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"extensions/v1beta1\",\"kind\":\"Deployment\",\"metadata\":{\"annotations\":{},\"labels\":{\"k8s-addon\":\"kube-dns.addons.k8s.io\",\"k8s-app\":\"kube-dns\",\"kubernetes.io/cluster-service\":\"true\"},\"name\":\"kube-dns\",\"namespace\":\"kube-system\"},\"spec\":{\"selector\":{\"matchLabels\":{\"k8s-app\":\"kube-dns\"}},\"strategy\":{\"rollingUpdate\":{\"maxSurge\":\"10%\",\"maxUnavailable\":0}},\"template\":{\"metadata\":{\"annotations\":{\"prometheus.io/port\":\"10055\",\"prometheus.io/scrape\":\"true\",\"scheduler.alpha.kubernetes.io/critical-pod\":\"\",\"scheduler.alpha.kubernetes.io/tolerations\":\"[{\\\"key\\\":\\\"CriticalAddonsOnly\\\", \\\"operator\\\":\\\"Exists\\\"}]\"},\"labels\":{\"k8s-app\":\"kube-dns\"}},\"spec\":{\"containers\":[{\"args\":[\"--config-dir=/kube-dns-config\",\"--dns-port=10053\",\"--domain=cluster.local.\",\"--v=2\"],\"env\":[{\"name\":\"PROMETHEUS_PORT\",\"value\":\"10055\"}],\"image\":\"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.10\",\"livenessProbe\":{\"failureThreshold\":5,\"httpGet\":{\"path\":\"/healthcheck/kubedns\",\"port\":10054,\"scheme\":\"HTTP\"},\"initialDelaySeconds\":60,\"successThreshold\":1,\"timeoutSeconds\":5},\"name\":\"kubedns\",\"ports\":[{\"containerPort\":10053,\"name\":\"dns-local\",\"protocol\":\"UDP\"},{\"containerPort\":10053,\"name\":\"dns-tcp-local\",\"protocol\":\"TCP\"},{\"containerPort\":10055,\"name\":\"metrics\",\"protocol\":\"TCP\"}],\"readinessProbe\":{\"httpGet\":{\"path\":\"/readiness\",\"port\":8081,\"scheme\":\"HTTP\"},\"initialDelaySeconds\":3,\"timeoutSeconds\":5},\"resources\":{\"limits\":{\"memory\":\"170Mi\"},\"requests\":{\"cpu\":\"100m\",\"memory\":\"70Mi\"}},\"volumeMounts\":[{\"mountPath\":\"/kube-dns-config\",\"name\":\"kube-dns-config\"}]},{\"args\":[\"-v=2\",\"-logtostderr\",\"-configDir=/etc/k8s/dns/dnsmasq-nanny\",\"-restartDnsmasq=true\",\"--\",\"-k\",\"--cache-size=1000\",\"--dns-forward-max=150\",\"--no-negcache\",\"--log-facility=-\",\"--server=/cluster.local/127.0.0.1#10053\",\"--server=/in-addr.arpa/127.0.0.1#10053\",\"--server=/in6.arpa/127.0.0.1#10053\"],\"image\":\"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.10\",\"livenessProbe\":{\"failureThreshold\":5,\"httpGet\":{\"path\":\"/healthcheck/dnsmasq\",\"port\":10054,\"scheme\":\"HTTP\"},\"initialDelaySeconds\":60,\"successThreshold\":1,\"timeoutSeconds\":5},\"name\":\"dnsmasq\",\"ports\":[{\"containerPort\":53,\"name\":\"dns\",\"protocol\":\"UDP\"},{\"containerPort\":53,\"name\":\"dns-tcp\",\"protocol\":\"TCP\"}],\"resources\":{\"requests\":{\"cpu\":\"150m\",\"memory\":\"20Mi\"}},\"volumeMounts\":[{\"mountPath\":\"/etc/k8s/dns/dnsmasq-nanny\",\"name\":\"kube-dns-config\"}]},{\"args\":[\"--v=2\",\"--logtostderr\",\"--probe=kubedns,127.0.0.1:10053,kubernetes.default.svc.cluster.local,5,A\",\"--probe=dnsmasq,127.0.0.1:53,kubernetes.default.svc.cluster.local,5,A\"],\"image\":\"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.10\",\"livenessProbe\":{\"failureThreshold\":5,\"httpGet\":{\"path\":\"/metrics\",\"port\":10054,\"scheme\":\"HTTP\"},\"initialDelaySeconds\":60,\"successThreshold\":1,\"timeoutSeconds\":5},\"name\":\"sidecar\",\"ports\":[{\"containerPort\":10054,\"name\":\"metrics\",\"protocol\":\"TCP\"}],\"resources\":{\"requests\":{\"cpu\":\"10m\",\"memory\":\"20Mi\"}}}],\"dnsPolicy\":\"Default\",\"serviceAccountName\":\"kube-dns\",\"volumes\":[{\"configMap\":{\"name\":\"kube-dns\",\"optional\":true},\"name\":\"kube-dns-config\"}]}}}}\n"
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"annotations\":{},\"labels\":{\"k8s-addon\":\"kube-dns.addons.k8s.io\",\"k8s-app\":\"kube-dns\",\"kubernetes.io/cluster-service\":\"true\"},\"name\":\"kube-dns\",\"namespace\":\"kube-system\"},\"spec\":{\"selector\":{\"matchLabels\":{\"k8s-app\":\"kube-dns\"}},\"strategy\":{\"rollingUpdate\":{\"maxSurge\":\"10%\",\"maxUnavailable\":0}},\"template\":{\"metadata\":{\"annotations\":{\"prometheus.io/port\":\"10055\",\"prometheus.io/scrape\":\"true\",\"scheduler.alpha.kubernetes.io/critical-pod\":\"\",\"scheduler.alpha.kubernetes.io/tolerations\":\"[{\\\"key\\\":\\\"CriticalAddonsOnly\\\", \\\"operator\\\":\\\"Exists\\\"}]\"},\"labels\":{\"k8s-app\":\"kube-dns\"}},\"spec\":{\"containers\":[{\"args\":[\"--config-dir=/kube-dns-config\",\"--dns-port=10053\",\"--domain=cluster.local.\",\"--v=2\"],\"env\":[{\"name\":\"PROMETHEUS_PORT\",\"value\":\"10055\"}],\"image\":\"k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.10\",\"livenessProbe\":{\"failureThreshold\":5,\"httpGet\":{\"path\":\"/healthcheck/kubedns\",\"port\":10054,\"scheme\":\"HTTP\"},\"initialDelaySeconds\":60,\"successThreshold\":1,\"timeoutSeconds\":5},\"name\":\"kubedns\",\"ports\":[{\"containerPort\":10053,\"name\":\"dns-local\",\"protocol\":\"UDP\"},{\"containerPort\":10053,\"name\":\"dns-tcp-local\",\"protocol\":\"TCP\"},{\"containerPort\":10055,\"name\":\"metrics\",\"protocol\":\"TCP\"}],\"readinessProbe\":{\"httpGet\":{\"path\":\"/readiness\",\"port\":8081,\"scheme\":\"HTTP\"},\"initialDelaySeconds\":3,\"timeoutSeconds\":5},\"resources\":{\"limits\":{\"memory\":\"170Mi\"},\"requests\":{\"cpu\":\"100m\",\"memory\":\"70Mi\"}},\"volumeMounts\":[{\"mountPath\":\"/kube-dns-config\",\"name\":\"kube-dns-config\"}]},{\"args\":[\"-v=2\",\"-logtostderr\",\"-configDir=/etc/k8s/dns/dnsmasq-nanny\",\"-restartDnsmasq=true\",\"--\",\"-k\",\"--cache-size=1000\",\"--dns-forward-max=150\",\"--no-negcache\",\"--log-facility=-\",\"--server=/cluster.local/127.0.0.1#10053\",\"--server=/in-addr.arpa/127.0.0.1#10053\",\"--server=/in6.arpa/127.0.0.1#10053\"],\"image\":\"k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.10\",\"livenessProbe\":{\"failureThreshold\":5,\"httpGet\":{\"path\":\"/healthcheck/dnsmasq\",\"port\":10054,\"scheme\":\"HTTP\"},\"initialDelaySeconds\":60,\"successThreshold\":1,\"timeoutSeconds\":5},\"name\":\"dnsmasq\",\"ports\":[{\"containerPort\":53,\"name\":\"dns\",\"protocol\":\"UDP\"},{\"containerPort\":53,\"name\":\"dns-tcp\",\"protocol\":\"TCP\"}],\"resources\":{\"requests\":{\"cpu\":\"150m\",\"memory\":\"20Mi\"}},\"volumeMounts\":[{\"mountPath\":\"/etc/k8s/dns/dnsmasq-nanny\",\"name\":\"kube-dns-config\"}]},{\"args\":[\"--v=2\",\"--logtostderr\",\"--probe=kubedns,127.0.0.1:10053,kubernetes.default.svc.cluster.local,5,A\",\"--probe=dnsmasq,127.0.0.1:53,kubernetes.default.svc.cluster.local,5,A\"],\"image\":\"k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.10\",\"livenessProbe\":{\"failureThreshold\":5,\"httpGet\":{\"path\":\"/metrics\",\"port\":10054,\"scheme\":\"HTTP\"},\"initialDelaySeconds\":60,\"successThreshold\":1,\"timeoutSeconds\":5},\"name\":\"sidecar\",\"ports\":[{\"containerPort\":10054,\"name\":\"metrics\",\"protocol\":\"TCP\"}],\"resources\":{\"requests\":{\"cpu\":\"10m\",\"memory\":\"20Mi\"}}}],\"dnsPolicy\":\"Default\",\"serviceAccountName\":\"kube-dns\",\"volumes\":[{\"configMap\":{\"name\":\"kube-dns\",\"optional\":true},\"name\":\"kube-dns-config\"}]}}}}\n"
},
"creationTimestamp": "2019-05-06T20:51:49Z",
"generation": 2,
Expand All @@ -16,7 +16,7 @@
"name": "kube-dns",
"namespace": "kube-system",
"resourceVersion": "856",
"selfLink": "/apis/extensions/v1beta1/namespaces/kube-system/deployments/kube-dns",
"selfLink": "/apis/apps/v1/namespaces/kube-system/deployments/kube-dns",
"uid": "c5000bad-7040-11e9-90f1-02324f7e0d1e"
},
"spec": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"annotations": {
Expand All @@ -13,7 +13,7 @@
"name": "curl-byi",
"namespace": "sumologic",
"resourceVersion": "1374472",
"selfLink": "/apis/extensions/v1beta1/namespaces/sumologic/deployments/curl-byi",
"selfLink": "/apis/apps/v1/namespaces/sumologic/deployments/curl-byi",
"uid": "1a1658f9-7818-11e9-90f1-02324f7e0d1e"
},
"spec": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"namespace": "kube-system",
"ownerReferences": [
{
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "ReplicaSet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"namespace": "sumologic",
"ownerReferences": [
{
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "ReplicaSet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"uid": "1a1e5ad4-7818-11e9-90f1-02324f7e0d1f",
"ownerReferences": [
{
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "ReplicaSet",
"name": "non-existent-replicaset",
"uid": "1a1a368a-7818-11e9-90f1-02324f7e0d1f"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"kind": "ReplicaSet",
"metadata": {
"annotations": {
Expand All @@ -17,7 +17,7 @@
"namespace": "kube-system",
"ownerReferences": [
{
"apiVersion": "extensions/v1beta1",
"apiVersion": "apps/v1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "Deployment",
Expand All @@ -26,7 +26,7 @@
}
],
"resourceVersion": "854",
"selfLink": "/apis/extensions/v1beta1/namespaces/kube-system/replicasets/kube-dns-5fbcb4d67b",
"selfLink": "/apis/apps/v1/namespaces/kube-system/replicasets/kube-dns-5fbcb4d67b",
"uid": "d00e6062-7040-11e9-90f1-02324f7e0d1e"
},
"spec": {
Expand Down
Loading

0 comments on commit f3fee12

Please sign in to comment.