Skip to content
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

fix: nil pointer on notifier #504

Merged
merged 1 commit into from
Mar 15, 2020
Merged

fix: nil pointer on notifier #504

merged 1 commit into from
Mar 15, 2020

Conversation

mathetake
Copy link
Collaborator

@mathetake mathetake commented Mar 15, 2020

resolves #496


if slack's url is configured through SLACK_URL environment variable without providing slack.url, current helm chart ignores slack.channel and slack.user, which results in notifier in the controller struct becoming nil.

just in case, i added nopNotifer for warning users about misconfigurations in notifiers.

pkg/controller/events.go Outdated Show resolved Hide resolved
@codecov-io
Copy link

Codecov Report

Merging #504 into master will decrease coverage by 0.09%.
The diff coverage is 5.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #504      +/-   ##
==========================================
- Coverage   52.17%   52.08%   -0.10%     
==========================================
  Files          60       61       +1     
  Lines        4529     4537       +8     
==========================================
  Hits         2363     2363              
- Misses       1770     1778       +8     
  Partials      396      396              
Impacted Files Coverage Δ
pkg/canary/daemonset_controller.go 59.88% <0.00%> (ø)
pkg/canary/deployment_controller.go 58.62% <0.00%> (ø)
pkg/notifier/factory.go 0.00% <0.00%> (ø)
pkg/notifier/nop.go 0.00% <0.00%> (ø)
pkg/controller/events.go 48.73% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b8682cc...38b893f. Read the comment docs.

@mathetake
Copy link
Collaborator Author

mathetake commented Mar 15, 2020

https://github.com/weaveworks/flagger/blob/nop-notifier/cmd/flagger/main.go#L329 there's still a possible branch for notifier being nil... 😞

@stefanprodan
Copy link
Member

@mathetake you are right, I made a mess out of the global notifier when I added env vars support.

@mathetake
Copy link
Collaborator Author

@stefanprodan thank you for quick response 👍
i will come back to this PR early in the next week and find a better way to refactor

@stefanprodan
Copy link
Member

@mathetake I think the NopNotifier shouldn't return an error and just be nop. This way the initNotifier could return a nop instead of nil and this will solve the issue.

@mathetake
Copy link
Collaborator Author

@mathetake I think the NopNotifier shouldn't return an error and just be nop. This way the initNotifier could return a nop instead of nil and this will solve the issue.

got it

client, err = notifierFactory.Notifier(provider)
if err != nil {
logger.Errorf("Notifier %v", err)
} else if len(notifierURL) > 30 {
Copy link
Collaborator Author

@mathetake mathetake Mar 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stefanprodan i am not sure what 30 means. could you tell me what is the purpose for slicing in the logging🤔 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to avoid logging secrets as the Slack/Teams URL will contain the API Key. But this is poorly done since the URL can be shorter for other providers (for example a self-hosted Rocket) and the info will never get logged.

Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @mathetake 🏅

@mathetake mathetake merged commit ebfbe1b into master Mar 15, 2020
@mathetake mathetake deleted the nop-notifier branch March 15, 2020 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flagger crashes if you define SLACK_URL env var and there's nothing in slack.url parameter
3 participants