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
b9fa35fa
Commit
b9fa35fa
authored
Feb 12, 2019
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kube-aggregator: split out openapi spec priority sorter
parent
1c67881c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
75 additions
and
54 deletions
+75
-54
BUILD
.../kube-aggregator/pkg/controllers/openapi/aggregator/BUILD
+1
-0
aggregator.go
...gregator/pkg/controllers/openapi/aggregator/aggregator.go
+0
-54
priority.go
...aggregator/pkg/controllers/openapi/aggregator/priority.go
+74
-0
No files found.
staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/aggregator/BUILD
View file @
b9fa35fa
...
...
@@ -5,6 +5,7 @@ go_library(
srcs = [
"aggregator.go",
"downloader.go",
"priority.go",
],
importmap = "k8s.io/kubernetes/vendor/k8s.io/kube-aggregator/pkg/controllers/openapi/aggregator",
importpath = "k8s.io/kube-aggregator/pkg/controllers/openapi/aggregator",
...
...
staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/aggregator/aggregator.go
View file @
b9fa35fa
...
...
@@ -19,7 +19,6 @@ package aggregator
import
(
"fmt"
"net/http"
"sort"
"sync"
"time"
...
...
@@ -137,59 +136,6 @@ type openAPISpecInfo struct {
etag
string
}
// byPriority can be used in sort.Sort to sort specs with their priorities.
type
byPriority
struct
{
specs
[]
openAPISpecInfo
groupPriorities
map
[
string
]
int32
}
func
(
a
byPriority
)
Len
()
int
{
return
len
(
a
.
specs
)
}
func
(
a
byPriority
)
Swap
(
i
,
j
int
)
{
a
.
specs
[
i
],
a
.
specs
[
j
]
=
a
.
specs
[
j
],
a
.
specs
[
i
]
}
func
(
a
byPriority
)
Less
(
i
,
j
int
)
bool
{
// All local specs will come first
if
a
.
specs
[
i
]
.
apiService
.
Spec
.
Service
==
nil
&&
a
.
specs
[
j
]
.
apiService
.
Spec
.
Service
!=
nil
{
return
true
}
if
a
.
specs
[
i
]
.
apiService
.
Spec
.
Service
!=
nil
&&
a
.
specs
[
j
]
.
apiService
.
Spec
.
Service
==
nil
{
return
false
}
// WARNING: This will result in not following priorities for local APIServices.
if
a
.
specs
[
i
]
.
apiService
.
Spec
.
Service
==
nil
{
// Sort local specs with their name. This is the order in the delegation chain (aggregator first).
return
a
.
specs
[
i
]
.
apiService
.
Name
<
a
.
specs
[
j
]
.
apiService
.
Name
}
var
iPriority
,
jPriority
int32
if
a
.
specs
[
i
]
.
apiService
.
Spec
.
Group
==
a
.
specs
[
j
]
.
apiService
.
Spec
.
Group
{
iPriority
=
a
.
specs
[
i
]
.
apiService
.
Spec
.
VersionPriority
jPriority
=
a
.
specs
[
i
]
.
apiService
.
Spec
.
VersionPriority
}
else
{
iPriority
=
a
.
groupPriorities
[
a
.
specs
[
i
]
.
apiService
.
Spec
.
Group
]
jPriority
=
a
.
groupPriorities
[
a
.
specs
[
j
]
.
apiService
.
Spec
.
Group
]
}
if
iPriority
!=
jPriority
{
// Sort by priority, higher first
return
iPriority
>
jPriority
}
// Sort by service name.
return
a
.
specs
[
i
]
.
apiService
.
Name
<
a
.
specs
[
j
]
.
apiService
.
Name
}
func
sortByPriority
(
specs
[]
openAPISpecInfo
)
{
b
:=
byPriority
{
specs
:
specs
,
groupPriorities
:
map
[
string
]
int32
{},
}
for
_
,
spec
:=
range
specs
{
if
spec
.
apiService
.
Spec
.
Service
==
nil
{
continue
}
if
pr
,
found
:=
b
.
groupPriorities
[
spec
.
apiService
.
Spec
.
Group
];
!
found
||
spec
.
apiService
.
Spec
.
GroupPriorityMinimum
>
pr
{
b
.
groupPriorities
[
spec
.
apiService
.
Spec
.
Group
]
=
spec
.
apiService
.
Spec
.
GroupPriorityMinimum
}
}
sort
.
Sort
(
b
)
}
// buildOpenAPISpec aggregates all OpenAPI specs. It is not thread-safe. The caller is responsible to hold proper locks.
func
(
s
*
specAggregator
)
buildOpenAPISpec
()
(
specToReturn
*
spec
.
Swagger
,
err
error
)
{
specs
:=
[]
openAPISpecInfo
{}
...
...
staging/src/k8s.io/kube-aggregator/pkg/controllers/openapi/aggregator/priority.go
0 → 100644
View file @
b9fa35fa
/*
Copyright 2017 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
aggregator
import
(
"sort"
)
// byPriority can be used in sort.Sort to sort specs with their priorities.
type
byPriority
struct
{
specs
[]
openAPISpecInfo
groupPriorities
map
[
string
]
int32
}
func
(
a
byPriority
)
Len
()
int
{
return
len
(
a
.
specs
)
}
func
(
a
byPriority
)
Swap
(
i
,
j
int
)
{
a
.
specs
[
i
],
a
.
specs
[
j
]
=
a
.
specs
[
j
],
a
.
specs
[
i
]
}
func
(
a
byPriority
)
Less
(
i
,
j
int
)
bool
{
// All local specs will come first
if
a
.
specs
[
i
]
.
apiService
.
Spec
.
Service
==
nil
&&
a
.
specs
[
j
]
.
apiService
.
Spec
.
Service
!=
nil
{
return
true
}
if
a
.
specs
[
i
]
.
apiService
.
Spec
.
Service
!=
nil
&&
a
.
specs
[
j
]
.
apiService
.
Spec
.
Service
==
nil
{
return
false
}
// WARNING: This will result in not following priorities for local APIServices.
if
a
.
specs
[
i
]
.
apiService
.
Spec
.
Service
==
nil
{
// Sort local specs with their name. This is the order in the delegation chain (aggregator first).
return
a
.
specs
[
i
]
.
apiService
.
Name
<
a
.
specs
[
j
]
.
apiService
.
Name
}
var
iPriority
,
jPriority
int32
if
a
.
specs
[
i
]
.
apiService
.
Spec
.
Group
==
a
.
specs
[
j
]
.
apiService
.
Spec
.
Group
{
iPriority
=
a
.
specs
[
i
]
.
apiService
.
Spec
.
VersionPriority
jPriority
=
a
.
specs
[
i
]
.
apiService
.
Spec
.
VersionPriority
}
else
{
iPriority
=
a
.
groupPriorities
[
a
.
specs
[
i
]
.
apiService
.
Spec
.
Group
]
jPriority
=
a
.
groupPriorities
[
a
.
specs
[
j
]
.
apiService
.
Spec
.
Group
]
}
if
iPriority
!=
jPriority
{
// Sort by priority, higher first
return
iPriority
>
jPriority
}
// Sort by service name.
return
a
.
specs
[
i
]
.
apiService
.
Name
<
a
.
specs
[
j
]
.
apiService
.
Name
}
func
sortByPriority
(
specs
[]
openAPISpecInfo
)
{
b
:=
byPriority
{
specs
:
specs
,
groupPriorities
:
map
[
string
]
int32
{},
}
for
_
,
spec
:=
range
specs
{
if
spec
.
apiService
.
Spec
.
Service
==
nil
{
continue
}
if
pr
,
found
:=
b
.
groupPriorities
[
spec
.
apiService
.
Spec
.
Group
];
!
found
||
spec
.
apiService
.
Spec
.
GroupPriorityMinimum
>
pr
{
b
.
groupPriorities
[
spec
.
apiService
.
Spec
.
Group
]
=
spec
.
apiService
.
Spec
.
GroupPriorityMinimum
}
}
sort
.
Sort
(
b
)
}
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