mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
update-staging-godeps: only mangle staging repos in Godeps.json
This commit is contained in:
parent
a514443091
commit
72d4e3f47a
@ -500,7 +500,6 @@ plugin/pkg/scheduler/metrics
|
||||
plugin/pkg/scheduler/schedulercache
|
||||
plugin/pkg/scheduler/testing
|
||||
plugin/pkg/scheduler/util
|
||||
staging
|
||||
staging/src/k8s.io/api/admission/v1alpha1
|
||||
staging/src/k8s.io/api/admissionregistration/v1alpha1
|
||||
staging/src/k8s.io/api/apps/v1beta1
|
||||
|
@ -75,8 +75,26 @@ function updateGodepManifest() {
|
||||
rm -rf Godeps # remove the current Godeps.json so we always rebuild it
|
||||
GOPATH="${TMP_GOPATH}:${GOPATH}:${GOPATH}/src/k8s.io/kubernetes/staging" godep save ${GODEP_OPTS} ./... 2>&1 | sed 's/^/ /'
|
||||
|
||||
# Rewriting Godeps.json to remove commits that don't really exist because we haven't pushed the prereqs yet
|
||||
go run "${KUBE_ROOT}/staging/godeps-json-updater.go" --godeps-file="${TMP_GOPATH}/src/k8s.io/${repo}/Godeps/Godeps.json" --override-import-path="k8s.io/${repo}"
|
||||
# Rewriting Godeps.json to cross-out commits that don't really exist because we haven't pushed the prereqs yet
|
||||
local repo
|
||||
for repo in $(ls -1 ${KUBE_ROOT}/staging/src/k8s.io); do
|
||||
# remove staging prefix
|
||||
jq '.Deps |= map(.ImportPath |= ltrimstr("k8s.io/kubernetes/staging/src/"))' Godeps/Godeps.json |
|
||||
|
||||
# x-out staging repo revisions. They will only be known when the publisher bot has created the final export.
|
||||
# We keep the staging dependencies in here though to give the publisher bot a way to detect when the staging
|
||||
# dependencies changed. If they have changed, the bot will run a complete godep restore+save. If they didn't
|
||||
# it will avoid that step, which takes quite some time.
|
||||
jq '.Deps |= map((select(.ImportPath | (startswith("k8s.io/'${repo}'/") or . == "k8s.io/'${repo}'")) | .Rev |= "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") // .)' |
|
||||
|
||||
# remove comments
|
||||
jq 'del(.Deps[].Comment)' |
|
||||
|
||||
# format with tabs
|
||||
unexpand --first-only --tabs=2 > Godeps/Godeps.json.out
|
||||
|
||||
mv Godeps/Godeps.json.out Godeps/Godeps.json
|
||||
done
|
||||
|
||||
# commit so that following repos do not see this repo as dirty
|
||||
git add vendor >/dev/null
|
||||
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
flag "github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
var (
|
||||
godepsFile = flag.String("godeps-file", "", "absolute path to Godeps.json")
|
||||
overrideImportPath = flag.String("override-import-path", "", "import path to be written into the Godeps.json, e.g., k8s.io/client-go")
|
||||
ignoredPrefixes = flag.StringSlice("ignored-prefixes", []string{"k8s.io/"}, "any godep entry prefixed with the ignored-prefix will be deleted from Godeps.json")
|
||||
rewrittenPrefixes = flag.StringSlice("rewritten-prefixes", []string{}, fmt.Sprintf("any godep entry prefixed with the rewritten-prefix will be filled will dummy rev %q; overridden by ignored-prefixes", dummyRev))
|
||||
)
|
||||
|
||||
const dummyRev = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
|
||||
type Dependency struct {
|
||||
ImportPath string
|
||||
Rev string
|
||||
}
|
||||
|
||||
type Godeps struct {
|
||||
ImportPath string
|
||||
GoVersion string
|
||||
GodepVersion string
|
||||
Packages []string `json:",omitempty"` // Arguments to save, if any.
|
||||
Deps []Dependency
|
||||
}
|
||||
|
||||
// rewrites the Godeps.ImportPath, removes the Deps whose ImportPath contains "k8s.io/kubernetes" or "k8s.io/apimachinery".
|
||||
// entries for k8s.io/apimahinery will be written by the publishing robot before publishing to the repository.
|
||||
func main() {
|
||||
flag.Parse()
|
||||
var g Godeps
|
||||
if len(*godepsFile) == 0 {
|
||||
log.Fatalf("absolute path to Godeps.json is required")
|
||||
}
|
||||
f, err := os.OpenFile(*godepsFile, os.O_RDWR, 0666)
|
||||
if err != nil {
|
||||
log.Fatalf("cannot open file %q: %v", *godepsFile, err)
|
||||
}
|
||||
defer f.Close()
|
||||
err = json.NewDecoder(f).Decode(&g)
|
||||
if err != nil {
|
||||
log.Fatalf("Unable to parse %q: %v", *godepsFile, err)
|
||||
}
|
||||
if len(*overrideImportPath) != 0 {
|
||||
g.ImportPath = *overrideImportPath
|
||||
}
|
||||
// removes the Deps whose ImportPath contains "k8s.io/kubernetes"
|
||||
i := 0
|
||||
for _, dep := range g.Deps {
|
||||
ignored := false
|
||||
for _, ignoredPrefix := range *ignoredPrefixes {
|
||||
if strings.HasPrefix(dep.ImportPath, ignoredPrefix) {
|
||||
ignored = true
|
||||
}
|
||||
}
|
||||
if ignored {
|
||||
continue
|
||||
}
|
||||
rewritten := false
|
||||
for _, rewrittenPrefix := range *rewrittenPrefixes {
|
||||
if strings.HasPrefix(dep.ImportPath, rewrittenPrefix) {
|
||||
rewritten = true
|
||||
}
|
||||
}
|
||||
if rewritten {
|
||||
dep.Rev = dummyRev
|
||||
}
|
||||
g.Deps[i] = dep
|
||||
i++
|
||||
}
|
||||
g.Deps = g.Deps[:i]
|
||||
b, err := json.MarshalIndent(g, "", "\t")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
n, err := f.WriteAt(append(b, '\n'), 0)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := f.Truncate(int64(n)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
#!/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 vendor/k8s.io/code-generator/cmd/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
|
||||
|
Loading…
Reference in New Issue
Block a user