1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-18 21:09:40 +02:00
portainer/pkg/libkubectl/restart.go

39 lines
945 B
Go

package libkubectl
import (
"bytes"
"context"
"fmt"
"k8s.io/kubectl/pkg/cmd/rollout"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
)
func (c *Client) RolloutRestart(ctx context.Context, manifests []string) (string, error) {
buf := new(bytes.Buffer)
var fatalErr error
cmdutil.BehaviorOnFatal(func(msg string, code int) {
fatalErr = newKubectlFatalError(code, msg)
})
defer cmdutil.DefaultBehaviorOnFatal()
cmd := rollout.NewCmdRollout(c.factory, c.streams)
args := []string{"restart"}
args = append(args, resourcesToArgs(manifests)...)
cmd.SetArgs(args)
cmd.SetOut(buf)
err := cmd.ExecuteContext(ctx)
// check for the fatal error first so we don't return the error from the command execution
if fatalErr != nil {
return "", fatalErr
}
// if there is no fatal error, return the error from the command execution
if err != nil {
return "", fmt.Errorf("error restarting resources: %w", err)
}
return buf.String(), nil
}