-
Notifications
You must be signed in to change notification settings - Fork 32
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 Implementation of Automatic forward port of asset versions, i.e: make auto-forward-port #138
Conversation
Returning *Status to be used by another package.
Improving timestamp for logs creation.
Updating references to version.rules.go at: - status.go - logs.go - versions.rules_test.go
Removing old git.go inside pkg/lifecycle
… and releasing charts. Created data structures and method for initializing dependencies.
receiving the status object from CheckLifecycleStatusAndSave(), parse the assetsToBeForwardPorted map, into a slice of bash script commands. Sort it alphabetically and by version.
…harts into PRs to be pushed later. Rules: - rancher-istio = 1 chart - rancher-eks-operator + rancher-eks-operator-crd = 1 chart - fleet + fleet-crd + fleet-agent = 1 chart 1 chart = 1 branch = 1 PR checkChartCommonPrefixes is a more complex set of rules, but basically it helps enforce the ones mentioned above, however removing "rancher-" prefix which is very common among many charts, but it does not mean that they are the same.
These are the core rules of this feature.
Steps of the manual process implemented by this automation: 1. Create a new branch from production branch 2. Clean release.yaml file 3. Add and commit 4. execute bash script: "make forward-port CHART=<chart> VERSION=<version> BRANCH=<dev branch> UPSTREAM=<remote_name> 5. Add and commit 6. Repeat it to all assets versions that belong to the same chart. 7. Push to forked repository This code is not yet implementing the push to a forked repository, it will be implemented in the next commit.
@nicholasSUSE You can use the DRAFT feature instead of |
@@ -146,5 +146,5 @@ func (vr *VersionRules) CheckChartVersionToRelease(chartVersion string) (bool, e | |||
logrus.Errorf("failed to check version to release for chartVersion:%s with error:%v", chartVersion, err) | |||
return false, err | |||
} | |||
return chartVersionInt == (vr.maxVersion - 1), nil | |||
return chartVersionInt == (vr.MaxVersion - 1), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parenthesis aren't necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it is not necessary.
I intentionally wrote this way for easier reading.
Can we keep this one?
pkg/auto/auto.go
Outdated
|
||
// createForwardPortCommands will create the forward port script commands for each asset and version, | ||
// and return a sorted slice of commands | ||
func (fp *ForwardPort) createForwardPortCommands(chart string) ([]Command, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using a single character for method receivers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing also for forward.port.go
pkg/auto/auto.go
Outdated
|
||
upstreamRemote, ok := fp.git.Remotes["https://github.com/rancher/charts"] | ||
if !ok { | ||
logrus.Error("upstream remote not found; you need to have the upstream remote configured in your git repository (https://github.com/rancher/charts)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be made into a value that can be printed here and returned below rather than being repeated.
var errUpstreamNotFound = errors.New("upstream remote not found; you need to have the upstream remote configured in your git repository (https://github.com/rancher/charts)")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing
pkg/auto/auto.go
Outdated
func checkIfChartChanged(lastChart, currentChart string) bool { | ||
// Check if the current chart is different from the last chart | ||
sameCharts := (lastChart == currentChart) | ||
if sameCharts { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified: Remove line 113 and add the conditional check to line 114.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing
pkg/auto/auto.go
Outdated
} | ||
|
||
// Check for special edge cases | ||
edgeCase := checkEdgeCasesIfChartChanged(lastChart, currentChart) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can also be simplified as:
return !checkEdgeCasesIfChartChanged(lastChart, currentChart)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing
pkg/auto/auto.go
Outdated
return true | ||
} | ||
if equalCounter == 1 && strings.HasPrefix("rancher-", lastParts[0]) && | ||
minLength < 3 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move tyhis up a line. Go doesn't care at all about line length, per Rob Pike.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing
pkg/auto/auto.go
Outdated
return err | ||
} | ||
// create new branch and checkout | ||
err = fp.git.CreateAndCheckoutBranch(branch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
err = fp.git.CreateAndCheckoutBranch(branch) | |
return fp.git.CreateAndCheckoutBranch(branch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing
pkg/auto/auto.go
Outdated
} | ||
|
||
// File exists, open it with O_TRUNC to erase its content | ||
file, err := os.OpenFile("release.yaml", os.O_WRONLY|os.O_TRUNC, 0644) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file, err := os.OpenFile("release.yaml", os.O_WRONLY|os.O_TRUNC, 0644) | |
if err := os.Truncate("release.yaml, 0); err != nil { | |
return err | |
} |
The defer can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wooow, did not know that.
Fixing.
pkg/auto/forward.port.go
Outdated
@@ -0,0 +1,161 @@ | |||
package auto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file isn't named according to Go standards. Replace the first .
with an _
. And do this for any other file names similarly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing.
main.go
Outdated
@@ -43,6 +44,8 @@ const ( | |||
DefaultDebugEnvironmentVariable = "DEBUG" | |||
// DefaultBranchVersionEnvironmentVariable is the default environment variable that indicates the branch version to compare against | |||
DefaultBranchVersionEnvironmentVariable = "BRANCH_VERSION" | |||
// DefaultForkEnvironmentVariable is the default environment variable that indicates the fork URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of these need to be exported since they can't be imported from main. Same for the new variable below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing
main.go
Outdated
func autoForwardPort(c *cli.Context) { | ||
|
||
if ForkURL == "" { | ||
logrus.Fatalf("FORK environment variable must be set to run auto-forward-port") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logrus.Fatalf("FORK environment variable must be set to run auto-forward-port") | |
logrus.Fatal("FORK environment variable must be set to run auto-forward-port") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing
@@ -71,6 +74,8 @@ var ( | |||
CacheMode = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In another pr this should be updated to match the ones above using the 0 value declaration rather than this declaration to false. The 0 value for bools is false but moreover like code should be consistent. Which means the new variable below should be defined as type string since the 0 value for string is "".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will also need to be unexported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created this issue so we don't lose track of this technical debt.
See if you agree please.
func prepareReleaseYaml() error { | ||
// Check if the file exists | ||
_, err := os.Stat("release.yaml") | ||
if os.IsNotExist(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The nil check on err should always be done first and if it's not nil, then inside that scope further error checking/handling should occur.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing
return false // Remote URL is empty | ||
} | ||
urlPart1, urlPart2 := extractCommonParts(upstreamURL, remoteURL) | ||
return (urlPart1 == "https://github.com" && urlPart2 == repo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (urlPart1 == "https://github.com" && urlPart2 == repo) | |
return urlPart1 == "https://github.com" && urlPart2 == repo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing
Problem
Forward porting each asset version individually is an effortful manual work and prone to human error.
For each asset version, this was the manual process:
Check if the asset version is not present at the
production branch
and present atdevelopment branch
.Open a new local branch
Clean release.yaml
Add and commit.
execute
make forward-port
Add and commit.
Repeat it for every asset version and it's dependencies
Push to a forked repository.
Open a Pull Request to the target
production branch
.Review and approve PR.
Monitor
git-mirror
.Solution
Implement automation to reduce the amount of manual work and human intervention.
This solution automates the above mentioned steps: (
1 -> 8
)Results
These are the automated
pushes
generated by this automation:rancher/charts#4137
rancher/charts#4138
rancher/charts#4139
rancher/charts#4140
rancher/charts#4141
rancher/charts#4142
rancher/charts#4143
rancher/charts#4144
rancher/charts#4145
rancher/charts#4146
rancher/charts#4147
rancher/charts#4148
rancher/charts#4149
rancher/charts#4150
rancher/charts#4151
rancher/charts#4152
rancher/charts#4153
rancher/charts#4154
rancher/charts#4155
rancher/charts#4156
rancher/charts#4157
rancher/charts#4158
rancher/charts#4159
rancher/charts#4160