mirror of https://github.com/k3s-io/k3s
Merge pull request #54568 from sttts/sttts-import-verifier-yaml
Automatic merge from submit-queue (batch tested with PRs 52717, 54568, 54452, 53997, 54237). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. import-verifier: use yaml for inline comments For iterative cutting of dependencies, we will have temporary execeptions in hack/import-restrictions.json. In order to document that, comments would help a lot and using yaml is simple and gives us that.pull/6/head
commit
e3ac8b330d
|
@ -16,6 +16,7 @@ go_library(
|
|||
name = "go_default_library",
|
||||
srcs = ["importverifier.go"],
|
||||
importpath = "k8s.io/kubernetes/cmd/importverifier",
|
||||
deps = ["//vendor/gopkg.in/yaml.v2:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
|
|
|
@ -27,15 +27,17 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Package is a subset of cmd/go.Package
|
||||
type Package struct {
|
||||
Dir string `json:",omitempty"` // directory containing package sources
|
||||
ImportPath string `json:",omitempty"` // import path of package in dir
|
||||
Imports []string `json:",omitempty"` // import paths used by this package
|
||||
TestImports []string `json:",omitempty"` // imports from TestGoFiles
|
||||
XTestImports []string `json:",omitempty"` // imports from XTestGoFiles
|
||||
Dir string `yaml:",omitempty"` // directory containing package sources
|
||||
ImportPath string `yaml:",omitempty"` // import path of package in dir
|
||||
Imports []string `yaml:",omitempty"` // import paths used by this package
|
||||
TestImports []string `yaml:",omitempty"` // imports from TestGoFiles
|
||||
XTestImports []string `yaml:",omitempty"` // imports from XTestGoFiles
|
||||
}
|
||||
|
||||
// ImportRestriction describes a set of allowable import
|
||||
|
@ -44,17 +46,17 @@ type ImportRestriction struct {
|
|||
// BaseDir is the root of the package tree that is
|
||||
// restricted by this configuration, given as a
|
||||
// relative path from the root of the repository
|
||||
BaseDir string `json:"baseImportPath"`
|
||||
BaseDir string `yaml:"baseImportPath"`
|
||||
// IgnoredSubTrees are roots of sub-trees of the
|
||||
// BaseDir for which we do not want to enforce
|
||||
// any import restrictions whatsoever, given as
|
||||
// relative paths from the root of the repository
|
||||
IgnoredSubTrees []string `json:"ignoredSubTrees,omitempty"`
|
||||
IgnoredSubTrees []string `yaml:"ignoredSubTrees,omitempty"`
|
||||
// AllowedImports are roots of package trees that
|
||||
// are allowed to be imported from the BaseDir,
|
||||
// given as paths that would be used in a Go
|
||||
// import statement
|
||||
AllowedImports []string `json:"allowedImports"`
|
||||
AllowedImports []string `yaml:"allowedImports"`
|
||||
}
|
||||
|
||||
// ForbiddenImportsFor determines all of the forbidden
|
||||
|
@ -164,7 +166,7 @@ var rootPackage string
|
|||
|
||||
func main() {
|
||||
if len(os.Args) != 3 {
|
||||
log.Fatalf("Usage: %s ROOT RESTRICTIONS.json", os.Args[0])
|
||||
log.Fatalf("Usage: %s ROOT RESTRICTIONS.yaml", os.Args[0])
|
||||
}
|
||||
|
||||
rootPackage = os.Args[1]
|
||||
|
@ -214,7 +216,7 @@ func loadImportRestrictions(configFile string) ([]ImportRestriction, error) {
|
|||
}
|
||||
|
||||
var importRestrictions []ImportRestriction
|
||||
if err := json.Unmarshal(config, &importRestrictions); err != nil {
|
||||
if err := yaml.Unmarshal(config, &importRestrictions); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal from %s: %v", configFile, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,92 +0,0 @@
|
|||
[
|
||||
{
|
||||
"baseImportPath": "./vendor/k8s.io/apimachinery/",
|
||||
"allowedImports": [
|
||||
"k8s.io/apimachinery",
|
||||
"k8s.io/kube-openapi"
|
||||
]
|
||||
},
|
||||
{
|
||||
"baseImportPath": "./vendor/k8s.io/api/",
|
||||
"allowedImports": [
|
||||
"k8s.io/api",
|
||||
"k8s.io/apimachinery"
|
||||
]
|
||||
},
|
||||
{
|
||||
"baseImportPath": "./vendor/k8s.io/code-generator/",
|
||||
"ignoredSubTrees": [
|
||||
"./vendor/k8s.io/code-generator/_test"
|
||||
],
|
||||
"allowedImports": [
|
||||
"k8s.io/gengo",
|
||||
"k8s.io/code-generator",
|
||||
"k8s.io/kube-openapi"
|
||||
]
|
||||
},
|
||||
{
|
||||
"baseImportPath": "./vendor/k8s.io/client-go/",
|
||||
"allowedImports": [
|
||||
"k8s.io/api",
|
||||
"k8s.io/apimachinery",
|
||||
"k8s.io/client-go"
|
||||
]
|
||||
},
|
||||
{
|
||||
"baseImportPath": "./vendor/k8s.io/apiserver/",
|
||||
"allowedImports": [
|
||||
"k8s.io/api",
|
||||
"k8s.io/apimachinery",
|
||||
"k8s.io/apiserver",
|
||||
"k8s.io/client-go",
|
||||
"k8s.io/kube-openapi"
|
||||
]
|
||||
},
|
||||
{
|
||||
"baseImportPath": "./vendor/k8s.io/metrics/",
|
||||
"allowedImports": [
|
||||
"k8s.io/api",
|
||||
"k8s.io/apimachinery",
|
||||
"k8s.io/client-go",
|
||||
"k8s.io/metrics"
|
||||
]
|
||||
},
|
||||
{
|
||||
"baseImportPath": "./vendor/k8s.io/kube-aggregator/",
|
||||
"allowedImports": [
|
||||
"k8s.io/api",
|
||||
"k8s.io/apimachinery",
|
||||
"k8s.io/apiserver",
|
||||
"k8s.io/client-go",
|
||||
"k8s.io/kube-aggregator",
|
||||
"k8s.io/kube-openapi"
|
||||
]
|
||||
},
|
||||
{
|
||||
"baseImportPath": "./vendor/k8s.io/sample-apiserver/",
|
||||
"allowedImports": [
|
||||
"k8s.io/api",
|
||||
"k8s.io/apimachinery",
|
||||
"k8s.io/apiserver",
|
||||
"k8s.io/client-go",
|
||||
"k8s.io/sample-apiserver"
|
||||
]
|
||||
},
|
||||
{
|
||||
"baseImportPath": "./vendor/k8s.io/apiextensions-apiserver/",
|
||||
"allowedImports": [
|
||||
"k8s.io/api",
|
||||
"k8s.io/apiextensions-apiserver",
|
||||
"k8s.io/apimachinery",
|
||||
"k8s.io/apiserver",
|
||||
"k8s.io/client-go"
|
||||
]
|
||||
},
|
||||
{
|
||||
"baseImportPath": "./vendor/k8s.io/kube-openapi/",
|
||||
"allowedImports": [
|
||||
"k8s.io/kube-openapi",
|
||||
"k8s.io/gengo"
|
||||
]
|
||||
}
|
||||
]
|
|
@ -0,0 +1,68 @@
|
|||
- baseImportPath: "./vendor/k8s.io/apimachinery/"
|
||||
allowedImports:
|
||||
- k8s.io/apimachinery
|
||||
- k8s.io/kube-openapi
|
||||
|
||||
- baseImportPath: "./vendor/k8s.io/api/"
|
||||
allowedImports:
|
||||
- k8s.io/api
|
||||
- k8s.io/apimachinery
|
||||
|
||||
- baseImportPath: "./vendor/k8s.io/code-generator/"
|
||||
ignoredSubTrees:
|
||||
- "./vendor/k8s.io/code-generator/_test"
|
||||
allowedImports:
|
||||
- k8s.io/gengo
|
||||
- k8s.io/code-generator
|
||||
- k8s.io/kube-openapi
|
||||
|
||||
- baseImportPath: "./vendor/k8s.io/client-go/"
|
||||
allowedImports:
|
||||
- k8s.io/api
|
||||
- k8s.io/apimachinery
|
||||
- k8s.io/client-go
|
||||
|
||||
- baseImportPath: "./vendor/k8s.io/apiserver/"
|
||||
allowedImports:
|
||||
- k8s.io/api
|
||||
- k8s.io/apimachinery
|
||||
- k8s.io/apiserver
|
||||
- k8s.io/client-go
|
||||
- k8s.io/kube-openapi
|
||||
|
||||
- baseImportPath: "./vendor/k8s.io/metrics/"
|
||||
allowedImports:
|
||||
- k8s.io/api
|
||||
- k8s.io/apimachinery
|
||||
- k8s.io/client-go
|
||||
- k8s.io/metrics
|
||||
|
||||
- baseImportPath: "./vendor/k8s.io/kube-aggregator/"
|
||||
allowedImports:
|
||||
- k8s.io/api
|
||||
- k8s.io/apimachinery
|
||||
- k8s.io/apiserver
|
||||
- k8s.io/client-go
|
||||
- k8s.io/kube-aggregator
|
||||
- k8s.io/kube-openapi
|
||||
|
||||
- baseImportPath: "./vendor/k8s.io/sample-apiserver/"
|
||||
allowedImports:
|
||||
- k8s.io/api
|
||||
- k8s.io/apimachinery
|
||||
- k8s.io/apiserver
|
||||
- k8s.io/client-go
|
||||
- k8s.io/sample-apiserver
|
||||
|
||||
- baseImportPath: "./vendor/k8s.io/apiextensions-apiserver/"
|
||||
allowedImports:
|
||||
- k8s.io/api
|
||||
- k8s.io/apiextensions-apiserver
|
||||
- k8s.io/apimachinery
|
||||
- k8s.io/apiserver
|
||||
- k8s.io/client-go
|
||||
|
||||
- baseImportPath: "./vendor/k8s.io/kube-openapi/"
|
||||
allowedImports:
|
||||
- k8s.io/kube-openapi
|
||||
- k8s.io/gengo
|
|
@ -38,4 +38,4 @@ if [[ ! -x "$importverifier" ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
"${importverifier}" "k8s.io/" "${KUBE_ROOT}/hack/import-restrictions.json"
|
||||
"${importverifier}" "k8s.io/" "${KUBE_ROOT}/hack/import-restrictions.yaml"
|
||||
|
|
Loading…
Reference in New Issue