From 6089137dd0a1a31343b387d1cf7a29b9bd0a1a41 Mon Sep 17 00:00:00 2001
From: Kajol Asabe <114986456+kasabe28@users.noreply.github.com>
Date: Mon, 22 Apr 2024 14:16:32 +0530
Subject: [PATCH] Add `Network` peering states `Ready`, `Error` & `Pending`
(#1055)
* change network peering states as Ready, Error & Pending
* address review comments
---
api/networking/v1alpha1/network_type.go | 6 +-
docs/api-reference/compute.md | 3 +
docs/api-reference/networking.md | 39 ++++++++
internal/apis/networking/network_type.go | 6 +-
.../network_peering_controller_test.go | 97 +++++++++++++++++++
5 files changed, 147 insertions(+), 4 deletions(-)
diff --git a/api/networking/v1alpha1/network_type.go b/api/networking/v1alpha1/network_type.go
index f47e1f4a7..b3dbe43e2 100644
--- a/api/networking/v1alpha1/network_type.go
+++ b/api/networking/v1alpha1/network_type.go
@@ -74,8 +74,10 @@ type NetworkPeeringState string
const (
// NetworkPeeringStatePending signals that the network peering is not applied.
NetworkPeeringStatePending NetworkPeeringState = "Pending"
- // NetworkPeeringStateApplied signals that the network peering is applied.
- NetworkPeeringStateApplied NetworkPeeringState = "Applied"
+ // NetworkPeeringStateReady signals that the network peering is ready.
+ NetworkPeeringStateReady NetworkPeeringState = "Ready"
+ // NetworkPeeringStateError signals that the network peering is in error state.
+ NetworkPeeringStateError NetworkPeeringState = "Error"
)
// NetworkPeeringStatus is the status of a network peering.
diff --git a/docs/api-reference/compute.md b/docs/api-reference/compute.md
index 0f10c00d6..f2f9f80d1 100644
--- a/docs/api-reference/compute.md
+++ b/docs/api-reference/compute.md
@@ -1178,6 +1178,9 @@ MachinePool.
"Terminated" |
MachineStateTerminated means the machine has been permanently stopped and cannot be started.
|
+
"Terminating" |
+MachineStateTerminating means the machine that is terminating.
+ |
MachineStatus
diff --git a/docs/api-reference/networking.md b/docs/api-reference/networking.md
index 834df1a3a..fc147fdc6 100644
--- a/docs/api-reference/networking.md
+++ b/docs/api-reference/networking.md
@@ -2003,6 +2003,32 @@ string
+NetworkPeeringState
+(string
alias)
+
+(Appears on:NetworkPeeringStatus)
+
+
+
NetworkPeeringState is the state a NetworkPeering can be in
+
+
+
+
+Value |
+Description |
+
+
+"Error" |
+NetworkPeeringStateError signals that the network peering is in error state.
+ |
+
"Pending" |
+NetworkPeeringStatePending signals that the network peering is not applied.
+ |
+
"Ready" |
+NetworkPeeringStateReady signals that the network peering is ready.
+ |
+
+
NetworkPeeringStatus
@@ -2030,6 +2056,19 @@ string
Name is the name of the network peering.
+
+
+state
+
+
+NetworkPeeringState
+
+
+ |
+
+ State represents the network peering state
+ |
+
NetworkPolicyCondition
diff --git a/internal/apis/networking/network_type.go b/internal/apis/networking/network_type.go
index e2d26b131..d6ded9fc1 100644
--- a/internal/apis/networking/network_type.go
+++ b/internal/apis/networking/network_type.go
@@ -74,8 +74,10 @@ type NetworkPeeringState string
const (
// NetworkPeeringStatePending signals that the network peering is not applied.
NetworkPeeringStatePending NetworkPeeringState = "Pending"
- // NetworkPeeringStateApplied signals that the network peering is applied.
- NetworkPeeringStateApplied NetworkPeeringState = "Applied"
+ // NetworkPeeringStateReady signals that the network peering is ready.
+ NetworkPeeringStateReady NetworkPeeringState = "Ready"
+ // NetworkPeeringStateError signals that the network peering is in error state.
+ NetworkPeeringStateError NetworkPeeringState = "Error"
)
// NetworkPeeringStatus is the status of a network peering.
diff --git a/internal/controllers/networking/network_peering_controller_test.go b/internal/controllers/networking/network_peering_controller_test.go
index 5f98e581c..d58ad50d1 100644
--- a/internal/controllers/networking/network_peering_controller_test.go
+++ b/internal/controllers/networking/network_peering_controller_test.go
@@ -550,4 +550,101 @@ var _ = Describe("NetworkPeeringController", func() {
Eventually(Get(network2)).Should(Satisfy(apierrors.IsNotFound))
Eventually(Get(network3)).Should(Satisfy(apierrors.IsNotFound))
})
+
+ It("should skip network peering for a non-existing network", func(ctx SpecContext) {
+ By("creating a network network-1")
+ network1 := &networkingv1alpha1.Network{
+ ObjectMeta: metav1.ObjectMeta{
+ Namespace: ns.Name,
+ Name: "network-1",
+ },
+ Spec: networkingv1alpha1.NetworkSpec{
+ Peerings: []networkingv1alpha1.NetworkPeering{
+ {
+ Name: "peering-1",
+ NetworkRef: networkingv1alpha1.NetworkPeeringNetworkRef{
+ Name: "network-2",
+ Namespace: ns.Name,
+ },
+ },
+ {
+ Name: "peering-2",
+ NetworkRef: networkingv1alpha1.NetworkPeeringNetworkRef{
+ Name: "network-3",
+ },
+ },
+ },
+ },
+ }
+ Expect(k8sClient.Create(ctx, network1)).To(Succeed())
+
+ By("creating a network network-3")
+ network3 := &networkingv1alpha1.Network{
+ ObjectMeta: metav1.ObjectMeta{
+ Namespace: ns.Name,
+ Name: "network-3",
+ },
+ Spec: networkingv1alpha1.NetworkSpec{
+ Peerings: []networkingv1alpha1.NetworkPeering{
+ {
+ Name: "peering-3",
+ NetworkRef: networkingv1alpha1.NetworkPeeringNetworkRef{
+ Name: "network-1",
+ Namespace: ns.Name,
+ },
+ },
+ },
+ },
+ }
+ Expect(k8sClient.Create(ctx, network3)).To(Succeed())
+
+ By("patching networks as available")
+ baseNetwork1 := network1.DeepCopy()
+ network1.Status.State = networkingv1alpha1.NetworkStateAvailable
+ Expect(k8sClient.Status().Patch(ctx, network1, client.MergeFrom(baseNetwork1))).To(Succeed())
+
+ baseNetwork3 := network3.DeepCopy()
+ network3.Status.State = networkingv1alpha1.NetworkStateAvailable
+ Expect(k8sClient.Status().Patch(ctx, network3, client.MergeFrom(baseNetwork3))).To(Succeed())
+
+ By("waiting for networks to reference each other")
+ Eventually(Object(network1)).
+ Should(SatisfyAll(
+ HaveField("Spec.PeeringClaimRefs", ConsistOf(networkingv1alpha1.NetworkPeeringClaimRef{
+ Namespace: network3.Namespace,
+ Name: network3.Name,
+ UID: network3.UID,
+ })),
+ HaveField("Status.State", Equal(networkingv1alpha1.NetworkStateAvailable)),
+ HaveField("Status.Peerings", ConsistOf(networkingv1alpha1.NetworkPeeringStatus{
+ Name: network1.Spec.Peerings[0].Name,
+ State: networkingv1alpha1.NetworkPeeringStatePending,
+ }, networkingv1alpha1.NetworkPeeringStatus{
+ Name: network1.Spec.Peerings[1].Name,
+ State: networkingv1alpha1.NetworkPeeringStatePending,
+ })),
+ ))
+
+ Eventually(Object(network3)).
+ Should(SatisfyAll(
+ HaveField("Spec.PeeringClaimRefs", ConsistOf(networkingv1alpha1.NetworkPeeringClaimRef{
+ Namespace: network1.Namespace,
+ Name: network1.Name,
+ UID: network1.UID,
+ })),
+ HaveField("Status.State", Equal(networkingv1alpha1.NetworkStateAvailable)),
+ HaveField("Status.Peerings", ConsistOf(networkingv1alpha1.NetworkPeeringStatus{
+ Name: network3.Spec.Peerings[0].Name,
+ State: networkingv1alpha1.NetworkPeeringStatePending,
+ })),
+ ))
+
+ By("deleting the networks")
+ Expect(k8sClient.Delete(ctx, network1)).To(Succeed())
+ Expect(k8sClient.Delete(ctx, network3)).To(Succeed())
+
+ By("waiting for networks to be gone")
+ Eventually(Get(network1)).Should(Satisfy(apierrors.IsNotFound))
+ Eventually(Get(network3)).Should(Satisfy(apierrors.IsNotFound))
+ })
})