Create a container.
(containerName string, watchSource watcher.ContainerWatchSource)
| 794 | |
| 795 | // Create a container. |
| 796 | func (m *manager) createContainer(containerName string, watchSource watcher.ContainerWatchSource) error { |
| 797 | namespacedName := namespacedContainerName{ |
| 798 | Name: containerName, |
| 799 | } |
| 800 | |
| 801 | // Check that the container didn't already exist. |
| 802 | if _, ok := m.containers.Load(namespacedName); ok { |
| 803 | return nil |
| 804 | } |
| 805 | |
| 806 | handler, accept, err := container.NewContainerHandler(containerName, watchSource, m.containerEnvMetadataWhiteList, m.inHostNamespace) |
| 807 | if err != nil { |
| 808 | return err |
| 809 | } |
| 810 | if !accept { |
| 811 | // ignoring this container. |
| 812 | klog.V(4).Infof("ignoring container %q", containerName) |
| 813 | return nil |
| 814 | } |
| 815 | cont, err := newContainerData(containerName, m.memoryCache, handler, m.maxHousekeepingInterval, m.allowDynamicHousekeeping, clock.RealClock{}) |
| 816 | if err != nil { |
| 817 | return err |
| 818 | } |
| 819 | |
| 820 | if m.includedMetrics.Has(container.PerfMetrics) { |
| 821 | perfCgroupPath, err := handler.GetCgroupPath("perf_event") |
| 822 | if err != nil { |
| 823 | klog.Warningf("Error getting perf_event cgroup path: %q", err) |
| 824 | } else { |
| 825 | cont.perfCollector, err = m.perfManager.GetCollector(perfCgroupPath) |
| 826 | if err != nil { |
| 827 | klog.Errorf("Perf event metrics will not be available for container %q: %v", containerName, err) |
| 828 | } |
| 829 | } |
| 830 | } |
| 831 | if m.includedMetrics.Has(container.ResctrlMetrics) { |
| 832 | m.machineMu.RLock() |
| 833 | noOfNUMA := len(m.machineInfo.Topology) |
| 834 | m.machineMu.RUnlock() |
| 835 | cont.resctrlCollector, err = m.resctrlManager.GetCollector(containerName, func() ([]string, error) { |
| 836 | pids, perr := handler.ListProcesses(container.ListSelf) |
| 837 | if perr != nil { |
| 838 | return nil, perr |
| 839 | } |
| 840 | ss := make([]string, len(pids)) |
| 841 | for i, p := range pids { |
| 842 | ss[i] = strconv.Itoa(p) |
| 843 | } |
| 844 | return ss, nil |
| 845 | }, noOfNUMA) |
| 846 | if err != nil { |
| 847 | klog.V(4).Infof("resctrl metrics will not be available for container %s: %s", cont.info.Name, err) |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | // Application-metrics collectors (binary-only; the kubelet leaves the factory |
| 852 | // nil). The readFile closure lets the collector factory read config files |
| 853 | // (declared via container labels) from inside the container. |
no test coverage detected