@@ -32,17 +32,18 @@ var (
32
32
33
33
// InjectionConfig is a specific instance of a injected config, for a given annotation
34
34
type InjectionConfig struct {
35
- Name string `json:"name"`
36
- Inherits string `json:"inherits"`
37
- Containers []corev1.Container `json:"containers"`
38
- Volumes []corev1.Volume `json:"volumes"`
39
- Environment []corev1.EnvVar `json:"env"`
40
- VolumeMounts []corev1.VolumeMount `json:"volumeMounts"`
41
- HostAliases []corev1.HostAlias `json:"hostAliases"`
42
- HostNetwork bool `json:"hostNetwork"`
43
- HostPID bool `json:"hostPID"`
44
- InitContainers []corev1.Container `json:"initContainers"`
45
- ServiceAccountName string `json:"serviceAccountName"`
35
+ Name string `json:"name"`
36
+ Inherits string `json:"inherits"`
37
+ Containers []corev1.Container `json:"containers"`
38
+ Volumes []corev1.Volume `json:"volumes"`
39
+ Environment []corev1.EnvVar `json:"env"`
40
+ VolumeMounts []corev1.VolumeMount `json:"volumeMounts"`
41
+ HostAliases []corev1.HostAlias `json:"hostAliases"`
42
+ HostNetwork bool `json:"hostNetwork"`
43
+ HostPID bool `json:"hostPID"`
44
+ InitContainers []corev1.Container `json:"initContainers"`
45
+ ServiceAccountName string `json:"serviceAccountName"`
46
+ PrependedContainers []corev1.Container `json:"prependedContainers"`
46
47
47
48
version string
48
49
}
@@ -68,7 +69,7 @@ func (c *InjectionConfig) String() string {
68
69
return fmt .Sprintf ("%s%s: %d containers, %d init containers, %d volumes, %d environment vars, %d volume mounts, %d host aliases%s" ,
69
70
c .FullName (),
70
71
inheritsString ,
71
- len (c .Containers ),
72
+ len (c .Containers )+ len ( c . PrependedContainers ) ,
72
73
len (c .InitContainers ),
73
74
len (c .Volumes ),
74
75
len (c .Environment ),
@@ -272,6 +273,22 @@ func (c *InjectionConfig) Merge(child *InjectionConfig) error {
272
273
}
273
274
}
274
275
276
+ // merge prepended containers
277
+ for _ , cv := range child .PrependedContainers {
278
+ contains := false
279
+
280
+ for bi , bv := range base .PrependedContainers {
281
+ if bv .Name == cv .Name {
282
+ contains = true
283
+ base .PrependedContainers [bi ] = cv
284
+ }
285
+ }
286
+
287
+ if ! contains {
288
+ base .PrependedContainers = append (base .PrependedContainers , cv )
289
+ }
290
+ }
291
+
275
292
// merge serviceAccount settings to the left
276
293
if child .ServiceAccountName != "" {
277
294
c .ServiceAccountName = child .ServiceAccountName
0 commit comments