diff --git a/cmd/libs/go2idl/.import-restrictions b/cmd/libs/go2idl/.import-restrictions index 5abc3747cc572..8832a0234bc13 100644 --- a/cmd/libs/go2idl/.import-restrictions +++ b/cmd/libs/go2idl/.import-restrictions @@ -6,7 +6,8 @@ "k8s.io/kubernetes/cmd/libs/go2idl", "k8s.io/gengo", "k8s.io/kubernetes/third_party", - "k8s.io/kubernetes/pkg/util/sets" + "k8s.io/apimachinery/third_party", + "k8s.io/apimachinery/pkg/util/sets" ] } ] diff --git a/cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go b/cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go index 38a20d676e22f..be4e5dc2810e8 100644 --- a/cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go +++ b/cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go @@ -62,9 +62,9 @@ func New() *Generator { Packages: strings.Join([]string{ `+k8s.io/kubernetes/pkg/util/intstr`, `+k8s.io/kubernetes/pkg/api/resource`, - `+k8s.io/kubernetes/pkg/runtime/schema`, - `+k8s.io/kubernetes/pkg/runtime`, - `k8s.io/kubernetes/pkg/apis/meta/v1`, + `+k8s.io/apimachinery/pkg/runtime/schema`, + `+k8s.io/apimachinery/pkg/runtime`, + `k8s.io/apimachinery/pkg/apis/meta/v1`, `k8s.io/kubernetes/pkg/api/v1`, `k8s.io/kubernetes/pkg/apis/policy/v1beta1`, `k8s.io/kubernetes/pkg/apis/extensions/v1beta1`, diff --git a/cmd/libs/go2idl/openapi-gen/.import-restrictions b/cmd/libs/go2idl/openapi-gen/.import-restrictions index 09df4a2886a3c..7273c8222eee3 100644 --- a/cmd/libs/go2idl/openapi-gen/.import-restrictions +++ b/cmd/libs/go2idl/openapi-gen/.import-restrictions @@ -4,10 +4,11 @@ "SelectorRegexp": "k8s[.]io", "AllowedPrefixes": [ "k8s.io/kubernetes/cmd/libs/go2idl", - "k8s.io/kubernetes/pkg/genericapiserver/openapi/common", + "k8s.io/apimachinery/pkg/genericapiserver/openapi/common", "k8s.io/gengo", "k8s.io/kubernetes/third_party", - "k8s.io/kubernetes/pkg/util/sets" + "k8s.io/apimachinery/third_party", + "k8s.io/apimachinery/pkg/util/sets" ] } ] diff --git a/hack/godep-save.sh b/hack/godep-save.sh index 281f3a815bacf..1bc1f19ff8f76 100755 --- a/hack/godep-save.sh +++ b/hack/godep-save.sh @@ -44,6 +44,9 @@ pushd "${KUBE_ROOT}" > /dev/null if [ ! -e "vendor/k8s.io/apiserver" ]; then ln -s ../../staging/src/k8s.io/apiserver vendor/k8s.io/apiserver fi + if [ ! -e "vendor/k8s.io/apimachinery" ]; then + ln -s ../../staging/src/k8s.io/apimachinery vendor/k8s.io/apimachinery + fi popd > /dev/null echo "Don't forget to run hack/update-godep-licenses.sh if you added or removed a dependency!" diff --git a/hack/make-rules/test.sh b/hack/make-rules/test.sh index 5700afad31ef5..e71d6d99ec432 100755 --- a/hack/make-rules/test.sh +++ b/hack/make-rules/test.sh @@ -60,6 +60,10 @@ kube::test::find_dirs() { # run tests for apiserver find ./staging/src/k8s.io/apiserver -name '*_test.go' \ -name '*_test.go' -print0 | xargs -0n1 dirname | sed 's|^\./staging/src/|./vendor/|' | LC_ALL=C sort -u + + # run tests for apimachinery + find ./staging/src/k8s.io/apimachinery -name '*_test.go' \ + -name '*_test.go' -print0 | xargs -0n1 dirname | sed 's|^\./staging/src/|./vendor/|' | LC_ALL=C sort -u ) } diff --git a/staging/prime-apimachinery.sh b/staging/prime-apimachinery.sh new file mode 100755 index 0000000000000..04930a38c24d3 --- /dev/null +++ b/staging/prime-apimachinery.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +# Copyright 2016 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit +set -o nounset +set -o pipefail + +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +source "${KUBE_ROOT}/hack/lib/init.sh" + +kube::golang::setup_env + +dir=$(mktemp -d "${TMPDIR:-/tmp/}$(basename 0).XXXXXXXXXXXX") +echo ${dir} + +echo k8s.io/kubernetes/pkg/apimachinery/registered > ${dir}/packages.txt +echo k8s.io/kubernetes/pkg/runtime/serializer >> ${dir}/packages.txt +echo k8s.io/kubernetes/pkg/runtime/serializer/yaml >> ${dir}/packages.txt +echo k8s.io/kubernetes/pkg/runtime/serializer/streaming >> ${dir}/packages.txt +echo k8s.io/kubernetes/pkg/runtime/serializer/recognizer/testing >> ${dir}/packages.txt +go list -f {{.Deps}} k8s.io/kubernetes/pkg/apimachinery/registered | sed -e 's/ /\n/g' - | grep k8s.io | grep -v vendor >> ${dir}/packages.txt +go list -f {{.Deps}} k8s.io/kubernetes/pkg/runtime/serializer | sed -e 's/ /\n/g' - | grep k8s.io | grep -v vendor >> ${dir}/packages.txt +go list -f {{.Deps}} k8s.io/kubernetes/pkg/runtime/serializer/yaml | sed -e 's/ /\n/g' - | grep k8s.io | grep -v vendor >> ${dir}/packages.txt +go list -f {{.Deps}} k8s.io/kubernetes/pkg/runtime/serializer/streaming | sed -e 's/ /\n/g' - | grep k8s.io | grep -v vendor >> ${dir}/packages.txt +# used by tests +echo k8s.io/kubernetes/pkg/util/diff >> ${dir}/packages.txt +go list -f {{.Deps}} k8s.io/kubernetes/pkg/util/diff | sed -e 's/ /\n/g' - | grep k8s.io | grep -v vendor >> ${dir}/packages.txt +LC_ALL=C sort -u -o ${dir}/packages.txt ${dir}/packages.txt + +echo "moving these packages" +cat ${dir}/packages.txt + +# copy all the packages over +while read package; do + unprefix_package=$(echo ${package} | sed 's|k8s.io/kubernetes/||g') + mkdir -p ${KUBE_ROOT}/staging/src/k8s.io/apimachinery/${unprefix_package} + cp ${KUBE_ROOT}/${unprefix_package}/* ${KUBE_ROOT}/staging/src/k8s.io/apimachinery/${unprefix_package} || true +done <${dir}/packages.txt + +# need to remove the bazel files or bazel fails when this moves into vendor +find ${KUBE_ROOT}/staging/src/k8s.io/apimachinery -name BUILD | xargs rm + +# need to rewrite all the package imports for k8s.io/kuberentes to k8s.io/apimachinery +find ${KUBE_ROOT}/staging/src/k8s.io/apimachinery -name "*.go" | xargs sed -i 's|k8s.io/kubernetes|k8s.io/apimachinery|g' + +# need to rewrite all the package imports for these packages in the main repo to use the vendored copy +while read package; do + echo "rewriting import for ${package}" + new_package=$(echo ${package} | sed 's|k8s.io/kubernetes|k8s.io/apimachinery|g') + find ${KUBE_ROOT}/cmd ${KUBE_ROOT}/examples ${KUBE_ROOT}/federation ${KUBE_ROOT}/pkg ${KUBE_ROOT}/plugin ${KUBE_ROOT}/test -name "*.go" | xargs sed -i "s|${package}\"|${new_package}\"|g" +done <${dir}/packages.txt + +# we don't want to rewrite imports for the packages we're modifying. So check those back out, but only the files directly in that directory, not subdirs +# also, add .readonly files to each folder we moved +while read package; do + unprefix_package=$(echo ${package} | sed 's|k8s.io/kubernetes/||g') + find ${unprefix_package} -type f -maxdepth 1 | xargs git checkout + touch ${unprefix_package}/.readonly +done <${dir}/packages.txt + +# this file generates something or other, but we don't want to accidentally have it generate into an apimachinery package +git checkout cmd/libs/go2idl/set-gen/main.go + + +# now run gofmt to get the sorting right +echo "running gofmt" +gofmt -s -w ${KUBE_ROOT}/cmd ${KUBE_ROOT}/examples ${KUBE_ROOT}/federation ${KUBE_ROOT}/pkg ${KUBE_ROOT}/plugin ${KUBE_ROOT}/test + diff --git a/vendor/k8s.io/apimachinery b/vendor/k8s.io/apimachinery new file mode 120000 index 0000000000000..b509d9e0f5c2e --- /dev/null +++ b/vendor/k8s.io/apimachinery @@ -0,0 +1 @@ +../../staging/src/k8s.io/apimachinery \ No newline at end of file