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

K3s release improvements #324

Merged
merged 24 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions cmd/k3s_release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,73 @@ k3s_release is a utility that performs the bulk of the actions to complete a K3s

Please reference the help menu from the binary.

## Requirements
* OS: Linux
* Docker
* Git
* Go (At least the version used upstream for kubernetes)
* Sed (GNU)
* All commands require a Github token (classic) with the following permissions:
* Be generated on behalf of an account with access to the `k3s-io/k3s` repo
* `repo`
* `write:packages`
* An SSH key is also required, follow the Github [Documentation](https://docs.github.com/en/authentication/connecting-to-github-with-ssh) to generate one.

## Configuration
| Name | Description |
|------------------|------------------------------------------------------------------------------------------------------------|
| old_k8s_version | Previous k8s patch version |
| new_k8s_version | Latest released k8s patch version |
| old_k8s_client | Previous k8s client patch version, usually the same as the k8s version, but with a major of 0 instead of 1 |
| new_k8s_client | Latest released k8s client patch version |
| old_k3s_suffix | Previous patch version suffix e.g: `k3s1`, this is used to update dependencies |
| new_k3s_suffix | Suffix for the next version `k3s1` |
| release_branch | Branch in `k3s-io/k3s` for the minor version e.g: `release-1.28` |
| workspace | Local directory to clone repos and create files |
| handler | Your Github username |
| k3s_remote | Custom K3S Remote, not required, defaults to `k3s-io` |
| k8s_rancher_url | Custom K8s Fork URL, not required, defaults to `[email protected]:k3s-io/kubernetes.git` |
| k3s_upstream_url | Custom K3s Upstream URL, not required, defaults to `https://github.com/k3s-io/k3s` |
| email | Email to signoff commits |
| ssh_key_path | Path for the local private ssh key |

Example:
```json
{
"old_k8s_version": "v1.28.4",
"new_k8s_version": "v1.28.5",
"old_k8s_client": "v0.28.4",
"new_k8s_client": "v0.28.5",
"old_k3s_version": "k3s1",
"new_k3s_version": "k3s1",
"release_branch": "release-1.28",
"workspace": "$GOPATH/src/github.com/kubernetes",
"handler": "YourUsername",
"email": "[email protected]",
"ssh_key_path": "$HOME/.ssh/github"
}
```
Export your Github token as an environment variable:
```bash
export GITHUB_TOKEN=your_token
```

## Errors

### Cache Permissions and Docker:
```bash
$ k3s_release create-tags -c config-2-26.json
> FATA[0014] failed to rebase and create tags: chown: changing ownership of '/home/go/.cache': Operation not permitted
failed to initialize build cache at /home/go/.cache: mkdir /home/go/.cache/00: permission denied
```
Verify if the `$GOPATH/.cache` directory is owned by the same user that is running the command. If not, change the ownership of the directory:
```bash
$ ls -la $GOPATH/
> drwxr-xr-x 2 root root 4096 Dec 20 15:50 .cache
$ sudo chown $USER $GOPATH/.cache
```


## Contributions

* File Issue with details of the problem, feature request, etc.
Expand Down
2 changes: 1 addition & 1 deletion cmd/k3s_release/create_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func createTags(c *cli.Context) error {
logrus.Fatalf("config file: %v", err)
}

client, err := k3s.NewGithubClient(ctx, release.Token)
client, err := k3s.NewGithubClient(ctx, release.GithubToken)
if err != nil {
logrus.Fatalf("failed to initialize a new github client from token: %v", err)
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/k3s_release/modify_k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func modifyK3S(c *cli.Context) error {
logrus.Fatalf("failed to read config file: %v", err)
}

client, err := k3s.NewGithubClient(ctx, release.Token)
client, err := k3s.NewGithubClient(ctx, release.GithubToken)
if err != nil {
logrus.Fatalf("failed to initialize a new github client from token: %v", err)
}
Expand All @@ -38,9 +38,12 @@ func modifyK3S(c *cli.Context) error {
}

logrus.Info("Creating pull request")
if release.DryRun {
logrus.Info("Dry Run, Skipping Pull Request")
return nil
}
if err := release.CreatePRFromK3S(ctx, client); err != nil {
logrus.Fatalf("failed to create a new PR: %v", err)
}

return nil
}
8 changes: 2 additions & 6 deletions cmd/k3s_release/push_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
"github.com/urfave/cli/v2"
)

const (
k3sRemote = "k3s-io"
)

func pushTagsCommand() *cli.Command {
return &cli.Command{
Name: "push-tags",
Expand All @@ -32,7 +28,7 @@ func pushTags(c *cli.Context) error {
logrus.Fatalf("failed to read config file: %v", err)
}

client, err := k3s.NewGithubClient(ctx, release.Token)
client, err := k3s.NewGithubClient(ctx, release.GithubToken)
if err != nil {
logrus.Fatalf("failed to initialize a new github client from token: %v", err)
}
Expand All @@ -44,7 +40,7 @@ func pushTags(c *cli.Context) error {
}

logrus.Infof("pushing tags to github")
if err := release.PushTags(ctx, tags, client, k3sRemote); err != nil {
if err := release.PushTags(ctx, tags, client); err != nil {
logrus.Fatalf("failed to push tags: %v", err)
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/k3s_release/tag_rc_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (

func tagRCReleaseCommand() *cli.Command {
return &cli.Command{
Name: "tag-rc-release",
Usage: "tag rc release for k3s repo",
Flags: rootFlags,
Action: createRCRelease,
Name: "tag-rc-release",
Usage: "tag rc release for k3s repo",
Flags: rootFlags,
Action: createRCRelease,
}
}

Expand All @@ -27,7 +27,7 @@ func createRCRelease(c *cli.Context) error {
logrus.Fatalf("failed to read config file: %v", err)
}

client, err := k3s.NewGithubClient(ctx, release.Token)
client, err := k3s.NewGithubClient(ctx, release.GithubToken)
if err != nil {
logrus.Fatalf("failed to initialize a new github client from token: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/k3s_release/tag_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func createRelease(c *cli.Context) error {
logrus.Fatalf("failed to read config file: %v", err)
}

client, err := k3s.NewGithubClient(ctx, release.Token)
client, err := k3s.NewGithubClient(ctx, release.GithubToken)
if err != nil {
logrus.Fatalf("failed to initialize a new github client from token: %v", err)
}
Expand Down
Loading