Skip to content

Commit

Permalink
Fix wrong writing of namespace (#4093)
Browse files Browse the repository at this point in the history
Signed-off-by: Quan Tian <[email protected]>
  • Loading branch information
tnqn authored Jul 20, 2023
1 parent 2037ff5 commit 07b7e6d
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (r *ResourceExportReconciler) updateEndpointResourceImport(ctx context.Cont

func (r *ResourceExportReconciler) getExistingResImport(ctx context.Context,
resExport mcsv1alpha1.ResourceExport) (bool, *mcsv1alpha1.ResourceImport, error) {
importedResNameSpace := resExport.Labels[constants.SourceNamespace]
importedResNamespace := resExport.Labels[constants.SourceNamespace]
importedResName := resExport.Labels[constants.SourceName]
var createResImport bool
existResImport := &mcsv1alpha1.ResourceImport{}
Expand All @@ -281,7 +281,7 @@ func (r *ResourceExportReconciler) getExistingResImport(ctx context.Context,
Spec: mcsv1alpha1.ResourceImportSpec{
ClusterIDs: []string{},
Name: importedResName,
Namespace: importedResNameSpace,
Namespace: importedResNamespace,
},
}
createResImport = true
Expand Down
8 changes: 4 additions & 4 deletions pkg/agent/cniserver/interface_configuration_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func findContainerIPConfig(ips []*current.IPConfig) (*current.IPConfig, error) {
// configureContainerLink creates a HNSEndpoint for the container using the IPAM result, and then attach it on the container interface.
func (ic *ifConfigurator) configureContainerLink(
podName string,
podNameSpace string,
podNamespace string,
containerID string,
containerNetNS string,
containerIFDev string,
Expand All @@ -134,15 +134,15 @@ func (ic *ifConfigurator) configureContainerLink(
// We must use the infra container to generate the endpoint name to ensure infra and workload containers use the
// same HNSEndpoint.
infraContainerID := getInfraContainer(containerID, containerNetNS)
epName := util.GenerateContainerInterfaceName(podName, podNameSpace, infraContainerID)
epName := util.GenerateContainerInterfaceName(podName, podNamespace, infraContainerID)
// Search endpoint from local cache.
endpoint, found := ic.getEndpoint(epName)
if !found {
if !isInfraContainer(containerNetNS) {
return fmt.Errorf("failed to find HNSEndpoint: %s", epName)
}
// Only create HNS Endpoint for infra container.
ep, err := ic.createContainerLink(epName, result, containerID, podName, podNameSpace)
ep, err := ic.createContainerLink(epName, result, containerID, podName, podNamespace)
if err != nil {
return err
}
Expand Down Expand Up @@ -307,7 +307,7 @@ func (ic *ifConfigurator) removeHNSEndpoint(endpoint *hcsshim.HNSEndpoint, conta
if hcnEndpoint != nil && isValidHostNamespace(hcnEndpoint.HostComputeNamespace) {
err := removeEndpointFromNamespaceFunc(hcnEndpoint.HostComputeNamespace, hcnEndpoint.Id)
if err != nil {
klog.Errorf("Failed to remove HostComputeEndpoint %s from HostComputeNameSpace %s: %v", hcnEndpoint.Name, hcnEndpoint.HostComputeNamespace, err)
klog.Errorf("Failed to remove HostComputeEndpoint %s from HostComputeNamespace %s: %v", hcnEndpoint.Name, hcnEndpoint.HostComputeNamespace, err)
deleteCh <- err
return
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/agent/cniserver/pod_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func ParseOVSPortInterfaceConfig(portData *ovsconfig.OVSPortData, portConfig *in

func (pc *podConfigurator) configureInterfaces(
podName string,
podNameSpace string,
podNamespace string,
containerID string,
containerNetNS string,
containerIFDev string,
Expand All @@ -210,7 +210,7 @@ func (pc *podConfigurator) configureInterfaces(
createOVSPort bool,
containerAccess *containerAccessArbitrator,
) error {
err := pc.ifConfigurator.configureContainerLink(podName, podNameSpace, containerID, containerNetNS, containerIFDev, mtu, sriovVFDeviceID, "", &result.Result, containerAccess)
err := pc.ifConfigurator.configureContainerLink(podName, podNamespace, containerID, containerNetNS, containerIFDev, mtu, sriovVFDeviceID, "", &result.Result, containerAccess)
if err != nil {
return err
}
Expand Down Expand Up @@ -243,7 +243,7 @@ func (pc *podConfigurator) configureInterfaces(
}

var containerConfig *interfacestore.InterfaceConfig
if containerConfig, err = pc.connectInterfaceToOVS(podName, podNameSpace, containerID, hostIface, containerIface, result.IPs, result.VLANID, containerAccess); err != nil {
if containerConfig, err = pc.connectInterfaceToOVS(podName, podNamespace, containerID, hostIface, containerIface, result.IPs, result.VLANID, containerAccess); err != nil {
return fmt.Errorf("failed to connect to ovs for container %s: %v", containerID, err)
}
defer func() {
Expand Down Expand Up @@ -544,7 +544,7 @@ func (pc *podConfigurator) disconnectInterfaceFromOVS(containerConfig *interface
// connectInterceptedInterface connects intercepted interface to ovs br-int.
func (pc *podConfigurator) connectInterceptedInterface(
podName string,
podNameSpace string,
podNamespace string,
containerID string,
containerNetNS string,
containerIFDev string,
Expand All @@ -562,7 +562,7 @@ func (pc *podConfigurator) connectInterceptedInterface(
if err = pc.routeClient.MigrateRoutesToGw(hostIface.Name); err != nil {
return fmt.Errorf("connectInterceptedInterface failed to migrate: %w", err)
}
_, err = pc.connectInterfaceToOVS(podName, podNameSpace, containerID, hostIface,
_, err = pc.connectInterfaceToOVS(podName, podNamespace, containerID, hostIface,
containerIface, containerIPs, 0, containerAccess)
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/cniserver/pod_configuration_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
// connectInterfaceToOVS connects an existing interface to ovs br-int.
func (pc *podConfigurator) connectInterfaceToOVS(
podName string,
podNameSpace string,
podNamespace string,
containerID string,
hostIface *current.Interface,
containerIface *current.Interface,
Expand All @@ -37,7 +37,7 @@ func (pc *podConfigurator) connectInterfaceToOVS(
) (*interfacestore.InterfaceConfig, error) {
// Use the outer veth interface name as the OVS port name.
ovsPortName := hostIface.Name
containerConfig := buildContainerConfig(ovsPortName, containerID, podName, podNameSpace, containerIface, ips, vlanID)
containerConfig := buildContainerConfig(ovsPortName, containerID, podName, podNamespace, containerIface, ips, vlanID)
return containerConfig, pc.connectInterfaceToOVSCommon(ovsPortName, containerConfig)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/cniserver/pod_configuration_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func TestCreateOVSPort(t *testing.T) {
controller := gomock.NewController(t)
containerID := generateUUID(t)
podName := "p0"
podNameSpace := testPodNamespace
podNamespace := testPodNamespace

for _, tc := range []struct {
name string
Expand All @@ -268,7 +268,7 @@ func TestCreateOVSPort(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
testIfaceConfigurator := &fakeInterfaceConfigurator{ovsInterfaceTypeMapping: map[string]int{tc.portName: tc.portType}}
podConfigurator := createPodConfigurator(controller, testIfaceConfigurator)
containerConfig := buildContainerConfig(tc.portName, containerID, podName, podNameSpace, &current.Interface{Mac: "01:02:03:04:05:06"}, ipamResult.IPs, tc.vlanID)
containerConfig := buildContainerConfig(tc.portName, containerID, podName, podNamespace, &current.Interface{Mac: "01:02:03:04:05:06"}, ipamResult.IPs, tc.vlanID)
attachInfo := BuildOVSPortExternalIDs(containerConfig)
if tc.createOVSPort {
mockOVSBridgeClient.EXPECT().CreatePort(tc.portName, tc.portName, attachInfo).Times(1).Return(generateUUID(t), nil)
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/cniserver/pod_configuration_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (pc *podConfigurator) connectInterfaceToOVSAsync(ifConfig *interfacestore.I
// connectInterfaceToOVS connects an existing interface to OVS br-int.
func (pc *podConfigurator) connectInterfaceToOVS(
podName string,
podNameSpace string,
podNamespace string,
containerID string,
hostIface *current.Interface,
containerIface *current.Interface,
Expand All @@ -74,7 +74,7 @@ func (pc *podConfigurator) connectInterfaceToOVS(
) (*interfacestore.InterfaceConfig, error) {
// Use the outer veth interface name as the OVS port name.
ovsPortName := hostIface.Name
containerConfig := buildContainerConfig(ovsPortName, containerID, podName, podNameSpace, containerIface, ips, vlanID)
containerConfig := buildContainerConfig(ovsPortName, containerID, podName, podNamespace, containerIface, ips, vlanID)
hostIfAlias := util.VirtualAdapterName(ovsPortName)
// - For containerd runtime, the container interface is created after CNI replying the network setup result.
// So for such case we need to use asynchronous way to wait for interface to be created: we create the OVS port
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/cniserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func (s *CNIServer) CmdAdd(ctx context.Context, request *cnipb.CniCmdRequest) (*

if s.secondaryNetworkEnabled {
// Go cache the CNI server info at CNIConfigInfo cache, for podWatch usage
cniInfo := &cnipodcache.CNIConfigInfo{CNIVersion: cniVersion, PodName: podName, PodNameSpace: podNamespace,
cniInfo := &cnipodcache.CNIConfigInfo{CNIVersion: cniVersion, PodName: podName, PodNamespace: podNamespace,
ContainerID: cniConfig.ContainerId, ContainerNetNS: netNS, PodCNIDeleted: false,
MTU: cniConfig.MTU}
s.podConfigurator.podInfoStore.AddCNIConfigInfo(cniInfo)
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/cniserver/server_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ func TestCmdDel(t *testing.T) {
testIfaceConfigurator.hostIfaceName = hostInterfaceName
cniserver.podConfigurator.ifConfigurator = testIfaceConfigurator
if tc.secondaryNetworkEnabled {
cniInfo := &cnipodcache.CNIConfigInfo{CNIVersion: supportedCNIVersion, PodName: tc.podName, PodNameSpace: testPodNamespace,
cniInfo := &cnipodcache.CNIConfigInfo{CNIVersion: supportedCNIVersion, PodName: tc.podName, PodNamespace: testPodNamespace,
ContainerID: containerID, ContainerNetNS: netns, PodCNIDeleted: false,
MTU: 1450}
cniserver.podConfigurator.podInfoStore.AddCNIConfigInfo(cniInfo)
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/cniserver/sriov.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func GetPodContainerDeviceIDs(podName string, podNamespace string) ([]string, er
// Limitation: only SR-IOV interface is supported as of now.
func (pc *podConfigurator) ConfigureSriovSecondaryInterface(
podName string,
podNameSpace string,
podNamespace string,
containerID string,
containerNetNS string,
containerIFDev string,
Expand All @@ -104,7 +104,7 @@ func (pc *podConfigurator) ConfigureSriovSecondaryInterface(
return fmt.Errorf("error getting the Pod SR-IOV VF device ID")
}

err := pc.ifConfigurator.configureContainerLink(podName, podNameSpace, containerID, containerNetNS, containerIFDev, mtu, "", podSriovVFDeviceID, result, nil)
err := pc.ifConfigurator.configureContainerLink(podName, podNamespace, containerID, containerNetNS, containerIFDev, mtu, "", podSriovVFDeviceID, result, nil)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/secondarynetwork/cnipodcache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (c *CNIPodInfoCache) GetCNIConfigInfoByContainerID(podName, podNamespace, c

func podIndexFunc(obj interface{}) ([]string, error) {
podConfig := obj.(*CNIConfigInfo)
return []string{k8s.NamespacedName(podConfig.PodNameSpace, podConfig.PodName)}, nil
return []string{k8s.NamespacedName(podConfig.PodNamespace, podConfig.PodName)}, nil
}

func getCNIPodInfoKey(obj interface{}) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/secondarynetwork/cnipodcache/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package cnipodcache
type CNIConfigInfo struct {
CNIVersion string
PodName string
PodNameSpace string
PodNamespace string
ContainerID string
ContainerNetNS string
MTU int
Expand Down
8 changes: 4 additions & 4 deletions pkg/agent/secondarynetwork/podwatch/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type podSriovVFDeviceIDInfo struct {
}

type InterfaceConfigurator interface {
ConfigureSriovSecondaryInterface(podName string, podNameSpace string, containerID string, containerNetNS string, containerIFDev string, mtu int, podSriovVFDeviceID string, result *current.Result) error
ConfigureSriovSecondaryInterface(podName string, podNamespace string, containerID string, containerNetNS string, containerIFDev string, mtu int, podSriovVFDeviceID string, result *current.Result) error
}

type PodController struct {
Expand Down Expand Up @@ -197,7 +197,7 @@ func whereaboutsArgsBuilder(cmd string, interfaceName string, podCNIInfo *cnipod
NetNS: podCNIInfo.ContainerNetNS, IfName: interfaceName,
Path: cniPath, PluginArgs: [][2]string{
{"K8S_POD_NAME", podCNIInfo.PodName},
{"K8S_POD_NAMESPACE", podCNIInfo.PodNameSpace},
{"K8S_POD_NAMESPACE", podCNIInfo.PodNamespace},
{"K8S_POD_INFRA_CONTAINER_ID", podCNIInfo.ContainerID},
}}

Expand Down Expand Up @@ -302,7 +302,7 @@ func (pc *PodController) handleRemovePod(key string) error {
// Delete cache entry from podCNIInfo.
pc.podCache.DeleteCNIConfigInfo(containerInfo)
// Delete Pod specific VF cache (if one exists)
pc.deleteVFDeviceIDListPerPod(containerInfo.PodName, containerInfo.PodNameSpace)
pc.deleteVFDeviceIDListPerPod(containerInfo.PodName, containerInfo.PodNamespace)
}
}
return nil
Expand Down Expand Up @@ -349,7 +349,7 @@ func (pc *PodController) configureSriovAsSecondaryInterface(pod *corev1.Pod, net

if err = pc.interfaceConfigurator.ConfigureSriovSecondaryInterface(
containerInfo.PodName,
containerInfo.PodNameSpace,
containerInfo.PodNamespace,
containerInfo.ContainerID,
containerInfo.ContainerNetNS,
network.InterfaceRequest,
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/secondarynetwork/podwatch/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func testPod(name string, container string, podIP string, networks ...netdefv1.N
}
cniConfig := &cnipodcache.CNIConfigInfo{
PodName: name,
PodNameSpace: testNamespace,
PodNamespace: testNamespace,
ContainerID: container,
ContainerNetNS: containerNetNs(container),
MTU: defaultMTU,
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/externalnode/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@ func (c *ExternalNodeController) updateExternalEntity(ee *v1alpha2.ExternalEntit
if errors.IsNotFound(err) {
_, err = c.crdClient.CrdV1alpha2().ExternalEntities(ee.Namespace).Create(context.TODO(), ee, metav1.CreateOptions{})
if err != nil {
klog.ErrorS(err, "Failed to create ExternalEntity", "entityName", ee.Name, "entityNameSpace", ee.Namespace)
klog.ErrorS(err, "Failed to create ExternalEntity", "entityName", ee.Name, "entityNamespace", ee.Namespace)
return err
}
return nil
}
klog.ErrorS(err, "Failed to get ExternalEntity", "entityName", ee.Name, "entityNameSpace", ee.Namespace)
klog.ErrorS(err, "Failed to get ExternalEntity", "entityName", ee.Name, "entityNamespace", ee.Namespace)
return err
}
isChanged := false
Expand Down

0 comments on commit 07b7e6d

Please sign in to comment.