Skip to content

Commit

Permalink
fix: handle IPv6 KUBERNETES_SERVICE_HOST (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdett authored Jul 21, 2023
1 parent 3db207f commit ad20c5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,15 @@ def normalize_param
log.info 'Kubernetes URL is not set - inspecting environment'
env_host = ENV['KUBERNETES_SERVICE_HOST']
env_port = ENV['KUBERNETES_SERVICE_PORT']
@kubernetes_url = "https://#{env_host}:#{env_port}" unless env_host.nil? || env_port.nil?
if present?(env_host) && present?(env_port)
if env_host =~ Resolv::IPv6::Regex
# Brackets are needed around IPv6 addresses
env_host = "[#{env_host}]"
end
@kubernetes_url = "https://#{env_host}:#{env_port}"
else
log.debug "No Kubernetes URL could be found in config or environment"
end
end
log.debug "Kubernetes URL: '#{@kubernetes_url}'"

Expand Down
10 changes: 9 additions & 1 deletion fluent-plugin-events/lib/fluent/plugin/in_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,15 @@ def normalize_param
log.debug 'Kubernetes URL is not set - inspecting environment'
env_host = ENV['KUBERNETES_SERVICE_HOST']
env_port = ENV['KUBERNETES_SERVICE_PORT']
@kubernetes_url = "https://#{env_host}:#{env_port}" unless env_host.nil? || env_port.nil?
if present?(env_host) && present?(env_port)
if env_host =~ Resolv::IPv6::Regex
# Brackets are needed around IPv6 addresses
env_host = "[#{env_host}]"
end
@kubernetes_url = "https://#{env_host}:#{env_port}"
else
log.debug "No Kubernetes URL could be found in config or environment"
end
end
log.debug "Kubernetes URL: '#{@kubernetes_url}'"

Expand Down

0 comments on commit ad20c5e

Please sign in to comment.