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

zalando-incubator / stackset-controller / 20363014342

19 Dec 2025 07:25AM UTC coverage: 49.925% (-0.2%) from 50.085%
20363014342

Pull #721

github

mikkeloscar
Add --enable-forward-support flag

Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
Pull Request #721: Improve forward feature

19 of 37 new or added lines in 6 files covered. (51.35%)

2 existing lines in 1 file now uncovered.

2663 of 5334 relevant lines covered (49.93%)

0.56 hits per line

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

0.0
/cmd/stackset-controller/main.go
1
package main
2

3
import (
4
        "context"
5
        "net"
6
        "net/http"
7
        "net/url"
8
        "os"
9
        "os/signal"
10
        "syscall"
11
        "time"
12

13
        "github.com/alecthomas/kingpin/v2"
14
        "github.com/prometheus/client_golang/prometheus"
15
        "github.com/prometheus/client_golang/prometheus/promhttp"
16
        log "github.com/sirupsen/logrus"
17
        "github.com/zalando-incubator/stackset-controller/controller"
18
        "github.com/zalando-incubator/stackset-controller/pkg/clientset"
19
        "github.com/zalando-incubator/stackset-controller/pkg/traffic"
20
        corev1 "k8s.io/api/core/v1"
21
        "k8s.io/client-go/rest"
22
        "k8s.io/client-go/transport"
23
)
24

25
const (
26
        defaultInterval               = "10s"
27
        defaultIngressSourceSwitchTTL = "5m"
28
        defaultMetricsAddress         = ":7979"
29
        defaultClientGOTimeout        = 30 * time.Second
30
        defaultReconcileWorkers       = "10"
31
)
32

33
var (
34
        config struct {
35
                Debug                       bool
36
                Interval                    time.Duration
37
                APIServer                   *url.URL
38
                Namespace                   string
39
                MetricsAddress              string
40
                ClusterDomains              []string
41
                NoTrafficScaledownTTL       time.Duration
42
                ControllerID                string
43
                BackendWeightsAnnotationKey string
44
                RouteGroupSupportEnabled    bool
45
                SyncIngressAnnotations      []string
46
                ReconcileWorkers            int
47
                ConfigMapSupportEnabled     bool
48
                SecretSupportEnabled        bool
49
                PCSSupportEnabled           bool
50
                ForwardSupportEnabled       bool
51
        }
52
)
53

54
func main() {
×
55
        kingpin.Flag("debug", "Enable debug logging.").BoolVar(&config.Debug)
×
56
        kingpin.Flag("interval", "Interval between syncing stacksets.").
×
57
                Default(defaultInterval).DurationVar(&config.Interval)
×
58
        kingpin.Flag("apiserver", "API server url.").URLVar(&config.APIServer)
×
59
        kingpin.Flag("namespace", "Limit scope to a particular namespace.").Default(corev1.NamespaceAll).StringVar(&config.Namespace)
×
60
        kingpin.Flag("metrics-address", "defines where to serve metrics").Default(defaultMetricsAddress).StringVar(&config.MetricsAddress)
×
61
        kingpin.Flag("controller-id", "ID of the controller used to determine ownership of StackSet resources").StringVar(&config.ControllerID)
×
62
        kingpin.Flag("reconcile-workers", "The amount of stacksets to reconcile in parallel at a time.").
×
63
                Default(defaultReconcileWorkers).IntVar(&config.ReconcileWorkers)
×
64
        kingpin.Flag("backend-weights-key", "Backend weights annotation key the controller will use to set current traffic values").Default(traffic.DefaultBackendWeightsAnnotationKey).StringVar(&config.BackendWeightsAnnotationKey)
×
65
        kingpin.Flag("cluster-domain", "Main domains of the cluster, used for generating Stack Ingress hostnames").Envar("CLUSTER_DOMAIN").Required().StringsVar(&config.ClusterDomains)
×
66
        kingpin.Flag("enable-routegroup-support", "Enable support for RouteGroups on StackSets.").Default("false").BoolVar(&config.RouteGroupSupportEnabled)
×
67
        kingpin.Flag(
×
68
                "sync-ingress-annotation",
×
69
                "Ingress/RouteGroup annotation to propagate to all traffic segments.",
×
70
        ).StringsVar(&config.SyncIngressAnnotations)
×
71
        kingpin.Flag("enable-configmap-support", "Enable support for ConfigMaps on StackSets.").Default("false").BoolVar(&config.ConfigMapSupportEnabled)
×
72
        kingpin.Flag("enable-secret-support", "Enable support for Secrets on StackSets.").Default("false").BoolVar(&config.SecretSupportEnabled)
×
73
        kingpin.Flag("enable-pcs-support", "Enable support for PlatformCredentialsSet on StackSets.").Default("false").BoolVar(&config.PCSSupportEnabled)
×
74
        kingpin.Flag("enable-forward-support", "Enable support for skipper traffic forwarding.").Default("false").BoolVar(&config.ForwardSupportEnabled)
×
NEW
75
        kingpin.Parse()
×
76

×
77
        if config.Debug {
×
78
                log.SetLevel(log.DebugLevel)
×
79
        }
×
80

81
        stackSetConfig := controller.StackSetConfig{
×
82
                Namespace:    config.Namespace,
×
83
                ControllerID: config.ControllerID,
×
84

×
85
                ClusterDomains:              config.ClusterDomains,
×
86
                BackendWeightsAnnotationKey: config.BackendWeightsAnnotationKey,
×
87
                SyncIngressAnnotations:      config.SyncIngressAnnotations,
×
88

×
89
                ReconcileWorkers: config.ReconcileWorkers,
×
90
                Interval:         config.Interval,
×
91

×
92
                RouteGroupSupportEnabled: config.RouteGroupSupportEnabled,
×
93
                ConfigMapSupportEnabled:  config.ConfigMapSupportEnabled,
×
94
                SecretSupportEnabled:     config.SecretSupportEnabled,
×
95
                PcsSupportEnabled:        config.PCSSupportEnabled,
×
96
                ForwardSupportEnabled:    config.ForwardSupportEnabled,
×
NEW
97
        }
×
98

×
99
        ctx, cancel := context.WithCancel(context.Background())
×
100
        kubeConfig, err := configureKubeConfig(config.APIServer, defaultClientGOTimeout, ctx.Done())
×
101
        if err != nil {
×
102
                log.Fatalf("Failed to setup Kubernetes config: %v", err)
×
103
        }
×
104

105
        client, err := clientset.NewForConfig(kubeConfig)
×
106
        if err != nil {
×
107
                log.Fatalf("Failed to initialize Kubernetes client: %v", err)
×
108
        }
×
109

110
        controller, err := controller.NewStackSetController(
×
111
                client,
×
112
                prometheus.DefaultRegisterer,
×
113
                stackSetConfig,
×
114
        )
×
115
        if err != nil {
×
116
                log.Fatalf("Failed to create Stackset controller: %v", err)
×
117
        }
×
118

119
        go handleSigterm(cancel)
×
120
        go serveMetrics(config.MetricsAddress)
×
121
        err = controller.Run(ctx)
×
122
        if err != nil {
×
123
                cancel()
×
124
                log.Fatalf("Failed to run controller: %v", err)
×
125
        }
×
126
}
127

128
// handleSigterm handles SIGTERM signal sent to the process.
129
func handleSigterm(cancelFunc func()) {
×
130
        signals := make(chan os.Signal, 1)
×
131
        signal.Notify(signals, syscall.SIGTERM)
×
132
        <-signals
×
133
        log.Info("Received Term signal. Terminating...")
×
134
        cancelFunc()
×
135
}
×
136

137
// configureKubeConfig configures a kubeconfig.
138
func configureKubeConfig(apiServerURL *url.URL, timeout time.Duration, stopCh <-chan struct{}) (*rest.Config, error) {
×
139
        tr := &http.Transport{
×
140
                DialContext: (&net.Dialer{
×
141
                        Timeout:   timeout,
×
142
                        KeepAlive: 30 * time.Second,
×
143
                        DualStack: false, // K8s do not work well with IPv6
×
144
                }).DialContext,
×
145
                TLSHandshakeTimeout:   timeout,
×
146
                ResponseHeaderTimeout: 10 * time.Second,
×
147
                MaxIdleConns:          10,
×
148
                MaxIdleConnsPerHost:   2,
×
149
                IdleConnTimeout:       20 * time.Second,
×
150
        }
×
151

×
152
        // We need this to reliably fade on DNS change, which is right
×
153
        // now not fixed with IdleConnTimeout in the http.Transport.
×
154
        // https://github.com/golang/go/issues/23427
×
155
        go func(d time.Duration) {
×
156
                for {
×
157
                        select {
×
158
                        case <-time.After(d):
×
159
                                tr.CloseIdleConnections()
×
160
                        case <-stopCh:
×
161
                                return
×
162
                        }
163
                }
164
        }(20 * time.Second)
165

166
        if apiServerURL != nil {
×
167
                return &rest.Config{
×
168
                        Host:      apiServerURL.String(),
×
169
                        Timeout:   timeout,
×
170
                        Transport: tr,
×
171
                        QPS:       100.0,
×
172
                        Burst:     500,
×
173
                }, nil
×
174
        }
×
175

176
        config, err := rest.InClusterConfig()
×
177
        if err != nil {
×
178
                return nil, err
×
179
        }
×
180

181
        // patch TLS config
182
        restTransportConfig, err := config.TransportConfig()
×
183
        if err != nil {
×
184
                return nil, err
×
185
        }
×
186
        restTLSConfig, err := transport.TLSConfigFor(restTransportConfig)
×
187
        if err != nil {
×
188
                return nil, err
×
189
        }
×
190
        tr.TLSClientConfig = restTLSConfig
×
191

×
192
        config.Timeout = timeout
×
193
        config.Transport = tr
×
194
        config.QPS = 100.0
×
195
        config.Burst = 500
×
196
        // disable TLSClientConfig to make the custom Transport work
×
197
        config.TLSClientConfig = rest.TLSClientConfig{}
×
198
        return config, nil
×
199
}
200

201
// gather go metrics
202
func serveMetrics(address string) {
×
203
        http.Handle("/metrics", promhttp.Handler())
×
204
        log.Fatal(http.ListenAndServe(address, nil))
×
205
}
×
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