@@ -140,36 +140,56 @@ func (r *registrator) handler(eventType watch.EventType, oldIngress *v1beta1.Ing
140
140
switch eventType {
141
141
case watch .Added :
142
142
log .Printf ("[DEBUG] received %s event for %s" , eventType , newIngress .Name )
143
+ metricUpdatesReceived .WithLabelValues (newIngress .Name , "add" ).Inc ()
143
144
hostnames := getHostnamesFromIngress (newIngress )
144
145
target := r .getTargetForIngress (newIngress )
145
- metricUpdatesReceived .WithLabelValues (newIngress .Name , "add" ).Inc ()
146
- if len (hostnames ) > 0 && target != "" {
147
- log .Printf ("[DEBUG] queued update of %d record(s) for ingress %s, pointing to %s" , len (hostnames ), newIngress .Name , target )
146
+ if target == "" {
147
+ log .Printf ("[INFO] invalid ingress target for new ingress %s: %s" , newIngress .Name , newIngress .Labels [r .options .TargetLabelName ])
148
+ } else if len (hostnames ) == 0 {
149
+ log .Printf ("[INFO] could not extract hostnames from new ingress %s" , newIngress .Name )
150
+ } else {
151
+ log .Printf ("[DEBUG] queued update of %d record(s) for new ingress %s, pointing to %s" , len (hostnames ), newIngress .Name , target )
148
152
r .queueUpdates (route53 .ChangeActionUpsert , hostnames , target )
149
153
}
150
154
case watch .Modified :
151
- log .Printf ("[DEBUG] received %s event for %s -> %s" , eventType , oldIngress .Name , newIngress .Name )
155
+ log .Printf ("[DEBUG] received %s event for %s" , eventType , newIngress .Name )
156
+ metricUpdatesReceived .WithLabelValues (newIngress .Name , "modify" ).Inc ()
152
157
newHostnames := getHostnamesFromIngress (newIngress )
153
158
newTarget := r .getTargetForIngress (newIngress )
154
- metricUpdatesReceived .WithLabelValues (newIngress .Name , "modify" ).Inc ()
155
- if len (newHostnames ) > 0 && newTarget != "" {
156
- log .Printf ("[DEBUG] queued update of %d record(s) for ingress %s, pointing to %s" , len (newHostnames ), newIngress .Name , newTarget )
157
- r .queueUpdates (route53 .ChangeActionUpsert , newHostnames , newTarget )
158
- }
159
159
oldHostnames := getHostnamesFromIngress (oldIngress )
160
160
oldTarget := r .getTargetForIngress (oldIngress )
161
161
diffHostnames := diffStringSlices (oldHostnames , newHostnames )
162
- if len (diffHostnames ) > 0 && oldTarget != "" {
163
- log .Printf ("[DEBUG] queued deletion of %d record(s) for ingress %s" , len (diffHostnames ), oldIngress .Name )
162
+ if len (diffHostnames ) == 0 && newIngress .Labels [r .options .TargetLabelName ] == oldIngress .Labels [r .options .TargetLabelName ] {
163
+ log .Printf ("[DEBUG] no changes for ingress %s, looks like a no-op resync" , newIngress .Name )
164
+ break
165
+ }
166
+ if newTarget == "" {
167
+ log .Printf ("[INFO] invalid ingress target for modified ingress %s: %s" , newIngress .Name , newIngress .Labels [r .options .TargetLabelName ])
168
+ } else if len (newHostnames ) == 0 {
169
+ log .Printf ("[INFO] could not extract hostnames from modified ingress %s" , newIngress .Name )
170
+ } else {
171
+ log .Printf ("[DEBUG] queued update of %d record(s) for modified ingress %s, pointing to %s" , len (newHostnames ), newIngress .Name , newTarget )
172
+ r .queueUpdates (route53 .ChangeActionUpsert , newHostnames , newTarget )
173
+ }
174
+ if oldTarget == "" {
175
+ log .Printf ("[INFO] invalid ingress target for previous ingress %s: %s" , oldIngress .Name , oldIngress .Labels [r .options .TargetLabelName ])
176
+ } else if len (diffHostnames ) == 0 {
177
+ log .Printf ("[DEBUG] no difference in hostnames from previous ingress %s" , oldIngress .Name )
178
+ } else {
179
+ log .Printf ("[DEBUG] queued deletion of %d record(s) for previous ingress %s" , len (diffHostnames ), oldIngress .Name )
164
180
r .queueUpdates (route53 .ChangeActionDelete , diffHostnames , oldTarget )
165
181
}
166
182
case watch .Deleted :
167
183
log .Printf ("[DEBUG] received %s event for %s" , eventType , oldIngress .Name )
184
+ metricUpdatesReceived .WithLabelValues (oldIngress .Name , "delete" ).Inc ()
168
185
hostnames := getHostnamesFromIngress (oldIngress )
169
186
target := r .getTargetForIngress (oldIngress )
170
- metricUpdatesReceived .WithLabelValues (oldIngress .Name , "delete" ).Inc ()
171
- if len (hostnames ) > 0 && target != "" {
172
- log .Printf ("[DEBUG] queued deletion of %d record(s) for ingress %s" , len (hostnames ), oldIngress .Name )
187
+ if target == "" {
188
+ log .Printf ("[INFO] invalid ingress target for old ingress %s: %s" , oldIngress .Name , oldIngress .Labels [r .options .TargetLabelName ])
189
+ } else if len (hostnames ) == 0 {
190
+ log .Printf ("[INFO] could not extract hostnames from old ingress %s" , oldIngress .Name )
191
+ } else {
192
+ log .Printf ("[DEBUG] queued deletion of %d record(s) for old ingress %s" , len (hostnames ), oldIngress .Name )
173
193
r .queueUpdates (route53 .ChangeActionDelete , hostnames , target )
174
194
}
175
195
default :
@@ -256,7 +276,6 @@ func (r *registrator) getTargetForIngress(ingress *v1beta1.Ingress) string {
256
276
return sat .Target
257
277
}
258
278
}
259
- log .Printf ("[INFO] invalid ingress target for %s: %s" , ingress .Name , ingress .Labels [r .options .TargetLabelName ])
260
279
return ""
261
280
}
262
281
0 commit comments