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

[feature] Rancher UI dashboard commands #474

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
77 changes: 77 additions & 0 deletions cmd/release/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ var (
k3sPrevMilestone string
k3sMilestone string

dashboardPrevMilestone string
dashboardMilestone string

concurrencyLimit int
imagesListURL string
ignoreImages []string
Expand Down Expand Up @@ -172,6 +175,52 @@ var rancherGenerateImagesSyncConfigSubCmd = &cobra.Command{
},
}

var uiGenerateSubCmd = &cobra.Command{
Use: "ui",
Short: "Generate ui related artifacts",
}

var uiGenerateReleaseNotesSubCmd = &cobra.Command{
Use: "release-notes",
Short: "Generate ui release notes",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

notes, err := release.GenReleaseNotes(ctx, "rancher", "ui", dashboardMilestone, dashboardPrevMilestone, client)
if err != nil {
return err
}

fmt.Print(notes.String())

return nil
},
}

var dashboardGenerateSubCmd = &cobra.Command{
Use: "dashboard",
Short: "Generate dashboard related artifacts",
}

var dashboardGenerateReleaseNotesSubCmd = &cobra.Command{
Use: "release-notes",
Short: "Generate dashboard release notes",
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
client := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

notes, err := release.GenReleaseNotes(ctx, "rancher", "dashboard", dashboardMilestone, dashboardPrevMilestone, client)
if err != nil {
return err
}

fmt.Print(notes.String())

return nil
},
}

func init() {
rootCmd.AddCommand(generateCmd)

Expand All @@ -182,10 +231,14 @@ func init() {
rancherGenerateSubCmd.AddCommand(rancherGenerateMissingImagesListSubCmd)
rancherGenerateSubCmd.AddCommand(rancherGenerateDockerImagesDigestsSubCmd)
rancherGenerateSubCmd.AddCommand(rancherGenerateImagesSyncConfigSubCmd)
uiGenerateSubCmd.AddCommand(uiGenerateReleaseNotesSubCmd)
dashboardGenerateSubCmd.AddCommand(dashboardGenerateReleaseNotesSubCmd)

generateCmd.AddCommand(k3sGenerateSubCmd)
generateCmd.AddCommand(rke2GenerateSubCmd)
generateCmd.AddCommand(rancherGenerateSubCmd)
generateCmd.AddCommand(uiGenerateSubCmd)
generateCmd.AddCommand(dashboardGenerateSubCmd)

// k3s release notes
k3sGenerateReleaseNotesSubCmd.Flags().StringVarP(&k3sPrevMilestone, "prev-milestone", "p", "", "Previous Milestone")
Expand All @@ -211,6 +264,30 @@ func init() {
os.Exit(1)
}

// ui release notes
uiGenerateReleaseNotesSubCmd.Flags().StringVarP(&dashboardPrevMilestone, "prev-milestone", "p", "", "Previous Milestone")
uiGenerateReleaseNotesSubCmd.Flags().StringVarP(&dashboardMilestone, "milestone", "m", "", "Milestone")
if err := uiGenerateReleaseNotesSubCmd.MarkFlagRequired("prev-milestone"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if err := uiGenerateReleaseNotesSubCmd.MarkFlagRequired("milestone"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

// dashboard release notes
dashboardGenerateReleaseNotesSubCmd.Flags().StringVarP(&dashboardPrevMilestone, "prev-milestone", "p", "", "Previous Milestone")
dashboardGenerateReleaseNotesSubCmd.Flags().StringVarP(&dashboardMilestone, "milestone", "m", "", "Milestone")
if err := dashboardGenerateReleaseNotesSubCmd.MarkFlagRequired("prev-milestone"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
if err := dashboardGenerateReleaseNotesSubCmd.MarkFlagRequired("milestone"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}

// rancher artifacts-index
rancherGenerateArtifactsIndexSubCmd.Flags().StringSliceVarP(&rancherArtifactsIndexIgnoreVersions, "ignore-versions", "i", []string{}, "Versions to ignore on the index")
rancherGenerateArtifactsIndexSubCmd.Flags().StringVarP(&rancherArtifactsIndexWriteToPath, "write-path", "w", "", "Write To Path")
Expand Down
70 changes: 70 additions & 0 deletions cmd/release/cmd/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"fmt"
"time"

"github.com/rancher/ecm-distro-tools/release/dashboard"
"github.com/rancher/ecm-distro-tools/release/k3s"
"github.com/rancher/ecm-distro-tools/release/rancher"
"github.com/rancher/ecm-distro-tools/release/rke2"
"github.com/rancher/ecm-distro-tools/release/ui"
"github.com/rancher/ecm-distro-tools/repository"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -146,11 +148,13 @@ var rancherTagSubCmd = &cobra.Command{
if len(args) < 2 {
return errors.New("expected at least two arguments: [ga,rc,debug,alpha] [version]")
}

releaseType := args[0]
preRelease, err := releaseTypePreRelease(releaseType)
if err != nil {
return err
}

tag := args[1]
rancherRelease, found := rootConfig.Rancher.Versions[tag]
if !found {
Expand Down Expand Up @@ -204,13 +208,79 @@ var systemAgentInstallerK3sTagSubCmd = &cobra.Command{
},
}

var uiTagSubCmd = &cobra.Command{
Use: "ui [ga,rc] [version]",
Short: "Tag ui 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 := releaseTypePreRelease(args[0])
if err != nil {
return err
}

tag := args[1]
briandowns marked this conversation as resolved.
Show resolved Hide resolved
uiRelease, found := rootConfig.UI.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: "ui",
Owner: uiRelease.UIRepoOwner,
Branch: uiRelease.ReleaseBranch,
}

return ui.CreateRelease(ctx, ghClient, &uiRelease, opts, rc)
},
}

var dashboardTagSubCmd = &cobra.Command{
Use: "dashboard [ga,rc] [version]",
Short: "Tag dashboard releases",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, see about doing validations on the standard Validation Arguments function of cobra like:
https://github.com/rancher/ecm-distro-tools/blob/master/cmd/release/cmd/push.go#L47

return errors.New("expected at least two arguments: [ga,rc] [version]")
}
rafaelbreno marked this conversation as resolved.
Show resolved Hide resolved

rc, err := releaseTypePreRelease(args[0])
if err != nil {
return err
}

tag := args[1]
dashboardRelease, found := rootConfig.Dashboard.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: "dashboard",
Owner: dashboardRelease.DashboardRepoOwner,
Branch: dashboardRelease.ReleaseBranch,
}

return dashboard.CreateRelease(ctx, ghClient, &dashboardRelease, opts, rc)
},
}

func init() {
rootCmd.AddCommand(tagCmd)

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

// rke2
tagRKE2Flags.AlpineVersion = rke2TagSubCmd.Flags().StringP("alpine-version", "a", "", "Alpine version")
Expand Down
43 changes: 43 additions & 0 deletions cmd/release/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"errors"
"fmt"
"os"
"strings"

"github.com/Masterminds/semver/v3"
"github.com/rancher/ecm-distro-tools/release/charts"
"github.com/rancher/ecm-distro-tools/release/k3s"
"github.com/rancher/ecm-distro-tools/release/rancher"
"github.com/rancher/ecm-distro-tools/repository"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -130,11 +133,51 @@ var updateChartsCmd = &cobra.Command{
},
}

var updateRancherCmd = &cobra.Command{
Use: "rancher",
Short: "Update rancher files",
}

var updateRancherDashboardCmd = &cobra.Command{
Use: "dashboard [version]",
Short: "Update Rancher's Dashboard and UI references and create a PR",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to use the standard ValidationArgs function of cobra for validating args?
https://github.com/rancher/ecm-distro-tools/blob/master/cmd/release/cmd/push.go#L47

return errors.New("expected at least one argument: [version]")
}

version := args[0]
rafaelbreno marked this conversation as resolved.
Show resolved Hide resolved

// checking if the provided version is valid
_, err := semver.NewVersion(version)
if err != nil {
return err
}

versionTrimmed, _, _ := strings.Cut(version, "-rc")
briandowns marked this conversation as resolved.
Show resolved Hide resolved

dashboardRelease, found := rootConfig.Dashboard.Versions[versionTrimmed]
if !found {
return errors.New("verify your config file, version not found: " + version)
}

dashboardRelease.Tag = version

ctx := context.Background()

ghClient := repository.NewGithub(ctx, rootConfig.Auth.GithubToken)

return rancher.UpdateDashboardReferences(ctx, ghClient, &dashboardRelease, rootConfig.User)
},
}

func init() {
rootCmd.AddCommand(updateCmd)
updateCmd.AddCommand(updateChartsCmd)
updateCmd.AddCommand(updateK3sCmd)
updateK3sCmd.AddCommand(updateK3sReferencesCmd)
updateCmd.AddCommand(updateRancherCmd)
updateRancherCmd.AddCommand(updateRancherDashboardCmd)
}

func validateChartConfig() error {
Expand Down
43 changes: 37 additions & 6 deletions cmd/release/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ type RancherRelease struct {
SkipStatusCheck bool `json:"skip_status_check"`
}

type UIRelease struct {
UIRepoOwner string `json:"ui_repo_owner" validate:"required"`
UIRepoName string `json:"ui_repo_name"`
PreviousTag string `json:"previous_tag"`
ReleaseBranch string `json:"release_branch" validate:"required"`
DryRun bool `json:"dry_run"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite using dry_run as a config in other places, I think using the global flag defined in cmd/release/cmd/root.go is way more convenient and better and easier to check if it's on or not

}

type DashboardRelease struct {
DashboardRepoOwner string `json:"dashboard_repo_owner" validate:"required"`
DashboardRepoName string `json:"dashboard_repo_name"`
PreviousTag string `json:"previous_tag"`
ReleaseBranch string `json:"release_branch" validate:"required"`
Tag string
RancherUpstreamURL string `json:"rancher_upstream_url" validate:"required"`
RancherReleaseBranch string `json:"rancher_release_branch" validate:"required"`
DryRun bool `json:"dry_run"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, but adding that I'll definitely make a PR updating the rancher cmd

}

// RKE2
type RKE2 struct {
Versions []string `json:"versions"`
Expand Down Expand Up @@ -70,6 +89,16 @@ type Rancher struct {
Versions map[string]RancherRelease `json:"versions" validate:"dive,omitempty"`
}

// UI
type UI struct {
Versions map[string]UIRelease `json:"versions" validate:"dive"`
}

// Dashboard
type Dashboard struct {
Versions map[string]DashboardRelease `json:"versions" validate:"dive"`
}

// Auth
type Auth struct {
GithubToken string `json:"github_token"`
Expand All @@ -82,12 +111,14 @@ type Auth struct {

// Config
type Config struct {
User *User `json:"user"`
K3s *K3s `json:"k3s" validate:"omitempty"`
Rancher *Rancher `json:"rancher" validate:"omitempty"`
RKE2 *RKE2 `json:"rke2" validate:"omitempty"`
Charts *ChartsRelease `json:"charts" validate:"omitempty"`
Auth *Auth `json:"auth"`
User *User `json:"user"`
K3s *K3s `json:"k3s" validate:"omitempty"`
Rancher *Rancher `json:"rancher" validate:"omitempty"`
RKE2 *RKE2 `json:"rke2" validate:"omitempty"`
Charts *ChartsRelease `json:"charts" validate:"omitempty"`
Auth *Auth `json:"auth"`
UI *UI `json:"ui"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this code needs to know about the UI repo unless there's code to check that the tag was created from the GitHub action when a tag is created in the dashboard repo.

Dashboard *Dashboard `json:"dashboard"`
}

// OpenOnEditor opens the given config file on the user's default text editor.
Expand Down
Loading
Loading