Last active
March 17, 2026 02:41
-
-
Save fukajun/ad0dc6e4368b4c8c37089fc81f7e8139 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # diffをファイル単位で分割して処理 | |
| # 実質的な変更がlabels/app.kubernetes.io/instanceの削除のみの場合はスキップ | |
| # Usage | |
| # kubectl diff -k . | ruby ./kubectl-diff-filter.rb | |
| IGNORABLE = /\A[-+][ \t]*(generation:\s*|labels:\s*|app\.kubernetes\.io\/instance:.*)/ | |
| ignored_diffs = [] | |
| diffs = STDIN.read.split(/^diff /).reject(&:empty?) | |
| diffs.each do |diff| | |
| diff = "diff " + diff | |
| changed_lines = diff.lines.select { |l| l.match?(/\A[-+]/) && !l.match?(/\A[-+]{3} /) } | |
| if changed_lines.all? { |l| l.match?(IGNORABLE) } | |
| ignored_diffs << changed_lines | |
| next | |
| end | |
| puts diff | |
| end | |
| puts "\n=== Ignored diff summary ===" | |
| ignored_diffs.map { |lines| lines.join }.tally.each do |k, v| | |
| puts "== Ignored diff lines count: #{v} ==" | |
| puts k | |
| puts "" | |
| end | |
| puts 'Filtered by https://gist.github.com/fukajun/ad0dc6e4368b4c8c37089fc81f7e8139' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment