24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/mkit/app/model/ingress.rb', line 24
def self.validate(yaml)
frontend_names = []
frontend_ports = []
raise_bad_configuration "Ingress section is mandatory" unless yaml
raise_bad_configuration "At least one frontend is mandatory" unless yaml["frontend"]
raise_bad_configuration "At least one backend is mandatory" unless yaml["backend"]
yaml["frontend"].each { |front| raise "Frontend name is mandatory" unless front["name"] }
yaml["backend"].each { |back| raise "Backend name is mandatory" unless back["name"] }
backend_names = yaml["backend"].map { |back| back["name"] }
yaml["frontend"].each do |front|
raise_bad_configuration "Frontend name is mandatory" unless front["name"]
if frontend_names.include?(front["name"])
raise_bad_configuration "Frontend name '#{front["name"]}' must be unique"
end
frontend_names << front["name"]
raise_bad_configuration "Frontend bind and mode are mandatory" unless front["bind"] && front["bind"]["mode"]
if frontend_ports.include?(front["bind"]["port"])
raise_bad_configuration "Frontend port '#{front["bind"]["port"]}' must be unique"
end
frontend_ports << front["bind"]["port"]
unless backend_names.include?(front["default_backend"])
raise_bad_configuration "Frontend default_backend '#{front["default_backend"]}' must point to a valid backend name"
end
end
backend_names.each do |name|
if backend_names.count(name) > 1
raise_bad_configuration "Backend name '#{name}' must be unique"
end
end
frontend_default_backends = yaml["frontend"].map { |front| front["default_backend"] }
yaml["backend"].each do |back|
unless frontend_default_backends.include?(back["name"])
raise_bad_configuration "Backend '#{back["name"]}' must be referenced by at least one frontend default_backend"
end
end
yaml["frontend"].each do |front|
if front["bind"]["port"] =~ /^\d+-\d+$/
referred_backend = yaml["backend"].find { |back| back["name"] == front["default_backend"] }
raise_bad_configuration "Frontend port range '#{front["bind"]["port"]}' must have an empty backend port" unless referred_backend && (referred_backend["bind"]["port"].nil?)
end
end
true
end
|