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

zalando-incubator / kube-ingress-aws-controller / 16516893494

25 Jul 2025 07:54AM UTC coverage: 71.184% (+0.3%) from 70.906%
16516893494

push

github

web-flow
Add worker type (#758)

Add worker struct to hold references to adapters, metrics and
configuration values and convert functions into its methods to avoid
using global variables and passing a lot of parameters around.

The only global variable still in use is `firstRun` ~hacked~ introduced
by #258

---------

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>

123 of 155 new or added lines in 3 files covered. (79.35%)

14 existing lines in 2 files now uncovered.

2831 of 3977 relevant lines covered (71.18%)

10.51 hits per line

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

41.19
/controller.go
1
package main
2

3
import (
4
        "context"
5
        "fmt"
6
        "os"
7
        "os/signal"
8
        "path"
9
        "strconv"
10
        "strings"
11
        "syscall"
12
        "time"
13

14
        kingpin "github.com/alecthomas/kingpin/v2"
15
        elbv2Types "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
16
        log "github.com/sirupsen/logrus"
17
        "github.com/zalando-incubator/kube-ingress-aws-controller/aws"
18
        "github.com/zalando-incubator/kube-ingress-aws-controller/certs"
19
        "github.com/zalando-incubator/kube-ingress-aws-controller/kubernetes"
20
)
21

22
const (
23
        defaultDisableSNISupport      = "false"
24
        defaultInstrumentedHttpClient = "false"
25
        defaultHTTPRedirectToHTTPS    = "false"
26
        defaultCertTTL                = "1h"
27
        customTagFilterEnvVarName     = "CUSTOM_FILTERS"
28
)
29

30
var (
31
        buildstamp                    = "Not set"
32
        githash                       = "Not set"
33
        version                       = "Not set"
34
        versionFlag                   bool
35
        apiServerBaseURL              string
36
        pollingInterval               time.Duration
37
        creationTimeout               time.Duration
38
        certPollingInterval           time.Duration
39
        healthCheckPath               string
40
        healthCheckPort               uint
41
        healthCheckInterval           time.Duration
42
        healthCheckTimeout            time.Duration
43
        albHealthyThresholdCount      uint
44
        albUnhealthyThresholdCount    uint
45
        nlbHealthyThresholdCount      uint
46
        targetPort                    uint
47
        albHTTPTargetPort             uint
48
        nlbHTTPTargetPort             uint
49
        targetHTTPS                   bool
50
        metricsAddress                string
51
        disableSNISupport             bool
52
        disableInstrumentedHttpClient bool
53
        certTTL                       time.Duration
54
        certFilterTag                 string
55
        stackTerminationProtection    bool
56
        additionalStackTags           = make(map[string]string)
57
        idleConnectionTimeout         time.Duration
58
        deregistrationDelayTimeout    time.Duration
59
        ingressClassFilters           string
60
        controllerID                  string
61
        clusterID                     string
62
        vpcID                         string
63
        clusterLocalDomain            string
64
        maxCertsPerALB                int
65
        sslPolicy                     string
66
        blacklistCertARNs             []string
67
        blacklistCertArnMap           map[string]bool
68
        ipAddressType                 string
69
        albLogsS3Bucket               string
70
        albLogsS3Prefix               string
71
        wafWebAclId                   string
72
        httpRedirectToHTTPS           bool
73
        debugFlag                     bool
74
        quietFlag                     bool
75
        firstRun                      bool = true
76
        cwAlarmConfigMap              string
77
        cwAlarmConfigMapLocation      *kubernetes.ResourceLocation
78
        loadBalancerType              string
79
        nlbZoneAffinity               string
80
        nlbCrossZone                  bool
81
        nlbHTTPEnabled                bool
82
        ingressAPIVersion             string
83
        internalDomains               []string
84
        targetAccessMode              string
85
        targetCNINamespace            string
86
        targetCNIPodLabelSelector     string
87
        denyInternalDomains           bool
88
        denyInternalRespBody          string
89
        denyInternalRespContentType   string
90
        denyInternalRespStatusCode    int
91
        defaultInternalDomains        = fmt.Sprintf("*%s", kubernetes.DefaultClusterLocalDomain)
92
)
93

94
func loadSettings() error {
1✔
95
        kingpin.Flag("version", "Print version and exit").Default("false").BoolVar(&versionFlag)
1✔
96
        kingpin.Flag("debug", "Enables debug logging level").Default("false").BoolVar(&debugFlag)
1✔
97
        kingpin.Flag("quiet", "Enables quiet logging").Default("false").BoolVar(&quietFlag)
1✔
98
        kingpin.Flag("api-server-base-url", "sets the kubernetes api server base url. If empty will try to use the configuration from the running cluster, else it will use InsecureConfig, that does not use encryption or authentication (use case to develop with kubectl proxy).").
1✔
99
                Envar("API_SERVER_BASE_URL").StringVar(&apiServerBaseURL)
1✔
100
        kingpin.Flag("polling-interval", "sets the polling interval for ingress resources. The flag accepts a value acceptable to time.ParseDuration").
1✔
101
                Envar("POLLING_INTERVAL").Default("30s").DurationVar(&pollingInterval)
1✔
102
        kingpin.Flag("creation-timeout", "sets the stack creation timeout. The flag accepts a value acceptable to time.ParseDuration. Should be >= 1min").
1✔
103
                Envar("CREATION_TIMEOUT").Default(aws.DefaultCreationTimeout.String()).DurationVar(&creationTimeout)
1✔
104
        kingpin.Flag("cert-polling-interval", "sets the polling interval for the certificates cache refresh. The flag accepts a value acceptable to time.ParseDuration").
1✔
105
                Envar("CERT_POLLING_INTERVAL").Default(aws.DefaultCertificateUpdateInterval.String()).DurationVar(&certPollingInterval)
1✔
106
        kingpin.Flag("disable-sni-support", "disables SNI support limiting the number of certificates per ALB to 1.").
1✔
107
                Default(defaultDisableSNISupport).BoolVar(&disableSNISupport)
1✔
108
        kingpin.Flag("disable-instrumented-http-client", "disables instrumented http client.").
1✔
109
                Default(defaultInstrumentedHttpClient).BoolVar(&disableInstrumentedHttpClient)
1✔
110
        kingpin.Flag("stack-termination-protection", "enables stack termination protection for the stacks managed by the controller.").
1✔
111
                Default("false").BoolVar(&stackTerminationProtection)
1✔
112
        kingpin.Flag("additional-stack-tags", "set additional custom tags on the Cloudformation Stacks managed by the controller.").
1✔
113
                StringMapVar(&additionalStackTags)
1✔
114
        kingpin.Flag("cert-ttl-timeout", "sets the timeout of how long a certificate is kept on an old ALB to be decommissioned.").
1✔
115
                Default(defaultCertTTL).DurationVar(&certTTL)
1✔
116

1✔
117
        kingpin.Flag("cert-filter-tag", "sets a tag so the ingress controller only consider ACM or IAM certificates that have this tag set when adding a certificate to a load balancer.").
1✔
118
                Default("").StringVar(&certFilterTag)
1✔
119
        kingpin.Flag("health-check-path", "sets the health check path for the created target groups").
1✔
120
                Default(aws.DefaultHealthCheckPath).StringVar(&healthCheckPath)
1✔
121
        kingpin.Flag("health-check-port", "sets the health check port for the created target groups").
1✔
122
                Default(strconv.FormatUint(aws.DefaultHealthCheckPort, 10)).UintVar(&healthCheckPort)
1✔
123
        kingpin.Flag("target-port", "sets the target port for the created target groups").
1✔
124
                Default(strconv.FormatUint(aws.DefaultTargetPort, 10)).UintVar(&targetPort)
1✔
125
        kingpin.Flag("alb-http-target-port", "Sets the target port for ALB HTTP listener different from --target-port.").
1✔
126
                UintVar(&albHTTPTargetPort)
1✔
127
        kingpin.Flag("nlb-http-target-port", "Sets the target port for NLB HTTP listener different from --target-port. Requires --nlb-http-enabled.").
1✔
128
                UintVar(&nlbHTTPTargetPort)
1✔
129
        kingpin.Flag("target-https", "sets the target protocol to https").
1✔
130
                Default("false").BoolVar(&targetHTTPS)
1✔
131
        kingpin.Flag("health-check-interval", "sets the health check interval for the created target groups. The flag accepts a value acceptable to time.ParseDuration").
1✔
132
                Default(aws.DefaultHealthCheckInterval.String()).DurationVar(&healthCheckInterval)
1✔
133
        kingpin.Flag("health-check-timeout", "sets the health check timeout for the created target groups. The flag accepts a value acceptable to time.ParseDuration").
1✔
134
                Default(aws.DefaultHealthCheckTimeout.String()).DurationVar(&healthCheckTimeout)
1✔
135
        kingpin.Flag("alb-healthy-threshold-count", "The number of consecutive successful health checks required before considering an unhealthy target healthy. The range is 2–10. (ALB only)").
1✔
136
                Default(strconv.FormatUint(aws.DefaultAlbHealthyThresholdCount, 10)).UintVar(&albHealthyThresholdCount)
1✔
137
        kingpin.Flag("alb-unhealthy-threshold-count", "The number of consecutive failed health checks required before considering a target unhealthy. The range is 2–10. (ALB only)").
1✔
138
                Default(strconv.FormatUint(aws.DefaultAlbUnhealthyThresholdCount, 10)).UintVar(&albUnhealthyThresholdCount)
1✔
139
        kingpin.Flag("nlb-healthy-threshold-count", "The number of consecutive successful or failed health checks required before considering a target healthy or unhealthy. The range is 2–10. (NLB only)").
1✔
140
                Default(strconv.FormatUint(aws.DefaultNlbHealthyThresholdCount, 10)).UintVar(&nlbHealthyThresholdCount)
1✔
141
        kingpin.Flag("idle-connection-timeout", "sets the idle connection timeout of all ALBs. The flag accepts a value acceptable to time.ParseDuration and are between 1s and 4000s.").
1✔
142
                Default(aws.DefaultIdleConnectionTimeout.String()).DurationVar(&idleConnectionTimeout)
1✔
143
        kingpin.Flag("deregistration-delay-timeout", "sets the deregistration delay timeout of all target groups.  The flag accepts a value acceptable to time.ParseDuration that is between 1s and 3600s.").
1✔
144
                Default(aws.DefaultDeregistrationTimeout.String()).DurationVar(&deregistrationDelayTimeout)
1✔
145
        kingpin.Flag("metrics-address", "defines where to serve metrics").Default(":7979").StringVar(&metricsAddress)
1✔
146
        kingpin.Flag("ingress-class-filter", "optional comma-seperated list of kubernetes.io/ingress.class annotation values to filter behaviour on.").
1✔
147
                StringVar(&ingressClassFilters)
1✔
148
        kingpin.Flag("controller-id", "controller ID used to differentiate resources from multiple aws ingress controller instances").
1✔
149
                Default(aws.DefaultControllerID).StringVar(&controllerID)
1✔
150
        kingpin.Flag("cluster-id", "ID of the Kubernetes cluster used to lookup cluster related resources tagged with `kubernetes.io/cluster/<cluster-id>` tags. Auto discovered from the EC2 instance where the controller is running if not specified.").
1✔
151
                StringVar(&clusterID)
1✔
152
        kingpin.Flag("vpc-id", "VPC ID for where the cluster is running. Used to lookup relevant subnets. Auto discovered from the EC2 instance where the controller is running if not specified.").
1✔
153
                StringVar(&vpcID)
1✔
154
        kingpin.Flag("cluster-local-domain", "Cluster local domain is used to detect hostnames, that won't trigger a creation of an AWS load balancer, empty string will not change the default behavior. In Kubernetes you might want to pass cluster.local").
1✔
155
                Default("").StringVar(&clusterLocalDomain)
1✔
156
        kingpin.Flag("max-certs-alb", fmt.Sprintf("sets the maximum number of certificates to be attached to an ALB. Cannot be higher than %d", aws.DefaultMaxCertsPerALB)).
1✔
157
                Default(strconv.Itoa(aws.DefaultMaxCertsPerALB)).IntVar(&maxCertsPerALB) // TODO: max
1✔
158
        kingpin.Flag("ssl-policy", "Security policy that will define the protocols/ciphers accepts by the SSL listener").
1✔
159
                Default(aws.DefaultSslPolicy).EnumVar(&sslPolicy, aws.SSLPoliciesList...)
1✔
160
        kingpin.Flag("blacklist-certificate-arns", "Certificate ARNs to not consider by the controller.").StringsVar(&blacklistCertARNs)
1✔
161
        kingpin.Flag("ip-addr-type", "IP Address type to use.").
1✔
162
                Default(aws.DefaultIpAddressType).EnumVar(&ipAddressType, aws.IPAddressTypeIPV4, aws.IPAddressTypeDualstack)
1✔
163
        kingpin.Flag("logs-s3-bucket", "S3 bucket to be used for ALB logging").
1✔
164
                Default(aws.DefaultAlbS3LogsBucket).StringVar(&albLogsS3Bucket)
1✔
165
        kingpin.Flag("logs-s3-prefix", "Prefix within S3 bucket to be used for ALB logging").
1✔
166
                Default(aws.DefaultAlbS3LogsPrefix).StringVar(&albLogsS3Prefix)
1✔
167
        kingpin.Flag("aws-waf-web-acl-id", "WAF web acl id to be associated with the ALB. For WAF v2 it is possible to specify the WebACL ARN arn:aws:wafv2:<region>:<account>:regional/webacl/<name>/<id>").
1✔
168
                Default("").StringVar(&wafWebAclId)
1✔
169
        kingpin.Flag("cloudwatch-alarms-config-map", "ConfigMap location of the form 'namespace/config-map-name' where to read CloudWatch Alarm configuration from. Ignored if empty.").
1✔
170
                StringVar(&cwAlarmConfigMap)
1✔
171
        kingpin.Flag("redirect-http-to-https", "Configure HTTP listener to redirect to HTTPS").
1✔
172
                Default(defaultHTTPRedirectToHTTPS).BoolVar(&httpRedirectToHTTPS)
1✔
173
        kingpin.Flag("load-balancer-type", "Sets default Load Balancer type (application or network).").
1✔
174
                Default(aws.LoadBalancerTypeApplication).EnumVar(&loadBalancerType, aws.LoadBalancerTypeApplication, aws.LoadBalancerTypeNetwork)
1✔
175
        kingpin.Flag("nlb-zone-affinity", "Specify whether Route53 should return zone aware Network Load Balancers IPs. It configures dns_record.client_routing_policy NLB configuration. This setting only apply to 'network' Load Balancers.").
1✔
176
                Default(aws.DefaultZoneAffinity).StringVar(&nlbZoneAffinity)
1✔
177
        kingpin.Flag("nlb-cross-zone", "Specify whether Network Load Balancers should balance cross availablity zones. This setting only apply to 'network' Load Balancers.").
1✔
178
                Default("false").BoolVar(&nlbCrossZone)
1✔
179
        kingpin.Flag("nlb-http-enabled", "Enable HTTP (port 80) for Network Load Balancers. By default this is disabled as NLB can't provide HTTP -> HTTPS redirect.").
1✔
180
                Default("false").BoolVar(&nlbHTTPEnabled)
1✔
181
        kingpin.Flag("deny-internal-domains", "Sets a rule on ALB's Listeners that denies requests with the Host header as a internal domain. Domains can be set with the -internal-domains flag.").
1✔
182
                Default("false").BoolVar(&denyInternalDomains)
1✔
183
        kingpin.Flag("internal-domains", "Define the internal domains to be blocked when -deny-internal-domains is set to true. Set it multiple times for multiple domains. The maximum size of each name is 128 characters. The following wildcard characters are supported: * (matches 0 or more characters) and ? (matches exactly 1 character).").
1✔
184
                Default(defaultInternalDomains).StringsVar(&internalDomains)
1✔
185
        kingpin.Flag("deny-internal-domains-response", "Defines the response body for a request identified as to an internal domain when -deny-internal-domains is set.").
1✔
186
                Default("Unauthorized").StringVar(&denyInternalRespBody)
1✔
187
        kingpin.Flag("deny-internal-domains-response-content-type", "Defines the response conten-type for a request identified as to an internal domain when -deny-internal-domains is set.").
1✔
188
                Default("text/plain").StringVar(&denyInternalRespContentType)
1✔
189
        kingpin.Flag("deny-internal-domains-response-status-code", "Defines the response status code for a request identified as to an internal domain when -deny-internal-domains is set.").
1✔
190
                Default("401").IntVar(&denyInternalRespStatusCode)
1✔
191
        kingpin.Flag("target-access-mode", "Defines target type of the target groups in CloudFormation and how loadbalancer targets are discovered. "+
1✔
192
                "HostPort sets target type to 'instance' and discovers EC2 instances using AWS API and instance filters. "+
1✔
193
                "AWSCNI sets target type to 'ip' and discovers target IPs using Kubernetes API and Pod label selector. "+
1✔
194
                "Legacy is the same as HostPort but does not set target type and relies on CloudFormation to use 'instance' as a default value. "+
1✔
195
                "Changing value from 'Legacy' to 'HostPort' will change target type in CloudFormation and trigger target group recreation and downtime.").
1✔
196
                Required().EnumVar(&targetAccessMode, aws.TargetAccessModeHostPort, aws.TargetAccessModeAWSCNI, aws.TargetAccessModeLegacy)
1✔
197
        kingpin.Flag("target-cni-namespace", "AWS VPC CNI only. Defines the namespace for ingress pods that should be linked to target group.").StringVar(&targetCNINamespace)
1✔
198
        // LabelSelector semantics https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
1✔
199
        kingpin.Flag("target-cni-pod-labelselector", "AWS VPC CNI only. Defines the labelselector for ingress pods that should be linked to target group. Supports simple equality and multi value form (a=x,b=y) as well as complex forms (a IN (x,y,z).").StringVar(&targetCNIPodLabelSelector)
1✔
200
        kingpin.Parse()
1✔
201

1✔
202
        // We currently only support one Ingress API Version
1✔
203
        ingressAPIVersion = kubernetes.IngressAPIVersionNetworking
1✔
204

1✔
205
        blacklistCertArnMap = make(map[string]bool)
1✔
206
        for _, s := range blacklistCertARNs {
1✔
207
                blacklistCertArnMap[s] = true
×
208
        }
×
209

210
        if targetAccessMode == aws.TargetAccessModeAWSCNI {
1✔
211
                if targetCNINamespace == "" {
×
212
                        return fmt.Errorf("target-cni-namespace is required when target-access-mode is set to %s", aws.TargetAccessModeAWSCNI)
×
213
                }
×
214
                // complex selector formats possible, late validation by the k8s client
215
                if targetCNIPodLabelSelector == "" {
×
216
                        return fmt.Errorf("target-cni-pod-labelselector definition cannot be empty when target-access-mode is set to %s", aws.TargetAccessModeAWSCNI)
×
217
                }
×
218
        }
219

220
        if creationTimeout < 1*time.Minute {
1✔
221
                return fmt.Errorf("invalid creation timeout %d. please specify a value > 1min", creationTimeout)
×
222
        }
×
223

224
        if healthCheckPort == 0 || healthCheckPort > 65535 {
1✔
225
                return fmt.Errorf("invalid health check port: %d. please use a valid TCP port", healthCheckPort)
×
226
        }
×
227

228
        for _, v := range []uint{albHealthyThresholdCount, albUnhealthyThresholdCount, nlbHealthyThresholdCount} {
4✔
229
                if v < 2 || v > 10 {
3✔
230
                        return fmt.Errorf("invalid (un)healthy threshold: %d. must be between 2 and 10", v)
×
231
                }
×
232
        }
233

234
        if targetPort == 0 || targetPort > 65535 {
1✔
235
                return fmt.Errorf("invalid target port: %d. please use a valid TCP port", targetPort)
×
236
        }
×
237

238
        if albHTTPTargetPort > 65535 { // default 0
1✔
239
                return fmt.Errorf("invalid ALB HTTP target port: %d. please use a valid TCP port", albHTTPTargetPort)
×
240
        }
×
241

242
        if nlbHTTPTargetPort > 65535 { // default 0
1✔
243
                return fmt.Errorf("invalid NLB HTTP target port: %d. please use a valid TCP port", nlbHTTPTargetPort)
×
244
        }
×
245

246
        if nlbHTTPTargetPort > 0 && !nlbHTTPEnabled {
1✔
247
                return fmt.Errorf("NLB HTTP is not enabled")
×
248
        }
×
249

250
        if maxCertsPerALB > aws.DefaultMaxCertsPerALB {
1✔
251
                return fmt.Errorf("invalid max number of certificates per ALB: %d. AWS does not allow more than %d", maxCertsPerALB, aws.DefaultMaxCertsPerALB)
×
252
        }
×
253

254
        if cwAlarmConfigMap != "" {
1✔
255
                loc, err := kubernetes.ParseResourceLocation(cwAlarmConfigMap)
×
256
                if err != nil {
×
257
                        return fmt.Errorf("failed to parse cloudwatch alarm config map location: %w", err)
×
258
                }
×
259

260
                cwAlarmConfigMapLocation = loc
×
261
        }
262

263
        if kv := strings.Split(certFilterTag, "="); len(kv) != 2 && certFilterTag != "" {
1✔
264
                log.Errorf("Certificate filter tag should be in the format \"key=value\", instead it is set to: %s", certFilterTag)
×
265
        }
×
266

267
        if quietFlag && debugFlag {
1✔
268
                log.Warn("--quiet and --debug flags are both set. Debug will be used as logging level.")
×
269
        }
×
270

271
        if quietFlag {
1✔
272
                log.SetLevel(log.WarnLevel)
×
273
        }
×
274

275
        if debugFlag {
1✔
276
                log.SetLevel(log.DebugLevel)
×
277
        }
×
278

279
        log.SetOutput(os.Stdout)
1✔
280

1✔
281
        return nil
1✔
282
}
283

284
func main() {
×
285
        log.Infof("Starting %s %s", os.Args[0], version)
×
286
        var (
×
287
                awsAdapter  *aws.Adapter
×
288
                kubeAdapter *kubernetes.Adapter
×
289
                kubeConfig  *kubernetes.Config
×
290
                err         error
×
291
        )
×
292
        if err = loadSettings(); err != nil {
×
293
                log.Fatal(err)
×
294
        }
×
295

296
        if versionFlag {
×
297
                log.Infof(`%s
×
298
===========================
×
299
  Version: %s
×
300
  Buildtime: %s
×
301
  GitHash: %s
×
302
`, path.Base(os.Args[0]), version, buildstamp, githash)
×
303
                os.Exit(0)
×
304
        }
×
305
        ctx, cancel := context.WithCancel(context.Background())
×
306
        defer cancel()
×
307
        log.Debug("aws.NewAdapter")
×
308
        awsAdapter, err = aws.NewAdapter(ctx, clusterID, controllerID, vpcID, debugFlag, disableInstrumentedHttpClient)
×
309
        if err != nil {
×
310
                log.Fatal(err)
×
311
        }
×
312

313
        customFilter, ok := os.LookupEnv(customTagFilterEnvVarName)
×
314
        if !ok {
×
315
                customFilter = ""
×
316
        }
×
317

318
        awsAdapter = awsAdapter.
×
319
                WithHealthCheckPath(healthCheckPath).
×
320
                WithHealthCheckPort(healthCheckPort).
×
321
                WithHealthCheckInterval(healthCheckInterval).
×
322
                WithHealthCheckTimeout(healthCheckTimeout).
×
323
                WithAlbHealthyThresholdCount(albHealthyThresholdCount).
×
324
                WithAlbUnhealthyThresholdCount(albUnhealthyThresholdCount).
×
325
                WithNlbHealthyThresholdCount(nlbHealthyThresholdCount).
×
326
                WithTargetPort(targetPort).
×
327
                WithALBHTTPTargetPort(albHTTPTargetPort).
×
328
                WithNLBHTTPTargetPort(nlbHTTPTargetPort).
×
329
                WithTargetHTTPS(targetHTTPS).
×
330
                WithCreationTimeout(creationTimeout).
×
331
                WithStackTerminationProtection(stackTerminationProtection).
×
332
                WithIdleConnectionTimeout(idleConnectionTimeout).
×
333
                WithDeregistrationDelayTimeout(deregistrationDelayTimeout).
×
334
                WithControllerID(controllerID).
×
335
                WithSslPolicy(sslPolicy).
×
336
                WithIpAddressType(ipAddressType).
×
337
                WithAlbLogsS3Bucket(albLogsS3Bucket).
×
338
                WithAlbLogsS3Prefix(albLogsS3Prefix).
×
339
                WithHTTPRedirectToHTTPS(httpRedirectToHTTPS).
×
340
                WithNLBCrossZone(nlbCrossZone).
×
341
                WithNLBZoneAffinity(nlbZoneAffinity).
×
342
                WithNLBHTTPEnabled(nlbHTTPEnabled).
×
343
                WithCustomFilter(customFilter).
×
344
                WithStackTags(additionalStackTags).
×
345
                WithInternalDomains(internalDomains).
×
346
                WithDenyInternalDomains(denyInternalDomains).
×
347
                WithInternalDomainsDenyResponse(denyInternalRespBody).
×
348
                WithInternalDomainsDenyResponseStatusCode(denyInternalRespStatusCode).
×
349
                WithInternalDomainsDenyResponseContenType(denyInternalRespContentType).
×
350
                WithTargetAccessMode(targetAccessMode)
×
351

×
352
        log.Debug("certs.NewCachingProvider")
×
353
        certificatesProvider, err := certs.NewCachingProvider(
×
354
                ctx,
×
355
                certPollingInterval,
×
356
                blacklistCertArnMap,
×
357
                awsAdapter.NewACMCertificateProvider(certFilterTag),
×
358
                awsAdapter.NewIAMCertificateProvider(certFilterTag),
×
359
        )
×
360
        if err != nil {
×
361
                log.Fatal(err)
×
362
        }
×
363

364
        if apiServerBaseURL == "" {
×
365
                log.Debug("kubernetes.InClusterConfig")
×
366
                kubeConfig, err = kubernetes.InClusterConfig()
×
367
                if err != nil {
×
368
                        log.Fatal(err)
×
369
                }
×
370
        } else {
×
371
                log.Debug("kubernetes.InsecureConfig")
×
372
                kubeConfig = kubernetes.InsecureConfig(apiServerBaseURL)
×
373
        }
×
374

375
        ingressClassFiltersList := []string{}
×
376
        if ingressClassFilters != "" {
×
377
                ingressClassFiltersList = strings.Split(ingressClassFilters, ",")
×
378
        }
×
379

380
        log.Debug("kubernetes.NewAdapter")
×
381
        kubeAdapter, err = kubernetes.NewAdapter(kubeConfig, ingressAPIVersion, ingressClassFiltersList, awsAdapter.SecurityGroupID(), sslPolicy, loadBalancerType, clusterLocalDomain, disableInstrumentedHttpClient)
×
382
        if err != nil {
×
383
                log.Fatal(err)
×
384
        }
×
385
        if targetAccessMode == aws.TargetAccessModeAWSCNI {
×
386
                if err = kubeAdapter.NewInclusterConfigClientset(ctx); err != nil {
×
387
                        log.Fatal(err)
×
388
                }
×
389
                kubeAdapter.WithTargetCNIPodSelector(targetCNINamespace, targetCNIPodLabelSelector)
×
390
        }
391

392
        certificatesPerALB := maxCertsPerALB
×
393
        if disableSNISupport {
×
394
                certificatesPerALB = 1
×
395
        }
×
396

397
        log.Infof("Kubernetes API server: %s", apiServerBaseURL)
×
398
        log.Infof("Cluster ID: %s", awsAdapter.ClusterID())
×
399
        log.Infof("VPC ID: %s", awsAdapter.VpcID())
×
400
        log.Infof("Instance ID: %s", awsAdapter.InstanceID())
×
401
        log.Infof("Security group ID: %s", awsAdapter.SecurityGroupID())
×
402
        log.Infof("Internal subnet IDs: %s", awsAdapter.FindLBSubnets(string(elbv2Types.LoadBalancerSchemeEnumInternal)))
×
403
        log.Infof("Public subnet IDs: %s", awsAdapter.FindLBSubnets(string(elbv2Types.LoadBalancerSchemeEnumInternetFacing)))
×
404
        log.Infof("EC2 filters: %s", awsAdapter.FiltersString())
×
405
        log.Infof("Certificates per ALB: %d (SNI: %t)", certificatesPerALB, certificatesPerALB > 1)
×
406
        log.Infof("Blacklisted Certificate ARNs (%d): %s", len(blacklistCertARNs), strings.Join(blacklistCertARNs, ","))
×
407
        log.Infof("Ingress class filters: %s", kubeAdapter.IngressFiltersString())
×
408
        log.Infof("ALB Logging S3 Bucket: %s", awsAdapter.S3Bucket())
×
409
        log.Infof("ALB Logging S3 Prefix: %s", awsAdapter.S3Prefix())
×
410
        log.Infof("CloudWatch Alarm ConfigMap: %s", cwAlarmConfigMapLocation)
×
411
        log.Infof("Default LoadBalancer type: %s", loadBalancerType)
×
412
        log.Infof("Target access mode: %s", targetAccessMode)
×
413
        log.Infof("NLB Cross Zone: %t", nlbCrossZone)
×
414
        log.Infof("NLB Zone Affinity: %s", nlbZoneAffinity)
×
415

×
NEW
416
        metrics := newMetrics()
×
NEW
417

×
418
        go handleTerminationSignals(cancel, syscall.SIGTERM, syscall.SIGQUIT)
×
NEW
419
        go metrics.serve(metricsAddress)
×
420
        if awsAdapter.TargetCNI.Enabled {
×
421
                go cniEventHandler(ctx, awsAdapter.TargetCNI, awsAdapter.SetTargetsOnCNITargetGroups, kubeAdapter.PodInformer)
×
422
        }
×
423

NEW
424
        w := &worker{
×
NEW
425
                awsAdapter:    awsAdapter,
×
NEW
426
                kubeAdapter:   kubeAdapter,
×
NEW
427
                metrics:       metrics,
×
NEW
428
                certsProvider: certificatesProvider,
×
NEW
429
                certsPerALB:   certificatesPerALB,
×
NEW
430
                certTTL:       certTTL,
×
NEW
431
                globalWAFACL:  wafWebAclId,
×
NEW
432
                cwAlarmConfig: cwAlarmConfigMapLocation,
×
NEW
433
        }
×
NEW
434

×
NEW
435
        w.startPolling(ctx, pollingInterval)
×
436

×
437
        log.Infof("Terminating %s", os.Args[0])
×
438
}
439

440
func handleTerminationSignals(cancelFunc func(), signals ...os.Signal) {
×
441
        sigsc := make(chan os.Signal, 1)
×
442
        signal.Notify(sigsc, signals...)
×
443
        <-sigsc
×
444
        cancelFunc()
×
445
}
×
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

© 2026 Coveralls, Inc