mirror of https://github.com/k3s-io/k3s
Remove StorageVersionHash
parent
d8dd57c681
commit
f20f1642c9
|
@ -95,7 +95,6 @@ func (c *DiscoveryController) sync(version schema.GroupVersion) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
foundThisVersion := false
|
foundThisVersion := false
|
||||||
var storageVersionHash string
|
|
||||||
for _, v := range crd.Spec.Versions {
|
for _, v := range crd.Spec.Versions {
|
||||||
if !v.Served {
|
if !v.Served {
|
||||||
continue
|
continue
|
||||||
|
@ -114,9 +113,6 @@ func (c *DiscoveryController) sync(version schema.GroupVersion) error {
|
||||||
if v.Name == version.Version {
|
if v.Name == version.Version {
|
||||||
foundThisVersion = true
|
foundThisVersion = true
|
||||||
}
|
}
|
||||||
if v.Storage {
|
|
||||||
storageVersionHash = discovery.StorageVersionHash(gv.Group, gv.Version, crd.Spec.Names.Kind)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !foundThisVersion {
|
if !foundThisVersion {
|
||||||
|
@ -138,7 +134,6 @@ func (c *DiscoveryController) sync(version schema.GroupVersion) error {
|
||||||
Verbs: verbs,
|
Verbs: verbs,
|
||||||
ShortNames: crd.Status.AcceptedNames.ShortNames,
|
ShortNames: crd.Status.AcceptedNames.ShortNames,
|
||||||
Categories: crd.Status.AcceptedNames.Categories,
|
Categories: crd.Status.AcceptedNames.Categories,
|
||||||
StorageVersionHash: storageVersionHash,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
subresources, err := apiextensions.GetSubresourcesForVersion(crd, version.Version)
|
subresources, err := apiextensions.GetSubresourcesForVersion(crd, version.Version)
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright 2019 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 discovery
|
|
||||||
|
|
||||||
import (
|
|
||||||
"crypto/sha256"
|
|
||||||
"encoding/base64"
|
|
||||||
)
|
|
||||||
|
|
||||||
// StorageVersionHash calculates the storage version hash for a
|
|
||||||
// <group/version/kind> tuple.
|
|
||||||
// WARNING: this function is subject to change. Clients shouldn't depend on
|
|
||||||
// this function.
|
|
||||||
func StorageVersionHash(group, version, kind string) string {
|
|
||||||
gvk := group + "/" + version + "/" + kind
|
|
||||||
if gvk == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
bytes := sha256.Sum256([]byte(gvk))
|
|
||||||
// Assuming there are N kinds in the cluster, and the hash is X-byte long,
|
|
||||||
// the chance of colliding hash P(N,X) approximates to 1-e^(-(N^2)/2^(8X+1)).
|
|
||||||
// P(10,000, 8) ~= 2.7*10^(-12), which is low enough.
|
|
||||||
// See https://en.wikipedia.org/wiki/Birthday_problem#Approximations.
|
|
||||||
return base64.StdEncoding.EncodeToString(
|
|
||||||
bytes[:8])
|
|
||||||
}
|
|
|
@ -26,20 +26,17 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
restful "github.com/emicklei/go-restful"
|
"github.com/emicklei/go-restful"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/conversion"
|
"k8s.io/apimachinery/pkg/conversion"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
"k8s.io/apiserver/pkg/admission"
|
"k8s.io/apiserver/pkg/admission"
|
||||||
"k8s.io/apiserver/pkg/endpoints/discovery"
|
|
||||||
"k8s.io/apiserver/pkg/endpoints/handlers"
|
"k8s.io/apiserver/pkg/endpoints/handlers"
|
||||||
"k8s.io/apiserver/pkg/endpoints/handlers/negotiation"
|
"k8s.io/apiserver/pkg/endpoints/handlers/negotiation"
|
||||||
"k8s.io/apiserver/pkg/endpoints/metrics"
|
"k8s.io/apiserver/pkg/endpoints/metrics"
|
||||||
"k8s.io/apiserver/pkg/features"
|
|
||||||
"k8s.io/apiserver/pkg/registry/rest"
|
"k8s.io/apiserver/pkg/registry/rest"
|
||||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -131,20 +128,6 @@ func (a *APIInstaller) newWebService() *restful.WebService {
|
||||||
return ws
|
return ws
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate the storage gvk, the gvk objects are converted to before persisted to the etcd.
|
|
||||||
func getStorageVersionKind(storageVersioner runtime.GroupVersioner, storage rest.Storage, typer runtime.ObjectTyper) (schema.GroupVersionKind, error) {
|
|
||||||
object := storage.New()
|
|
||||||
fqKinds, _, err := typer.ObjectKinds(object)
|
|
||||||
if err != nil {
|
|
||||||
return schema.GroupVersionKind{}, err
|
|
||||||
}
|
|
||||||
gvk, ok := storageVersioner.KindForGroupVersionKinds(fqKinds)
|
|
||||||
if !ok {
|
|
||||||
return schema.GroupVersionKind{}, fmt.Errorf("cannot find the storage version kind for %v", reflect.TypeOf(object))
|
|
||||||
}
|
|
||||||
return gvk, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetResourceKind returns the external group version kind registered for the given storage
|
// GetResourceKind returns the external group version kind registered for the given storage
|
||||||
// object. If the storage object is a subresource and has an override supplied for it, it returns
|
// object. If the storage object is a subresource and has an override supplied for it, it returns
|
||||||
// the group version kind supplied in the override.
|
// the group version kind supplied in the override.
|
||||||
|
@ -239,7 +222,6 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
||||||
watcher, isWatcher := storage.(rest.Watcher)
|
watcher, isWatcher := storage.(rest.Watcher)
|
||||||
connecter, isConnecter := storage.(rest.Connecter)
|
connecter, isConnecter := storage.(rest.Connecter)
|
||||||
storageMeta, isMetadata := storage.(rest.StorageMetadata)
|
storageMeta, isMetadata := storage.(rest.StorageMetadata)
|
||||||
storageVersionProvider, isStorageVersionProvider := storage.(rest.StorageVersionProvider)
|
|
||||||
if !isMetadata {
|
if !isMetadata {
|
||||||
storageMeta = defaultStorageMetadata{}
|
storageMeta = defaultStorageMetadata{}
|
||||||
}
|
}
|
||||||
|
@ -378,16 +360,6 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag
|
||||||
tableProvider, _ := storage.(rest.TableConvertor)
|
tableProvider, _ := storage.(rest.TableConvertor)
|
||||||
|
|
||||||
var apiResource metav1.APIResource
|
var apiResource metav1.APIResource
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.StorageVersionHash) &&
|
|
||||||
isStorageVersionProvider &&
|
|
||||||
storageVersionProvider.StorageVersion() != nil {
|
|
||||||
versioner := storageVersionProvider.StorageVersion()
|
|
||||||
gvk, err := getStorageVersionKind(versioner, storage, a.group.Typer)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
apiResource.StorageVersionHash = discovery.StorageVersionHash(gvk.Group, gvk.Version, gvk.Kind)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the list of actions for the given scope.
|
// Get the list of actions for the given scope.
|
||||||
switch {
|
switch {
|
||||||
|
|
|
@ -70,13 +70,6 @@ const (
|
||||||
// committing.
|
// committing.
|
||||||
DryRun utilfeature.Feature = "DryRun"
|
DryRun utilfeature.Feature = "DryRun"
|
||||||
|
|
||||||
// owner: @caesarxuchao
|
|
||||||
// alpha: v1.14
|
|
||||||
//
|
|
||||||
// Allow apiservers to expose the storage version hash in the discovery
|
|
||||||
// document.
|
|
||||||
StorageVersionHash utilfeature.Feature = "StorageVersionHash"
|
|
||||||
|
|
||||||
// owner: @ksubrmnn
|
// owner: @ksubrmnn
|
||||||
// alpha: v1.14
|
// alpha: v1.14
|
||||||
//
|
//
|
||||||
|
@ -103,7 +96,6 @@ var defaultKubernetesFeatureGates = map[utilfeature.Feature]utilfeature.FeatureS
|
||||||
AdvancedAuditing: {Default: true, PreRelease: utilfeature.GA},
|
AdvancedAuditing: {Default: true, PreRelease: utilfeature.GA},
|
||||||
APIListChunking: {Default: true, PreRelease: utilfeature.Beta},
|
APIListChunking: {Default: true, PreRelease: utilfeature.Beta},
|
||||||
DryRun: {Default: true, PreRelease: utilfeature.Beta},
|
DryRun: {Default: true, PreRelease: utilfeature.Beta},
|
||||||
StorageVersionHash: {Default: false, PreRelease: utilfeature.Alpha},
|
|
||||||
WinOverlay: {Default: false, PreRelease: utilfeature.Alpha},
|
WinOverlay: {Default: false, PreRelease: utilfeature.Alpha},
|
||||||
WinDSR: {Default: false, PreRelease: utilfeature.Alpha},
|
WinDSR: {Default: false, PreRelease: utilfeature.Alpha},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue