generate kube on multiple containers

add the ability to add multiple containers into a single k8s pod
instead of just one.

also fixed some bugs in the resulting yaml where an empty service
description was being added on error causing the k8s validation to fail.

Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
baude
2020-12-02 16:06:31 -06:00
parent e6f80fa61a
commit 749ee2a10e
11 changed files with 159 additions and 47 deletions

View File

@ -60,7 +60,8 @@ func GenerateKube(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
decoder := r.Context().Value("decoder").(*schema.Decoder)
query := struct {
Service bool `schema:"service"`
Names []string `schema:"names"`
Service bool `schema:"service"`
}{
// Defaults would go here.
}
@ -73,7 +74,7 @@ func GenerateKube(w http.ResponseWriter, r *http.Request) {
containerEngine := abi.ContainerEngine{Libpod: runtime}
options := entities.GenerateKubeOptions{Service: query.Service}
report, err := containerEngine.GenerateKube(r.Context(), utils.GetName(r), options)
report, err := containerEngine.GenerateKube(r.Context(), query.Names, options)
if err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "error generating YAML"))
return

View File

@ -70,7 +70,7 @@ func (s *APIServer) registerGenerateHandlers(r *mux.Router) error {
// $ref: "#/responses/InternalError"
r.HandleFunc(VersionedPath("/libpod/generate/{name:.*}/systemd"), s.APIHandler(libpod.GenerateSystemd)).Methods(http.MethodGet)
// swagger:operation GET /libpod/generate/{name:.*}/kube libpod libpodGenerateKube
// swagger:operation GET /libpod/generate/kube libpod libpodGenerateKube
// ---
// tags:
// - containers
@ -78,9 +78,11 @@ func (s *APIServer) registerGenerateHandlers(r *mux.Router) error {
// summary: Generate a Kubernetes YAML file.
// description: Generate Kubernetes YAML based on a pod or container.
// parameters:
// - in: path
// name: name:.*
// type: string
// - in: query
// name: names
// type: array
// items:
// type: string
// required: true
// description: Name or ID of the container or pod.
// - in: query
@ -98,6 +100,6 @@ func (s *APIServer) registerGenerateHandlers(r *mux.Router) error {
// format: binary
// 500:
// $ref: "#/responses/InternalError"
r.HandleFunc(VersionedPath("/libpod/generate/{name:.*}/kube"), s.APIHandler(libpod.GenerateKube)).Methods(http.MethodGet)
r.HandleFunc(VersionedPath("/libpod/generate/kube"), s.APIHandler(libpod.GenerateKube)).Methods(http.MethodGet)
return nil
}