Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TPR to CRD migration helper. #46677

Merged
merged 1 commit into from
Jun 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/kube-apiserver/app/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ go_library(
"//vendor/k8s.io/apiserver/pkg/admission:go_default_library",
"//vendor/k8s.io/apiserver/pkg/authentication/authenticator:go_default_library",
"//vendor/k8s.io/apiserver/pkg/authorization/authorizer:go_default_library",
"//vendor/k8s.io/apiserver/pkg/registry/generic:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server/filters:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server/healthz:go_default_library",
Expand Down
7 changes: 4 additions & 3 deletions cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"k8s.io/apiserver/pkg/admission"
"k8s.io/apiserver/pkg/authentication/authenticator"
"k8s.io/apiserver/pkg/authorization/authorizer"
genericregistry "k8s.io/apiserver/pkg/registry/generic"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/apiserver/pkg/server/filters"
serverstorage "k8s.io/apiserver/pkg/server/storage"
Expand Down Expand Up @@ -117,7 +118,7 @@ func Run(runOptions *options.ServerRunOptions, stopCh <-chan struct{}) error {
return err
}

kubeAPIServer, err := CreateKubeAPIServer(kubeAPIServerConfig, apiExtensionsServer.GenericAPIServer, sharedInformers)
kubeAPIServer, err := CreateKubeAPIServer(kubeAPIServerConfig, apiExtensionsServer.GenericAPIServer, sharedInformers, apiExtensionsConfig.CRDRESTOptionsGetter)
if err != nil {
return err
}
Expand Down Expand Up @@ -161,8 +162,8 @@ func Run(runOptions *options.ServerRunOptions, stopCh <-chan struct{}) error {
}

// CreateKubeAPIServer creates and wires a workable kube-apiserver
func CreateKubeAPIServer(kubeAPIServerConfig *master.Config, delegateAPIServer genericapiserver.DelegationTarget, sharedInformers informers.SharedInformerFactory) (*master.Master, error) {
kubeAPIServer, err := kubeAPIServerConfig.Complete().New(delegateAPIServer)
func CreateKubeAPIServer(kubeAPIServerConfig *master.Config, delegateAPIServer genericapiserver.DelegationTarget, sharedInformers informers.SharedInformerFactory, crdRESTOptionsGetter genericregistry.RESTOptionsGetter) (*master.Master, error) {
kubeAPIServer, err := kubeAPIServerConfig.Complete().New(delegateAPIServer, crdRESTOptionsGetter)
if err != nil {
return nil, err
}
Expand Down
109 changes: 104 additions & 5 deletions hack/make-rules/test-cmd-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ function kubectl-with-retry()
# wait-for-pods-with-label "app=foo" "nginx-0nginx-1"
function wait-for-pods-with-label()
{
local i
for i in $(seq 1 10); do
kubeout=`kubectl get po -l $1 --template '{{range.items}}{{.metadata.name}}{{end}}' --sort-by metadata.name "${kube_flags[@]}"`
if [[ $kubeout = $2 ]]; then
Expand Down Expand Up @@ -1413,6 +1414,101 @@ __EOF__
kubectl delete thirdpartyresources/bar.company.com "${kube_flags[@]}"
}

run_tpr_migration_tests() {
local i tries
create_and_use_new_namespace

# Create CRD first. This is sort of backwards so we can create a marker below.
kubectl "${kube_flags_with_token[@]}" create -f - << __EOF__
{
"kind": "CustomResourceDefinition",
"apiVersion": "apiextensions.k8s.io/v1beta1",
"metadata": {
"name": "foos.company.crd"
},
"spec": {
"group": "company.crd",
"version": "v1",
"names": {
"plural": "foos",
"kind": "Foo"
}
}
}
__EOF__
# Wait for API to become available.
tries=0
until kubectl "${kube_flags[@]}" get foos.company.crd || [ $tries -gt 10 ]; do
tries=$((tries+1))
sleep ${tries}
done
kube::test::get_object_assert foos.company.crd '{{len .items}}' '0'

# Create a marker that only exists in CRD so we know when CRD is active vs. TPR.
kubectl "${kube_flags[@]}" create -f - << __EOF__
{
"kind": "Foo",
"apiVersion": "company.crd/v1",
"metadata": {
"name": "crd-marker"
},
"testValue": "only exists in CRD"
}
__EOF__
kube::test::get_object_assert foos.company.crd '{{len .items}}' '1'

# Now create a TPR that sits in front of the CRD and hides it.
kubectl "${kube_flags[@]}" create -f - << __EOF__
{
"kind": "ThirdPartyResource",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "foo.company.crd"
},
"versions": [
{
"name": "v1"
}
]
}
__EOF__
# The marker should disappear.
kube::test::wait_object_assert foos.company.crd '{{len .items}}' '0'

# Add some items to the TPR.
for i in {1..10}; do
kubectl "${kube_flags[@]}" create -f - << __EOF__
{
"kind": "Foo",
"apiVersion": "company.crd/v1",
"metadata": {
"name": "tpr-${i}"
},
"testValue": "migrate-${i}"
}
__EOF__
done
kube::test::get_object_assert foos.company.crd '{{len .items}}' '10'

# Delete the TPR and wait for the CRD to take over.
kubectl "${kube_flags[@]}" delete thirdpartyresource/foo.company.crd
tries=0
until kubectl "${kube_flags[@]}" get foos.company.crd/crd-marker || [ $tries -gt 10 ]; do
tries=$((tries+1))
sleep ${tries}
done
kube::test::get_object_assert foos.company.crd/crd-marker '{{.testValue}}' 'only exists in CRD'

# Check if the TPR items were migrated to CRD.
kube::test::get_object_assert foos.company.crd '{{len .items}}' '11'
for i in {1..10}; do
kube::test::get_object_assert foos.company.crd/tpr-${i} '{{.testValue}}' "migrate-${i}"
done

# teardown
kubectl delete customresourcedefinitions/foos.company.crd "${kube_flags_with_token[@]}"
}


kube::util::non_native_resources() {
local times
Expand Down Expand Up @@ -2951,12 +3047,12 @@ runTests() {
kube::log::status "Checking kubectl version"
kubectl version

i=0
ns_num=0
create_and_use_new_namespace() {
i=$(($i+1))
kube::log::status "Creating namespace namespace${i}"
kubectl create namespace "namespace${i}"
kubectl config set-context "${CONTEXT}" --namespace="namespace${i}"
ns_num=$(($ns_num+1))
kube::log::status "Creating namespace namespace${ns_num}"
kubectl create namespace "namespace${ns_num}"
kubectl config set-context "${CONTEXT}" --namespace="namespace${ns_num}"
}

kube_flags=(
Expand Down Expand Up @@ -3290,6 +3386,9 @@ runTests() {

if kube::test::if_supports_resource "${thirdpartyresources}" ; then
run_tpr_tests
if kube::test::if_supports_resource "${customresourcedefinitions}" ; then
run_tpr_migration_tests
fi
fi

#################
Expand Down
6 changes: 4 additions & 2 deletions pkg/master/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/apiserver/pkg/endpoints/discovery"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry "k8s.io/apiserver/pkg/registry/generic"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/apiserver/pkg/server/healthz"
serverstorage "k8s.io/apiserver/pkg/server/storage"
Expand Down Expand Up @@ -210,7 +211,7 @@ func (c *Config) SkipComplete() completedConfig {
// Certain config fields will be set to a default value if unset.
// Certain config fields must be specified, including:
// KubeletClientConfig
func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget) (*Master, error) {
func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget, crdRESTOptionsGetter genericregistry.RESTOptionsGetter) (*Master, error) {
if reflect.DeepEqual(c.KubeletClientConfig, kubeletclient.KubeletClientConfig{}) {
return nil, fmt.Errorf("Master.New() called with empty config.KubeletClientConfig")
}
Expand Down Expand Up @@ -254,7 +255,8 @@ func (c completedConfig) New(delegationTarget genericapiserver.DelegationTarget)
autoscalingrest.RESTStorageProvider{},
batchrest.RESTStorageProvider{},
certificatesrest.RESTStorageProvider{},
extensionsrest.RESTStorageProvider{ResourceInterface: thirdparty.NewThirdPartyResourceServer(s, s.DiscoveryGroupManager, c.StorageFactory)},
// TODO(enisoc): Remove crdRESTOptionsGetter input argument when TPR code is removed.
extensionsrest.RESTStorageProvider{ResourceInterface: thirdparty.NewThirdPartyResourceServer(s, s.DiscoveryGroupManager, c.StorageFactory, crdRESTOptionsGetter)},
networkingrest.RESTStorageProvider{},
policyrest.RESTStorageProvider{},
rbacrest.RESTStorageProvider{Authorizer: c.GenericConfig.Authorizer},
Expand Down
2 changes: 1 addition & 1 deletion pkg/master/master_openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestValidOpenAPISpec(t *testing.T) {
}
config.GenericConfig.SwaggerConfig = genericapiserver.DefaultSwaggerConfig()

master, err := config.Complete().New(genericapiserver.EmptyDelegate)
master, err := config.Complete().New(genericapiserver.EmptyDelegate, nil)
if err != nil {
t.Fatalf("Error in bringing up the master: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/master/master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func setUp(t *testing.T) (*etcdtesting.EtcdTestServer, Config, *assert.Assertion
func newMaster(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.Assertions) {
etcdserver, config, assert := setUp(t)

master, err := config.Complete().New(genericapiserver.EmptyDelegate)
master, err := config.Complete().New(genericapiserver.EmptyDelegate, nil)
if err != nil {
t.Fatalf("Error in bringing up the master: %v", err)
}
Expand All @@ -141,7 +141,7 @@ func limitedAPIResourceConfigSource() *serverstorage.ResourceConfig {
func newLimitedMaster(t *testing.T) (*Master, *etcdtesting.EtcdTestServer, Config, *assert.Assertions) {
etcdserver, config, assert := setUp(t)
config.APIResourceConfigSource = limitedAPIResourceConfigSource()
master, err := config.Complete().New(genericapiserver.EmptyDelegate)
master, err := config.Complete().New(genericapiserver.EmptyDelegate, nil)
if err != nil {
t.Fatalf("Error in bringing up the master: %v", err)
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/master/thirdparty/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ go_library(
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels: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",
"//vendor/k8s.io/apimachinery/pkg/util/json:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/apiserver/pkg/endpoints:go_default_library",
Expand All @@ -40,12 +43,16 @@ go_library(
"//vendor/k8s.io/apiserver/pkg/server:go_default_library",
"//vendor/k8s.io/apiserver/pkg/server/storage:go_default_library",
"//vendor/k8s.io/apiserver/pkg/storage/storagebackend:go_default_library",
"//vendor/k8s.io/client-go/discovery:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
"//vendor/k8s.io/client-go/util/workqueue:go_default_library",
"//vendor/k8s.io/kube-aggregator/pkg/apis/apiregistration:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/apis/apiextensions:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/apiserver:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/client/clientset/internalclientset/typed/apiextensions/internalversion:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/client/informers/internalversion/apiextensions/internalversion:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/client/listers/apiextensions/internalversion:go_default_library",
"//vendor/k8s.io/kube-apiextensions-server/pkg/registry/customresource:go_default_library",
],
)

Expand Down
Loading