Skip to content

Commit

Permalink
resolving review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohit Sharma committed Oct 31, 2023
1 parent 05a400d commit 69f351f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
_output
/coverage.out
.idea/*
8 changes: 4 additions & 4 deletions cmd/update-rules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Run the command line as:
update-rules -branch release-1.24 -go 1.17.1 -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml
# Remove rules and export to /tmp/rules.yaml
update-rules -branch release-1.24 -remove true -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml
update-rules -branch release-1.24 -delete -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml
-alsologtostderr
log to standard error as well as files
Expand All @@ -79,8 +79,8 @@ Run the command line as:
log to standard error instead of files
-o string
Path to export the updated rules to, e.g. -o /tmp/rules.yaml
-remove
Remove old rules to deprecated branch
-delete
Remove old rules of deprecated branch
-rules string
[required] URL or Path of the rules file to update rules for, e.g. --rules path/or/url/to/rules/file.yaml
-stderrthreshold value
Expand All @@ -99,5 +99,5 @@ Run the command line as:
#### Optional flags:

- `-go` flag refers to golang version which should be pinned for given branch, if not given an empty string is set
- `-remove` flag refers to removing the branch from rules, defaults to false
- `-delete` flag refers to removing the branch from rules, if not set defaults to false
- `-o` flag refers to output file where the processed rules should be exported, otherwise rules are printed on stdout
26 changes: 13 additions & 13 deletions cmd/update-rules/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const GitDefaultBranch = "master"

type options struct {
branch string
remove bool
delete bool
rulesFile string
goVersion string
out string
Expand All @@ -42,7 +42,7 @@ func parseOptions() options {
var o options
flag.StringVar(&o.branch, "branch", "", "[required] Branch to update rules for, e.g. --branch release-x.yy")
flag.StringVar(&o.rulesFile, "rules", "", "[required] URL or Path of the rules file to update rules for, e.g. --rules path/or/url/to/rules/file.yaml")
flag.BoolVar(&o.remove, "remove", false, "Remove old rules to deprecated branch")
flag.BoolVar(&o.delete, "delete", false, "Remove old rules to deprecated branch")
flag.StringVar(&o.goVersion, "go", "", "Golang version to pin for this branch, e.g. --go 1.16.1")
flag.StringVar(&o.out, "o", "", "Path to export the updated rules to, e.g. -o /tmp/rules.yaml")

Expand All @@ -58,10 +58,10 @@ func parseOptions() options {
update-rules -branch release-1.22 -go 1.17.1 -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml
# Update rules to remove deprecated branch and export to /tmp/rules.yaml
update-rules -branch release-1.22 -remove true -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml`
update-rules -branch release-1.22 -delete -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml`

flag.Usage = func() {
fmt.Fprintf(os.Stdout, "\n Usage: update-rules --branch BRANCH --rules PATHorURL [--go VERSION | -o PATH | -remove true/false]")
fmt.Fprintf(os.Stdout, "\n Usage: update-rules --branch BRANCH --rules PATHorURL [--go VERSION | -o PATH | --delete ]")
fmt.Fprintf(os.Stdout, "\n %s\n\n", examples)
flag.PrintDefaults()
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func main() {
}

// update rules for all destination repos
UpdateRules(rules, o.branch, o.goVersion, o.remove)
UpdateRules(rules, o.branch, o.goVersion, o.delete)
// validate rules after update
if err := config.Validate(rules); err != nil {
glog.Fatalf("update failed, found invalid rules after update: %v", err)
Expand Down Expand Up @@ -160,14 +160,14 @@ func UpdateRules(rules *config.RepositoryRules, branch, goVer string, removeRule
break
}
}
for i, br := range r.Branches {
if removeRules && br.Name == branch {
glog.Infof("Will remove rule for %s %s", branch, r.DestinationRepository)
r.Branches = append(r.Branches[:i], r.Branches[i+1:]...)
branchRuleExists = true
break
}
}
// for i, br := range r.Branches {
// if removeRules && br.Name == branch {
// glog.Infof("Will remove rule for %s %s", branch, r.DestinationRepository)
// r.Branches = append(r.Branches[:i], r.Branches[i+1:]...)
// branchRuleExists = true
// break
// }
// }
// new rules, append to destination's branches
if !branchRuleExists {
r.Branches = append(r.Branches, newBranchRule)
Expand Down

0 comments on commit 69f351f

Please sign in to comment.