Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix equality comparison of policy specs #538

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

mlguerrero12
Copy link
Contributor

When the last policy is deleted, the network node states objects are not updated because the DeepDerivative function only compares the DPConfigVersion and ignores the Interfaces. The new spec has no interfaces. The node states are eventually updated when the resync period forces the reconcilation loop to trigger again.

This causes a long delay on the processing of the deletion by the sriov config daemon. This started to be an issue when we changed the order of the methdos syncAllSriovNetworkNodeStates and syncDevicePluginConfigMap. The last one was run first and the param DPConfigVersion was always different for this particular case.

When the last policy is deleted, the network node states objects
are not updated because the DeepDerivative function only compares
the DPConfigVersion and ignores the Interfaces. The new spec has no
interfaces. The node states are eventually updated when the resync
period forces the reconcilation loop to trigger again.

This causes a long delay on the processing of the deletion by the
sriov config daemon. This started to be an issue when we changed
the order of the methdos syncAllSriovNetworkNodeStates and
syncDevicePluginConfigMap. The last one was run first and the param
DPConfigVersion was always different for this particular case.
Copy link

github-actions bot commented Nov 6, 2023

Thanks for your PR,
To run vendors CIs use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 6767949555

  • 0 of 1 (0.0%) changed or added relevant line in 1 file are covered.
  • 7 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.06%) to 25.409%

Changes Missing Coverage Covered Lines Changed/Added Lines %
controllers/sriovnetworknodepolicy_controller.go 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
api/v1/helper.go 3 42.94%
controllers/sriovnetwork_controller.go 4 70.68%
Totals Coverage Status
Change from base Build 6744863425: -0.06%
Covered Lines: 2329
Relevant Lines: 9166

💛 - Coveralls

@zeeke
Copy link
Member

zeeke commented Nov 9, 2023

Please, consider adding a unit test to cover this case:

func Test_NodeStateIsUpdatedWhenTheLastPolicyIsDeleted(t *testing.T) {

	defaultPolicy := sriovnetworkv1.SriovNetworkNodePolicy{
		ObjectMeta: metav1.ObjectMeta{Name: consts.DefaultPolicyName},
		Spec: v1.SriovNetworkNodePolicySpec{
			NumVfs:       0,
			NodeSelector: make(map[string]string),
			NicSelector:  sriovnetworkv1.SriovNetworkNicSelector{},
		},
	}
	p1 := sriovnetworkv1.SriovNetworkNodePolicy{
		ObjectMeta: metav1.ObjectMeta{Name: "p1"},
		Spec: v1.SriovNetworkNodePolicySpec{
			NicSelector: v1.SriovNetworkNicSelector{PfNames: []string{"ens1f0"}},
			NumVfs:      4,
		},
	}

	reconciler := SriovNetworkNodePolicyReconciler{}

	node := corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: "node1"}}
	nodeState := sriovnetworkv1.SriovNetworkNodeState{
		ObjectMeta: metav1.ObjectMeta{Name: node.Name, Namespace: namespace},
		Status: v1.SriovNetworkNodeStateStatus{
			Interfaces: []sriovnetworkv1.InterfaceExt{{
				Name: "ens1f0",
			}},
		},
	}

	scheme := runtime.NewScheme()
	utilruntime.Must(sriovnetworkv1.AddToScheme(scheme))
	reconciler.Client = fake.NewClientBuilder().
		WithScheme(scheme).
		WithObjects(&nodeState).
		Build()
	reconciler.Scheme = scheme

	policyList := sriovnetworkv1.SriovNetworkNodePolicyList{Items: []sriovnetworkv1.SriovNetworkNodePolicy{defaultPolicy, p1}}

	err := reconciler.syncSriovNetworkNodeState(context.Background(),
		&defaultPolicy,
		&policyList,
		&sriovnetworkv1.SriovNetworkNodeState{ObjectMeta: metav1.ObjectMeta{Name: node.Name, Namespace: namespace}},
		&node,
		"111")
	assert.NoError(t, err)

	err = reconciler.Client.Get(context.Background(), types.NamespacedName{Name: node.Name, Namespace: namespace}, &nodeState)
	assert.NoError(t, err)
	assert.Equal(t, len(nodeState.Spec.Interfaces), 1)

	err = reconciler.syncSriovNetworkNodeState(context.Background(),
		&defaultPolicy,
		&sriovnetworkv1.SriovNetworkNodePolicyList{Items: []sriovnetworkv1.SriovNetworkNodePolicy{defaultPolicy}},
		&sriovnetworkv1.SriovNetworkNodeState{ObjectMeta: metav1.ObjectMeta{Name: node.Name, Namespace: namespace}},
		&node,
		"111")
	assert.NoError(t, err)
	err = reconciler.Client.Get(context.Background(), types.NamespacedName{Name: node.Name, Namespace: namespace}, &nodeState)
	assert.NoError(t, err)
	assert.Equal(t, len(nodeState.Spec.Interfaces), 0)
}

@mlguerrero12
Copy link
Contributor Author

Please create a pr with the test you posted. Let's not delay the merge of this fix

Copy link
Member

@zeeke zeeke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine to have the unit test in a different PR to avoid regressions on this.

@zeeke zeeke merged commit 2988e1d into k8snetworkplumbingwg:master Nov 9, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants