Files
podman/pkg/bindings/containers/update.go
Jan Rodák a1249425bd Configure HealthCheck with podman update
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>
2024-11-19 19:44:14 +01:00

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)
}