forked from weaveworks/kubediff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubediff
executable file
·40 lines (31 loc) · 1.2 KB
/
kubediff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
import optparse
import sys
from kubedifflib import (
check_files,
JSONPrinter,
QuietTextPrinter,
)
def main():
parser = optparse.OptionParser("""usage: %prog [options] <dir/file>...
Compare yaml files in <dir> to running state in kubernetes and print the
differences. This is useful to ensure you have applied all your changes to the
appropriate environment. This tools runs kubectl, so unless your
~/.kube/config is configured for the correct environment, you will need to
supply the kubeconfig for the appropriate environment.""")
parser.add_option("--kubeconfig", help="path to kubeconfig")
parser.add_option("-j", "--json", help="output in json format", action="store_true", dest="json")
parser.add_option("--no-error-on-diff", help="don't exit with 2 if diff exists",
action="store_false", dest="exit_on_diff", default="true")
(options, args) = parser.parse_args()
if len(args) == 0:
parser.print_help()
sys.exit(1)
printer = QuietTextPrinter()
if options.json:
printer = JSONPrinter()
failed = check_files(args, printer, options.kubeconfig)
if failed and options.exit_on_diff:
sys.exit(2)
if __name__ == '__main__':
main()