mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-31 05:40:42 +00:00 
			
		
		
		
	add apigroup installer and tests
This commit is contained in:
		| @@ -19,5 +19,6 @@ package main | ||||
| // These imports are the API groups the kube-version-change tool will support. | ||||
| import ( | ||||
| 	_ "k8s.io/kubernetes/pkg/api/install" | ||||
| 	_ "k8s.io/kubernetes/pkg/apis/componentconfig/install" | ||||
| 	_ "k8s.io/kubernetes/pkg/apis/extensions/install" | ||||
| ) | ||||
|   | ||||
| @@ -315,7 +315,7 @@ for (( i=0, j=0; ; )); do | ||||
|   # KUBE_TEST_API sets the version of each group to be tested. KUBE_API_VERSIONS | ||||
|   # register the groups/versions as supported by k8s. So KUBE_API_VERSIONS | ||||
|   # needs to be the superset of KUBE_TEST_API. | ||||
|   KUBE_TEST_API="${apiVersion}" KUBE_API_VERSIONS="v1,extensions/v1beta1" ETCD_PREFIX=${etcdPrefix} runTests "$@" | ||||
|   KUBE_TEST_API="${apiVersion}" KUBE_API_VERSIONS="v1,extensions/v1beta1,componentconfig/v1alpha1" ETCD_PREFIX=${etcdPrefix} runTests "$@" | ||||
|   i=${i}+1 | ||||
|   j=${j}+1 | ||||
|   if [[ i -eq ${apiVersionsCount} ]] && [[ j -eq ${etcdPrefixesCount} ]]; then | ||||
|   | ||||
							
								
								
									
										92
									
								
								pkg/apis/componentconfig/install/install.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								pkg/apis/componentconfig/install/install.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | ||||
| /* | ||||
| Copyright 2015 The Kubernetes Authors All rights reserved. | ||||
|  | ||||
| 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 install installs the experimental API group, making it available as | ||||
| // an option to all of the API encoding/decoding machinery. | ||||
| package install | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strings" | ||||
|  | ||||
| 	"github.com/golang/glog" | ||||
|  | ||||
| 	"k8s.io/kubernetes/pkg/api" | ||||
| 	"k8s.io/kubernetes/pkg/api/latest" | ||||
| 	"k8s.io/kubernetes/pkg/api/meta" | ||||
| 	"k8s.io/kubernetes/pkg/api/registered" | ||||
| 	apiutil "k8s.io/kubernetes/pkg/api/util" | ||||
| 	_ "k8s.io/kubernetes/pkg/apis/componentconfig" | ||||
| 	"k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1" | ||||
| 	"k8s.io/kubernetes/pkg/runtime" | ||||
| 	"k8s.io/kubernetes/pkg/util/sets" | ||||
| ) | ||||
|  | ||||
| const importPrefix = "k8s.io/kubernetes/pkg/apis/componentconfig" | ||||
|  | ||||
| var accessor = meta.NewAccessor() | ||||
|  | ||||
| func init() { | ||||
| 	groupMeta, err := latest.RegisterGroup("componentconfig") | ||||
| 	if err != nil { | ||||
| 		glog.V(4).Infof("%v", err) | ||||
| 		return | ||||
| 	} | ||||
| 	registeredGroupVersions := registered.GroupVersionsForGroup("componentconfig") | ||||
| 	groupVersion := registeredGroupVersions[0] | ||||
| 	*groupMeta = latest.GroupMeta{ | ||||
| 		GroupVersion: groupVersion, | ||||
| 		Group:        apiutil.GetGroup(groupVersion), | ||||
| 		Version:      apiutil.GetVersion(groupVersion), | ||||
| 		Codec:        runtime.CodecFor(api.Scheme, groupVersion), | ||||
| 	} | ||||
| 	var versions []string | ||||
| 	var groupVersions []string | ||||
| 	for i := len(registeredGroupVersions) - 1; i >= 0; i-- { | ||||
| 		versions = append(versions, apiutil.GetVersion(registeredGroupVersions[i])) | ||||
| 		groupVersions = append(groupVersions, registeredGroupVersions[i]) | ||||
| 	} | ||||
| 	groupMeta.Versions = versions | ||||
| 	groupMeta.GroupVersions = groupVersions | ||||
|  | ||||
| 	groupMeta.SelfLinker = runtime.SelfLinker(accessor) | ||||
|  | ||||
| 	// the list of kinds that are scoped at the root of the api hierarchy | ||||
| 	// if a kind is not enumerated here, it is assumed to have a namespace scope | ||||
| 	rootScoped := sets.NewString() | ||||
|  | ||||
| 	ignoredKinds := sets.NewString() | ||||
|  | ||||
| 	groupMeta.RESTMapper = api.NewDefaultRESTMapper("componentconfig", groupVersions, interfacesFor, importPrefix, ignoredKinds, rootScoped) | ||||
| 	api.RegisterRESTMapper(groupMeta.RESTMapper) | ||||
| 	groupMeta.InterfacesFor = interfacesFor | ||||
| } | ||||
|  | ||||
| // interfacesFor returns the default Codec and ResourceVersioner for a given version | ||||
| // string, or an error if the version is not known. | ||||
| func interfacesFor(version string) (*meta.VersionInterfaces, error) { | ||||
| 	switch version { | ||||
| 	case "componentconfig/v1alpha1": | ||||
| 		return &meta.VersionInterfaces{ | ||||
| 			Codec:            v1alpha1.Codec, | ||||
| 			ObjectConvertor:  api.Scheme, | ||||
| 			MetadataAccessor: accessor, | ||||
| 		}, nil | ||||
| 	default: | ||||
| 		g, _ := latest.Group("componentconfig") | ||||
| 		return nil, fmt.Errorf("unsupported storage version: %s (valid: %s)", version, strings.Join(g.Versions, ", ")) | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										82
									
								
								pkg/apis/componentconfig/install/install_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										82
									
								
								pkg/apis/componentconfig/install/install_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,82 @@ | ||||
| /* | ||||
| Copyright 2014 The Kubernetes Authors All rights reserved. | ||||
|  | ||||
| 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 install | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"testing" | ||||
|  | ||||
| 	"k8s.io/kubernetes/pkg/api/latest" | ||||
| 	"k8s.io/kubernetes/pkg/apis/componentconfig" | ||||
| ) | ||||
|  | ||||
| func TestCodec(t *testing.T) { | ||||
| 	daemonSet := componentconfig.KubeProxyConfiguration{} | ||||
| 	// We do want to use package latest rather than testapi here, because we | ||||
| 	// want to test if the package install and package latest work as expected. | ||||
| 	data, err := latest.GroupOrDie("componentconfig").Codec.Encode(&daemonSet) | ||||
| 	if err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
| 	other := componentconfig.KubeProxyConfiguration{} | ||||
| 	if err := json.Unmarshal(data, &other); err != nil { | ||||
| 		t.Fatalf("unexpected error: %v", err) | ||||
| 	} | ||||
| 	if other.APIVersion != latest.GroupOrDie("componentconfig").GroupVersion || other.Kind != "KubeProxyConfiguration" { | ||||
| 		t.Errorf("unexpected unmarshalled object %#v", other) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestInterfacesFor(t *testing.T) { | ||||
| 	if _, err := latest.GroupOrDie("componentconfig").InterfacesFor(""); err == nil { | ||||
| 		t.Fatalf("unexpected non-error: %v", err) | ||||
| 	} | ||||
| 	for i, groupVersion := range append([]string{latest.GroupOrDie("componentconfig").GroupVersion}, latest.GroupOrDie("componentconfig").GroupVersions...) { | ||||
| 		if vi, err := latest.GroupOrDie("componentconfig").InterfacesFor(groupVersion); err != nil || vi == nil { | ||||
| 			t.Fatalf("%d: unexpected result: %v", i, err) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestRESTMapper(t *testing.T) { | ||||
| 	if v, k, err := latest.GroupOrDie("componentconfig").RESTMapper.VersionAndKindForResource("kubeproxyconfiguration"); err != nil || v != "componentconfig/v1alpha1" || k != "KubeProxyConfiguration" { | ||||
| 		t.Errorf("unexpected version mapping: %s %s %v", v, k, err) | ||||
| 	} | ||||
|  | ||||
| 	if m, err := latest.GroupOrDie("componentconfig").RESTMapper.RESTMapping("KubeProxyConfiguration", ""); err != nil || m.APIVersion != "componentconfig/v1alpha1" || m.Resource != "kubeproxyconfigurations" { | ||||
| 		t.Errorf("unexpected version mapping: %#v %v", m, err) | ||||
| 	} | ||||
|  | ||||
| 	for _, groupVersion := range latest.GroupOrDie("componentconfig").GroupVersions { | ||||
| 		mapping, err := latest.GroupOrDie("componentconfig").RESTMapper.RESTMapping("KubeProxyConfiguration", groupVersion) | ||||
| 		if err != nil { | ||||
| 			t.Errorf("unexpected error: %v", err) | ||||
| 		} | ||||
|  | ||||
| 		if mapping.Resource != "kubeproxyconfigurations" { | ||||
| 			t.Errorf("incorrect resource name: %#v", mapping) | ||||
| 		} | ||||
| 		if mapping.APIVersion != groupVersion { | ||||
| 			t.Errorf("incorrect groupVersion: %v", mapping) | ||||
| 		} | ||||
|  | ||||
| 		interfaces, _ := latest.GroupOrDie("componentconfig").InterfacesFor(groupVersion) | ||||
| 		if mapping.Codec != interfaces.Codec { | ||||
| 			t.Errorf("unexpected codec: %#v, expected: %#v", mapping, interfaces) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @@ -19,5 +19,6 @@ package unversioned | ||||
| // These imports are the API groups the client will support. | ||||
| import ( | ||||
| 	_ "k8s.io/kubernetes/pkg/api/install" | ||||
| 	_ "k8s.io/kubernetes/pkg/apis/componentconfig/install" | ||||
| 	_ "k8s.io/kubernetes/pkg/apis/extensions/install" | ||||
| ) | ||||
|   | ||||
| @@ -19,5 +19,6 @@ package master | ||||
| // These imports are the API groups the API server will support. | ||||
| import ( | ||||
| 	_ "k8s.io/kubernetes/pkg/api/install" | ||||
| 	_ "k8s.io/kubernetes/pkg/apis/componentconfig/install" | ||||
| 	_ "k8s.io/kubernetes/pkg/apis/extensions/install" | ||||
| ) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user