Skip to content

Commit

Permalink
Introduce "Failed" phase in ANP status (#4608)
Browse files Browse the repository at this point in the history
Set the ANP status phase as "Failed" when all Agents have reported
the status and at least one Agent reports failure.

Signed-off-by: wenyingd <wenyingd@vmware.com>
  • Loading branch information
wenyingd authored May 5, 2023
1 parent e635aef commit c9c9559
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/crd/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ const (
NetworkPolicyRealizing NetworkPolicyPhase = "Realizing"
// NetworkPolicyRealized means the NetworkPolicy has been enforced to all Pods on all Nodes it applies to.
NetworkPolicyRealized NetworkPolicyPhase = "Realized"
// NetworkPolicyFailed means the NetworkPolicy is failed to be enforced on at least one Node.
NetworkPolicyFailed NetworkPolicyPhase = "Failed"
)

// These are valid conditions of a deployment.
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/networkpolicy/status_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ func (c *StatusController) syncHandler(key string) error {
phase := crdv1alpha1.NetworkPolicyRealizing
if currentNodes == desiredNodes {
phase = crdv1alpha1.NetworkPolicyRealized
} else if currentNodes+len(failedNodes) == desiredNodes {
phase = crdv1alpha1.NetworkPolicyFailed
}

return updateStatus(phase, currentNodes, desiredNodes, conditions)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/networkpolicy/status_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,14 @@ func TestCreateAntreaNetworkPolicy(t *testing.T) {
newNetworkPolicyStatus("cnp1", "node2", 5, "agent crash"),
},
expectedANPStatus: &crdv1alpha1.NetworkPolicyStatus{
Phase: crdv1alpha1.NetworkPolicyRealizing,
Phase: crdv1alpha1.NetworkPolicyFailed,
ObservedGeneration: 4,
CurrentNodesRealized: 1,
DesiredNodesRealized: 2,
Conditions: generateRealizationFailureConditions(1, `"node1":"agent failure"`),
},
expectedCNPStatus: &crdv1alpha1.NetworkPolicyStatus{
Phase: crdv1alpha1.NetworkPolicyRealizing,
Phase: crdv1alpha1.NetworkPolicyFailed,
ObservedGeneration: 5,
CurrentNodesRealized: 0,
DesiredNodesRealized: 2,
Expand Down

0 comments on commit c9c9559

Please sign in to comment.