Skip to content

Commit

Permalink
Merge pull request #185 from nicholasSUSE/auto-bump-fleet-support-rc-…
Browse files Browse the repository at this point in the history
…deletion

Auto bump fleet support rc deletion
  • Loading branch information
nicholasSUSE authored Feb 12, 2025
2 parents 9fa3307 + 47efd9e commit b55ef47
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 45 deletions.
188 changes: 171 additions & 17 deletions pkg/auto/chart_bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package auto
import (
"errors"
"fmt"
"os"
"os/exec"
"strings"

"github.com/rancher/charts-build-scripts/pkg/charts"
"github.com/rancher/charts-build-scripts/pkg/filesystem"
"github.com/rancher/charts-build-scripts/pkg/git"
"github.com/rancher/charts-build-scripts/pkg/lifecycle"
"github.com/rancher/charts-build-scripts/pkg/options"
"github.com/rancher/charts-build-scripts/pkg/path"
Expand Down Expand Up @@ -177,8 +180,6 @@ func (b *Bump) parsePackageYaml(packages []*charts.Package) error {
return errAdditionalChartWorkDir
case additionalChart.CRDChartOptions.CRDDirectory == "":
return errCRDWorkDir
case additionalChart.CRDChartOptions.AddCRDValidationToMainChart == false:
return errAdditionalChartCRDValidation
}
}
}
Expand Down Expand Up @@ -207,18 +208,41 @@ func checkUpstreamOptions(options *options.UpstreamOptions) error {
// BumpChart will execute a similar approach as the defined development workflow for chartowners.
// The main difference is that between the steps: (make prepare and make patch) we will calculate the next version to release.
func (b *Bump) BumpChart() error {

targetCharts, err := chartsTargets(b.targetChart)
if err != nil {
return err
}

git, err := git.OpenGitRepo(".")
if err != nil {
return err
}

// make prepare
if err := b.Pkg.Prepare(); err != nil {
err = fmt.Errorf("error while preparing package: %w", err)
return err
}

// Download logo at assets/logos
if err := b.Pkg.DownloadIcon(); err != nil {
err = fmt.Errorf("error while downloading icon: %w", err)
if err := git.AddAndCommit("make prepare"); err != nil {
return err
}

// Download logo at assets/logos (webhook and fleet are exceptions)
if b.targetChart != "fleet" && b.targetChart != "rancher-webhook" {
if err := b.Pkg.DownloadIcon(); err != nil {
err = fmt.Errorf("error while downloading icon: %w", err)
return err
}
}

if clean, _ := git.StatusProcelain(); !clean {
if err := git.AddAndCommit("make icon"); err != nil {
return err
}
}

// Calculate the next version to release
if err := b.calculateNextVersion(); err != nil {
return err
Expand All @@ -230,6 +254,12 @@ func (b *Bump) BumpChart() error {
return err
}

if clean, _ := git.StatusProcelain(); !clean {
if err := git.AddAndCommit("make patch"); err != nil {
return err
}
}

// make clean
if err := b.Pkg.Clean(); err != nil {
err = fmt.Errorf("error while cleaning package: %w", err)
Expand All @@ -242,31 +272,155 @@ func (b *Bump) BumpChart() error {
return err
}

if err := git.AddAndCommit("make chart"); err != nil {
return err
}

bumpVersion := b.Pkg.AutoGeneratedBumpVersion.String()
newBranch := "auto-bump-" + b.targetChart + "-" + bumpVersion
if err := git.CreateAndCheckoutBranch(newBranch); err != nil {
return err
}

if strings.Contains(b.versions.latest.txt, "-rc") {
if err := b.makeRemove(targetCharts, git); err != nil {
return err
}
}

// modify the release.yaml
if err := b.updateReleaseYaml(); err != nil {
if err := b.updateReleaseYaml(targetCharts); err != nil {
err = fmt.Errorf("error while updating release.yaml: %w", err)
return err
}

if err := git.AddAndCommit("update release.yaml"); err != nil {
return err
}

// This will be used by the GHA job to update the auto generated Pull Request
fmt.Printf("\n%s", b.Pkg.AutoGeneratedBumpVersion.String())
fmt.Printf("\n%s", bumpVersion)

return nil
}

func (b *Bump) updateReleaseYaml() error {
// upadte chart release yaml
if err := b.releaseYaml.UpdateReleaseYaml(); err != nil {
return err
func (b *Bump) updateReleaseYaml(targetCharts []string) error {
for _, chart := range targetCharts {
b.releaseYaml.Chart = chart
if err := b.releaseYaml.UpdateReleaseYaml(); err != nil {
return err
}
}
return nil
}

func chartsTargets(targetChart string) ([]string, error) {

switch targetChart {
case "elemental":
return []string{"elemental", "elemental-crd"}, nil

case "fleet":
return []string{"fleet", "fleet-crd", "fleet-agent"}, nil

case "harvester-cloud-provider":
return []string{"harvester-cloud-provider"}, nil

case "harvester-csi-driver":
return []string{"harvester-csi-driver"}, nil

case "longhorn":
return []string{"longhorn", "longhorn-crd"}, nil

case "neuvector":
return []string{"neuvector", "neuvector-crd", "neuvector-monitor"}, nil

case "prometheus-federator":
return []string{"prometheus-federator"}, nil

case "rancher-aks-operator":
return []string{"rancher-aks-operator", "rancher-aks-operator-crd"}, nil

case "rancher-alerting-drivers":
return []string{"rancher-alerting-drivers"}, nil

case "rancher-backup":
return []string{"rancher-backup", "rancher-backup-crd"}, nil

case "rancher-cis-benchmark":
return []string{"rancher-cis-benchmark", "rancher-cis-benchmark-crd"}, nil

case "rancher-csp-adapter":
return []string{"rancher-csp-adapter"}, nil

case "rancher-eks-operator":
return []string{"rancher-eks-operator", "rancher-eks-operator-crd"}, nil

case "rancher-gatekeeper":
return []string{"rancher-gatekeeper", "rancher-gatekeeper-crd"}, nil

case "rancher-gke-operator":
return []string{"rancher-gke-operator", "rancher-gke-operator-crd"}, nil

case "rancher-istio":
return []string{"rancher-istio"}, nil

case "rancher-logging":
return []string{"rancher-logging", "rancher-logging-crd"}, nil

case "rancher-monitoring":
return []string{"rancher-monitoring", "rancher-monitoring-crd"}, nil

case "rancher-project-monitoring":
return []string{"rancher-project-monitoring"}, nil

case "rancher-provisioning-capi":
return []string{"rancher-provisioning-capi"}, nil

case "rancher-pushprox":
return []string{"rancher-pushprox"}, nil

case "rancher-vsphere-csi":
return []string{"rancher-vsphere-csi"}, nil

case "rancher-vsphere-cpi":
return []string{"rancher-vsphere-cpi"}, nil

case "rancher-webhook":
return []string{"rancher-webhook"}, nil

case "rancher-windows-gmsa":
return []string{"rancher-windows-gmsa", "rancher-windows-gmsa-crd"}, nil

case "rancher-wins-upgrader":
return []string{"rancher-wins-upgrader"}, nil

case "sriov":
return []string{"sriov", "sriov-crd"}, nil

case "system-upgrade-controller":
return []string{"system-upgrade-controller"}, nil

case "ui-plugin-operator":
return []string{"ui-plugin-operator", "ui-plugin-operator-crd"}, nil
}

// Check if there is a crd and update it.
if len(b.Pkg.AdditionalCharts) > 0 {
if b.Pkg.AdditionalCharts[0].CRDChartOptions != nil {
b.releaseYaml.Chart = b.releaseYaml.Chart + "-crd"
return b.releaseYaml.UpdateReleaseYaml()
return nil, fmt.Errorf("chart %s not listed", targetChart)
}

func (b *Bump) makeRemove(targetCharts []string, g *git.Git) error {
version := b.versions.latestRepoPrefix.txt + "+up" + b.versions.latest.txt

for _, chart := range targetCharts {
cmd := exec.Command("make", "remove", fmt.Sprintf("CHART=%s", chart), fmt.Sprintf("VERSION=%s", version))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return fmt.Errorf("failed to execute remove command for chart %s: %w", chart, err)
}
if err := g.AddAndCommit(fmt.Sprintf("remove RC of: %s", chart)); err != nil {
return err
}
}

return nil
}
27 changes: 0 additions & 27 deletions pkg/auto/chart_bump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,6 @@ func Test_parsePackageYaml(t *testing.T) {
},
expected: expected{err: errCRDWorkDir},
},
{
name: "#13",
input: input{
packages: newValidPackagesFunc(),
b: &Bump{targetChart: "rancher-chart"},
},
expected: expected{err: errAdditionalChartCRDValidation},
},
}

for _, tc := range tests {
Expand Down Expand Up @@ -492,25 +484,6 @@ func Test_parsePackageYaml(t *testing.T) {
},
},
}
case "#13":
someBranch := "some-branch"
someSubDir := "some-subdir"
// use the newInvalidUpstreamFunc but passing valid options; these options are being tested above.
validUpstreamOpts := newInvalidUpstreamFunc(options.UpstreamOptions{
URL: "https://github.com/<owner/<repo>.git",
ChartRepoBranch: &someBranch,
Subdirectory: &someSubDir,
})
tc.input.packages[0].AdditionalCharts = []*charts.AdditionalChart{
{
Upstream: &validUpstreamOpts,
CRDChartOptions: &options.CRDChartOptions{
TemplateDirectory: "crd-template",
CRDDirectory: "templates",
AddCRDValidationToMainChart: false,
},
},
}
}

err := tc.input.b.parsePackageYaml(tc.input.packages)
Expand Down
1 change: 1 addition & 0 deletions pkg/charts/additionalchart.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func (c *AdditionalChart) Prepare(rootFs, pkgFs billy.Filesystem, mainChartUpstr
if !exists {
return fmt.Errorf("unable to prepare a CRD chart since there are no CRDs at %s", filepath.Join(mainChartWorkingDir, path.ChartCRDDir))
}

if err := GenerateCRDChartFromTemplate(pkgFs, c.WorkingDir, filepath.Join(path.PackageTemplatesDir, c.CRDChartOptions.TemplateDirectory), c.CRDChartOptions.CRDDirectory); err != nil {
return fmt.Errorf("encountered error while trying to generate CRD chart from template at %s: %s", c.CRDChartOptions.TemplateDirectory, err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func UpdateIndex(original, new *helmRepo.IndexFile) (*helmRepo.IndexFile, bool)
// Ensure newer version of chart is used if it has been updated
for chartName, chartVersions := range updatedIndex.Entries {
for i, chartVersion := range chartVersions {
if !original.Has(chartName, chartVersion.Version) {
version := chartVersion.Version
if !original.Has(chartName, version) {
// Keep the newly generated chart version as-is
upToDate = false
logrus.Debugf("Chart %s has introduced a new version %s: %v", chartName, chartVersion.Version, *chartVersion)
Expand Down

0 comments on commit b55ef47

Please sign in to comment.