mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
In module lists, handle allowed replacements.
This commit is contained in:
@@ -38,7 +38,7 @@ var (
|
||||
"site",
|
||||
}
|
||||
// TODO: make this a PATH-like flag
|
||||
allowedReplacements = []string {
|
||||
allowedReplacements = []string{
|
||||
"gopkg.in/yaml.v3",
|
||||
}
|
||||
)
|
||||
|
||||
@@ -50,6 +50,9 @@ type LaModule interface {
|
||||
|
||||
// GetReplacements returns a list of replacements.
|
||||
GetReplacements() []string
|
||||
|
||||
// GetDisallowedReplacements returns a list of disallowed replacements.
|
||||
GetDisallowedReplacements([]string) []string
|
||||
}
|
||||
|
||||
// VersionMap holds the versions associated with modules.
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"golang.org/x/mod/modfile"
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/misc"
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/semver"
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/utils"
|
||||
)
|
||||
|
||||
// Module is an immutable representation of a Go module.
|
||||
@@ -77,3 +78,14 @@ func (m *Module) GetReplacements() (result []string) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (m *Module) GetDisallowedReplacements(
|
||||
allowedReplacements []string) (badReps []string) {
|
||||
for _, r := range m.GetReplacements() {
|
||||
m := utils.ExtractModule(r)
|
||||
if !utils.SliceContains(allowedReplacements, m) {
|
||||
badReps = append(badReps, r)
|
||||
}
|
||||
}
|
||||
return badReps
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/git"
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/misc"
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/semver"
|
||||
"sigs.k8s.io/kustomize/cmd/gorepomod/internal/utils"
|
||||
)
|
||||
|
||||
// Manager manages a git repo.
|
||||
@@ -23,6 +22,9 @@ type Manager struct {
|
||||
|
||||
// The list of known Go modules in the repo.
|
||||
modules misc.LesModules
|
||||
|
||||
// List of globally allowed module replacements.
|
||||
allowedReplacements []string
|
||||
}
|
||||
|
||||
func (mgr *Manager) AbsPath() string {
|
||||
@@ -67,8 +69,8 @@ func (mgr *Manager) UnPin(
|
||||
})
|
||||
}
|
||||
|
||||
func hasUnPinnedDeps(m misc.LaModule) string {
|
||||
if len(m.GetReplacements()) > 0 {
|
||||
func (mgr *Manager) hasUnPinnedDeps(m misc.LaModule) string {
|
||||
if len(m.GetDisallowedReplacements(mgr.allowedReplacements)) > 0 {
|
||||
return "yes"
|
||||
}
|
||||
return ""
|
||||
@@ -92,7 +94,7 @@ func (mgr *Manager) List() error {
|
||||
format, m.ShortName(),
|
||||
m.VersionLocal().Pretty(),
|
||||
m.VersionRemote().Pretty(),
|
||||
hasUnPinnedDeps(m),
|
||||
mgr.hasUnPinnedDeps(m),
|
||||
mgr.modules.InternalDeps(m))
|
||||
return nil
|
||||
})
|
||||
@@ -119,16 +121,13 @@ func (mgr *Manager) Debug(_ misc.LaModule, doIt bool) error {
|
||||
// * Each minor release gets its own branch.
|
||||
//
|
||||
func (mgr *Manager) Release(
|
||||
target misc.LaModule, bump semver.SvBump,
|
||||
allowedReplacements []string, doIt bool) error {
|
||||
target misc.LaModule, bump semver.SvBump, doIt bool) error {
|
||||
|
||||
if reps := target.GetReplacements(); len(reps) > 0 {
|
||||
badReps := findDisallowedReplacements(reps, allowedReplacements)
|
||||
if len(badReps) > 0 {
|
||||
return fmt.Errorf(
|
||||
"to release %q, first pin these replacements: %v",
|
||||
target.ShortName(), badReps)
|
||||
}
|
||||
if reps := target.GetDisallowedReplacements(
|
||||
mgr.allowedReplacements); len(reps) > 0 {
|
||||
return fmt.Errorf(
|
||||
"to release %q, first pin these replacements: %v",
|
||||
target.ShortName(), reps)
|
||||
}
|
||||
|
||||
newVersion := target.VersionLocal().Bump(bump)
|
||||
@@ -187,18 +186,6 @@ func (mgr *Manager) Release(
|
||||
return nil
|
||||
}
|
||||
|
||||
func findDisallowedReplacements(
|
||||
reps []string, allowedReplacements []string) []string {
|
||||
var badReps []string
|
||||
for _, r := range reps {
|
||||
km := utils.ExtractModule(r)
|
||||
if !utils.SliceContains(allowedReplacements, km) {
|
||||
badReps = append(badReps, r)
|
||||
}
|
||||
}
|
||||
return badReps
|
||||
}
|
||||
|
||||
func (mgr *Manager) UnRelease(target misc.LaModule, doIt bool) error {
|
||||
fmt.Printf(
|
||||
"Unreleasing %s/%s\n",
|
||||
|
||||
@@ -15,7 +15,7 @@ type ManagerFactory struct {
|
||||
versionMapRemote misc.VersionMap
|
||||
}
|
||||
|
||||
func (mf *ManagerFactory) NewRepoManager() *Manager {
|
||||
func (mf *ManagerFactory) NewRepoManager(allowedReplacements []string) *Manager {
|
||||
result := &Manager{
|
||||
dg: mf.dg,
|
||||
remoteName: mf.remoteName,
|
||||
@@ -31,5 +31,6 @@ func (mf *ManagerFactory) NewRepoManager() *Manager {
|
||||
mf.versionMapRemote.Latest(shortName)))
|
||||
}
|
||||
result.modules = modules
|
||||
result.allowedReplacements = allowedReplacements
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ func loadRepoManager(args *arguments.Args) (*repo.Manager, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pr.NewRepoManager(), nil
|
||||
return pr.NewRepoManager(args.AllowedReplacements()), nil
|
||||
}
|
||||
|
||||
func findModule(
|
||||
@@ -71,8 +71,7 @@ func actualMain() error {
|
||||
case arguments.UnPin:
|
||||
return mgr.UnPin(args.DoIt(), targetModule, conditionalModule)
|
||||
case arguments.Release:
|
||||
return mgr.Release(
|
||||
targetModule, args.Bump(), args.AllowedReplacements(), args.DoIt())
|
||||
return mgr.Release(targetModule, args.Bump(), args.DoIt())
|
||||
case arguments.UnRelease:
|
||||
return mgr.UnRelease(targetModule, args.DoIt())
|
||||
case arguments.Debug:
|
||||
|
||||
Reference in New Issue
Block a user