mirror of
https://github.com/rancher/steve.git
synced 2025-04-28 03:10:32 +00:00
Only drop API type if replacement type can be found
This commit is contained in:
parent
06de395825
commit
c7a5c4f069
@ -89,14 +89,6 @@ func validSchema(schema *types.APISchema) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if attributes.PreferredVersion(schema) != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
if attributes.PreferredGroup(schema) != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
listPool = semaphore.NewWeighted(10)
|
||||
listPool = semaphore.NewWeighted(10)
|
||||
typeNameChanges = map[string]string{
|
||||
"extensions.v1beta1.ingress": "networking.k8s.io.v1beta1.ingress",
|
||||
}
|
||||
)
|
||||
|
||||
type SchemasHandler interface {
|
||||
@ -151,8 +154,7 @@ func (h *handler) refreshAll() error {
|
||||
filteredSchemas := map[string]*types.APISchema{}
|
||||
for _, schema := range schemas {
|
||||
if isListWatchable(schema) {
|
||||
if attributes.PreferredGroup(schema) != "" ||
|
||||
attributes.PreferredVersion(schema) != "" {
|
||||
if preferredTypeExists(schema, schemas) {
|
||||
continue
|
||||
}
|
||||
if ok, err := h.allowed(schema); err != nil {
|
||||
@ -183,6 +185,28 @@ func (h *handler) refreshAll() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func preferredTypeExists(schema *types.APISchema, schemas map[string]*types.APISchema) bool {
|
||||
if replacement, ok := typeNameChanges[schema.ID]; ok && schemas[replacement] != nil {
|
||||
return true
|
||||
}
|
||||
pg := attributes.PreferredGroup(schema)
|
||||
pv := attributes.PreferredVersion(schema)
|
||||
if pg == "" && pv == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
gvk := attributes.GVK(schema)
|
||||
if pg != "" {
|
||||
gvk.Group = pg
|
||||
}
|
||||
if pv != "" {
|
||||
gvk.Version = pv
|
||||
}
|
||||
|
||||
_, ok := schemas[converter.GVKToVersionedSchemaID(gvk)]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (h *handler) allowed(schema *types.APISchema) (bool, error) {
|
||||
gvr := attributes.GVR(schema)
|
||||
ssar, err := h.ssar.Create(&authorizationv1.SelfSubjectAccessReview{
|
||||
|
@ -72,7 +72,7 @@ func forVersion(crd *beta1.CustomResourceDefinition, group, version, kind string
|
||||
versionColumns = columns
|
||||
}
|
||||
|
||||
id := gvkToSchemaID(schema.GroupVersionKind{
|
||||
id := GVKToVersionedSchemaID(schema.GroupVersionKind{
|
||||
Group: group,
|
||||
Version: version,
|
||||
Kind: kind,
|
||||
|
@ -69,11 +69,11 @@ func refresh(gv schema.GroupVersion, groupToPreferredVersion map[string]string,
|
||||
|
||||
logrus.Infof("APIVersion %s/%s Kind %s", gvk.Group, gvk.Version, gvk.Kind)
|
||||
|
||||
schema := schemasMap[gvkToSchemaID(gvk)]
|
||||
schema := schemasMap[GVKToVersionedSchemaID(gvk)]
|
||||
if schema == nil {
|
||||
schema = &types.APISchema{
|
||||
Schema: &schemas.Schema{
|
||||
ID: gvkToSchemaID(gvk),
|
||||
ID: GVKToVersionedSchemaID(gvk),
|
||||
},
|
||||
}
|
||||
attributes.SetGVK(schema, gvk)
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
"k8s.io/client-go/discovery"
|
||||
)
|
||||
|
||||
func gvkToSchemaID(gvk schema.GroupVersionKind) string {
|
||||
func GVKToVersionedSchemaID(gvk schema.GroupVersionKind) string {
|
||||
if gvk.Group == "" {
|
||||
return strings.ToLower(fmt.Sprintf("core.%s.%s", gvk.Version, gvk.Kind))
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func modelToSchema(modelName string, k *proto.Kind) *types.APISchema {
|
||||
Kind: convert.ToString(m["kind"]),
|
||||
}
|
||||
|
||||
s.ID = gvkToSchemaID(gvk)
|
||||
s.ID = GVKToVersionedSchemaID(gvk)
|
||||
attributes.SetGVK(&s, gvk)
|
||||
}
|
||||
}
|
||||
|
@ -182,14 +182,6 @@ func (s *Store) schemasToWatch(apiOp *types.APIRequest) (result []*types.APISche
|
||||
continue
|
||||
}
|
||||
|
||||
if attributes.PreferredVersion(schema) != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if attributes.PreferredGroup(schema) != "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if schema.Store == nil {
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user