Skip to content

Commit 567f655

Browse files
committed
Update kube rebase docs
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
1 parent e1c04ac commit 567f655

File tree

1 file changed

+116
-123
lines changed

1 file changed

+116
-123
lines changed

docs/content/contributing/guides/rebasing-kubernetes.md

Lines changed: 116 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Rebasing Kubernetes
22

33
This describes the process of rebasing kcp onto a new Kubernetes version. For the examples below, we'll be rebasing
4-
onto v1.31.0
4+
onto v1.33.3
55

66
# 1. Update kcp-dev/apimachinery
77

@@ -11,7 +11,7 @@ onto v1.31.0
1111
Kubernetes repo. This is not required, but probably a good idea.
1212
2. Update the primary Kubernetes dependencies:
1313
```
14-
14+
1515
```
1616
3. Run `go mod tidy`.
1717
3. Manually review the code that is upstream from `third_party` and make the same/similar edits to anything that
@@ -25,19 +25,15 @@ onto v1.31.0
2525
# 2. Update kcp-dev/code-generator
2626
2727
1. Create a new branch for the update, such as `1.26-prep`.
28-
2. Update go.mod:
28+
2. Update `go.mod`:
2929
1. You may need to change the go version at the top of the file to match what's in go.mod in the root of the
3030
Kubernetes repo. This is not required, but probably a good idea.
3131
2. Update the primary Kubernetes dependencies:
3232
```
33-
go get -u k8s.io/[email protected] k8s.io/[email protected]
33+
3434
```
3535
3. Run `go mod tidy`.
36-
3. Update Kubernetes tooling versions in the `Makefile`:
37-
1. `KUBE_CLIENT_GEN_VER := v0.31.0`
38-
2. `KUBE_LISTER_GEN_VER := v0.31.0`
39-
3. `KUBE_INFORMER_GEN_VER := v0.31.0`
40-
4. `KUBE_APPLYCONFIGURATION_GEN_VER := v0.31.0`
36+
3. Repeat step 2 for `examples/go.mod`:
4137
4. Update generators, if needed:
4238
1. Manually review upstream to check for any changes to these generators in the `kubernetes` repository:
4339
1. staging/src/k8s.io/code-generator/cmd/client-gen
@@ -46,20 +42,10 @@ onto v1.31.0
4642
2. If there were any substantive changes, make the corresponding edits to our generators.
4743
3. You'll probably want to commit your changes at this point.
4844
5. Run `make codegen`. You'll probably want to commit these changes as a standalone commit.
49-
1. Note: `examples` is separate go module, so you may need to run `go mod tidy` in that directory and update the
50-
go.mod file accordingly if you make changes to the code-generator.
5145
6. Run `make lint test build` and fix any issues you encounter.
5246
7. Commit any remaining changes.
5347
8. Push to your fork.
54-
1. Open a PR; get it reviewed and merged.
55-
9. Push release:
56-
```
57-
REF=upstream/main
58-
REMOTE=upstream
59-
TAG=v2.3.0
60-
git tag --sign --message "$TAG" "$TAG" "$REF"
61-
git push "$REMOTE" "$TAG"
62-
```
48+
9. Open a PR; get it reviewed and merged.
6349
6450
# 3. Update kcp-dev/client-go
6551
1. Create a new branch for the update, such as `1.26-prep`.
@@ -68,18 +54,16 @@ onto v1.31.0
6854
Kubernetes repo. This is not required, but probably a good idea.
6955
2. Update the `kcp-dev/apimachinery` dependency:
7056
```
71-
go get -u github.com/kcp-dev/apimachinery@main
57+
go get github.com/kcp-dev/apimachinery@main github.com/kcp-dev/code-generator@main
7258
```
7359
3. That should have updated the primary Kubernetes dependencies, but in case it didn't, you can do so manually:
7460
```
75-
61+
7662
```
7763
4. Run `go mod tidy`.
78-
5. Update the kcp code-generator tooling version in the `Makefile`:
79-
1. Look up the latest commit from the main branch in https://github.com/kcp-dev/code-generator.
80-
2. Adjust `go.mod` accordingly.
81-
3. Manually review the code that is upstream from `third_party` and make the same/similar edits to anything that
82-
changed upstream.
64+
3. Run `hack/populate-copies.sh`, this will copy files originally copied
65+
from upstream over the local copies. Review the changes and ensure
66+
changes from upstream are handled.
8367
4. Run `make codegen`. You'll probably want to commit these changes as a standalone commit.
8468
5. Run `make lint` and fix any issues you encounter.
8569
6. Commit any remaining changes.
@@ -110,24 +94,6 @@ Commits merged into `kcp-dev/kubernetes` follow this commit message format:
11094
- In general, these commits are used to maintain the codebase in ways that are
11195
branch-specific, like the update of generated files or dependencies.
11296
113-
## Spreadsheet of Carry Commits from Previous Release
114-
115-
If the old branch (generally also the default branch) is `upstream/kcp-feature-logical-cluster-1.24-v3`
116-
and the old version is `v1.24.3`, then a tsv file containing the set of carry commits that need to be
117-
considered for cherry-picking later can be generated using:
118-
119-
```sh
120-
# create column headers
121-
echo 'Comment Sha\tSummary\tCommit link\tPR link\tAction' > ~/Documents/v1.24.3.tsv
122-
123-
# populate the sheet
124-
git log $( git merge-base upstream/kcp-feature-logical-clusters-1.24-v3 v1.24.3 )..upstream/kcp-feature-logical-clusters-1.24-v3 --ancestry-path --reverse --no-merges --pretty='tformat:%h%x09%s%x09https://github.com/kcp-dev/kubernetes/commit/%h?w=1' | grep -E $'\t''UPSTREAM: .'$'\t' | sed -E 's~UPSTREAM: ([0-9]+)(:.)~UPSTREAM: \1\2\thttps://github.com/kubernetes/kubernetes/pull/\1~' >> ~/Documents/v1.24.3.tsv
125-
```
126-
127-
The tsv file can be imported into a google sheets spreadsheet to track the progress of picking commits
128-
to the new rebase branch. The spreadsheet can also be a way of communicating with rebase reviewers.
129-
For an example, please see the [spreadsheet used for the v1.27.3 rebase](https://docs.google.com/spreadsheets/d/15k9sih-xBKICuLUHj4HMrqYf60mliaslImqqv6fGSJI/edit?usp=sharing).
130-
13197
## Rebase Process
13298
13399
1. First and foremost, take notes of what worked/didn't work well. Update this guide based on your experiences!
@@ -137,85 +103,64 @@ For an example, please see the [spreadsheet used for the v1.27.3 rebase](https:/
137103
- "New" version: the new Kubernetes version on top of which you are rebasing
138104
4. The `upstream` in e.g. `upstream/kcp-feature-logical-cluster-1.24-v3` is the name of the git remote that points
139105
to github.com/kcp-dev/kubernetes. Please adjust the commands below if your remote is named differently.
140-
5. Prepare the old branch for rebasing:
141-
1. In this example, the old version is 1.31.0, and the new version is 1.31.0
142-
2. Create a new temporary branch to clean up the accumulated commits on the old branch:
143-
```
144-
git checkout -b kcp-1.31-clean upstream/kcp-feature-logical-cluster-1.31-v3
145-
```
146-
3. Start by doing a soft git reset so your working directory contains all the changes from the branch in an
147-
uncommitted state:
148-
```
149-
git reset v1.31.1 # this must be whatever upstream commit was the starting point for the old branch
150-
```
151-
4. Revert the following types of changes:
152-
- go.mod/go.sum
153-
- Generated clients, listers, informers, applyconfigurations
154-
- vendor/*
155-
```
156-
git checkout go.mod go.sum vendor
157-
158-
# for any untracked files
159-
git clean -n -d vendor/* # to check what files would be removed
160-
git clean -f vendor/* # actually remove the new untracked files
161-
```
162-
5. Create a single baseline commit:
163-
```
164-
git add .
165-
git commit -m 'UPSTREAM: <carry>: baseline for kcp 1.31'
166-
```
167-
6. Create a baseline branch that starts from the new version. We'll use this to cherry-pick any commits from
168-
upstream that we need to continue carrying (i.e., they have not yet merged into the new version).
169-
```
170-
git checkout -b kcp-1.31-baseline v1.31.1
171-
```
172-
7. Review the list of carry commits in the spreadsheet generated above. Look
173-
for commit messages of the format
174-
`UPSTREAM: 12345: ...`. The number indicates the upstream pull request. You'll need to inspect each pull request
175-
to determine when it was merged. Anything that merged **before** the rebase version can be ignored and omitted
176-
from the baseline branch. Anything that merged **after** the rebase version as well as anything not yet merged
177-
must be cherry-picked to the baseline branch. For example, in 1.24, we have `UPSTREAM: 111898: Reflector: support
178-
logging Unstructured type`. This was added in 1.31, and therefore needs to be cherry-picked to the
179-
`kcp-1.31-baseline` branch.
180-
8. Create a branch where you'll attempt to do the rebase. This will start from the cleaned up old version branch:
181-
```
182-
git checkout -b kcp-1.31-rebase kcp-1.31-clean
106+
5. Prepare a list of commits:
107+
1. Checkout the current fork branch:
108+
```
109+
git checkout kcp-dev/kcp-1.32.3
110+
```
111+
2. Export the commits to cherry-pick them:
112+
```
113+
git log --oneline --reverse --no-merges --no-decorate v1.32.3..HEAD \
114+
| grep -v '<drop>' > commits.txt
115+
```
116+
You will use this commits.txt to also note conflicts and changes
117+
you had to make, so reviewers know where to focus their
118+
attention.
119+
6. Prepare a branch to cherry-pick the commits onto:
183120
```
184-
9. Rebase onto the baseline branch you created above:
185-
```
186-
git rebase kcp-1.31-baseline
121+
git reset --hard v1.33.3
187122
```
188123
189-
You will likely encounter numerous conflicts. This is 100% normal! Go through each file and resolve them as best
190-
as you can. Make notes of any particular changes you have questions about, so you don't forget them.
191-
10. Update kcp dependencies, for all kcp repositories that changed. For example:
192-
```
193-
hack/pin-dependency.sh github.com/kcp-dev/logicalcluster/v3 v3.0.4
194-
hack/pin-dependency.sh github.com/kcp-dev/apimachinery/v2 767ac05aebce82530dee46e9dab8c7bb47f1c823
195-
hack/pin-dependency.sh github.com/kcp-dev/client-go 654321d8cac56f9944e8cf801dc15e37b3a582f3
196-
```
197-
11. Review changes to the origins of pkg/genericcontrolplane to see if similar changes are needed in the new version:
198-
199-
| Destination | Source(s) |
200-
|------------------------------------------------------------------|------------------------------------------------------|
201-
| pkg/genericcontrolplane | cmd/kube-apiserver/app, pkg/kubeapiserver/admission |
202-
| pkg/genericcontrolplane/apis/apis.go | pkg/controlplane/instance.go |
203-
| pkg/genericcontrolplane/options.go | cmd/kube-apiserver/app/options/options.go |
204-
| pkg/api/genericcontrolplane/scheme.go | pkg/api/legacyscheme/scheme.go |
205-
| pkg/apis/core/install/genericcontrolplane/install.go | pkg/apis/core/install/install.go |
206-
| pkg/apis/core/register_generic_control_plane.go | pkg/apis/core/register.go |
207-
| pkg/apis/core/v1/register_generic_control_plane.go | pkg/apis/core/v1/register.go |
208-
| staging/src/k8s.io/api/core/v1/register_generic_control_plane.go | staging/src/k8s.io/api/core/v1/register.go |
209-
| pkg/registry/core/rest/genericcontrolplane/storage_core.go | pkg/registry/core/rest/storage_core.go |
210-
| pkg/kubeapiserver/legacy_storage_factory_builder.go | pkg/kubeapiserver/default_storage_factory_builder.go |
211-
212-
12. Update generated clients, informers, listers, etc. because we generate logical cluster aware versions of these
213-
for Kubernetes to use:
214-
```
215-
hack/update-codegen.sh
216-
```
124+
Note: To make validating changes easier you can use these functions:
125+
126+
```bash
127+
# record the changed files between the version kcp will jump
128+
git diff --name-only v1.32.3 v1.33.3 > ../changed_files.txt
129+
130+
# list_changed_files lists the files changed in the current commit
131+
list_changed_files() {
132+
for changed_file in $(git diff --name-only @ @~1); do
133+
if grep -q "$changed_file" ../changed_files.txt; then
134+
echo "./$changed_file"
135+
fi
136+
done
137+
}
138+
139+
# view_changed_files shows the diff of the files changed in the current
140+
# commit
141+
view_changed_files() {
142+
local changed="$(list_changed_files)"
143+
[[ -z "$changed" ]] && return 0
144+
git diff-tree -r -p @ -- $changed
145+
}
146+
```
147+
148+
If a commit applied clean and `list_changed_files` shows no output, you
149+
can move on to the next commit because there were no changes to the
150+
files that commit touched between the two kube versions.
151+
152+
Additionally `view_changed_files` only shows the changes of the
153+
currently cherry-picked commit to files that were changed betwene the
154+
two kube versions.
217155

218-
13. Check if any new controllers were added to Kubernetes. If so, determine if they are relevant to the control
156+
7. Cherry-pick each commit one by one.
157+
1. If you encounter conflicts resolve them as best as you can.
158+
2. If you have to make substantial changes document it in the commit
159+
message, add your signed-off-by and add a note in your commits.txt.
160+
3. Check the changes with `list_changed_files` and `view_changed_files`
161+
(see above).
162+
163+
8. Check if any new controllers were added to Kubernetes. If so, determine if they are relevant to the control
219164
plane, or if they're specific to workloads (anything related to pods/nodes/etc.). If they're for the control
220165
plane and you think they should be enabled in kcp, you have 1 of 2 choices:
221166

@@ -226,12 +171,60 @@ For an example, please see the [spreadsheet used for the v1.27.3 rebase](https:/
226171

227172
For option 2, follow what we did in kcp in either the garbage collector or quota controllers.
228173

229-
14. Check if any new admission plugins were added to Kubernetes. Decide if we need them in kcp. If so, make a note
174+
11. Check if any new admission plugins were added to Kubernetes. Decide if we need them in kcp. If so, make a note
230175
of them, and we'll add them to kcp below.
231176

232-
15. Push your commits to your fork of Kubernetes in GitHub.
233177

234-
16. Open a pull request for review **against the baseline branch, e.g. kcp-1.26-baseline**, but mark it `WIP` and maybe
178+
12. Update kcp dependencies, for all kcp repositories that changed. For example:
179+
```
180+
hack/pin-dependency.sh github.com/kcp-dev/logicalcluster/v3 v3.0.4
181+
hack/pin-dependency.sh github.com/kcp-dev/apimachinery/v2 kcp-1.33.3
182+
hack/pin-dependency.sh github.com/kcp-dev/client-go kcp-1.33.3
183+
```
184+
185+
13. Commmit the dependency updates:
186+
```
187+
git add .
188+
git commit -m 'CARRY: <drop>: Add KCP dependencies'
189+
```
190+
191+
14. Update the vendor directory:
192+
```
193+
hack/update-vendor.sh
194+
git add .
195+
git commit -m 'CARRY: <drop>: Update vendor'
196+
```
197+
198+
15. Update generated clients, informers, listers, etc. because we generate logical cluster aware versions of these
199+
for Kubernetes to use:
200+
```
201+
hack/update-codegen.sh
202+
```
203+
204+
This can delete the `zz_generated.validations.go` - this is expected
205+
as we drop the validation-gen generator. See
206+
https://github.com/kcp-dev/kcp/issues/3562a for details.
207+
208+
This step can pin kube dependencies to versions instead of v0.0.0,
209+
which can lead to opaque errors laters.
210+
To fix this run:
211+
```
212+
gsed -e '/k8s.io/ s#v0.33.3#v0.0.0#' -i "go.mod"
213+
find staging -iname go.mod \
214+
| while read go_mod; do
215+
gsed -e '/k8s.io/ s#v0.33.3#v0.0.0#' -i "$go_mod"
216+
done
217+
```
218+
219+
16. Commit the generated code changes:
220+
```
221+
git add .
222+
git commit -m 'CARRY: <drop>: Update generated code'
223+
```
224+
225+
17. Push your commits to your fork of Kubernetes in GitHub.
226+
227+
18. Open a pull request for review **against the baseline branch, e.g. kcp-1.26-baseline**, but mark it `WIP` and maybe
235228
even open it in draft mode - you don't want to merge anything just yet.
236229
237230
# 5. Update kcp-dev/kcp

0 commit comments

Comments
 (0)