Skip to content

Add support for IPv6 #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ RUN yum update -y \
RUN groupadd -r $FLUENT_USER && \
useradd -r -g $FLUENT_USER $FLUENT_USER && \
mkdir -p /fluentd/log /fluentd/etc /fluentd/plugins && \
chown -R $FLUENT_USER /fluentd && chgrp -R $FLUENT_USER /fluentd
chown -R $FLUENT_USER /fluentd && chgrp -R $FLUENT_USER /fluentd && \
chmod +t /tmp

USER $FLUENT_USER
CMD bundle exec fluentd -c /fluentd/etc/fluent.conf
4 changes: 4 additions & 0 deletions lib/fluent/plugin/in_kubernetes_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
require 'fluent/plugin/input'
require 'kubeclient'
require 'multi_json'
require 'resolv'

module Fluent
module Plugin
Expand Down Expand Up @@ -76,6 +77,8 @@ class KubernetesMetricsInput < Fluent::Plugin::Input
def configure(conf)
super

@kubelet_address = "[#{@kubelet_address}]" if @kubelet_address =~ Resolv::IPv6::Regex

if @use_rest_client
raise Fluentd::ConfigError, 'node_name is required' if @node_name.nil? || @node_name.empty?
else
Expand Down Expand Up @@ -136,6 +139,7 @@ def init_without_kubeconfig(_options = {})
if @kubernetes_url.nil?
# Use Kubernetes default service account if we're in a pod.
env_host = ENV['KUBERNETES_SERVICE_HOST']
env_host = "[#{env_host}]" if env_host =~ Resolv::IPv6::Regex
env_port = ENV['KUBERNETES_SERVICE_PORT']
if env_host && env_port
@kubernetes_url = "https://#{env_host}:#{env_port}/api/"
Expand Down
24 changes: 24 additions & 0 deletions test/plugin/test_in_kubernetes_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ def create_driver(conf = CONFIG)
assert_equal true, d.instance.use_rest_client
end

test 'IPv6 node configuration' do
IPv6_CONFIG = %(
type kubernetes_metrics
node_name generics-aws-node-name
tag kube.*
insecure_ssl true
interval 10s
use_rest_client true
use_rest_client_ssl false
kubelet_port 10_255
kubelet_address fd55:4d62:e00f::1
)
assert_nothing_raised(Fluent::ConfigError) do
create_driver(IPv6_CONFIG)
end

d = create_driver(IPv6_CONFIG)
assert_equal '[fd55:4d62:e00f::1]', d.instance.kubelet_address
assert_equal 'http://[fd55:4d62:e00f::1]:10255/stats/summary', d.instance.instance_variable_get('@kubelet_url')
assert_equal 'http://[fd55:4d62:e00f::1]:10255/stats', d.instance.instance_variable_get('@kubelet_url_stats')
assert_equal 'http://[fd55:4d62:e00f::1]:10255/metrics/cadvisor', d.instance.instance_variable_get('@cadvisor_url')

end

sub_test_case 'node_unit_tests' do
test 'test_emit_cpu_metrics' do
assert_not_nil @@hash_map_test.key?('kube.node.cpu.usage')
Expand Down