Skip to content

Instantly share code, notes, and snippets.

@dchandekstark
Created August 3, 2021 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dchandekstark/c148339975ba2749e3db2b3a597eac2c to your computer and use it in GitHub Desktop.
Save dchandekstark/c148339975ba2749e3db2b3a597eac2c to your computer and use it in GitHub Desktop.
Ruby script to strip out content from OKD resources for helm
#!/usr/bin/env ruby
require 'yaml'
data = YAML.load(STDIN.read)
kind = data['kind']
# status
if kind == 'Route'
data['status']['ingress'] = []
else
data.delete('status')
end
# metadata
%w( creationTimestamp generation resourceVersion selfLink uid ).each do |key|
data['metadata'].delete(key)
end
# spec
if spec = data['spec']
# spec.strategy
if spec.key?('strategy')
%w( activeDeadlineSeconds resources rollingParams ).each do |key|
spec['strategy'].delete(key)
end
end
if spec.key?('template')
spec['template']['metadata']&.delete('creationTimestamp')
# spec.template.spec.containers[]
spec['template']['spec']['containers'].each do |con|
con['image'] &&= con['image'].split(/@/, 2).first
%w( resources terminationMessagePath terminationMessagePolicy ).each do |key|
con.delete(key)
end
end
# spec.template.spec
%w( dnsPolicy schedulerName securityContext ).each do |key|
spec['template']['spec'].delete(key)
end
end
# spec.triggers[]
if spec.key?('triggers')
spec['triggers'].each do |trig|
trig['imageChangeParams']&.delete('lastTriggeredImage')
end
end
end
puts YAML.dump(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment