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

Tag system agent installer k3s command #356

Merged
merged 6 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
2 changes: 2 additions & 0 deletions cmd/release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ release generate k3s tags v1.29.2
release push k3s tags v1.29.2
release update k3s references v1.29.2
release tag k3s rc v1.29.2
release tag system-agent-installer-k3s rc v1.29.2
release tag k3s ga v1.29.2
release tag system-agent-installer-k3s ga v1.29.2
```

#### Cache Permissions and Docker:
Expand Down
37 changes: 36 additions & 1 deletion cmd/release/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ var k3sTagSubCmd = &cobra.Command{
}
ctx := context.Background()
ghClient := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)
return k3s.CreateRelease(ctx, ghClient, &k3sRelease, tag, rc)
opts := &repository.CreateReleaseOpts{
Tag: tag,
Repo: "k3s",
Owner: k3sRelease.K3sRepoOwner,
Branch: k3sRelease.ReleaseBranch,
}
return k3s.CreateRelease(ctx, ghClient, &k3sRelease, opts, rc)
},
}

Expand Down Expand Up @@ -157,12 +163,41 @@ var rancherTagSubCmd = &cobra.Command{
},
}

var systemAgentInstallerK3sTagSubCmd = &cobra.Command{
Use: "system-agent-installer-k3s [ga,rc] [version]",
Short: "Tag system-agent-installer-k3s releases",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
return errors.New("expected at least two arguments: [ga,rc] [version]")
}
rc, err := releaseTypeRC(args[0])
if err != nil {
return err
}
tag := args[1]
k3sRelease, found := rootConfig.K3s.Versions[tag]
if !found {
return errors.New("verify your config file, version not found: " + tag)
}
ctx := context.Background()
ghClient := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)
opts := &repository.CreateReleaseOpts{
Tag: tag,
Repo: "system-agent-installer-k3s",
Owner: k3sRelease.K3sRepoOwner,
Branch: "main",
}
return k3s.CreateRelease(ctx, ghClient, &k3sRelease, opts, rc)
},
}

func init() {
rootCmd.AddCommand(tagCmd)

tagCmd.AddCommand(k3sTagSubCmd)
tagCmd.AddCommand(rke2TagSubCmd)
tagCmd.AddCommand(rancherTagSubCmd)
tagCmd.AddCommand(systemAgentInstallerK3sTagSubCmd)

dryRun = tagCmd.PersistentFlags().BoolP("dry-run", "r", false, "Dry run")

Expand Down
41 changes: 19 additions & 22 deletions release/k3s/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,10 @@ func cleanGitRepo(dir string) error {
return nil
}

func CreateRelease(ctx context.Context, client *github.Client, r *ecmConfig.K3sRelease, tag string, rc bool) error {
func CreateRelease(ctx context.Context, client *github.Client, r *ecmConfig.K3sRelease, opts *repository.CreateReleaseOpts, rc bool) error {
fmt.Println("validating tag")
if !semver.IsValid(tag) {
return errors.New("tag isn't a valid semver: " + tag)
if !semver.IsValid(opts.Tag) {
return errors.New("tag isn't a valid semver: " + opts.Tag)
}
var createdReleaseURL string
rcNum := 1
Expand All @@ -700,15 +700,10 @@ func CreateRelease(ctx context.Context, client *github.Client, r *ecmConfig.K3sR
name = r.NewK8sVersion + "-rc" + strconv.Itoa(rcNum) + "+" + r.NewSuffix
}

opts := &repository.CreateReleaseOpts{
Repo: k3sRepo,
Name: name,
Owner: r.K3sRepoOwner,
Prerelease: true,
Branch: r.ReleaseBranch,
Draft: !rc,
ReleaseNotes: "",
}
opts.Name = name
opts.Prerelease = true
opts.Draft = !rc
opts.ReleaseNotes = ""

fmt.Printf("create release options: %+v\n", *opts)

Expand All @@ -717,13 +712,13 @@ func CreateRelease(ctx context.Context, client *github.Client, r *ecmConfig.K3sR
break
}

if !rc {
latestRc, err := release.LatestRC(ctx, r.K3sRepoOwner, k3sRepo, r.NewK8sVersion, client)
if !rc && opts.Repo == "k3s" {
latestRc, err := release.LatestRC(ctx, opts.Owner, opts.Repo, r.NewK8sVersion, client)
if err != nil {
return err
}

buff, err := release.GenReleaseNotes(ctx, r.K3sRepoOwner, k3sRepo, latestRc, oldName, client)
buff, err := release.GenReleaseNotes(ctx, opts.Owner, opts.Repo, latestRc, oldName, client)
if err != nil {
return err
}
Expand All @@ -733,14 +728,16 @@ func CreateRelease(ctx context.Context, client *github.Client, r *ecmConfig.K3sR
createdRelease, err := repository.CreateRelease(ctx, client, opts)
if err != nil {
githubErr := err.(*github.ErrorResponse)
if strings.Contains(githubErr.Errors[0].Code, "already_exists") {
if !rc {
return err
if len(githubErr.Errors) > 0 {
if strings.Contains(githubErr.Errors[0].Code, "already_exists") {
if !rc {
return err
}

fmt.Println("RC " + strconv.Itoa(rcNum) + " already exists, trying to create next")
rcNum += 1
continue
}

fmt.Println("RC " + strconv.Itoa(rcNum) + " already exists, trying to create next")
rcNum += 1
continue
}

return err
Expand Down
1 change: 1 addition & 0 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type CreateReleaseOpts struct {
Owner string `json:"owner"`
Repo string `json:"repo"`
Name string `json:"name"`
Tag string `json:"tag"`
Prerelease bool `json:"pre_release"`
Branch string `json:"branch"`
ReleaseNotes string `json:"release_notes"`
Expand Down
Loading