Skip to content

Instantly share code, notes, and snippets.

@ronan-mch
Created September 3, 2018 08:33
Show Gist options
  • Save ronan-mch/616d93666c66ed6cf40bd4d4e91e41b6 to your computer and use it in GitHub Desktop.
Save ronan-mch/616d93666c66ed6cf40bd4d4e91e41b6 to your computer and use it in GitHub Desktop.
Check K8s secrets synchronisation
require 'yaml'
puts "Checking Kubernetes templates for annotation mismatches..."
blacklist = %w(kubernetes/app_server.yml kubernetes/console.yml)
templates = Dir.glob("kubernetes/*.yml") - blacklist
template_vars = {}
reference_vars = []
errors = []
templates.each do |template|
next if blacklist.include?(template)
yaml = YAML.load(File.read(template))
annotations = yaml.dig("spec", "template", "metadata", "annotations")
raise "Annotations missing for template #{template}" if annotations.nil?
template_vars[template] = annotations.keys
# We assume the file with the most annotations is the most complete
if annotations.keys.size > reference_vars.size
reference_vars = annotations.keys
end
end
template_vars.each do |template, vars|
if vars.size < reference_vars.size
missing_vars = reference_vars - vars
errors << "Template #{template} is missing the following annotations: \n #{missing_vars.join("\n")}"
end
end
puts "Completed template check"
puts errors.join("\n")
exit(errors.size == 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment