Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
4ea07084
Commit
4ea07084
authored
Sep 28, 2018
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify the resource_encoding_config.go, since we don't need per group override at all
parent
a76c2666
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
42 deletions
+19
-42
resource_encoding_config.go
.../apiserver/pkg/server/storage/resource_encoding_config.go
+19
-42
No files found.
staging/src/k8s.io/apiserver/pkg/server/storage/resource_encoding_config.go
View file @
4ea07084
...
@@ -34,37 +34,27 @@ type ResourceEncodingConfig interface {
...
@@ -34,37 +34,27 @@ type ResourceEncodingConfig interface {
}
}
type
DefaultResourceEncodingConfig
struct
{
type
DefaultResourceEncodingConfig
struct
{
groups
map
[
string
]
*
GroupResourceEncodingConfig
// resources records the overriding encoding configs for individual resources.
scheme
*
runtime
.
Scheme
resources
map
[
schema
.
GroupResource
]
*
OverridingResourceEncoding
scheme
*
runtime
.
Scheme
}
}
type
GroupResourceEncodingConfi
g
struct
{
type
OverridingResourceEncodin
g
struct
{
ExternalResourceEncoding
s
map
[
string
]
schema
.
GroupVersion
ExternalResourceEncoding
schema
.
GroupVersion
InternalResourceEncoding
s
map
[
string
]
schema
.
GroupVersion
InternalResourceEncoding
schema
.
GroupVersion
}
}
var
_
ResourceEncodingConfig
=
&
DefaultResourceEncodingConfig
{}
var
_
ResourceEncodingConfig
=
&
DefaultResourceEncodingConfig
{}
func
NewDefaultResourceEncodingConfig
(
scheme
*
runtime
.
Scheme
)
*
DefaultResourceEncodingConfig
{
func
NewDefaultResourceEncodingConfig
(
scheme
*
runtime
.
Scheme
)
*
DefaultResourceEncodingConfig
{
return
&
DefaultResourceEncodingConfig
{
groups
:
map
[
string
]
*
GroupResourceEncodingConfig
{},
scheme
:
scheme
}
return
&
DefaultResourceEncodingConfig
{
resources
:
map
[
schema
.
GroupResource
]
*
OverridingResourceEncoding
{},
scheme
:
scheme
}
}
func
newGroupResourceEncodingConfig
()
*
GroupResourceEncodingConfig
{
return
&
GroupResourceEncodingConfig
{
ExternalResourceEncodings
:
map
[
string
]
schema
.
GroupVersion
{},
InternalResourceEncodings
:
map
[
string
]
schema
.
GroupVersion
{},
}
}
}
func
(
o
*
DefaultResourceEncodingConfig
)
SetResourceEncoding
(
resourceBeingStored
schema
.
GroupResource
,
externalEncodingVersion
,
internalVersion
schema
.
GroupVersion
)
{
func
(
o
*
DefaultResourceEncodingConfig
)
SetResourceEncoding
(
resourceBeingStored
schema
.
GroupResource
,
externalEncodingVersion
,
internalVersion
schema
.
GroupVersion
)
{
group
:=
resourceBeingStored
.
Group
o
.
resources
[
resourceBeingStored
]
=
&
OverridingResourceEncoding
{
_
,
groupExists
:=
o
.
groups
[
group
]
ExternalResourceEncoding
:
externalEncodingVersion
,
if
!
groupExists
{
InternalResourceEncoding
:
internalVersion
,
o
.
groups
[
group
]
=
newGroupResourceEncodingConfig
()
}
}
o
.
groups
[
group
]
.
ExternalResourceEncodings
[
resourceBeingStored
.
Resource
]
=
externalEncodingVersion
o
.
groups
[
group
]
.
InternalResourceEncodings
[
resourceBeingStored
.
Resource
]
=
internalVersion
}
}
func
(
o
*
DefaultResourceEncodingConfig
)
StorageEncodingFor
(
resource
schema
.
GroupResource
)
(
schema
.
GroupVersion
,
error
)
{
func
(
o
*
DefaultResourceEncodingConfig
)
StorageEncodingFor
(
resource
schema
.
GroupResource
)
(
schema
.
GroupVersion
,
error
)
{
...
@@ -72,20 +62,13 @@ func (o *DefaultResourceEncodingConfig) StorageEncodingFor(resource schema.Group
...
@@ -72,20 +62,13 @@ func (o *DefaultResourceEncodingConfig) StorageEncodingFor(resource schema.Group
return
schema
.
GroupVersion
{},
fmt
.
Errorf
(
"group %q is not registered in scheme"
,
resource
.
Group
)
return
schema
.
GroupVersion
{},
fmt
.
Errorf
(
"group %q is not registered in scheme"
,
resource
.
Group
)
}
}
groupEncoding
,
groupExists
:=
o
.
groups
[
resource
.
Group
]
resourceOverride
,
resourceExists
:=
o
.
resources
[
resource
]
if
resourceExists
{
if
!
groupExists
{
return
resourceOverride
.
ExternalResourceEncoding
,
nil
// return the most preferred external version for the group
return
o
.
scheme
.
PrioritizedVersionsForGroup
(
resource
.
Group
)[
0
],
nil
}
resourceOverride
,
resourceExists
:=
groupEncoding
.
ExternalResourceEncodings
[
resource
.
Resource
]
if
!
resourceExists
{
// return the most preferred external version for the group
return
o
.
scheme
.
PrioritizedVersionsForGroup
(
resource
.
Group
)[
0
],
nil
}
}
return
resourceOverride
,
nil
// return the most preferred external version for the group
return
o
.
scheme
.
PrioritizedVersionsForGroup
(
resource
.
Group
)[
0
],
nil
}
}
func
(
o
*
DefaultResourceEncodingConfig
)
InMemoryEncodingFor
(
resource
schema
.
GroupResource
)
(
schema
.
GroupVersion
,
error
)
{
func
(
o
*
DefaultResourceEncodingConfig
)
InMemoryEncodingFor
(
resource
schema
.
GroupResource
)
(
schema
.
GroupVersion
,
error
)
{
...
@@ -93,15 +76,9 @@ func (o *DefaultResourceEncodingConfig) InMemoryEncodingFor(resource schema.Grou
...
@@ -93,15 +76,9 @@ func (o *DefaultResourceEncodingConfig) InMemoryEncodingFor(resource schema.Grou
return
schema
.
GroupVersion
{},
fmt
.
Errorf
(
"group %q is not registered in scheme"
,
resource
.
Group
)
return
schema
.
GroupVersion
{},
fmt
.
Errorf
(
"group %q is not registered in scheme"
,
resource
.
Group
)
}
}
groupEncoding
,
groupExists
:=
o
.
groups
[
resource
.
Group
]
resourceOverride
,
resourceExists
:=
o
.
resources
[
resource
]
if
!
group
Exists
{
if
resource
Exists
{
return
schema
.
GroupVersion
{
Group
:
resource
.
Group
,
Version
:
runtime
.
APIVersionInternal
}
,
nil
return
resourceOverride
.
InternalResourceEncoding
,
nil
}
}
return
schema
.
GroupVersion
{
Group
:
resource
.
Group
,
Version
:
runtime
.
APIVersionInternal
},
nil
resourceOverride
,
resourceExists
:=
groupEncoding
.
InternalResourceEncodings
[
resource
.
Resource
]
if
!
resourceExists
{
return
schema
.
GroupVersion
{
Group
:
resource
.
Group
,
Version
:
runtime
.
APIVersionInternal
},
nil
}
return
resourceOverride
,
nil
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment