From d58752dae7221598161a4bb9d541e0f1a92f44e2 Mon Sep 17 00:00:00 2001 From: Pedro Tashima Date: Thu, 30 Nov 2023 18:40:00 -0300 Subject: [PATCH] reorganize in subcommands and add documentation --- cmd/rke2_release/README.md | 69 ++++++++++++++ cmd/rke2_release/main.go | 2 +- cmd/rke2_release/update_image_build.go | 126 ++++++++++++++----------- release/rke2/rke2.go | 6 +- 4 files changed, 146 insertions(+), 57 deletions(-) diff --git a/cmd/rke2_release/README.md b/cmd/rke2_release/README.md index 84014779..be741957 100644 --- a/cmd/rke2_release/README.md +++ b/cmd/rke2_release/README.md @@ -35,6 +35,75 @@ rke2_release components -l image-build-k8s-metrics-server image-build-k8s-metrics-server|v0.6.3-build20231009 ``` +### image-build + +#### list-repos +List all repos supported by this command + +```sh +rke2_release image-build list-repos + +> INFO[0000] Supported repos: + image-build-sriov-network-resources-injector + image-build-containerd + image-build-multus + image-build-ib-sriov-cni + image-build-sriov-network-device-plugin + image-build-cni-plugins + image-build-rke2-cloud-provider + image-build-dns-nodecache + image-build-k8s-metrics-server + image-build-calico + image-build-flannel + image-build-sriov-cni + image-build-whereabouts + image-build-etcd + image-build-runc +``` + +#### update +Updates references to the `hardened-build-base` docker image in the `rancher/image-build-*` repos. + +| **Flag** | **Description** | **Required** | +| ----------------------------------- | --------------- | ------------ | +| `github-token`, `g`, `GITHUB_TOKEN` | Github Token | TRUE | +| `repo`, `r` | What image-build repo to update, use `rke2_release image-build list-repos` for a full list | TRUE | +| `owner`, `o` | Owner of the repo, default is 'rancher' only used for testing purposes | FALSE | +| `repo-path`, `p` | Local copy of the image-build repo that is being updated | TRUE | +| `working-dir`, `w` | Directory in which the temporary scripts will be created, default is /tmp | FALSE | +| `build-base-tag`, `t` | hardened-build-base Docker image tag to update the references in the repo to | TRUE | +| `dry-run`, `d` | Don't push changes to remote and don't create the PR, just log the information | FALSE | +| `create-pr`, `p` | If not set, the images will be pushed to a new branch, but a PR won't be created | FALSE | + +**Examples** + +```sh +export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} + +rke2_release image-build update --repo image-build-calico --repo-path /tmp/image-build-calico --build-base-tag v1.21.3b1 --create-pr --dry-run +``` + +```sh +export GITHUB_TOKEN={YOUR_GITHUB_TOKEN} + +rke2_release image-build update -r image-build-calico -p /tmp/image-build-calico -t v1.21.3b1 -p -d +``` + +### Components + +```sh +rke2_release components -l all +image-build-base |v1.21.3b1 +image-build-calico |v3.26.1-build20231009 +image-build-cni-plugins |v1.2.0-build20231009 +... +``` + +```sh +rke2_release components -l image-build-k8s-metrics-server +image-build-k8s-metrics-server|v0.6.3-build20231009 +``` + ## Contributions - File Issue with details of the problem, feature request, etc. diff --git a/cmd/rke2_release/main.go b/cmd/rke2_release/main.go index 52c97762..3cd4fa6e 100644 --- a/cmd/rke2_release/main.go +++ b/cmd/rke2_release/main.go @@ -29,7 +29,7 @@ func main() { app.Commands = []*cli.Command{ imageBuildBaseReleaseCommand(), componentsCommand(), - updateImageBuildCommand(), + imageBuildCommand(), } app.Flags = rootFlags diff --git a/cmd/rke2_release/update_image_build.go b/cmd/rke2_release/update_image_build.go index 11956a12..fb430003 100644 --- a/cmd/rke2_release/update_image_build.go +++ b/cmd/rke2_release/update_image_build.go @@ -5,66 +5,77 @@ import ( "github.com/rancher/ecm-distro-tools/release/rke2" "github.com/rancher/ecm-distro-tools/repository" + "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) -func updateImageBuildCommand() *cli.Command { +func imageBuildCommand() *cli.Command { return &cli.Command{ - Name: "update-image-build", - Usage: "checks if a new release is available at rancher/image-build-base and updates the references at the rancher/image-build repos", - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "github-token", - Aliases: []string{"g"}, - EnvVars: []string{"GITHUB_TOKEN"}, - Required: true, + Name: "image-build", + Subcommands: []*cli.Command{ + { + Name: "list-repos", + Usage: "List all repos supported by this command", + Action: listRepos, }, - &cli.StringFlag{ - Name: "repo", - Aliases: []string{"r"}, - Usage: "what image-build repo to update, use `rke2_release update-image-build list-repos` for a full list", - Required: true, - }, - &cli.StringFlag{ - Name: "owner", - Aliases: []string{"o"}, - Usage: "Owner of the repo, default is 'rancher' only used for testing purposes", - Value: "rancher", - Required: false, - }, - &cli.StringFlag{ - Name: "repo-path", - Aliases: []string{"c"}, - Usage: "Local copy of the image-build repo that is being updated", - Required: true, - }, - &cli.StringFlag{ - Name: "working-dir", - Aliases: []string{"w"}, - Usage: "Directory in which the temporary scripts will be created, default is /tmp", - Value: "/tmp", - Required: false, - }, - &cli.StringFlag{ - Name: "build-base-tag", - Aliases: []string{"t"}, - Usage: "hardened-build-base Docker image tag to update the references in the repo to", - Required: true, - }, - &cli.BoolFlag{ - Name: "dry-run", - Aliases: []string{"d"}, - Usage: "don't push changes to remote and don't create the PR, just log the information", - Required: false, - }, - &cli.BoolFlag{ - Name: "create-pr", - Aliases: []string{"p"}, - Usage: "If not set, the images will be pushed to a new branch, but a PR won't be created", - Required: false, + { + Name: "update", + Usage: "updates hardened-build-base references in the rancher/image-build-* repos", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "github-token", + Aliases: []string{"g"}, + EnvVars: []string{"GITHUB_TOKEN"}, + Required: true, + }, + &cli.StringFlag{ + Name: "repo", + Aliases: []string{"r"}, + Usage: "What image-build repo to update, use `rke2_release image-build list-repos` for a full list", + Required: true, + }, + &cli.StringFlag{ + Name: "owner", + Aliases: []string{"o"}, + Usage: "Owner of the repo, default is 'rancher' only used for testing purposes", + Value: "rancher", + Required: false, + }, + &cli.StringFlag{ + Name: "repo-path", + Aliases: []string{"c"}, + Usage: "Local copy of the image-build repo that is being updated", + Required: true, + }, + &cli.StringFlag{ + Name: "working-dir", + Aliases: []string{"w"}, + Usage: "Directory in which the temporary scripts will be created, default is /tmp", + Value: "/tmp", + Required: false, + }, + &cli.StringFlag{ + Name: "build-base-tag", + Aliases: []string{"t"}, + Usage: "hardened-build-base Docker image tag to update the references in the repo to", + Required: true, + }, + &cli.BoolFlag{ + Name: "dry-run", + Aliases: []string{"d"}, + Usage: "Don't push changes to remote and don't create the PR, just log the information", + Required: false, + }, + &cli.BoolFlag{ + Name: "create-pr", + Aliases: []string{"p"}, + Usage: "If not set, the images will be pushed to a new branch, but a PR won't be created", + Required: false, + }, + }, + Action: updateImageBuild, }, }, - Action: updateImageBuild, } } @@ -81,3 +92,12 @@ func updateImageBuild(c *cli.Context) error { ghClient := repository.NewGithub(ctx, token) return rke2.UpdateImageBuild(ctx, ghClient, repo, owner, repoPath, workingDir, buildBaseTag, dryRun, createPR) } + +func listRepos(c *cli.Context) error { + repos := "" + for k := range rke2.ImageBuildRepos { + repos += " " + k + "\n" + } + logrus.Info("Supported repos: \n" + repos) + return nil +} diff --git a/release/rke2/rke2.go b/release/rke2/rke2.go index 88f3c258..51f11c93 100644 --- a/release/rke2/rke2.go +++ b/release/rke2/rke2.go @@ -83,7 +83,7 @@ type UpdateImageBuildArgs struct { CurrentTag string } -var imageBuildRepos map[string]bool = map[string]bool{ +var ImageBuildRepos map[string]bool = map[string]bool{ "image-build-dns-nodecache": true, "image-build-k8s-metrics-server": true, "image-build-sriov-cni": true, @@ -170,8 +170,8 @@ func goVersions(goDevURL string) ([]goVersionRecord, error) { } func UpdateImageBuild(ctx context.Context, ghClient *github.Client, repo, owner, repoPath, workingDir, newTag string, dryRun, createPR bool) error { - if _, ok := imageBuildRepos[repo]; !ok { - return errors.New("invalid repo, please review the `imageBuildRepos` map") + if _, ok := ImageBuildRepos[repo]; !ok { + return errors.New("invalid repo, please review the supported repos list") } branchName := "update-to-" + newTag data := UpdateImageBuildArgs{