Skip to content

Commit

Permalink
Merge pull request kubevirt#6802 from rmohr/separate-api
Browse files Browse the repository at this point in the history
Separate kubevirts api from client-go
  • Loading branch information
kubevirt-bot authored Nov 17, 2021
2 parents ad74241 + bca2a7a commit debf29e
Show file tree
Hide file tree
Showing 612 changed files with 6,627 additions and 31,990 deletions.
202 changes: 119 additions & 83 deletions api/api-rule-violations-known.list

Large diffs are not rendered by default.

202 changes: 119 additions & 83 deletions api/api-rule-violations.list

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmd/example-cloudinit-hook-sidecar/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ go_library(
"//pkg/hooks:go_default_library",
"//pkg/hooks/info:go_default_library",
"//pkg/hooks/v1alpha2:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/core/v1:go_default_library",
"//staging/src/kubevirt.io/api/core/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/log:go_default_library",
"@org_golang_google_grpc//:go_default_library",
],
Expand Down
2 changes: 1 addition & 1 deletion cmd/example-cloudinit-hook-sidecar/cloudinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (

"google.golang.org/grpc"

v1 "kubevirt.io/client-go/apis/core/v1"
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/log"
cloudinit "kubevirt.io/kubevirt/pkg/cloud-init"
hooks "kubevirt.io/kubevirt/pkg/hooks"
Expand Down
2 changes: 1 addition & 1 deletion cmd/example-hook-sidecar/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ go_library(
"//pkg/hooks/v1alpha1:go_default_library",
"//pkg/hooks/v1alpha2:go_default_library",
"//pkg/virt-launcher/virtwrap/api:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/core/v1:go_default_library",
"//staging/src/kubevirt.io/api/core/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/log:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"@org_golang_google_grpc//:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion cmd/example-hook-sidecar/smbios.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/spf13/pflag"
"google.golang.org/grpc"

vmSchema "kubevirt.io/client-go/apis/core/v1"
vmSchema "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/log"
"kubevirt.io/kubevirt/pkg/hooks"
hooksInfo "kubevirt.io/kubevirt/pkg/hooks/info"
Expand Down
2 changes: 1 addition & 1 deletion cmd/subresource-access-test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ go_library(
importpath = "kubevirt.io/kubevirt/cmd/subresource-access-test",
visibility = ["//visibility:private"],
deps = [
"//staging/src/kubevirt.io/client-go/apis/core/v1:go_default_library",
"//staging/src/kubevirt.io/api/core/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/kubecli:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
],
Expand Down
2 changes: 1 addition & 1 deletion cmd/subresource-access-test/subresource-access-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

"k8s.io/client-go/rest"

v1 "kubevirt.io/client-go/apis/core/v1"
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/virt-freezer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go_library(
visibility = ["//visibility:private"],
deps = [
"//pkg/virt-handler/cmd-client:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/core/v1:go_default_library",
"//staging/src/kubevirt.io/api/core/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/log:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion cmd/virt-freezer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/spf13/pflag"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "kubevirt.io/client-go/apis/core/v1"
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/log"
cmdclient "kubevirt.io/kubevirt/pkg/virt-handler/cmd-client"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/virt-handler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ go_library(
"//pkg/virt-launcher/virtwrap/api:go_default_library",
"//pkg/watchdog:go_default_library",
"//staging/src/github.com/golang/glog:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/core/v1:go_default_library",
"//staging/src/kubevirt.io/api/core/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/kubecli:go_default_library",
"//staging/src/kubevirt.io/client-go/log:go_default_library",
"//staging/src/kubevirt.io/client-go/util:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion cmd/virt-handler/virt-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

v1 "kubevirt.io/client-go/apis/core/v1"
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/kubecli"
"kubevirt.io/client-go/log"
clientutil "kubevirt.io/client-go/util"
Expand Down
2 changes: 1 addition & 1 deletion cmd/virt-launcher/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ go_library(
"//pkg/virt-launcher/virtwrap/cli:go_default_library",
"//pkg/virt-launcher/virtwrap/cmd-server:go_default_library",
"//pkg/virt-launcher/virtwrap/util:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/core/v1:go_default_library",
"//staging/src/kubevirt.io/api/core/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/log:go_default_library",
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion cmd/virt-launcher/virt-launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/util/retry"

v1 "kubevirt.io/client-go/apis/core/v1"
v1 "kubevirt.io/api/core/v1"
"kubevirt.io/client-go/log"
cloudinit "kubevirt.io/kubevirt/pkg/cloud-init"
"kubevirt.io/kubevirt/pkg/config"
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ require (
k8s.io/kube-aggregator v0.20.2
k8s.io/kube-openapi v0.0.0-20210113233702-8566a335510f
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009
kubevirt.io/api v0.0.0-00010101000000-000000000000
kubevirt.io/client-go v0.0.0-00010101000000-000000000000
kubevirt.io/containerized-data-importer v1.41.0
kubevirt.io/containerized-data-importer-api v1.41.0
Expand Down Expand Up @@ -119,6 +120,7 @@ replace (
k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.20.2
k8s.io/sample-controller => k8s.io/sample-controller v0.20.2

kubevirt.io/api => ./staging/src/kubevirt.io/api
kubevirt.io/client-go => ./staging/src/kubevirt.io/client-go

kubevirt.io/containerized-data-importer => kubevirt.io/containerized-data-importer v1.41.0
Expand Down
5 changes: 5 additions & 0 deletions hack/dep-prune.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ ln -s ../../../staging/src/github.com/golang/glog/ ${KUBEVIRT_DIR}/vendor/github
rm -rf ${KUBEVIRT_DIR}/vendor/kubevirt.io/client-go
mkdir -p ${KUBEVIRT_DIR}/vendor/kubevirt.io
ln -s ../../staging/src/kubevirt.io/client-go/ ${KUBEVIRT_DIR}/vendor/kubevirt.io/client-go

# create symbolic link on api package to avoid duplication
rm -rf ${KUBEVIRT_DIR}/vendor/kubevirt.io/api
mkdir -p ${KUBEVIRT_DIR}/vendor/kubevirt.io
ln -s ../../staging/src/kubevirt.io/api/ ${KUBEVIRT_DIR}/vendor/kubevirt.io/api
6 changes: 6 additions & 0 deletions hack/dep-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ while true; do
esac
done

(
echo $_sync_only
cd staging/src/kubevirt.io/api
if [ "${_sync_only}" == "false" ]; then go get $@ ./...; fi
go mod tidy
)
(
echo $_sync_only
cd staging/src/kubevirt.io/client-go
Expand Down
2 changes: 1 addition & 1 deletion hack/gen-swagger-doc/gen-swagger-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ gradle -b $GRADLE_BUILD_FILE $GRADLE_EXTRA_PARAMS convertSwagger2markup --info

#insert a TOC for top level API objects
buf="${HEADER}${HEADER} Top Level API Objects\n\n"
top_level_models=$(grep '&[A-Za-z]*{},' staging/src/kubevirt.io/client-go/apis/core/${VERSION}/types.go | sed 's/.*&//;s/{},//')
top_level_models=$(grep '&[A-Za-z]*{},' staging/src/kubevirt.io/api/core/${VERSION}/types.go | sed 's/.*&//;s/{},//')

# check if the top level models exist in the definitions.$SUFFIX. If they exist,
# their name will be <version>.<model_name>
Expand Down
28 changes: 17 additions & 11 deletions hack/generate.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -ex

source $(dirname "$0")/common.sh
source $(dirname "$0")/config.sh
Expand All @@ -10,17 +10,23 @@ CLIENT_GEN_BASE=kubevirt.io/client-go/generated
rm -rf ${KUBEVIRT_DIR}/staging/src/${CLIENT_GEN_BASE}

# KubeVirt stuff
swagger-doc -in ${KUBEVIRT_DIR}/staging/src/kubevirt.io/client-go/apis/snapshot/v1alpha1/types.go
swagger-doc -in ${KUBEVIRT_DIR}/staging/src/kubevirt.io/api/core/v1/types.go
swagger-doc -in ${KUBEVIRT_DIR}/staging/src/kubevirt.io/api/core/v1/schema.go
swagger-doc -in ${KUBEVIRT_DIR}/staging/src/kubevirt.io/api/snapshot/v1alpha1/types.go
swagger-doc -in ${KUBEVIRT_DIR}/staging/src/kubevirt.io/api/flavor/v1alpha1/types.go

swagger-doc -in ${KUBEVIRT_DIR}/staging/src/kubevirt.io/client-go/apis/flavor/v1alpha1/types.go
deepcopy-gen --input-dirs kubevirt.io/api/snapshot/v1alpha1,kubevirt.io/api/flavor/v1alpha1,kubevirt.io/api/core/v1 \
--bounding-dirs kubevirt.io/api \
--go-header-file ${KUBEVIRT_DIR}/hack/boilerplate/boilerplate.go.txt

deepcopy-gen --input-dirs kubevirt.io/client-go/apis/snapshot/v1alpha1,kubevirt.io/client-go/apis/flavor/v1alpha1 \
--bounding-dirs kubevirt.io/client-go/apis \
defaulter-gen --input-dirs kubevirt.io/api/core/v1 \
--output-base ${KUBEVIRT_DIR}/staging/src \
--output-package kubevirt.io/api/core/v1 \
--go-header-file ${KUBEVIRT_DIR}/hack/boilerplate/boilerplate.go.txt

openapi-gen --input-dirs kubevirt.io/client-go/apis/snapshot/v1alpha1,kubevirt.io/client-go/apis/flavor/v1alpha1,k8s.io/api/core/v1,k8s.io/apimachinery/pkg/apis/meta/v1,kubevirt.io/client-go/apis/core/v1 \
openapi-gen --input-dirs kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1,k8s.io/apimachinery/pkg/util/intstr,k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/runtime,k8s.io/api/core/v1,k8s.io/apimachinery/pkg/apis/meta/v1,kubevirt.io/api/core/v1,kubevirt.io/api/snapshot/v1alpha1,kubevirt.io/api/flavor/v1alpha1 \
--output-base ${KUBEVIRT_DIR}/staging/src \
--output-package kubevirt.io/client-go/apis/snapshot/v1alpha1 \
--output-package kubevirt.io/client-go/api/ \
--go-header-file ${KUBEVIRT_DIR}/hack/boilerplate/boilerplate.go.txt >${KUBEVIRT_DIR}/api/api-rule-violations.list

if cmp ${KUBEVIRT_DIR}/api/api-rule-violations.list ${KUBEVIRT_DIR}/api/api-rule-violations-known.list; then
Expand All @@ -33,7 +39,7 @@ else
fi

client-gen --clientset-name versioned \
--input-base kubevirt.io/client-go/apis \
--input-base kubevirt.io/api \
--input snapshot/v1alpha1,flavor/v1alpha1 \
--output-base ${KUBEVIRT_DIR}/staging/src \
--output-package ${CLIENT_GEN_BASE}/kubevirt/clientset \
Expand Down Expand Up @@ -79,12 +85,12 @@ deepcopy-gen --input-dirs ./pkg/virt-launcher/virtwrap/api \
(
cd ${KUBEVIRT_DIR}/staging/src/kubevirt.io/client-go &&
# supress -mod=vendor
GOFLAGS= controller-gen crd:allowDangerousTypes=true paths=./apis/core/v1/
GOFLAGS= controller-gen crd:allowDangerousTypes=true paths=../api/core/v1/
#include snapshot
GOFLAGS= controller-gen crd paths=./apis/snapshot/v1alpha1/
GOFLAGS= controller-gen crd paths=../api/snapshot/v1alpha1/

#include flavor
GOFLAGS= controller-gen crd paths=./apis/flavor/v1alpha1/
GOFLAGS= controller-gen crd paths=../api/flavor/v1alpha1/

#remove some weird stuff from controller-gen
cd config/crd
Expand Down
145 changes: 100 additions & 45 deletions hack/publish-staging.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
set -exo pipefail

GITHUB_FQDN=github.com
GO_API_REF_REPO=${GO_API_REF_REPO:-kubevirt/client-go}
API_REF_DIR=/tmp/client-go
GITHUB_IO_FQDN="https://kubevirt.github.io/client-go"

TARGET_BRANCH="$PULL_BASE_REF"
if [ -n "${DOCKER_TAG}" ]; then
Expand All @@ -14,57 +11,115 @@ fi

# if we are not on default branch and there is no tag, do nothing
if [ -z "${TARGET_TAG}" ] && [ "${TARGET_BRANCH}" != "main" ]; then
echo "not on a tag and not on master branch, nothing to do."
echo "not on a tag and not on main branch, nothing to do."
exit 0
fi

rm -rf ${API_REF_DIR}
git clone \
"https://${GIT_USER_NAME}@${GITHUB_FQDN}/${GO_API_REF_REPO}.git" \
"${API_REF_DIR}" >/dev/null 2>&1
pushd ${API_REF_DIR}
git checkout -B ${TARGET_BRANCH}-local
git rm -rf .
git clean -fxd
popd
cp -rf staging/src/kubevirt.io/client-go/. "${API_REF_DIR}/"

# copy files which are the same on both repos
cp -f LICENSE "${API_REF_DIR}/"
cp -f SECURITY.md "${API_REF_DIR}/"

cd "${API_REF_DIR}"

# Generate .gitignore file. We want to keep bazel files in kubevirt/kubevirt, but not in kubevirt/client-go
cat >.gitignore <<__EOF__
function prepare_repo() {
NAME=$1
API_REF_DIR=/tmp/${NAME}
GO_API_REF_REPO=kubevirt/${NAME}
STAGING_PATH=staging/src/kubevirt.io/${NAME}/
rm -rf ${API_REF_DIR}
git clone \
"https://${GIT_USER_NAME}@${GITHUB_FQDN}/${GO_API_REF_REPO}.git" \
"${API_REF_DIR}" >/dev/null 2>&1
pushd ${API_REF_DIR}
git checkout -B ${TARGET_BRANCH}-local
git rm -rf .
git clean -fxd
popd
cp -rf ${STAGING_PATH}/. "${API_REF_DIR}/"

# copy files which are the same on both repos
cp -f LICENSE "${API_REF_DIR}/"
cp -f SECURITY.md "${API_REF_DIR}/"

pushd ${API_REF_DIR}
# Generate .gitignore file. We want to keep bazel files in kubevirt/kubevirt, but not in sync target repos
cat >.gitignore <<__EOF__
BUILD
BUILD.bazel
__EOF__
popd
}

git config user.email "${GIT_AUTHOR_NAME:-kubevirt-bot}"
git config user.name "${GIT_AUTHOR_EMAIL:-rmohr+kubebot@redhat.com}"

git add -A
function commit_repo() {
NAME=$1
API_REF_DIR=/tmp/${NAME}
pushd ${API_REF_DIR}
git config user.email "${GIT_AUTHOR_NAME:-kubevirt-bot}"
git config user.name "${GIT_AUTHOR_EMAIL:-rmohr+kubebot@redhat.com}"

if [ -n "$(git status --porcelain)" ]; then
git commit --message "client-go update by KubeVirt Prow build ${BUILD_ID}"
git add -A

# we only push branch changes on master
if [ "${TARGET_BRANCH}" == "master" ]; then
git push origin ${TARGET_BRANCH}-local:${TARGET_BRANCH}
echo "client-go updated for ${TARGET_BRANCH}."
if [ -n "$(git status --porcelain)" ]; then
git commit --message "${NAME} update by KubeVirt Prow build ${BUILD_ID}"
else
echo "${NAME} hasn't changed."
fi
else
echo "client-go hasn't changed."
fi
popd
}

function get_pseudo_tag() {
NAME=$1
API_REF_DIR=/tmp/${NAME}
pushd ${API_REF_DIR} >/dev/null
echo "v0.0.0-$(date -u +%Y%M%d%H%M%S)-$(git rev-parse --short=12 HEAD)"
popd >/dev/null
}

if [ -n "${TARGET_TAG}" ]; then
if [ $(git tag -l "${TARGET_TAG}") ]; then
# tag already exists
echo "tag already exists remotely, doing nothing."
exit 0
function push_repo() {
NAME=$1
API_REF_DIR=/tmp/${NAME}
pushd ${API_REF_DIR}
if [ -n "${TARGET_TAG}" ]; then
if [ $(git tag -l "${TARGET_TAG}") ]; then
# tag already exists
echo "tag already exists remotely, doing nothing."
exit 0
fi
git tag ${TARGET_TAG}
git push origin ${TARGET_TAG}
echo "${NAME} updated for tag ${TARGET_TAG}."
else
if [ "${TARGET_BRANCH}" == "main" ]; then
git push origin ${TARGET_BRANCH}-local:${TARGET_BRANCH}
echo "${NAME} updated for ${TARGET_BRANCH}."
fi
fi
git tag ${TARGET_TAG}
git push origin ${TARGET_TAG}
echo "client-go updated for tag ${TARGET_TAG}."
fi
popd
}

function go_mod_remove_staging() {
NAME=$1
API_REF_DIR=/tmp/${NAME}
pushd ${API_REF_DIR}
go mod edit -dropreplace kubevirt.io/api
popd
}

function go_mod_populate_pseudoversion() {
NAME=$1
API_REF_DIR=/tmp/${NAME}
pushd ${API_REF_DIR}
local repo=$2
local version=$3
go mod edit -require ${repo}@${version}
popd
}

# prepare kubevirt.io/api
prepare_repo api
commit_repo api
API_PSEUDO_TAG="$(get_pseudo_tag api)"

# prepare kubevirt.io/client-go
prepare_repo client-go
go_mod_remove_staging client-go
go_mod_populate_pseudoversion client-go kubevirt.io/api ${API_PSEUDO_TAG}
commit_repo client-go

# push the prepared repos
push_repo api
push_repo client-go
2 changes: 1 addition & 1 deletion pkg/certificates/bootstrap/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ go_test(
deps = [
"//pkg/certificates/triple:go_default_library",
"//pkg/certificates/triple/cert:go_default_library",
"//staging/src/kubevirt.io/client-go/apis/core/v1:go_default_library",
"//staging/src/kubevirt.io/api/core/v1:go_default_library",
"//staging/src/kubevirt.io/client-go/testutils:go_default_library",
"//vendor/github.com/onsi/ginkgo:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
Expand Down
Loading

0 comments on commit debf29e

Please sign in to comment.