Skip to content

Commit adbbbc2

Browse files
authored
[release-0.64] capture: Get currentState from cli (#1000)
Calculating the captured state with the NNS is problematic since there are some latencies between nmstatectl set and NNS being updated, so it could happend that next NNCP is calculated with inaccurate network configuration. This change read the currentState from nmstatectl to get accurate data. Cherry picked from (#998) Signed-off-by: Quique Llorente <[email protected]>
1 parent e59fc55 commit adbbbc2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

controllers/handler/nodenetworkconfigurationpolicy_controller.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import (
5252
"github.com/nmstate/kubernetes-nmstate/pkg/environment"
5353
nmstate "github.com/nmstate/kubernetes-nmstate/pkg/helper"
5454
"github.com/nmstate/kubernetes-nmstate/pkg/nmpolicy"
55+
"github.com/nmstate/kubernetes-nmstate/pkg/nmstatectl"
5556
"github.com/nmstate/kubernetes-nmstate/pkg/node"
5657
"github.com/nmstate/kubernetes-nmstate/pkg/policyconditions"
5758
"github.com/nmstate/kubernetes-nmstate/pkg/probe"
@@ -90,6 +91,7 @@ var (
9091
return false
9192
},
9293
}
94+
nmstatectlShowFn = nmstatectl.Show
9395
)
9496

9597
// NodeNetworkConfigurationPolicyReconciler reconciles a NodeNetworkConfigurationPolicy object
@@ -165,12 +167,7 @@ func (r *NodeNetworkConfigurationPolicyReconciler) Reconcile(ctx context.Context
165167

166168
enactmentConditions := enactmentconditions.New(r.APIClient, nmstateapi.EnactmentKey(nodeName, instance.Name))
167169

168-
nns, err := r.readNNS(nodeName)
169-
if err != nil {
170-
return ctrl.Result{}, err
171-
}
172-
173-
err = r.fillInEnactmentStatus(nns, *instance, *enactmentInstance, enactmentConditions)
170+
err = r.fillInEnactmentStatus(*instance, *enactmentInstance, enactmentConditions)
174171
if err != nil {
175172
log.Error(err, "failed filling in the NNCE status")
176173
if apierrors.IsNotFound(err) {
@@ -308,11 +305,15 @@ func (r *NodeNetworkConfigurationPolicyReconciler) initializeEnactment(policy nm
308305
return &enactment, nil
309306
}
310307

311-
func (r *NodeNetworkConfigurationPolicyReconciler) fillInEnactmentStatus(nns *nmstatev1beta1.NodeNetworkState,
308+
func (r *NodeNetworkConfigurationPolicyReconciler) fillInEnactmentStatus(
312309
policy nmstatev1.NodeNetworkConfigurationPolicy,
313310
enactment nmstatev1beta1.NodeNetworkConfigurationEnactment,
314311
enactmentConditions enactmentconditions.EnactmentConditions) error {
315-
capturedStates, desiredStateMetaInfo, generatedDesiredState, err := nmpolicy.GenerateState(policy.Spec.DesiredState, policy.Spec, nns.Status.CurrentState, enactment.Status.CapturedStates)
312+
currentState, err := nmstatectlShowFn()
313+
if err != nil {
314+
return err
315+
}
316+
capturedStates, desiredStateMetaInfo, generatedDesiredState, err := nmpolicy.GenerateState(policy.Spec.DesiredState, policy.Spec, nmstateapi.NewState(currentState), enactment.Status.CapturedStates)
316317
if err != nil {
317318
err2 := enactmentstatus.Update(r.APIClient, nmstateapi.EnactmentKey(nodeName, policy.Name), func(status *nmstateapi.NodeNetworkConfigurationEnactmentStatus) {
318319
status.PolicyGeneration = policy.Generation

controllers/handler/nodenetworkconfigurationpolicy_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ var _ = Describe("NodeNetworkConfigurationPolicy controller predicates", func()
9696
}
9797
DescribeTable("when claimNodeRunningUpdate is called and",
9898
func(c incrementUnavailableNodeCountCase) {
99+
nmstatectlShowFn = func() (string, error) { return "", nil }
99100
reconciler := NodeNetworkConfigurationPolicyReconciler{}
100101
s := scheme.Scheme
101102
s.AddKnownTypes(nmstatev1beta1.GroupVersion,

0 commit comments

Comments
 (0)