Skip to content
Merged
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
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/rancher/charts-build-scripts/pkg/util"
"io/ioutil"
"os"
"strings"
Expand Down Expand Up @@ -54,6 +55,8 @@ const (
defaultPRNumberEnvironmentVariable = "PR_NUMBER"
// defaultSkipEnvironmentVariable is the default environment variable that indicates whether to skip execution
defaultSkipEnvironmentVariable = "SKIP"
// softErrorsEnvironmentVariable is the default environment variable that indicates if soft error mode is enabled
softErrorsEnvironmentVariable = "SOFT_ERRORS"
)

var (
Expand Down Expand Up @@ -89,12 +92,15 @@ var (
GithubToken string
// Skip indicates whether to skip execution
Skip bool
// SoftErrorMode indicates if certain non-fatal errors will be turned into warnings
SoftErrorMode = false
)

func main() {
if len(os.Getenv("DEBUG")) > 0 {
logrus.SetLevel(logrus.DebugLevel)
}
util.InitSoftErrorMode()

app := cli.NewApp()
app.Name = "charts-build-scripts"
Expand Down Expand Up @@ -239,6 +245,12 @@ func main() {
EnvVar: defaultSkipEnvironmentVariable,
Destination: &Skip,
}
softErrorsFlag := cli.BoolFlag{
Name: "soft-errors",
Usage: "Enables soft error mode - some non-fatal errors will become warnings",
EnvVar: softErrorsEnvironmentVariable,
Destination: &SoftErrorMode,
}

// Commands
app.Commands = []cli.Command{
Expand All @@ -253,7 +265,7 @@ func main() {
Usage: "Pull in the chart specified from upstream to the charts directory and apply any patch files",
Action: prepareCharts,
Before: setupCache,
Flags: []cli.Flag{packageFlag, cacheFlag},
Flags: []cli.Flag{packageFlag, cacheFlag, softErrorsFlag},
Copy link
Collaborator

@nicholasSUSE nicholasSUSE Feb 4, 2025

Choose a reason for hiding this comment

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

I think you will need to add softErrorsFlag also to make charts Flags (line 282).

make charts command also calls make prepare internally before running.

You will have the same problem later on that stage.

Copy link
Member Author

Choose a reason for hiding this comment

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

For now I've excluded charts subcommand intentionally - I'm open to expanding there, I just wanted to put some more consideration into if there should be more DX features around that one.

For now I'd expect - at least on O&B team - we would do something like:

  • Find all patches with errors,
  • Move those to a patch-off folder from patch,
  • Be able to run make chart
  • Work to recreate/fix the patches that were disabled

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok approved.

},
{
Name: "patch",
Expand Down Expand Up @@ -422,6 +434,7 @@ func listPackages(c *cli.Context) {
}

func prepareCharts(c *cli.Context) {
util.SetSoftErrorMode(SoftErrorMode)
packages := getPackages()
if len(packages) == 0 {
logrus.Fatal("Could not find any packages in packages/")
Expand Down
14 changes: 12 additions & 2 deletions pkg/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"compress/gzip"
"crypto/sha1"
"fmt"
"github.com/rancher/charts-build-scripts/pkg/util"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -561,13 +562,22 @@ func WalkDir(fs billy.Filesystem, dirPath string, doFunc RelativePathFunc) error
// Path does not exist anymore, so do not walk it
return nil
}
return err
if !util.IsSoftErrorOn() {
return err
}
logrus.Error(err)
}
path, err := GetRelativePath(fs, abspath)
if err != nil {
return err
}
return doFunc(fs, path, info.IsDir())
walkFuncRes := doFunc(fs, path, info.IsDir())
if !util.IsSoftErrorOn() {
return walkFuncRes
} else if walkFuncRes != nil {
logrus.Error(walkFuncRes)
}
return nil
})
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/util/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package util

// SoftErrorMode allows for skipping certain non-fatal errors from breaking execution
type SoftErrorMode struct {
Enabled bool
}

var _softErrorMode *SoftErrorMode

func InitSoftErrorMode() {

Check failure on line 10 in pkg/util/errors.go

View workflow job for this annotation

GitHub Actions / lint

exported function InitSoftErrorMode should have comment or be unexported
_softErrorMode = &SoftErrorMode{false}
}

func SetSoftErrorMode(newValue bool) {

Check failure on line 14 in pkg/util/errors.go

View workflow job for this annotation

GitHub Actions / lint

exported function SetSoftErrorMode should have comment or be unexported
_softErrorMode.Enabled = newValue
}

func IsSoftErrorOn() bool {

Check failure on line 18 in pkg/util/errors.go

View workflow job for this annotation

GitHub Actions / lint

exported function IsSoftErrorOn should have comment or be unexported
return _softErrorMode.Enabled
}