• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zalando / postgres-operator / 17069871161

19 Aug 2025 12:40PM UTC coverage: 42.059% (-3.4%) from 45.498%
17069871161

push

github

web-flow
upgrade Go from 1.23.4 to 1.25.0 (#2945)

* upgrade go to 1.25
* add minor version to be Go 1.25.0
* revert the Go version on README to keep the history of the release

5 of 9 new or added lines in 7 files covered. (55.56%)

531 existing lines in 13 files now uncovered.

6493 of 15438 relevant lines covered (42.06%)

15.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/pkg/cluster/exec.go
1
package cluster
2

3
import (
4
        "bytes"
5
        "context"
6
        "fmt"
7
        "strings"
8

9
        v1 "k8s.io/api/core/v1"
10
        metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
        "k8s.io/client-go/kubernetes/scheme"
12
        "k8s.io/client-go/tools/remotecommand"
13

14
        "github.com/zalando/postgres-operator/pkg/spec"
15
        "github.com/zalando/postgres-operator/pkg/util/constants"
16
)
17

18
// ExecCommand executes arbitrary command inside the pod
19
func (c *Cluster) ExecCommand(podName *spec.NamespacedName, command ...string) (string, error) {
×
20
        c.setProcessName("executing command %q", strings.Join(command, " "))
×
21

×
22
        var (
×
23
                execOut bytes.Buffer
×
24
                execErr bytes.Buffer
×
25
        )
×
26

×
27
        pod, err := c.KubeClient.Pods(podName.Namespace).Get(context.TODO(), podName.Name, metav1.GetOptions{})
×
28
        if err != nil {
×
29
                return "", fmt.Errorf("could not get pod info: %v", err)
×
30
        }
×
31

32
        // iterate through all containers looking for the one running PostgreSQL.
33
        targetContainer := -1
×
34
        for i, cr := range pod.Spec.Containers {
×
35
                if cr.Name == constants.PostgresContainerName {
×
36
                        targetContainer = i
×
37
                        break
×
38
                }
39
        }
40

41
        if targetContainer < 0 {
×
42
                return "", fmt.Errorf("could not find %s container to exec to", constants.PostgresContainerName)
×
43
        }
×
44

45
        req := c.KubeClient.RESTClient.Post().
×
46
                Resource("pods").
×
47
                Name(podName.Name).
×
48
                Namespace(podName.Namespace).
×
49
                SubResource("exec")
×
50
        req.VersionedParams(&v1.PodExecOptions{
×
51
                Container: pod.Spec.Containers[targetContainer].Name,
×
52
                Command:   command,
×
53
                Stdout:    true,
×
54
                Stderr:    true,
×
55
        }, scheme.ParameterCodec)
×
56

×
57
        exec, err := remotecommand.NewSPDYExecutor(c.RestConfig, "POST", req.URL())
×
58
        if err != nil {
×
59
                return "", fmt.Errorf("failed to init executor: %v", err)
×
60
        }
×
61

62
        err = exec.StreamWithContext(context.TODO(), remotecommand.StreamOptions{
×
63
                Stdout: &execOut,
×
64
                Stderr: &execErr,
×
65
                Tty:    false,
×
66
        })
×
67

×
68
        if err != nil {
×
69
                return "", fmt.Errorf("could not execute: %v", err)
×
70
        }
×
71

72
        if execErr.Len() > 0 {
×
73
                return "", fmt.Errorf("stderr: %v", execErr.String())
×
74
        }
×
75

76
        return execOut.String(), nil
×
77
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc