mirror of
https://github.com/containers/podman.git
synced 2025-12-12 17:57:31 +08:00
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>
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package generate
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"net/url"
|
|
"strconv"
|
|
|
|
"github.com/containers/podman/v2/pkg/bindings"
|
|
"github.com/containers/podman/v2/pkg/domain/entities"
|
|
)
|
|
|
|
func Systemd(ctx context.Context, nameOrID string, options entities.GenerateSystemdOptions) (*entities.GenerateSystemdReport, error) {
|
|
conn, err := bindings.GetClient(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
params := url.Values{}
|
|
|
|
params.Set("useName", strconv.FormatBool(options.Name))
|
|
params.Set("new", strconv.FormatBool(options.New))
|
|
if options.RestartPolicy != "" {
|
|
params.Set("restartPolicy", options.RestartPolicy)
|
|
}
|
|
if options.StopTimeout != nil {
|
|
params.Set("stopTimeout", strconv.FormatUint(uint64(*options.StopTimeout), 10))
|
|
}
|
|
params.Set("containerPrefix", options.ContainerPrefix)
|
|
params.Set("podPrefix", options.PodPrefix)
|
|
params.Set("separator", options.Separator)
|
|
|
|
response, err := conn.DoRequest(nil, http.MethodGet, "/generate/%s/systemd", params, nil, nameOrID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
report := &entities.GenerateSystemdReport{}
|
|
return report, response.Process(&report.Units)
|
|
}
|
|
|
|
func Kube(ctx context.Context, nameOrIDs []string, options entities.GenerateKubeOptions) (*entities.GenerateKubeReport, error) {
|
|
conn, err := bindings.GetClient(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(nameOrIDs) < 1 {
|
|
return nil, errors.New("must provide the name or ID of one container or pod")
|
|
}
|
|
params := url.Values{}
|
|
for _, name := range nameOrIDs {
|
|
params.Add("names", name)
|
|
}
|
|
params.Set("service", strconv.FormatBool(options.Service))
|
|
|
|
response, err := conn.DoRequest(nil, http.MethodGet, "/generate/kube", params, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if response.StatusCode == http.StatusOK {
|
|
return &entities.GenerateKubeReport{Reader: response.Body}, nil
|
|
}
|
|
|
|
// Unpack the error.
|
|
return nil, response.Process(nil)
|
|
}
|