diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2022-08-16 13:04:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-16 13:04:41 +0000 |
commit | d0567dd078982fcdb937868c9d80887a5bf73026 (patch) | |
tree | f60ea57840bd26def5b97abaa63968e454dfbd9d /pkg | |
parent | 311b5946f74c94c5d6024c904abf6976c75e4d8f (diff) | |
parent | d856fb43e11b3a4a93b423d330ce3435afddde4b (diff) | |
download | podman-d0567dd078982fcdb937868c9d80887a5bf73026.tar.gz podman-d0567dd078982fcdb937868c9d80887a5bf73026.tar.bz2 podman-d0567dd078982fcdb937868c9d80887a5bf73026.zip |
Merge pull request #15270 from nicrowe00/kubegenerate
Add "podman kube generate" command
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/api/handlers/libpod/kube.go | 4 | ||||
-rw-r--r-- | pkg/api/server/register_kube.go (renamed from pkg/api/server/register_play.go) | 35 | ||||
-rw-r--r-- | pkg/api/server/server.go | 2 | ||||
-rw-r--r-- | pkg/bindings/kube/kube.go | 6 | ||||
-rw-r--r-- | pkg/domain/entities/generate.go | 2 |
5 files changed, 47 insertions, 2 deletions
diff --git a/pkg/api/handlers/libpod/kube.go b/pkg/api/handlers/libpod/kube.go index 6cad58795..5c891b707 100644 --- a/pkg/api/handlers/libpod/kube.go +++ b/pkg/api/handlers/libpod/kube.go @@ -121,3 +121,7 @@ func KubePlayDown(w http.ResponseWriter, r *http.Request) { } utils.WriteResponse(w, http.StatusOK, report) } + +func KubeGenerate(w http.ResponseWriter, r *http.Request) { + GenerateKube(w, r) +} diff --git a/pkg/api/server/register_play.go b/pkg/api/server/register_kube.go index 76e150504..0c3cd1d04 100644 --- a/pkg/api/server/register_play.go +++ b/pkg/api/server/register_kube.go @@ -7,7 +7,7 @@ import ( "github.com/gorilla/mux" ) -func (s *APIServer) registerPlayHandlers(r *mux.Router) error { +func (s *APIServer) registerKubeHandlers(r *mux.Router) error { // swagger:operation POST /libpod/play/kube libpod PlayKubeLibpod // --- // tags: @@ -78,5 +78,38 @@ func (s *APIServer) registerPlayHandlers(r *mux.Router) error { // $ref: "#/responses/internalError" r.HandleFunc(VersionedPath("/libpod/play/kube"), s.APIHandler(libpod.PlayKubeDown)).Methods(http.MethodDelete) r.HandleFunc(VersionedPath("/libpod/kube/play"), s.APIHandler(libpod.KubePlayDown)).Methods(http.MethodDelete) + // swagger:operation GET /libpod/generate/kube libpod GenerateKubeLibpod + // --- + // tags: + // - containers + // - pods + // summary: Generate a Kubernetes YAML file. + // description: Generate Kubernetes YAML based on a pod or container. + // parameters: + // - in: query + // name: names + // type: array + // items: + // type: string + // required: true + // description: Name or ID of the container or pod. + // - in: query + // name: service + // type: boolean + // default: false + // description: Generate YAML for a Kubernetes service object. + // produces: + // - text/vnd.yaml + // - application/json + // responses: + // 200: + // description: Kubernetes YAML file describing pod + // schema: + // type: string + // format: binary + // 500: + // $ref: "#/responses/internalError" + r.HandleFunc(VersionedPath("/libpod/generate/kube"), s.APIHandler(libpod.GenerateKube)).Methods(http.MethodGet) + r.HandleFunc(VersionedPath("/libpod/kube/generate"), s.APIHandler(libpod.KubeGenerate)).Methods(http.MethodGet) return nil } diff --git a/pkg/api/server/server.go b/pkg/api/server/server.go index 5482a8ec2..39423dabe 100644 --- a/pkg/api/server/server.go +++ b/pkg/api/server/server.go @@ -130,7 +130,7 @@ func newServer(runtime *libpod.Runtime, listener net.Listener, opts entities.Ser server.registerMonitorHandlers, server.registerNetworkHandlers, server.registerPingHandlers, - server.registerPlayHandlers, + server.registerKubeHandlers, server.registerPluginsHandlers, server.registerPodsHandlers, server.registerSecretHandlers, diff --git a/pkg/bindings/kube/kube.go b/pkg/bindings/kube/kube.go index db40c5134..e727439cf 100644 --- a/pkg/bindings/kube/kube.go +++ b/pkg/bindings/kube/kube.go @@ -10,6 +10,7 @@ import ( "github.com/containers/image/v5/types" "github.com/containers/podman/v4/pkg/auth" "github.com/containers/podman/v4/pkg/bindings" + "github.com/containers/podman/v4/pkg/bindings/generate" "github.com/containers/podman/v4/pkg/domain/entities" "github.com/sirupsen/logrus" ) @@ -94,3 +95,8 @@ func DownWithBody(ctx context.Context, body io.Reader) (*entities.KubePlayReport } return &report, nil } + +// Kube generate Kubernetes YAML (v1 specification) +func Generate(ctx context.Context, nameOrIDs []string, options generate.KubeOptions) (*entities.GenerateKubeReport, error) { + return generate.Kube(ctx, nameOrIDs, &options) +} diff --git a/pkg/domain/entities/generate.go b/pkg/domain/entities/generate.go index cc5fbb6fb..f18e79b47 100644 --- a/pkg/domain/entities/generate.go +++ b/pkg/domain/entities/generate.go @@ -46,6 +46,8 @@ type GenerateKubeOptions struct { Service bool } +type KubeGenerateOptions = GenerateKubeOptions + // GenerateKubeReport // // FIXME: Podman4.0 should change io.Reader to io.ReaderCloser |