@@ -80,26 +80,33 @@ func (b BuildDefaults) applyPodDefaults(pod *v1.Pod) {
80
80
81
81
// Apply default resources
82
82
defaultResources := b .config .Resources
83
+ allContainers := make ([]* v1.Container , 0 , len (pod .Spec .Containers )+ len (pod .Spec .InitContainers ))
83
84
for i := range pod .Spec .Containers {
84
- podEnv := & pod .Spec .Containers [i ].Env
85
- util .MergeTrustedEnvWithoutDuplicates (util .CopyApiEnvVarToV1EnvVar (b .config .Env ), podEnv , false )
85
+ allContainers = append (allContainers , & pod .Spec .Containers [i ])
86
+ }
87
+ for i := range pod .Spec .InitContainers {
88
+ allContainers = append (allContainers , & pod .Spec .InitContainers [i ])
89
+ }
90
+
91
+ for _ , c := range allContainers {
92
+ util .MergeTrustedEnvWithoutDuplicates (util .CopyApiEnvVarToV1EnvVar (b .config .Env ), & c .Env , false )
86
93
87
- if pod . Spec . Containers [ i ] .Resources .Limits == nil {
88
- pod . Spec . Containers [ i ] .Resources .Limits = v1.ResourceList {}
94
+ if c .Resources .Limits == nil {
95
+ c .Resources .Limits = v1.ResourceList {}
89
96
}
90
97
for name , value := range defaultResources .Limits {
91
- if _ , ok := pod . Spec . Containers [ i ] .Resources .Limits [v1 .ResourceName (name )]; ! ok {
98
+ if _ , ok := c .Resources .Limits [v1 .ResourceName (name )]; ! ok {
92
99
glog .V (5 ).Infof ("Setting default resource limit %s for pod %s/%s to %v" , name , pod .Namespace , pod .Name , value )
93
- pod . Spec . Containers [ i ] .Resources .Limits [v1 .ResourceName (name )] = value
100
+ c .Resources .Limits [v1 .ResourceName (name )] = value
94
101
}
95
102
}
96
- if pod . Spec . Containers [ i ] .Resources .Requests == nil {
97
- pod . Spec . Containers [ i ] .Resources .Requests = v1.ResourceList {}
103
+ if c .Resources .Requests == nil {
104
+ c .Resources .Requests = v1.ResourceList {}
98
105
}
99
106
for name , value := range defaultResources .Requests {
100
- if _ , ok := pod . Spec . Containers [ i ] .Resources .Requests [v1 .ResourceName (name )]; ! ok {
107
+ if _ , ok := c .Resources .Requests [v1 .ResourceName (name )]; ! ok {
101
108
glog .V (5 ).Infof ("Setting default resource request %s for pod %s/%s to %v" , name , pod .Namespace , pod .Name , value )
102
- pod . Spec . Containers [ i ] .Resources .Requests [v1 .ResourceName (name )] = value
109
+ c .Resources .Requests [v1 .ResourceName (name )] = value
103
110
}
104
111
}
105
112
}
0 commit comments