MCPcopy
hub / github.com/google/cadvisor / newContainerData

Function newContainerData

lib/manager/container.go:212–270  ·  view source on GitHub ↗
(containerName string, memoryCache *memory.InMemoryCache, handler container.ContainerHandler, maxHousekeepingInterval time.Duration, allowDynamicHousekeeping bool, clock clock.Clock)

Source from the content-addressed store, hash-verified

210}
211
212func newContainerData(containerName string, memoryCache *memory.InMemoryCache, handler container.ContainerHandler, maxHousekeepingInterval time.Duration, allowDynamicHousekeeping bool, clock clock.Clock) (*containerData, error) {
213 if memoryCache == nil {
214 return nil, fmt.Errorf("nil memory storage")
215 }
216 if handler == nil {
217 return nil, fmt.Errorf("nil container handler")
218 }
219 ref, err := handler.ContainerReference()
220 if err != nil {
221 return nil, err
222 }
223
224 cont := &containerData{
225 handler: handler,
226 memoryCache: memoryCache,
227 housekeepingInterval: *HousekeepingInterval,
228 maxHousekeepingInterval: maxHousekeepingInterval,
229 allowDynamicHousekeeping: allowDynamicHousekeeping,
230 firstHousekeeping: true,
231 initialSplayFactor: *InitialSplayFactor,
232 jitterFactor: *JitterFactor,
233 loadAvg: -1.0, // negative value indicates uninitialized.
234 loadDAvg: -1.0, // negative value indicates uninitialized.
235 stop: make(chan struct{}),
236 onDemandChan: make(chan chan struct{}, 100),
237 clock: clock,
238 perfCollector: &stats.NoopCollector{},
239 resctrlCollector: &stats.NoopCollector{},
240 }
241 cont.info.ContainerReference = ref
242
243 cont.loadDecay = math.Exp(float64(-cont.housekeepingInterval.Seconds() / 10))
244
245 if *enableLoadReader && CpuLoadReaderFactory != nil {
246 loadReader, err := CpuLoadReaderFactory()
247 if err != nil {
248 klog.Warningf("Could not initialize cpu load reader for %q: %s", ref.Name, err)
249 } else {
250 cont.loadReader = loadReader
251 }
252 }
253
254 err = cont.updateSpec()
255 if err != nil {
256 return nil, err
257 }
258
259 // Derived-stats summary reader (binary-only; nil for the kubelet). Failure to
260 // create it is non-fatal — the container is still tracked.
261 if SummaryReaderFactory != nil {
262 summaryReader, serr := SummaryReaderFactory(cont.info.Spec)
263 if serr != nil {
264 klog.V(5).Infof("Failed to create summary reader for %q: %v", ref.Name, serr)
265 } else {
266 cont.summaryReader = summaryReader
267 }
268 }
269 return cont, nil

Callers 5

setupContainerDataFunction · 0.85
addContainerMethod · 0.85
createContainerMethod · 0.85

Calls 5

updateSpecMethod · 0.95
ErrorfMethod · 0.80
WarningfMethod · 0.80
InfofMethod · 0.80
ContainerReferenceMethod · 0.65

Tested by 4

setupContainerDataFunction · 0.68
addContainerMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…