Skip to content

Commit 890140e

Browse files
Merge branch 'kubernetes:master' into fix-corp-cla-info-6584
2 parents 48e0a2b + 7cf09cb commit 890140e

File tree

14 files changed

+329
-153
lines changed

14 files changed

+329
-153
lines changed

communication/slack-config/channels.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,3 +472,5 @@ channels:
472472
- name: windows-containerd
473473
- name: workshop-chat
474474
- name: yaml-overlay-tool
475+
- name: zarf
476+
- name: zarf-dev

contributors/devel/running-locally.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ change the service-cluster-ip-range flag to something else.
156156

157157
### I cannot create a replication controller with replica size greater than 1! What gives?
158158

159-
You are running a single node setup. This has the limitation of only supporting a single replica of a given pod. If you are interested in running with larger replica sizes, we encourage you to try the local vagrant setup or one of the cloud providers.
159+
You are running a single node setup. This has the limitation of only supporting a single replica of a given pod. If you are interested in running with larger replica sizes, we encourage you to try Kind or one of the cloud providers.
160160

161161
### I changed Kubernetes code, how do I run it?
162162

contributors/devel/sig-instrumentation/migration-to-structured-logging.md

Lines changed: 125 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
# Structured Logging migration instructions
1+
# Structured and Contextual Logging migration instructions
22

3-
This document describes instructions for migration proposed by [Structured Logging KEP]. It describes new structured
3+
This document describes instructions for the migration proposed by [Structured Logging KEP] and [Contextual Logging KEP]. It describes new
44
functions introduced in `klog` (Kubernetes logging library) and how log calls should be changed to utilize new features.
5-
This document was written for the initial migration of `kubernetes/kubernetes` repository proposed for Alpha stage, but
5+
This document was written for the initial migration of `kubernetes/kubernetes` repository proposed for Alpha stage of structured logging, but
66
should be applicable at later stages or for other projects using `klog` logging library.
77

88
[Structured Logging KEP]: https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/1602-structured-logging
9+
[Contextual Logging KEP]: https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging
910

1011
## How to contribute
1112

1213
### About the migration
1314

14-
We would like for the Kubernetes community to settle on one preferred log message structure, that will be enforced by new klog methods. The goal of the migration is to switch C like format string logs to structured logs with explicit metadata about parameters.
15+
We would like for the Kubernetes community to settle on one preferred log message structure and log calls as defined by [logr].
16+
The goal of the migration is to switch C-like format string logs to structured logs with explicit metadata about parameters and
17+
to remove the global logger in klog with a `logr.Logger` instance that gets chosen by the caller of a function.
1518

1619
Migration within the structured logging working group happens in two different ways - organized & non-organized.
1720

@@ -42,6 +45,7 @@ Before sending a PR our way, please ensure that there isn't one already in place
4245
* 1.21 Kubelet was migrated
4346
* 1.22 Collected feedback and improved the process.
4447
* 1.23 kube-scheduler and kube-proxy were migrated.
48+
* 1.24 Contextual logging infrastructure (updated klog, component-base/logs enables it) in place.
4549

4650
## Sending a Structured Logging Migration Pull Request
4751

@@ -78,7 +82,7 @@ Migrate <directory/file> to structured logging
7882

7983
### Why my PR was rejected?
8084

81-
Even though the Kubernetes project is organizing migration of Structured Logging, this doesn't mean that we are able to accept all the PRs that come our way. We reserve the right to reject the Pull Request in situations listed below:
85+
Even though the Kubernetes project is organizing migration of logging, this doesn't mean that we are able to accept all the PRs that come our way. We reserve the right to reject the Pull Request in situations listed below:
8286

8387
* Pull request is below minimum quality standards and clearly shows that author hasn't read the guide at all, for example PR just renames `Infof` to `InfoS`.
8488
* Pull request migrates components that the owners have decided against migrating. List of those components:
@@ -168,47 +172,129 @@ type KMetadata interface {
168172
}
169173
```
170174

175+
## Contextual logging in Kubernetes
176+
177+
Contextual logging builds on top of structured logging because the parameters
178+
for individual log calls are the same. The difference is that different
179+
functions need to be used:
180+
181+
- `klog.ErrorS` -> `logger.Error`
182+
- `klog.InfoS` -> `logger.Info`
183+
- `klog.V().InfoS` -> `logger.V().Info`
184+
185+
In all of these cases, `logger` is a `logr.Logger` instance. `klog.Logger` is
186+
an alias for that type. Determining where that instance comes from is the main
187+
challenge when migrating code to contextual logging.
188+
189+
Several new klog functions help with that:
190+
191+
- [`klog.FromContext`](https://pkg.go.dev/k8s.io/klog/v2#FromContext)
192+
- [`klog.Background`](https://pkg.go.dev/k8s.io/klog/v2#Background)
193+
- [`klog.TODO`](https://pkg.go.dev/k8s.io/klog/v2#TODO)
194+
195+
The preferred approach is to retrieve the instance with `klog.FromContext` from
196+
a `ctx context` parameter. If a function or method does not have one, consider
197+
adding it. This API change then implies that all callers also need to be
198+
updated. If there are any `context.TODO` calls in the modified functions,
199+
replace with the new `ctx` parameter.
200+
201+
In performance critical code it may be faster to add a `logger klog.Logger`
202+
parameter. This needs to be decided on a case-by-case basis.
203+
204+
When such API changes trickle up to a unit test, then enable contextual logging
205+
with per-test output with
206+
[`ktesting`](https://pkg.go.dev/k8s.io/klog/[email protected]/ktesting):
207+
208+
```go
209+
import (
210+
"testing"
211+
212+
"k8s.io/klog/v2/ktesting"
213+
_ "k8s.io/klog/v2/ktesting/init" # Add command line flags for ktesting.
214+
)
215+
216+
func TestFoo(t *testing.T) {
217+
_, ctx := ktesting.NewTestContext(t)
218+
doSomething(ctx)
219+
}
220+
```
221+
222+
If a logger instance is needed instead, then use:
223+
224+
```go
225+
logger, _ := ktesting.NewTestContext(t)
226+
```
227+
228+
The KEP has further instructions about the [transition to contextual
229+
logging](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging#transition). It
230+
also lists several
231+
[pitfalls](https://github.com/kubernetes/enhancements/tree/master/keps/sig-instrumentation/3077-contextual-logging#pitfalls-during-usage)
232+
that developers and reviewers need to be aware of.
233+
171234
## Migration
172235

173-
1. Change log functions to structured equivalent
236+
1. Optional: find code locations that need to be changed:
237+
238+
- `(cd hack/tools && go install k8s.io/klog/hack/tools/logcheck)`
239+
- structured logging: `$GOPATH/bin/logcheck -check-structured ./pkg/controller/...`
240+
- contextual logging: `$GOPATH/bin/logcheck -check-contextual ./pkg/scheduler/...`
241+
242+
1. Change log functions to structured or (better!) contextual equivalent
174243
1. Remove string formatting from log message
175244
1. Name arguments
176245
1. Ensure that value is properly passed
177246
1. Verify log output
247+
1. Prevent re-adding banned functions after migration
178248

179-
## Change log functions to structured equivalent
249+
## Change log functions
180250

181251
Structured logging functions follow a different logging interface design than other functions in `klog`. They follow
182252
minimal design from [logr] thus there is no one-to-one mapping.
183253

184-
Simplified mapping between functions:
254+
Simplified mapping between functions for structured logging:
185255
* `klog.Infof`, `klog.Info`, `klog.Infoln` -> `klog.InfoS`
186256
* `klog.InfoDepth` -> `klog.InfoSDepth`
187257
* `klog.V(N).Infof`, `klog.V(N).Info`, `klog.V(N).Infoln` -> `klog.V(N).InfoS`
188258
* `klog.Warning`, `klog.Warningf`, `klog.Warningln` -> `klog.InfoS`
189259
* `klog.WarningDepth` -> `klog.InfoSDepth`
190260
* `klog.Error`, `klog.Errorf`, `klog.Errorln` -> `klog.ErrorS`
191261
* `klog.ErrorDepth` -> `klog.ErrorSDepth`
192-
* `klog.Fatal`, `klog.Fatalf`, `klog.Fatalln` -> `klog.ErrorS` followed by `os.Exit(1)` ([see below])
193-
* `klog.FatalDepth` -> `klog.ErrorDepth` followed by `os.Exit(1)` ([see below])
262+
* `klog.Fatal`, `klog.Fatalf`, `klog.Fatalln` -> `klog.ErrorS` followed by `klog.FlushAndExit(klog.ExitFlushTimeout, klog.1)` ([see below])
263+
* `klog.FatalDepth` -> `klog.ErrorDepth` followed by `klog.FlushAndExit(klog.ExitFlushTimeout, klog.1)` ([see below])
264+
265+
For contextual logging, replace furthermore:
266+
267+
- `klog.ErrorS` -> `logger.Error`
268+
- `klog.InfoS` -> `logger.Info`
269+
- `klog.V().InfoS` -> `logger.V().Info`
194270

195271
[see below]: #replacing-fatal-calls
196272

197-
### Using ErrorS
273+
### Using ErrorS or logger.Error
198274

199275
With `klog` structured logging borrowing the interface from [logr] it also inherits it's differences in semantic of
200276
error function. Logs generated by `ErrorS` command may be enhanced with additional debug information
201277
(such as stack traces) or be additionally sent to special error recording tools. Errors should be used to indicate
202278
unexpected behaviours in code, like unexpected errors returned by subroutine function calls.
279+
In contrast to info log calls, error log calls always record the log entry, regardless of the current verbosity
280+
settings.
203281

204-
Calling `ErrorS` with `nil` as error is semi-acceptable if there is error condition that deserves a stack trace at this
205-
origin point. For expected errors (`errors` that can happen during routine operations) please consider using
282+
Calling `ErrorS` with `nil` as error is acceptable if there is an error condition that deserves a stack trace at this
283+
origin point or always must be logged. For expected errors (`errors` that can happen during routine operations) please consider using
206284
`klog.InfoS` and pass error in `err` key instead.
207285

208286
### Replacing Fatal calls
209287

210288
Use of Fatal should be discouraged and it's not available in new functions. Instead of depending on the logger to exit
211-
the process, you should call `os.Exit()` yourself.
289+
the process, you should:
290+
- rewrite code to return an `error` and let the caller deal with it or, if that is not feasible,
291+
- log and exit separately.
292+
293+
`os.Exit` should be avoided because it skips log data flushing. Instead use
294+
[`klog.FlushAndExit`](https://pkg.go.dev/k8s.io/klog/v2#FlushAndExit). The first
295+
parameter determines how long the program is allowed to flush log data before
296+
`os.Exit` is called. If unsure, use `klog.ExitFlushTimeout`, the value used
297+
by `klog.Fatal`.
212298

213299
Fatal calls use a default exit code of 255. When migrating, please use an exit code of 1 and include an "ACTION REQUIRED:" release note.
214300

@@ -217,7 +303,6 @@ For example
217303
func validateFlags(cfg *config.Config, flags *pflag.FlagSet) error {
218304
if err := cfg.ReadAndValidate(flags); err != nil {
219305
klog.FatalF("Error in reading and validating flags %s", err)
220-
os.Exit(1)
221306
}
222307
}
223308
```
@@ -226,7 +311,7 @@ should be changed to
226311
func validateFlags(cfg *config.Config, flags *pflag.FlagSet) error {
227312
if err := cfg.ReadAndValidate(flags); err != nil {
228313
klog.ErrorS(err, "Error in reading and validating flags")
229-
os.Exit(1)
314+
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
230315
}
231316
}
232317
```
@@ -526,3 +611,27 @@ After
526611
```
527612
I0528 19:15:22.737588 47512 logtest.go:55] "Received HTTP request" verb="GET" URI="/metrics" latency="1s" resp=200 userAgent="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0. 2272.118 Safari/537.36." srcIP="127.0.0.1"
528613
```
614+
615+
## Prevent re-adding banned functions after migration
616+
617+
After a package has been migrated to structured and/or contextual logging, we
618+
want to ensure that all log calls that get added in future PRs are structured
619+
resp. contextual.
620+
621+
For structured logging, the list of migrated packages in
622+
[`hack/logcheck.conf`](https://github.com/kubernetes/kubernetes/blob/b9792a9daef4d978c5c30b6d10cbcdfa77a9b6ac/hack/logcheck.conf#L16-L22)
623+
can be extended.
624+
625+
For contextual logging, a new list can be added at the bottom once the code is
626+
ready, with content like this:
627+
628+
```
629+
# Packages that have been migrated to contextual logging:
630+
contextual k8s.io/kubernetes/pkg/scheduler/.*
631+
```
632+
633+
The corresponding line with `structured k8s.io/kubernetes/pkg/scheduler/.*`
634+
then is redundant and can be removed because "contextual" implies "structured".
635+
636+
Both lists should be sorted alphabetically. That reduces the risk of code
637+
conflicts and makes the file more readable.

contributors/guide/issue-triage.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,15 @@ Note that adding labels requires Kubernetes GitHub org membership. If you are no
154154

155155
GitHub allows you to filter out types of issues and pull requests, which helps you discover items in need of triaging. This table includes some predetermined searches for convenience:
156156

157-
<!--- NOTE: Table syntax is for the Hugo rendered page -->
158-
{{< table caption="Example issue and pull request searches" >}}
157+
159158
| Search | What it sorts |
160159
|--------------------------------------------------------------------------------------------------------------|---------------------------------------------------------|
161160
| [created-asc](https://github.com/kubernetes/kubernetes/issues?q=is%3Aissue+is%3Aopen+sort%3Acreated-asc) | Untriaged issues by age |
162161
| [needs-sig](https://github.com/kubernetes/kubernetes/issues?q=is%3Aissue+is%3Aopen+label%3Aneeds-sig) | Issues that need to be assigned to a SIG |
163162
| [`is:open is:issue`](https://github.com/kubernetes/kubernetes/issues?q=is%3Aopen+is%3Aissue) | Newest incoming issues |
164163
| [comments-desc](https://github.com/kubernetes/kubernetes/issues?q=is%3Aissue+is%3Aopen+sort%3Acomments-desc) | Busiest untriaged issues, sorted by # of comments |
165164
| [comments-asc](https://github.com/kubernetes/kubernetes/issues?q=is%3Aissue+is%3Aopen+sort%3Acomments-asc) | Issues that need more attention, based on # of comments |
166-
{{</ table >}}
165+
167166

168167
We suggest preparing your triage by filtering out the oldest, unlabelled issues and pull requests first.
169168

@@ -223,16 +222,15 @@ We use GitHub labels for prioritization. If an issue lacks a `priority` label, t
223222

224223
We aim for consistency across the entire project. However, if you notice an issue that you believe to be incorrectly prioritized, please leave a comment offering your counter-proposal and we will evaluate it.
225224

226-
<!--- NOTE: Table syntax is for the Hugo rendered page -->
227-
{{< table caption="Priority labels for issues" >}}
225+
228226
|Priority label|What it means|Examples|
229227
|---|---|---|
230228
| `priority/critical-urgent` | Team leaders are responsible for making sure that these issues (in their area) are being actively worked on—i.e., drop what you're doing. Stuff is burning. These should be fixed before the next release. | user-visible bugs in core features <br> broken builds <br> tests and critical security issues |
231229
| `priority/important-soon` | Must be staffed and worked on either currently or very soon—ideally in time for the next release. Important, but wouldn't block a release. | [**XXXX**] |
232230
| `priority/important-longterm` | Important over the long term, but may not be currently staffed and/or may require multiple releases to complete. Wouldn't block a release. | [**XXXX**]|
233231
| `priority/backlog` | General agreement that this is a nice-to-have, but no one's available to work on it anytime soon. Community contributions would be most welcome in the meantime, though it might take a while to get them reviewed if reviewers are fully occupied with higher-priority issues—for example, immediately before a release.| [**XXXX**] |
234232
| `priority/awaiting-more-evidence` | Possibly useful, but not yet enough support to actually get it done. | Mostly placeholders for potentially good ideas, so that they don't get completely forgotten, and can be referenced or deduped every time they come up |
235-
{{< /table >}}
233+
236234

237235
## Step Four: Find and Set the Right SIG(s) to Own an Issue
238236

mentoring/programs/mentoring-lead.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Internship Mentoring Lead Handbook
2+
3+
## Overview
4+
5+
The Mentoring Lead role is created to help upstream Kubernetes contributors to participates in various mentorship programs like [GSoC](https://github.com/kubernetes/community/blob/master/mentoring/programs/google-summer-of-code.md), [GSoD](https://github.com/kubernetes/community/blob/master/mentoring/programs/google-season-of-docs.md), [LFX Mentorship](https://github.com/kubernetes/community/blob/master/mentoring/programs/lfx-mentorship.md) and many more as an independent organisation or under Cloud Native Computing Foundation(CNCF).
6+
7+
## Responsibilities
8+
The role lead should:
9+
10+
- Keep a calendar of dates for each program (when to submit our project name, when to submit the project scope, when selecting period is, etc) throughout the year and
11+
- Coordinate all submissions and participation in each one
12+
- Go to sig meetings and slack channels to proactively help with scoping and planning work / job descriptions
13+
- Help onboard interns to the k8s specific community items like coordinate a hello for them at the k8s monthly community meeting
14+
- Help off board interns to the k8s specific community items like demo at monthly community meeting
15+
16+
17+
### Role Description
18+
19+
Major responsibilities includes a commitment to:
20+
21+
- Be proactive in information sharing, through the mailing list/slack channels, regarding various mentorship cohorts
22+
- Be a bridge between the CNCF staff, mentors, and mentees from kubernetes project
23+
- Be an active contributor, who could identify parts of the project that could get help from mentorship programs
24+
- Be a go-to person for all SIGs to help them with their mentorship proposals
25+
- Be welcoming of everyone by being your unique self
26+
- Be inclusive on contributors, especially with new contributors joining kubernetes project as part of the mentoring process
27+
- Be a leader of the mentoring sub-project with a commitment to its charter
28+
29+
### Minimum Skills and Requirements
30+
31+
Skills:
32+
33+
- Be comfortable with general GitHub workflows. You'll be working inside of multiple repositories with different workflows and helping others on the team with troubleshooting.
34+
- Be a team player, making the project welcoming for new mentees and helping other members of the project interested to part in mentorship with the process.
35+
- Be willing and capable of saying "no" as necessary, but try to get to a "yes, and" to help the community achieve its goals. In short, be empathetic.
36+
- Strong written and verbal communication skills. A willingness to meet (a lot) of new people is important for this work.
37+
38+
Requirements:
39+
40+
- Member of the [Kubernetes GitHub Org]
41+
- [Reviewer] in the mentoring folder
42+
- Not Necessary, but a previous mentee/mentor in any of the mentorship programme is preferrable
43+
44+
#### Expected Time Investment
45+
46+
- Four hours a week as a minimal target, might be two hours more during the proposal submission perios
47+
48+
#### Duration
49+
50+
Ideally, no lead should be in the same position indefinitely. With that in mind,the project would like to see new leadership every 24 months to keep a fresh perspective.
51+
52+
### Becoming a Shadow
53+
54+
Any regular contributor to mentoring subproject can put forward their interest to the mentoring lead to become a shadow. If accepted, the objective of the council members is to nurture that shadow into a leadership position in the next 12 months.
55+
56+
#### Expectations of a Shadow
57+
58+
Consistently communicate and collaborate closely with the lead. The objective is to get you, as the shadown, to be a confident leader of the above responsibilities. Be ready to backfill for them when they are unable to attend a meeting or represent the subproject.

0 commit comments

Comments
 (0)