mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #48822 from caseydavenport/drive-by-fix-todo
Automatic merge from submit-queue (batch tested with PRs 47738, 49196, 48907, 48533, 48822) Fix TODO: rename podInfraContainerID to sandboxID **What this PR does / why we need it**: Code-cleanup in kubelet to use consistent naming for sandbox ID. Not super urgent, but thought it would be nice to knock off some TODOs. **Which issue this PR fixes** Fixes a TODO in the code, no associated issue. **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
This commit is contained in:
commit
f2dc80bfe5
@ -159,8 +159,8 @@ func attachContainer(client libdocker.Interface, containerID string, stdin io.Re
|
|||||||
return client.AttachToContainer(containerID, opts, sopts)
|
return client.AttachToContainer(containerID, opts, sopts)
|
||||||
}
|
}
|
||||||
|
|
||||||
func portForward(client libdocker.Interface, podInfraContainerID string, port int32, stream io.ReadWriteCloser) error {
|
func portForward(client libdocker.Interface, podSandboxID string, port int32, stream io.ReadWriteCloser) error {
|
||||||
container, err := client.InspectContainer(podInfraContainerID)
|
container, err := client.InspectContainer(podSandboxID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func applySandboxSecurityContext(lc *runtimeapi.LinuxPodSandboxConfig, config *d
|
|||||||
}
|
}
|
||||||
|
|
||||||
// applyContainerSecurityContext updates docker container options according to security context.
|
// applyContainerSecurityContext updates docker container options according to security context.
|
||||||
func applyContainerSecurityContext(lc *runtimeapi.LinuxContainerConfig, sandboxID string, config *dockercontainer.Config, hc *dockercontainer.HostConfig, separator rune) error {
|
func applyContainerSecurityContext(lc *runtimeapi.LinuxContainerConfig, podSandboxID string, config *dockercontainer.Config, hc *dockercontainer.HostConfig, separator rune) error {
|
||||||
if lc == nil {
|
if lc == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ func applyContainerSecurityContext(lc *runtimeapi.LinuxContainerConfig, sandboxI
|
|||||||
if err := modifyHostConfig(lc.SecurityContext, hc, separator); err != nil {
|
if err := modifyHostConfig(lc.SecurityContext, hc, separator); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
modifyContainerNamespaceOptions(lc.SecurityContext.GetNamespaceOptions(), sandboxID, hc)
|
modifyContainerNamespaceOptions(lc.SecurityContext.GetNamespaceOptions(), podSandboxID, hc)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,14 +127,14 @@ func modifySandboxNamespaceOptions(nsOpts *runtimeapi.NamespaceOption, hostConfi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// modifyContainerNamespaceOptions apply namespace options for container
|
// modifyContainerNamespaceOptions apply namespace options for container
|
||||||
func modifyContainerNamespaceOptions(nsOpts *runtimeapi.NamespaceOption, sandboxID string, hostConfig *dockercontainer.HostConfig) {
|
func modifyContainerNamespaceOptions(nsOpts *runtimeapi.NamespaceOption, podSandboxID string, hostConfig *dockercontainer.HostConfig) {
|
||||||
hostNetwork := false
|
hostNetwork := false
|
||||||
if nsOpts != nil {
|
if nsOpts != nil {
|
||||||
hostNetwork = nsOpts.HostNetwork
|
hostNetwork = nsOpts.HostNetwork
|
||||||
}
|
}
|
||||||
hostConfig.PidMode = dockercontainer.PidMode(fmt.Sprintf("container:%v", sandboxID))
|
hostConfig.PidMode = dockercontainer.PidMode(fmt.Sprintf("container:%v", podSandboxID))
|
||||||
modifyCommonNamespaceOptions(nsOpts, hostConfig)
|
modifyCommonNamespaceOptions(nsOpts, hostConfig)
|
||||||
modifyHostNetworkOptionForContainer(hostNetwork, sandboxID, hostConfig)
|
modifyHostNetworkOptionForContainer(hostNetwork, podSandboxID, hostConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// modifyCommonNamespaceOptions apply common namespace options for sandbox and container
|
// modifyCommonNamespaceOptions apply common namespace options for sandbox and container
|
||||||
@ -172,8 +172,8 @@ func modifyHostNetworkOptionForSandbox(hostNetwork bool, network *knetwork.Plugi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// modifyHostNetworkOptionForContainer applies NetworkMode/UTSMode to container's dockercontainer.HostConfig.
|
// modifyHostNetworkOptionForContainer applies NetworkMode/UTSMode to container's dockercontainer.HostConfig.
|
||||||
func modifyHostNetworkOptionForContainer(hostNetwork bool, sandboxID string, hc *dockercontainer.HostConfig) {
|
func modifyHostNetworkOptionForContainer(hostNetwork bool, podSandboxID string, hc *dockercontainer.HostConfig) {
|
||||||
sandboxNSMode := fmt.Sprintf("container:%v", sandboxID)
|
sandboxNSMode := fmt.Sprintf("container:%v", podSandboxID)
|
||||||
hc.NetworkMode = dockercontainer.NetworkMode(sandboxNSMode)
|
hc.NetworkMode = dockercontainer.NetworkMode(sandboxNSMode)
|
||||||
hc.IpcMode = dockercontainer.IpcMode(sandboxNSMode)
|
hc.IpcMode = dockercontainer.IpcMode(sandboxNSMode)
|
||||||
hc.UTSMode = ""
|
hc.UTSMode = ""
|
||||||
|
@ -280,8 +280,8 @@ func (plugin *cniNetworkPlugin) GetPodNetworkStatus(namespace string, name strin
|
|||||||
return &network.PodNetworkStatus{IP: ip}, nil
|
return &network.PodNetworkStatus{IP: ip}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *cniNetworkPlugin) addToNetwork(network *cniNetwork, podName string, podNamespace string, podInfraContainerID kubecontainer.ContainerID, podNetnsPath string) (cnitypes.Result, error) {
|
func (plugin *cniNetworkPlugin) addToNetwork(network *cniNetwork, podName string, podNamespace string, podSandboxID kubecontainer.ContainerID, podNetnsPath string) (cnitypes.Result, error) {
|
||||||
rt, err := plugin.buildCNIRuntimeConf(podName, podNamespace, podInfraContainerID, podNetnsPath)
|
rt, err := plugin.buildCNIRuntimeConf(podName, podNamespace, podSandboxID, podNetnsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error adding network when building cni runtime conf: %v", err)
|
glog.Errorf("Error adding network when building cni runtime conf: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -298,8 +298,8 @@ func (plugin *cniNetworkPlugin) addToNetwork(network *cniNetwork, podName string
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *cniNetworkPlugin) deleteFromNetwork(network *cniNetwork, podName string, podNamespace string, podInfraContainerID kubecontainer.ContainerID, podNetnsPath string) error {
|
func (plugin *cniNetworkPlugin) deleteFromNetwork(network *cniNetwork, podName string, podNamespace string, podSandboxID kubecontainer.ContainerID, podNetnsPath string) error {
|
||||||
rt, err := plugin.buildCNIRuntimeConf(podName, podNamespace, podInfraContainerID, podNetnsPath)
|
rt, err := plugin.buildCNIRuntimeConf(podName, podNamespace, podSandboxID, podNetnsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Error deleting network when building cni runtime conf: %v", err)
|
glog.Errorf("Error deleting network when building cni runtime conf: %v", err)
|
||||||
return err
|
return err
|
||||||
@ -315,25 +315,25 @@ func (plugin *cniNetworkPlugin) deleteFromNetwork(network *cniNetwork, podName s
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *cniNetworkPlugin) buildCNIRuntimeConf(podName string, podNs string, podInfraContainerID kubecontainer.ContainerID, podNetnsPath string) (*libcni.RuntimeConf, error) {
|
func (plugin *cniNetworkPlugin) buildCNIRuntimeConf(podName string, podNs string, podSandboxID kubecontainer.ContainerID, podNetnsPath string) (*libcni.RuntimeConf, error) {
|
||||||
glog.V(4).Infof("Got netns path %v", podNetnsPath)
|
glog.V(4).Infof("Got netns path %v", podNetnsPath)
|
||||||
glog.V(4).Infof("Using netns path %v", podNs)
|
glog.V(4).Infof("Using netns path %v", podNs)
|
||||||
|
|
||||||
rt := &libcni.RuntimeConf{
|
rt := &libcni.RuntimeConf{
|
||||||
ContainerID: podInfraContainerID.ID,
|
ContainerID: podSandboxID.ID,
|
||||||
NetNS: podNetnsPath,
|
NetNS: podNetnsPath,
|
||||||
IfName: network.DefaultInterfaceName,
|
IfName: network.DefaultInterfaceName,
|
||||||
Args: [][2]string{
|
Args: [][2]string{
|
||||||
{"IgnoreUnknown", "1"},
|
{"IgnoreUnknown", "1"},
|
||||||
{"K8S_POD_NAMESPACE", podNs},
|
{"K8S_POD_NAMESPACE", podNs},
|
||||||
{"K8S_POD_NAME", podName},
|
{"K8S_POD_NAME", podName},
|
||||||
{"K8S_POD_INFRA_CONTAINER_ID", podInfraContainerID.ID},
|
{"K8S_POD_INFRA_CONTAINER_ID", podSandboxID.ID},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// port mappings are a cni capability-based args, rather than parameters
|
// port mappings are a cni capability-based args, rather than parameters
|
||||||
// to a specific plugin
|
// to a specific plugin
|
||||||
portMappings, err := plugin.host.GetPodPortMappings(podInfraContainerID.ID)
|
portMappings, err := plugin.host.GetPodPortMappings(podSandboxID.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not retrieve port mappings: %v", err)
|
return nil, fmt.Errorf("could not retrieve port mappings: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -63,16 +63,13 @@ type NetworkPlugin interface {
|
|||||||
// SetUpPod is the method called after the infra container of
|
// SetUpPod is the method called after the infra container of
|
||||||
// the pod has been created but before the other containers of the
|
// the pod has been created but before the other containers of the
|
||||||
// pod are launched.
|
// pod are launched.
|
||||||
// TODO: rename podInfraContainerID to sandboxID
|
SetUpPod(namespace string, name string, podSandboxID kubecontainer.ContainerID, annotations map[string]string) error
|
||||||
SetUpPod(namespace string, name string, podInfraContainerID kubecontainer.ContainerID, annotations map[string]string) error
|
|
||||||
|
|
||||||
// TearDownPod is the method called before a pod's infra container will be deleted
|
// TearDownPod is the method called before a pod's infra container will be deleted
|
||||||
// TODO: rename podInfraContainerID to sandboxID
|
TearDownPod(namespace string, name string, podSandboxID kubecontainer.ContainerID) error
|
||||||
TearDownPod(namespace string, name string, podInfraContainerID kubecontainer.ContainerID) error
|
|
||||||
|
|
||||||
// GetPodNetworkStatus is the method called to obtain the ipv4 or ipv6 addresses of the container
|
// GetPodNetworkStatus is the method called to obtain the ipv4 or ipv6 addresses of the container
|
||||||
// TODO: rename podInfraContainerID to sandboxID
|
GetPodNetworkStatus(namespace string, name string, podSandboxID kubecontainer.ContainerID) (*PodNetworkStatus, error)
|
||||||
GetPodNetworkStatus(namespace string, name string, podInfraContainerID kubecontainer.ContainerID) (*PodNetworkStatus, error)
|
|
||||||
|
|
||||||
// Status returns error if the network plugin is in error state
|
// Status returns error if the network plugin is in error state
|
||||||
Status() error
|
Status() error
|
||||||
@ -136,7 +133,7 @@ type Host interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NamespaceGetter is an interface to retrieve namespace information for a given
|
// NamespaceGetter is an interface to retrieve namespace information for a given
|
||||||
// sandboxID. Typically implemented by runtime shims that are closely coupled to
|
// podSandboxID. Typically implemented by runtime shims that are closely coupled to
|
||||||
// CNI plugin wrappers like kubenet.
|
// CNI plugin wrappers like kubenet.
|
||||||
type NamespaceGetter interface {
|
type NamespaceGetter interface {
|
||||||
// GetNetNS returns network namespace information for the given containerID.
|
// GetNetNS returns network namespace information for the given containerID.
|
||||||
@ -146,7 +143,7 @@ type NamespaceGetter interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PortMappingGetter is an interface to retrieve port mapping information for a given
|
// PortMappingGetter is an interface to retrieve port mapping information for a given
|
||||||
// sandboxID. Typically implemented by runtime shims that are closely coupled to
|
// podSandboxID. Typically implemented by runtime shims that are closely coupled to
|
||||||
// CNI plugin wrappers like kubenet.
|
// CNI plugin wrappers like kubenet.
|
||||||
type PortMappingGetter interface {
|
type PortMappingGetter interface {
|
||||||
// GetPodPortMappings returns sandbox port mappings information.
|
// GetPodPortMappings returns sandbox port mappings information.
|
||||||
|
Loading…
Reference in New Issue
Block a user