-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add logs for policy ignores #4816
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,10 @@ limitations under the License. | |
|
||
package plan | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// Policy allows to apply different rules to a set of changes. | ||
type Policy interface { | ||
Apply(changes *Changes) *Changes | ||
|
@@ -41,6 +45,11 @@ type UpsertOnlyPolicy struct{} | |
|
||
// Apply applies the upsert-only policy which strips out any deletions. | ||
func (p *UpsertOnlyPolicy) Apply(changes *Changes) *Changes { | ||
if log.GetLevel() == log.DebugLevel { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any chance to cover all this changes with tests? |
||
for _, ep := range changes.Delete { | ||
log.Debugf(`Skipping deletion of endpoint %v due to "upsert-only" policy`, ep) | ||
} | ||
} | ||
return &Changes{ | ||
Create: changes.Create, | ||
UpdateOld: changes.UpdateOld, | ||
|
@@ -53,6 +62,17 @@ type CreateOnlyPolicy struct{} | |
|
||
// Apply applies the create-only policy which strips out updates and deletions. | ||
func (p *CreateOnlyPolicy) Apply(changes *Changes) *Changes { | ||
if log.GetLevel() == log.DebugLevel { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shell we consider something like that. To avoid code duplication and improve readability, you can extract the logging logic to a separate function.
|
||
for _, ep := range changes.Delete { | ||
log.Debugf(`Skipping deletion of endpoint %v due to "create-only" policy`, ep) | ||
} | ||
for _, ep := range changes.UpdateOld { | ||
log.Debugf(`Skipping update-old of endpoint %v due to "create-only" policy`, ep) | ||
} | ||
for _, ep := range changes.UpdateNew { | ||
log.Debugf(`Skipping update-new of endpoint %v due to "create-only" policy`, ep) | ||
} | ||
} | ||
return &Changes{ | ||
Create: changes.Create, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is order matter?