@@ -17,10 +17,13 @@ import (
17
17
)
18
18
19
19
var (
20
+ // DSNExec annotations
20
21
DeprecatedAnnotationDSNExecConfig = "infoblox.com/dsnexec-config-secret"
21
22
DeprecatedAnnotationRemoteDBDSN = "infoblox.com/remote-db-dsn-secret"
22
- DeprecatedAnnotationDBSecretPath = "infoblox.com/db-secret-path"
23
- DeprecatedAnnotationMessages = "persistance.atlas.infoblox.com/deprecation-messages"
23
+ // DBProxy annotations
24
+ DeprecatedAnnotationDBSecretPath = "infoblox.com/db-secret-path"
25
+
26
+ DeprecatedAnnotationMessages = "persistance.atlas.infoblox.com/deprecation-messages"
24
27
)
25
28
26
29
// +kubebuilder:webhook:path=/convert-deprecated-pod,mutating=true,failurePolicy=fail,groups="",resources=pods,verbs=create;update,versions=v1,name=podconversion.persistance.atlas.infoblox.com,sideEffects=None,timeoutSeconds=10,admissionReviewVersions=v1
@@ -94,10 +97,18 @@ func (p *podConverter) Handle(ctx context.Context, req admission.Request) admiss
94
97
}
95
98
96
99
// Check if any of the deprecated annotations are present
100
+ // dsnexec
97
101
dsnExecConfigSecret := pod .Annotations [DeprecatedAnnotationDSNExecConfig ]
98
102
remoteDBDSNSecret := pod .Annotations [DeprecatedAnnotationRemoteDBDSN ]
103
+ // dbproxy
99
104
dbSecretPath := pod .Annotations [DeprecatedAnnotationDBSecretPath ]
100
105
106
+ if pod .Labels [LabelCheckExec ] == "enabled" || pod .Labels [LabelCheckProxy ] == "enabled" {
107
+ // This would log on every pod creation in the cluster
108
+ // log.V(1).Info("Skipped conversion, already converted", "uid", req.UID)
109
+ return admission .Allowed ("Skipped conversion, already converted" )
110
+ }
111
+
101
112
if dsnExecConfigSecret == "" && remoteDBDSNSecret == "" && dbSecretPath == "" {
102
113
// This would log on every pod creation in the cluster
103
114
// log.V(1).Info("Skipped conversion, no deprecated annotations found", "uid", req.UID)
@@ -112,7 +123,7 @@ func (p *podConverter) Handle(ctx context.Context, req admission.Request) admiss
112
123
if err != nil {
113
124
return admission .Errored (http .StatusInternalServerError , err )
114
125
}
115
- log .Info ("converted_pod " )
126
+ log .Info ("deprecated_pod_annotations_found " )
116
127
return admission .PatchResponseFromRaw (req .Object .Raw , bs )
117
128
}
118
129
@@ -139,41 +150,45 @@ func convertPod(ctx context.Context, reader client.Reader, class string, pod *co
139
150
secretName = dbSecretPath
140
151
}
141
152
142
- log = log .WithValues ("secret" , secretName )
153
+ log = log .WithValues ("secret" , secretName ).WithValues ("annotations" , pod .Annotations ).WithValues ("labels" , pod .Labels )
154
+
155
+ log .Info ("converting_pod" )
143
156
144
157
// db-secret-path has a key in it, so remove the key
145
158
parts := strings .Split (secretName , "/" )
146
159
if len (parts ) > 1 {
147
160
secretName = parts [0 ]
148
161
}
149
162
150
- labelConfigExec := pod . Labels [ LabelConfigExec ]
151
- if labelConfigExec == "" && dsnExecConfigSecret != "" {
152
- pod . Labels [ LabelConfigExec ] = pod .Annotations [ DeprecatedAnnotationDSNExecConfig ]
153
- pod . Labels [ LabelCheckExec ] = "enabled"
154
- deprecationMsgs = append ( deprecationMsgs , fmt . Sprintf ( `Label "%s" replaces annotation "%s"` , LabelConfigExec , DeprecatedAnnotationDSNExecConfig ))
163
+ var claimName string
164
+ var err error
165
+ if claimName , err = getClaimName ( ctx , reader , pod .GetNamespace (), secretName ); err != nil {
166
+ log . Error ( err , "unable to find claim" )
167
+ return err
155
168
}
156
169
157
- // Process claims label
158
- if pod .Labels [LabelClaim ] == "" {
170
+ // dsnexec
171
+ if dsnExecConfigSecret != "" && remoteDBDSNSecret != "" {
172
+ pod .Labels [LabelClaim ] = claimName
173
+ pod .Labels [LabelClass ] = class
174
+ pod .Labels [LabelConfigExec ] = dsnExecConfigSecret
175
+ pod .Labels [LabelCheckExec ] = "enabled"
159
176
160
- if pod .Annotations [DeprecatedAnnotationRemoteDBDSN ] != "" {
161
- deprecationMsgs = append (deprecationMsgs , fmt .Sprintf (`Label "%s" replaces annotation "%s"` , LabelClaim , DeprecatedAnnotationRemoteDBDSN ))
162
- }
163
- if pod .Annotations [DeprecatedAnnotationDBSecretPath ] != "" {
164
- deprecationMsgs = append (deprecationMsgs , fmt .Sprintf (`Label "%s" replaces annotation "%s"` , LabelClaim , DeprecatedAnnotationDBSecretPath ))
165
- }
177
+ deprecationMsgs = append (deprecationMsgs , fmt .Sprintf (`Use label "%s", annotation "%s" is deprecated` , LabelConfigExec , DeprecatedAnnotationDSNExecConfig ))
166
178
167
- var claimName string
168
- var err error
169
- if claimName , err = getClaimName (ctx , reader , pod .GetNamespace (), secretName ); err != nil {
170
- log .Error (err , "unable to find claim" )
171
- return err
179
+ if pod .Annotations [DeprecatedAnnotationRemoteDBDSN ] != "" {
180
+ deprecationMsgs = append (deprecationMsgs , fmt .Sprintf (`Use label "%s", annotation "%s" is deprecated` , LabelClaim , DeprecatedAnnotationRemoteDBDSN ))
172
181
}
182
+ }
173
183
184
+ // dbproxy
185
+ if dbSecretPath != "" {
174
186
pod .Labels [LabelClaim ] = claimName
175
187
pod .Labels [LabelClass ] = class
176
188
pod .Labels [LabelCheckProxy ] = "enabled"
189
+
190
+ deprecationMsgs = append (deprecationMsgs , fmt .Sprintf (`Label "%s" replaces annotation "%s"` , LabelClaim , DeprecatedAnnotationDBSecretPath ))
191
+
177
192
}
178
193
179
194
// Remove deprecated annotations
0 commit comments