Skip to content

Commit

Permalink
k8s.io/apimachinery scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Jan 11, 2017
1 parent ba61119 commit 70778cc
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cmd/libs/go2idl/.import-restrictions
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
Expand Down
6 changes: 3 additions & 3 deletions cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
5 changes: 3 additions & 2 deletions cmd/libs/go2idl/openapi-gen/.import-restrictions
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
]
Expand Down
3 changes: 3 additions & 0 deletions hack/godep-save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
4 changes: 4 additions & 0 deletions hack/make-rules/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
81 changes: 81 additions & 0 deletions staging/prime-apimachinery.sh
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions vendor/k8s.io/apimachinery

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 70778cc

Please sign in to comment.