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
1502ad25
Commit
1502ad25
authored
Jan 25, 2019
by
Darren Shepherd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Package serialized version of openapi
parent
93841ffb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
0 deletions
+51
-0
main.go
main.go
+1
-0
zz_generated_bindata.go
pkg/openapi/zz_generated_bindata.go
+0
-0
router.go
pkg/server/router.go
+32
-0
main.go
types/codegen/main.go
+18
-0
No files found.
main.go
View file @
1502ad25
//go:generate go run types/codegen/cleanup/main.go
//go:generate go run types/codegen/main.go
//go:generate go fmt pkg/deploy/zz_generated_bindata.go
//go:generate go fmt pkg/openapi/zz_generated_bindata.go
package
main
...
...
pkg/openapi/zz_generated_bindata.go
0 → 100644
View file @
1502ad25
This source diff could not be displayed because it is too large. You can
view the blob
instead.
pkg/server/router.go
View file @
1502ad25
...
...
@@ -2,12 +2,21 @@ package server
import
(
"net/http"
"strconv"
"github.com/gorilla/mux"
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/openapi"
"k8s.io/apimachinery/pkg/util/json"
)
const
(
jsonMediaType
=
"application/json"
binaryMediaType
=
"application/octet-stream"
pbMediaType
=
"application/com.github.proto-openapi.spec.v2@v1.0+protobuf"
openapiPrefix
=
"openapi."
)
type
CACertsGetter
func
()
(
string
,
error
)
func
router
(
serverConfig
*
config
.
Control
,
tunnel
http
.
Handler
,
cacertsGetter
CACertsGetter
)
http
.
Handler
{
...
...
@@ -22,6 +31,7 @@ func router(serverConfig *config.Control, tunnel http.Handler, cacertsGetter CAC
router
:=
mux
.
NewRouter
()
router
.
NotFoundHandler
=
authed
router
.
Path
(
"/cacerts"
)
.
Handler
(
cacerts
(
cacertsGetter
))
router
.
Path
(
"/openapi/v2"
)
.
Handler
(
serveOpenapi
())
return
router
}
...
...
@@ -68,3 +78,25 @@ func configHandler(server *config.Control) http.Handler {
json
.
NewEncoder
(
resp
)
.
Encode
(
server
)
})
}
func
serveOpenapi
()
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
resp
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
suffix
:=
"json"
contentType
:=
jsonMediaType
if
req
.
Header
.
Get
(
"Accept"
)
==
pbMediaType
{
suffix
=
"pb"
contentType
=
binaryMediaType
}
data
,
err
:=
openapi
.
Asset
(
openapiPrefix
+
suffix
)
if
err
!=
nil
{
resp
.
WriteHeader
(
http
.
StatusInternalServerError
)
resp
.
Write
([]
byte
(
err
.
Error
()))
return
}
resp
.
Header
()
.
Set
(
"Content-Type"
,
contentType
)
resp
.
Header
()
.
Set
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
data
)))
resp
.
Write
(
data
)
})
}
types/codegen/main.go
View file @
1502ad25
...
...
@@ -44,6 +44,24 @@ func main() {
logrus
.
Fatal
(
err
)
}
bc
=
&
bindata
.
Config
{
Input
:
[]
bindata
.
InputConfig
{
{
Path
:
"vendor/k8s.io/kubernetes/openapi.json"
,
},
{
Path
:
"vendor/k8s.io/kubernetes/openapi.pb"
,
},
},
Package
:
"openapi"
,
NoMetadata
:
true
,
Prefix
:
"vendor/k8s.io/kubernetes/"
,
Output
:
"pkg/openapi/zz_generated_bindata.go"
,
}
if
err
:=
bindata
.
Translate
(
bc
);
err
!=
nil
{
logrus
.
Fatal
(
err
)
}
if
err
:=
generator
.
DefaultGenerate
(
v1
.
Schemas
,
basePackage
,
false
,
nil
);
err
!=
nil
{
logrus
.
Fatal
(
err
)
}
...
...
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