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

zalando / postgres-operator / 11628064950

01 Nov 2024 10:36AM UTC coverage: 44.798% (-0.02%) from 44.813%
11628064950

Pull #2667

github

web-flow
Merge 464fbc182 into 8231797ef
Pull Request #2667: Add abitility to set QPS and Burst limits for api client

0 of 5 new or added lines in 1 file covered. (0.0%)

6739 of 15043 relevant lines covered (44.8%)

26.88 hits per line

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

0.0
/cmd/main.go
1
package main
2

3
import (
4
        "flag"
5
        "os"
6
        "os/signal"
7
        "sync"
8
        "syscall"
9
        "time"
10

11
        log "github.com/sirupsen/logrus"
12

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

18
var (
19
        kubeConfigFile string
20
        outOfCluster   bool
21
        version        string
22
        config         spec.ControllerConfig
23
)
24

25
func mustParseDuration(d string) time.Duration {
×
26
        duration, err := time.ParseDuration(d)
×
27
        if err != nil {
×
28
                panic(err)
×
29
        }
30
        return duration
×
31
}
32

33
func init() {
×
34
        flag.StringVar(&kubeConfigFile, "kubeconfig", "", "Path to kubeconfig file with authorization and master location information.")
×
35
        flag.BoolVar(&outOfCluster, "outofcluster", false, "Whether the operator runs in- our outside of the Kubernetes cluster.")
×
36
        flag.BoolVar(&config.NoDatabaseAccess, "nodatabaseaccess", false, "Disable all access to the database from the operator side.")
×
37
        flag.BoolVar(&config.NoTeamsAPI, "noteamsapi", false, "Disable all access to the teams API")
×
NEW
38
        flag.IntVar(&config.KubeQPS, "kubeqps", 5, "Kubernetes api requests per second.")
×
NEW
39
        flag.IntVar(&config.KubeBurst, "kubeburst", 10, "Kubernetes api requests burst limit.")
×
40
        flag.Parse()
×
41

×
42
        config.EnableJsonLogging = os.Getenv("ENABLE_JSON_LOGGING") == "true"
×
43

×
44
        configMapRawName := os.Getenv("CONFIG_MAP_NAME")
×
45
        if configMapRawName != "" {
×
46

×
47
                err := config.ConfigMapName.Decode(configMapRawName)
×
48
                if err != nil {
×
49
                        log.Fatalf("incorrect config map name: %v", configMapRawName)
×
50
                }
×
51

52
                log.Printf("Fully qualified configmap name: %v", config.ConfigMapName)
×
53

54
        }
55
        if crdInterval := os.Getenv("CRD_READY_WAIT_INTERVAL"); crdInterval != "" {
×
56
                config.CRDReadyWaitInterval = mustParseDuration(crdInterval)
×
57
        } else {
×
58
                config.CRDReadyWaitInterval = 4 * time.Second
×
59
        }
×
60

61
        if crdTimeout := os.Getenv("CRD_READY_WAIT_TIMEOUT"); crdTimeout != "" {
×
62
                config.CRDReadyWaitTimeout = mustParseDuration(crdTimeout)
×
63
        } else {
×
64
                config.CRDReadyWaitTimeout = 30 * time.Second
×
65
        }
×
66
}
67

68
func main() {
×
69
        var err error
×
70

×
71
        if config.EnableJsonLogging {
×
72
                log.SetFormatter(&log.JSONFormatter{})
×
73
        }
×
74
        log.SetOutput(os.Stdout)
×
75
        log.Printf("Spilo operator %s\n", version)
×
76

×
77
        sigs := make(chan os.Signal, 1)
×
78
        stop := make(chan struct{})
×
79
        signal.Notify(sigs, os.Interrupt, syscall.SIGTERM) // Push signals into channel
×
80

×
81
        wg := &sync.WaitGroup{} // Goroutines can add themselves to this to be waited on
×
82

×
83
        config.RestConfig, err = k8sutil.RestConfig(kubeConfigFile, outOfCluster)
×
84
        if err != nil {
×
85
                log.Fatalf("couldn't get REST config: %v", err)
×
86
        }
×
87

NEW
88
        config.RestConfig.QPS = float32(config.KubeQPS)
×
NEW
89
        config.RestConfig.Burst = config.KubeBurst
×
NEW
90

×
91
        c := controller.NewController(&config, "")
×
92

×
93
        c.Run(stop, wg)
×
94

×
95
        sig := <-sigs
×
96
        log.Printf("Shutting down... %+v", sig)
×
97

×
98
        close(stop) // Tell goroutines to stop themselves
×
99
        wg.Wait()   // Wait for all to be stopped
×
100
}
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