Merge pull request #63169 from smarterclayton/limit_dependencies

Automatic merge from submit-queue (batch tested with PRs 63251, 59166, 63250, 63180, 63169). 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>.

Break a generic package dependency to core/api/v1

It is not necessary for this package to depend on core/v1.
This commit is contained in:
Kubernetes Submit Queue 2018-04-27 10:45:21 -07:00 committed by GitHub
commit 625bce3ff6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 10 deletions

View File

@ -57,6 +57,8 @@ type ImportRestriction struct {
// given as paths that would be used in a Go
// import statement
AllowedImports []string `yaml:"allowedImports"`
// ExcludeTests will skip checking test dependencies.
ExcludeTests bool `yaml:"excludeTests"`
}
// ForbiddenImportsFor determines all of the forbidden
@ -120,7 +122,11 @@ func isPathUnder(base, path string) (bool, error) {
// and returns a deduplicated list of them
func (i *ImportRestriction) forbiddenImportsFor(pkg Package) []string {
forbiddenImportSet := map[string]struct{}{}
for _, imp := range append(pkg.Imports, append(pkg.TestImports, pkg.XTestImports...)...) {
imports := pkg.Imports
if !i.ExcludeTests {
imports = append(imports, append(pkg.TestImports, pkg.XTestImports...)...)
}
for _, imp := range imports {
path := extractVendorPath(imp)
if i.isForbidden(path) {
forbiddenImportSet[path] = struct{}{}

View File

@ -45,6 +45,28 @@
- k8s.io/apimachinery
- k8s.io/client-go
# prevent core machinery from taking explicit v1 references unless
# necessary
- baseImportPath: "./vendor/k8s.io/client-go/rest/"
excludeTests: true
allowedImports:
- k8s.io/apimachinery
- k8s.io/client-go
- baseImportPath: "./vendor/k8s.io/client-go/tools/"
excludeTests: true
ignoredSubTrees:
- "./vendor/k8s.io/client-go/tools/bootstrap/token/api"
- "./vendor/k8s.io/client-go/tools/cache/testing"
- "./vendor/k8s.io/client-go/tools/leaderelection/resourcelock"
- "./vendor/k8s.io/client-go/tools/portforward"
- "./vendor/k8s.io/client-go/tools/record"
- "./vendor/k8s.io/client-go/tools/reference"
- "./vendor/k8s.io/client-go/tools/remotecommand"
allowedImports:
- k8s.io/apimachinery
- k8s.io/client-go
- baseImportPath: "./vendor/k8s.io/apiserver/"
allowedImports:
- k8s.io/api

View File

@ -60,7 +60,6 @@ go_library(
deps = [
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/golang.org/x/net/http2:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",

View File

@ -29,7 +29,6 @@ import (
"github.com/golang/glog"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
@ -316,12 +315,12 @@ func InClusterConfig() (*Config, error) {
return nil, fmt.Errorf("unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined")
}
token, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/" + v1.ServiceAccountTokenKey)
token, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/token")
if err != nil {
return nil, err
}
tlsClientConfig := TLSClientConfig{}
rootCAFile := "/var/run/secrets/kubernetes.io/serviceaccount/" + v1.ServiceAccountRootCAKey
rootCAFile := "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
if _, err := certutil.NewPool(rootCAFile); err != nil {
glog.Errorf("Expected to load root CA config from %s, but got err: %v", rootCAFile, err)
} else {

View File

@ -48,7 +48,6 @@ go_library(
"//vendor/github.com/imdario/mergo:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/golang.org/x/crypto/ssh/terminal:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",

View File

@ -27,7 +27,6 @@ import (
"github.com/golang/glog"
"github.com/imdario/mergo"
"k8s.io/api/core/v1"
restclient "k8s.io/client-go/rest"
clientauth "k8s.io/client-go/tools/auth"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
@ -338,7 +337,7 @@ func (config *DirectClientConfig) Namespace() (string, bool, error) {
}
if len(configContext.Namespace) == 0 {
return v1.NamespaceDefault, false, nil
return "default", false, nil
}
return configContext.Namespace, false, nil

View File

@ -22,7 +22,6 @@ import (
"github.com/golang/glog"
"k8s.io/api/core/v1"
restclient "k8s.io/client-go/rest"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)
@ -145,7 +144,7 @@ func (config *DeferredLoadingClientConfig) Namespace() (string, bool, error) {
if len(ns) > 0 {
// if we got a non-default namespace from the kubeconfig, use it
if ns != v1.NamespaceDefault {
if ns != "default" {
return ns, false, nil
}