@@ -3,6 +3,7 @@ package config
3
3
import (
4
4
"github.com/pkg/errors"
5
5
"github.com/spf13/pflag"
6
+ "k8s.io/apimachinery/pkg/util/sets"
6
7
"sigs.k8s.io/aws-load-balancer-controller/pkg/aws"
7
8
"sigs.k8s.io/aws-load-balancer-controller/pkg/inject"
8
9
)
@@ -11,6 +12,7 @@ const (
11
12
flagLogLevel = "log-level"
12
13
flagK8sClusterName = "cluster-name"
13
14
flagDefaultTags = "default-tags"
15
+ flagExternalManagedTags = "external-managed-tags"
14
16
flagServiceMaxConcurrentReconciles = "service-max-concurrent-reconciles"
15
17
flagTargetGroupBindingMaxConcurrentReconciles = "targetgroupbinding-max-concurrent-reconciles"
16
18
flagDefaultSSLPolicy = "default-ssl-policy"
@@ -19,6 +21,16 @@ const (
19
21
defaultSSLPolicy = "ELBSecurityPolicy-2016-08"
20
22
)
21
23
24
+ var (
25
+ trackingTagKeys = sets .NewString (
26
+ "elbv2.k8s.aws/cluster" ,
27
+ "ingress.k8s.aws/stack" ,
28
+ "ingress.k8s.aws/resource" ,
29
+ "service.k8s.aws/stack" ,
30
+ "service.k8s.aws/resource" ,
31
+ )
32
+ )
33
+
22
34
// ControllerConfig contains the controller configuration
23
35
type ControllerConfig struct {
24
36
// Log level for the controller logs
@@ -39,6 +51,9 @@ type ControllerConfig struct {
39
51
// Default AWS Tags that will be applied to all AWS resources managed by this controller.
40
52
DefaultTags map [string ]string
41
53
54
+ // List of Tag keys on AWS resources that will be managed externally.
55
+ ExternalManagedTags []string
56
+
42
57
// Default SSL Policy that will be applied to all ingresses or services that do not have
43
58
// the SSL Policy annotation.
44
59
DefaultSSLPolicy string
@@ -56,6 +71,8 @@ func (cfg *ControllerConfig) BindFlags(fs *pflag.FlagSet) {
56
71
fs .StringVar (& cfg .ClusterName , flagK8sClusterName , "" , "Kubernetes cluster name" )
57
72
fs .StringToStringVar (& cfg .DefaultTags , flagDefaultTags , nil ,
58
73
"Default AWS Tags that will be applied to all AWS resources managed by this controller" )
74
+ fs .StringSliceVar (& cfg .ExternalManagedTags , flagExternalManagedTags , nil ,
75
+ "List of Tag keys on AWS resources that will be managed externally" )
59
76
fs .IntVar (& cfg .ServiceMaxConcurrentReconciles , flagServiceMaxConcurrentReconciles , defaultMaxConcurrentReconciles ,
60
77
"Maximum number of concurrently running reconcile loops for service" )
61
78
fs .IntVar (& cfg .TargetGroupBindingMaxConcurrentReconciles , flagTargetGroupBindingMaxConcurrentReconciles , defaultMaxConcurrentReconciles ,
@@ -76,5 +93,43 @@ func (cfg *ControllerConfig) Validate() error {
76
93
if len (cfg .ClusterName ) == 0 {
77
94
return errors .New ("kubernetes cluster name must be specified" )
78
95
}
96
+
97
+ if err := cfg .validateDefaultTagsCollisionWithTrackingTags (); err != nil {
98
+ return err
99
+ }
100
+ if err := cfg .validateExternalManagedTagsCollisionWithTrackingTags (); err != nil {
101
+ return err
102
+ }
103
+ if err := cfg .validateExternalManagedTagsCollisionWithDefaultTags (); err != nil {
104
+ return err
105
+ }
106
+ return nil
107
+ }
108
+
109
+ func (cfg * ControllerConfig ) validateDefaultTagsCollisionWithTrackingTags () error {
110
+ for tagKey := range cfg .DefaultTags {
111
+ if trackingTagKeys .Has (tagKey ) {
112
+ return errors .Errorf ("tag key %v cannot be specified in %v flag" , tagKey , flagDefaultTags )
113
+ }
114
+ }
115
+ return nil
116
+ }
117
+
118
+ func (cfg * ControllerConfig ) validateExternalManagedTagsCollisionWithTrackingTags () error {
119
+ for _ , tagKey := range cfg .ExternalManagedTags {
120
+ if trackingTagKeys .Has (tagKey ) {
121
+ return errors .Errorf ("tag key %v cannot be specified in %v flag" , tagKey , flagExternalManagedTags )
122
+ }
123
+ }
124
+ return nil
125
+ }
126
+
127
+ func (cfg * ControllerConfig ) validateExternalManagedTagsCollisionWithDefaultTags () error {
128
+ for _ , tagKey := range cfg .ExternalManagedTags {
129
+ if _ , ok := cfg .DefaultTags [tagKey ]; ok {
130
+ return errors .Errorf ("tag key %v cannot be specified in both %v and %v flag" ,
131
+ tagKey , flagDefaultTags , flagExternalManagedTags )
132
+ }
133
+ }
79
134
return nil
80
135
}
0 commit comments