Skip to content

Commit

Permalink
Small changes (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
briandowns authored Jul 1, 2024
1 parent f19ed7e commit 6d3563d
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 60 deletions.
7 changes: 4 additions & 3 deletions cmd/gen_release_report/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (r *RKE2Release) trace() (context.Context, trace.Span, error) {
trace.WithAttributes(attribute.String("service", "github")),
trace.WithAttributes(attribute.String("repo", "rancher/rke2")),
trace.WithAttributes(attribute.String("event", "pull_request")),
trace.WithAttributes(attribute.String("ref", fmt.Sprintf("/refs/tags/%s", *r.ga.TagName))),
trace.WithAttributes(attribute.String("ref", "/refs/tags/"+*r.ga.TagName)),
trace.WithAttributes(attribute.String("tag", r.version)),
trace.WithAttributes(attribute.String("link", *r.ga.HTMLURL)),
}
Expand All @@ -39,6 +39,7 @@ func (r *RKE2Release) trace() (context.Context, trace.Span, error) {
for _, build := range builds {
buildCtx := build.trace(k8sCtx)
pkgBuilds := rke2PkgBuildsByBuild(build, r.builds)

for _, pkgBuild := range pkgBuilds {
pkgBuild.trace(buildCtx)
}
Expand Down Expand Up @@ -159,7 +160,7 @@ func rke2BuildsByRelease(builds []*Build, r *github.RepositoryRelease) []*Build
if build.Owner != "rancher" || build.Repo != "rke2" {
continue
}
if build.Event == "tag" && build.Ref == fmt.Sprintf("refs/tags/%s", *r.TagName) {
if build.Event == "tag" && build.Ref == "refs/tags/"+*r.TagName {
result = append(result, build)
}
}
Expand All @@ -172,7 +173,7 @@ func k8sBuildsByRelease(builds []*Build, r *github.RepositoryRelease) []*Build {
if build.Owner != "rancher" || build.Repo != "image-build-kubernetes" {
continue
}
if build.Event == "tag" && strings.Contains(build.Ref, fmt.Sprintf("refs/tags/%s", *r.TagName)) {
if build.Event == "tag" && strings.Contains(build.Ref, "refs/tags/"+*r.TagName) {
result = append(result, build)
}
}
Expand Down
18 changes: 15 additions & 3 deletions cmd/release/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ type K3sRelease struct {
OldSuffix string `json:"old_suffix"`
NewSuffix string `json:"new_suffix"`
ReleaseBranch string `json:"release_branch"`
DryRun bool `json:"dry_run"`
Workspace string `json:"workspace"`
NewGoVersion string `json:"-"`
K3sRepoOwner string `json:"k3s_repo_owner"`
SystemAgentInstallerRepoOwner string `json:"system_agent_installer_repo_owner"`
K8sRancherURL string `json:"k8s_rancher_url"`
K3sUpstreamURL string `json:"k3s_upstream_url"`
DryRun bool `json:"dry_run"`
}

// RancherRelease
type RancherRelease struct {
ReleaseBranch string `json:"release_branch"`
DryRun bool `json:"dry_run"`
SkipStatusCheck bool `json:"skip_status_check"`
RancherRepoOwner string `json:"rancher_repo_owner"`
IssueNumber string `json:"issue_number"`
CheckImages []string `json:"check_images"`
BaseRegistry string `json:"base_registry"`
Registry string `json:"registry"`
PrimeArtifactsBucket string `json:"prime_artifacts_bucket"`
DryRun bool `json:"dry_run"`
SkipStatusCheck bool `json:"skip_status_check"`
}

// RKE2
Expand Down Expand Up @@ -97,6 +97,7 @@ func DefaultConfigPath() (string, error) {
if err != nil {
return "", nil
}

return filepath.Join(homeDir, ecmDistroDir, configFileName), nil
}

Expand All @@ -107,6 +108,7 @@ func Load(configFile string) (*Config, error) {
if err != nil {
return nil, err
}

return read(f)
}

Expand All @@ -115,6 +117,7 @@ func read(r io.Reader) (*Config, error) {
if err := json.NewDecoder(r).Decode(&c); err != nil {
return nil, err
}

return &c, nil
}

Expand All @@ -123,18 +126,22 @@ func OpenOnEditor() error {
if err != nil {
return err
}

cmd := exec.Command(textEditorName(), confPath)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout

return cmd.Run()
}

func Generate() error {
configExists := true

configPath, err := DefaultConfigPath()
if err != nil {
return err
}

if _, err := os.Stat(configPath); err != nil {
if !strings.Contains(err.Error(), "no such file or directory") {
return err
Expand All @@ -144,10 +151,12 @@ func Generate() error {
if configExists {
return errors.New("config already exists at " + configPath)
}

confB, err := json.MarshalIndent(exampleConfig(), "", " ")
if err != nil {
return err
}

return os.WriteFile(configPath, confB, 0644)
}

Expand All @@ -156,11 +165,13 @@ func textEditorName() string {
if editor == "" {
editor = "vi"
}

return editor
}

func exampleConfig() Config {
gopath := os.Getenv("GOPATH")

return Config{
User: &User{
Email: "[email protected]",
Expand Down Expand Up @@ -219,6 +230,7 @@ func View(config *Config) error {
if err != nil {
return err
}

return tmp.Execute(os.Stdout, config)
}

Expand Down
1 change: 1 addition & 0 deletions cmd/test_coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func coverage(c *cli.Context) error {
for _, f := range usedFlags {
fmt.Println(f)
}

fmt.Printf("Unused flags:\n\n")
for _, f := range unusedFlags {
fmt.Println(f)
Expand Down
5 changes: 5 additions & 0 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,18 @@ func dockerTag(ctx context.Context, org, repo, tag, registryURL string) (map[str
if err != nil {
return nil, err
}

httpClient := ecmHTTP.NewClient(time.Second * 15)
res, err := httpClient.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()

if res.StatusCode != http.StatusOK {
return nil, fmt.Errorf("failed to find docker tag \"%s\", unexpected status code: %d", tag, res.StatusCode)
}

var dt DockerTag
if err := json.NewDecoder(res.Body).Decode(&dt); err != nil {
return nil, err
Expand All @@ -67,5 +71,6 @@ func dockerTag(ctx context.Context, org, repo, tag, registryURL string) (map[str
for _, image := range dt.Images {
images[image.Architecture] = image
}

return images, nil
}
5 changes: 2 additions & 3 deletions docs/releasing_rke2.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,8 @@ Please see "[Releasing RKE2 Explained](./releasing_rke2_explained.md)" for more

1. Run the update script
```shell
export GHT='<your github token>'
alias edt='docker run --rm -it --env GITHUB_TOKEN=$GHT rancher/ecm-distro-tools'
edt gen_release_notes -r rke2 -m v1.24.2-rc1+rke2r1 -p v1.24.1+rke2r2
export GITHUB_TOKEN='<your github token>'
./release generate k3s|rke2 release-notes -m v1.24.2-rc1+rke2r1 -p v1.24.1+rke2r2
```
1. Copy the generated release notes
1. Validate and update the release notes as necessary
Expand Down
5 changes: 2 additions & 3 deletions docs/releasing_rke2_explained.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,8 @@ Before making any pull requests, please make sure you understand:
* example branch name: `june-rke2-release`
1. Run the update script
```shell
export GHT='<your github token>'
alias edt='docker run --rm -it --env GITHUB_TOKEN=$GHT rancher/ecm-distro-tools'
edt gen_release_notes -r rke2 -m v1.24.2-rc1+rke2r1 -p v1.24.1+rke2r2
export GITHUB_TOKEN='<your github token>'
./release generate k3s|rke2 release-notes -m v1.24.2-rc1+rke2r1 -p v1.24.1+rke2r2
```
* the tool may not work on arm systems (like a Mac M1), in which case you will need to build the bin locally using make
1. clone the [ecm distro tools repo](https://github.com/rancher/ecm-distro-tools)
Expand Down
16 changes: 11 additions & 5 deletions release/k3s/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,26 @@ type UpdateScriptVars struct {
// generate tags to be pushed
func GenerateTags(ctx context.Context, ghClient *github.Client, r *ecmConfig.K3sRelease, u *ecmConfig.User, sshKeyPath string) error {
fmt.Println("setting up k8s remotes")
if err := setupK8sRemotes(ghClient, r, u, sshKeyPath); err != nil {
if err := setupK8sRemotes(r, u, sshKeyPath); err != nil {
return errors.New("failed to clone and setup remotes for k8s repos: " + err.Error())
}

tagsExists, err := tagsFileExists(r)
if err != nil {
return errors.New("failed to verify if tags file already exists: " + err.Error())
}
if tagsExists {
return errors.New("tag file already exists, skipping rebase and tag")
}

fmt.Println("rebasing and tagging")
tags, err := rebaseAndTag(ghClient, r, u)

tags, err := rebaseAndTag(r, u)
if err != nil {
return errors.New("failed to rebase and tag: " + err.Error())
}
fmt.Println("successfully rebased and tagged")

return writeTagsFile(r, tags)
}

Expand All @@ -124,14 +128,15 @@ func writeTagsFile(r *ecmConfig.K3sRelease, tags []string) error {

// setupK8sRemotes will clone the kubernetes upstream repo and proceed with setting up remotes
// for rancher and user's forks, then it will fetch branches and tags for all remotes
func setupK8sRemotes(ghClient *github.Client, r *ecmConfig.K3sRelease, u *ecmConfig.User, sshKeyPath string) error {
func setupK8sRemotes(r *ecmConfig.K3sRelease, u *ecmConfig.User, sshKeyPath string) error {
k8sDir := filepath.Join(r.Workspace, "kubernetes")

fmt.Println("verifying if the k8s dir already exists: " + k8sDir)
if _, err := os.Stat(r.Workspace); err != nil {
if !os.IsNotExist(err) {
return err
}

fmt.Println("dir doesn't exists, creating")
if err := os.MkdirAll(r.Workspace, 0755); err != nil {
return err
Expand Down Expand Up @@ -221,7 +226,7 @@ func setupK8sRemotes(ghClient *github.Client, r *ecmConfig.K3sRelease, u *ecmCon
return nil
}

func rebaseAndTag(ghClient *github.Client, r *ecmConfig.K3sRelease, u *ecmConfig.User) ([]string, error) {
func rebaseAndTag(r *ecmConfig.K3sRelease, u *ecmConfig.User) ([]string, error) {
rebaseOut, err := gitRebaseOnto(r)
if err != nil {
return nil, err
Expand Down Expand Up @@ -269,7 +274,7 @@ func rebaseAndTag(ghClient *github.Client, r *ecmConfig.K3sRelease, u *ecmConfig
// Finally, the function returns the publicKeys variable, which is now an ssh.AuthMethod, and a nil error.
func getAuth(privateKey string) (ssh.AuthMethod, error) {
if privateKey == "" {
privateKey = fmt.Sprintf("%s/.ssh/id_rsa", os.Getenv("HOME"))
privateKey = os.Getenv("HOME") + "/.ssh/id_rsa"
}

publicKeys, err := ssh.NewPublicKeysFromFile("git", privateKey, "")
Expand All @@ -294,6 +299,7 @@ func gitRebaseOnto(r *ecmConfig.K3sRelease) (string, error) {
r.NewK8sVersion,
r.OldK8sVersion,
r.OldK8sVersion), " ")

fmt.Println("git ", commandArgs)
return ecmExec.RunCommand(dir, "git", commandArgs...)
}
Expand Down
Loading

0 comments on commit 6d3563d

Please sign in to comment.