Skip to content

Commit b12ab02

Browse files
committed
apply changes per feedback review
Signed-off-by: cpanato <[email protected]>
1 parent 0218214 commit b12ab02

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

cmd/patch-release-notification/main.go

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"embed"
2323
"fmt"
2424
"io"
25-
"log"
2625
"math"
2726
"net/http"
2827
"os"
@@ -91,7 +90,7 @@ func getConfig() (*Config, error) {
9190
return &c, nil
9291
}
9392

94-
func New(ctx context.Context) (*Options, error) {
93+
func NewOptions(ctx context.Context) (*Options, error) {
9594
config, err := getConfig()
9695
if err != nil {
9796
return nil, fmt.Errorf("failed to get config: %w", err)
@@ -102,7 +101,6 @@ func New(ctx context.Context) (*Options, error) {
102101
Region: aws.String(config.AWSRegion),
103102
})
104103
if err != nil {
105-
log.Println("Error occurred while creating aws session", err)
106104
return nil, err
107105
}
108106

@@ -114,20 +112,21 @@ func New(ctx context.Context) (*Options, error) {
114112
}
115113

116114
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { //nolint: gocritic
117-
o, err := New(ctx)
115+
o, err := NewOptions(ctx)
118116
if err != nil {
119117
return events.APIGatewayProxyResponse{
120118
Body: `{"status": "nok"}`,
121119
StatusCode: http.StatusInternalServerError,
122120
}, err
123121
}
124122

123+
logrus.Infof("Will pull the patch release schedule from: %s", o.Config.SchedulePath)
125124
data, err := loadFileOrURL(o.Config.SchedulePath)
126125
if err != nil {
127126
return events.APIGatewayProxyResponse{
128127
Body: `{"status": "nok"}`,
129128
StatusCode: http.StatusInternalServerError,
130-
}, fmt.Errorf("failed to read the file: %w", err)
129+
}, fmt.Errorf("reading the file: %w", err)
131130
}
132131

133132
patchSchedule := &model.PatchSchedule{}
@@ -138,7 +137,7 @@ func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events
138137
return events.APIGatewayProxyResponse{
139138
Body: `{"status": "nok"}`,
140139
StatusCode: http.StatusInternalServerError,
141-
}, fmt.Errorf("failed to decode the file: %w", err)
140+
}, fmt.Errorf("decoding the file: %w", err)
142141
}
143142

144143
output := &Template{}
@@ -157,7 +156,7 @@ func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events
157156
currentTime := time.Now().UTC()
158157
days := t.Sub(currentTime).Hours() / 24
159158
intDay, _ := math.Modf(days)
160-
logrus.Infof("cherry pick deadline: %d, days to alert: %d", int(intDay), o.Config.DaysToAlert)
159+
logrus.Infof("Cherry pick deadline: %d, days to alert: %d", int(intDay), o.Config.DaysToAlert)
161160
if int(intDay) == o.Config.DaysToAlert {
162161
output.Releases = append(output.Releases, TemplateRelease{
163162
Release: patch.Release,
@@ -167,6 +166,14 @@ func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events
167166
}
168167
}
169168

169+
if !shouldSendEmail {
170+
logrus.Info("No email is needed to send")
171+
return events.APIGatewayProxyResponse{
172+
Body: `{"status": "ok"}`,
173+
StatusCode: http.StatusOK,
174+
}, nil
175+
}
176+
170177
tmpl, err := template.ParseFS(tpls, "templates/email.tmpl")
171178
if err != nil {
172179
return events.APIGatewayProxyResponse{
@@ -181,19 +188,11 @@ func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events
181188
return events.APIGatewayProxyResponse{
182189
Body: `{"status": "nok"}`,
183190
StatusCode: http.StatusInternalServerError,
184-
}, fmt.Errorf("parsing values to the template: %w", err)
185-
}
186-
187-
if !shouldSendEmail {
188-
logrus.Info("No email is needed to send")
189-
return events.APIGatewayProxyResponse{
190-
Body: `{"status": "ok"}`,
191-
StatusCode: http.StatusOK,
192-
}, nil
191+
}, fmt.Errorf("executing the template: %w", err)
193192
}
194193

195194
logrus.Info("Sending mail")
196-
subject := "[Please Read] Patch Releases cherry-pick deadline"
195+
subject := "[Please Read] Upcoming Patch Releases Cherry-Pick Deadline for Kubernetes"
197196
fromEmail := o.Config.FromEmail
198197

199198
recipient := Recipient{
@@ -212,7 +211,7 @@ func handler(ctx context.Context, request events.APIGatewayProxyRequest) (events
212211
return events.APIGatewayProxyResponse{
213212
Body: `{"status": "nok"}`,
214213
StatusCode: http.StatusInternalServerError,
215-
}, fmt.Errorf("parsing values to the template: %w", err)
214+
}, fmt.Errorf("sending the email: %w", err)
216215
}
217216

218217
return events.APIGatewayProxyResponse{
@@ -240,9 +239,6 @@ func (o *Options) SendEmailRawSES(messageBody, subject, fromEmail string, recipi
240239
recipients = append(recipients, &recipient)
241240
}
242241

243-
// Set to emails
244-
msg.SetHeader("To", recipient.toEmails...)
245-
246242
// cc mails mentioned
247243
if len(recipient.ccEmails) != 0 {
248244
// Need to add cc mail IDs also in recipient list
@@ -275,7 +271,7 @@ func (o *Options) SendEmailRawSES(messageBody, subject, fromEmail string, recipi
275271
var emailRaw bytes.Buffer
276272
_, err := msg.WriteTo(&emailRaw)
277273
if err != nil {
278-
log.Printf("failed to write mail: %v\n", err)
274+
logrus.Errorf("Failed to write mail: %v", err)
279275
return err
280276
}
281277

@@ -287,11 +283,11 @@ func (o *Options) SendEmailRawSES(messageBody, subject, fromEmail string, recipi
287283
// send raw email
288284
_, err = svc.SendRawEmail(input)
289285
if err != nil {
290-
log.Println("Error sending mail - ", err)
286+
logrus.Errorf("Error sending mail - %v", err)
291287
return err
292288
}
293289

294-
log.Println("Email sent successfully to: ", recipient.toEmails)
290+
logrus.Infof("Email sent successfully to: %q", recipient.toEmails)
295291
return nil
296292
}
297293

@@ -314,5 +310,6 @@ func loadFileOrURL(fileRef string) ([]byte, error) {
314310
return nil, err
315311
}
316312
}
313+
317314
return raw, nil
318315
}

cmd/patch-release-notification/templates/email.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{end}}
88
<br><p>Here are some quick links to search for cherry-pick PRs:</p>
99
{{range .Releases}}
10-
<p> - release-{{ .Release }}: https://github.com/kubernetes/kubernetes/pulls?q=is%3Apr+is%3Aopen+base%3Arelease-{{ .Release }}+label%3Ado-not-merge%2Fcherry-pick-not-approved</p>
10+
<p> - <a href="https://github.com/kubernetes/kubernetes/pulls?q=is%3Apr+is%3Aopen+base%3Arelease-{{ .Release }}+label%3Ado-not-merge%2Fcherry-pick-not-approved">Check PRs for release-{{ .Release }}</a></p>
1111
{{end}}
1212
<br>
1313
<p>For PRs that you intend to land for the upcoming patch sets, please
@@ -18,7 +18,7 @@ ensure they have:</p>
1818
<p> - /priority</p>
1919
<p> - /lgtm</p>
2020
<p> - /approve</p>
21-
<p> - passing tests</p>
21+
<p> - passing tests and not on hold.</p>
2222
<br>
2323
<p>Details on the cherry-pick process can be found here:</p>
2424
<p>https://git.k8s.io/community/contributors/devel/sig-release/cherry-picks.md</p>
@@ -27,6 +27,6 @@ ensure they have:</p>
2727
<p>If you have any questions for the Release Managers, please feel free to
2828
reach out to us at #release-management (Kubernetes Slack) or [email protected]</p><br>
2929
<p>We wish everyone a happy and safe week!</p>
30-
<p>SIG-Release Team</p>
30+
<p>SIG Release Team</p>
3131
</body>
3232
</html>

0 commit comments

Comments
 (0)