mirror of
https://github.com/containers/podman.git
synced 2025-12-05 12:52:12 +08:00
New flags in a `podman update` can change the configuration of HealthCheck when the container is started, without having to restart or recreate the container. This can help determine why a given container suddenly started failing HealthCheck without interfering with the services it provides. For example, reconfigure HealthCheck to keep logs longer than the usual last X results, store logs to other destinations, etc. Fixes: https://issues.redhat.com/browse/RHEL-60561 Signed-off-by: Jan Rodák <hony.com@seznam.cz>
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package containers
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/containers/podman/v5/pkg/api/handlers"
|
|
"github.com/containers/podman/v5/pkg/bindings"
|
|
"github.com/containers/podman/v5/pkg/domain/entities/types"
|
|
jsoniter "github.com/json-iterator/go"
|
|
)
|
|
|
|
func Update(ctx context.Context, options *types.ContainerUpdateOptions) (string, error) {
|
|
conn, err := bindings.GetClient(ctx)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
params := url.Values{}
|
|
if options.Specgen.RestartPolicy != "" {
|
|
params.Set("restartPolicy", options.Specgen.RestartPolicy)
|
|
if options.Specgen.RestartRetries != nil {
|
|
params.Set("restartRetries", strconv.Itoa(int(*options.Specgen.RestartRetries)))
|
|
}
|
|
}
|
|
updateEntities := &handlers.UpdateEntities{
|
|
LinuxResources: *options.Specgen.ResourceLimits,
|
|
UpdateHealthCheckConfig: *options.ChangedHealthCheckConfiguration,
|
|
}
|
|
requestData, err := jsoniter.MarshalToString(updateEntities)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
stringReader := strings.NewReader(requestData)
|
|
response, err := conn.DoRequest(ctx, stringReader, http.MethodPost, "/containers/%s/update", params, nil, options.NameOrID)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer response.Body.Close()
|
|
|
|
return options.NameOrID, response.Process(nil)
|
|
}
|