|
| 1 | +package e2e |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + g "github.com/onsi/ginkgo/v2" |
| 7 | + o "github.com/onsi/gomega" |
| 8 | + |
| 9 | + exutil "github.com/openshift/origin/test/extended/util" |
| 10 | + |
| 11 | + admissionapi "k8s.io/pod-security-admission/api" |
| 12 | + |
| 13 | + e2enode "k8s.io/kubernetes/test/e2e/framework/node" |
| 14 | +) |
| 15 | + |
| 16 | +var _ = g.Describe("[sig-network] CNO", func() { |
| 17 | + defer g.GinkgoRecover() |
| 18 | + oc := exutil.NewCLIWithPodSecurityLevel("networking-cno", admissionapi.LevelBaseline) |
| 19 | + |
| 20 | + g.It("Author:anusaxen-High-73205-High-72817-Make sure internalJoinSubnet and internalTransitSwitchSubnet is configurable post install as a Day 2 operation [Disruptive]", func() { |
| 21 | + var ( |
| 22 | + pod1Name = "hello-pod1" |
| 23 | + pod2Name = "hello-pod2" |
| 24 | + podLabel = "hello-pod" |
| 25 | + serviceName = "test-service-73205" |
| 26 | + servicePort = 27017 |
| 27 | + serviceTargetPort = 8080 |
| 28 | + ) |
| 29 | + ipStackType := checkIPStackType(oc) |
| 30 | + o.Expect(ipStackType).NotTo(o.BeEmpty()) |
| 31 | + |
| 32 | + nodeList, err := e2enode.GetReadySchedulableNodes(context.TODO(), oc.KubeFramework().ClientSet) |
| 33 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 34 | + if len(nodeList.Items) < 2 { |
| 35 | + g.Skip("This case requires 2 nodes, but the cluster has less than two nodes") |
| 36 | + } |
| 37 | + |
| 38 | + // Create hello-pod1 on the first node |
| 39 | + createPingPodOnNode(oc, pod1Name, oc.Namespace(), podLabel, nodeList.Items[0].Name) |
| 40 | + |
| 41 | + // Create hello-pod2 on the second node |
| 42 | + createPingPodOnNode(oc, pod2Name, oc.Namespace(), podLabel, nodeList.Items[1].Name) |
| 43 | + |
| 44 | + // Determine ipFamilyPolicy based on cluster type |
| 45 | + var ipFamilyPolicy string |
| 46 | + if ipStackType == "ipv4single" { |
| 47 | + ipFamilyPolicy = "SingleStack" |
| 48 | + } else { |
| 49 | + ipFamilyPolicy = "PreferDualStack" |
| 50 | + } |
| 51 | + internalTrafficPolicy := "Cluster" |
| 52 | + externalTrafficPolicy := "" |
| 53 | + // Create service backing both pods |
| 54 | + createGenericService(oc, serviceName, oc.Namespace(), "TCP", podLabel, "ClusterIP", ipFamilyPolicy, internalTrafficPolicy, externalTrafficPolicy, servicePort, serviceTargetPort) |
| 55 | + //custom patches to test depending on type of cluster addressing |
| 56 | + customPatchIPv4 := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"100.99.0.0/16\",\"internalTransitSwitchSubnet\": \"100.69.0.0/16\"}}}}}" |
| 57 | + customPatchIPv6 := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv6\":{\"internalJoinSubnet\": \"ab98::/64\",\"internalTransitSwitchSubnet\": \"ab97::/64\"}}}}}" |
| 58 | + customPatchDualstack := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"100.99.0.0/16\",\"internalTransitSwitchSubnet\": \"100.69.0.0/16\"},\"ipv6\": {\"internalJoinSubnet\": \"ab98::/64\",\"internalTransitSwitchSubnet\": \"ab97::/64\"}}}}}" |
| 59 | + |
| 60 | + //gather original cluster values so that we can defer to them later once test done |
| 61 | + currentinternalJoinSubnetIPv4Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.spec.defaultNetwork.ovnKubernetesConfig.ipv4.internalJoinSubnet}").Output() |
| 62 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 63 | + currentinternalTransitSwSubnetIPv4Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.spec.defaultNetwork.ovnKubernetesConfig.ipv4.internalTransitSwitchSubnet}").Output() |
| 64 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 65 | + currentinternalJoinSubnetIPv6Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.spec.defaultNetwork.ovnKubernetesConfig.ipv6.internalJoinSubnet}").Output() |
| 66 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 67 | + currentinternalTransitSwSubnetIPv6Value, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("Network.operator.openshift.io/cluster", "-o=jsonpath={.spec.defaultNetwork.ovnKubernetesConfig.ipv6.internalTransitSwitchSubnet}").Output() |
| 68 | + o.Expect(err).NotTo(o.HaveOccurred()) |
| 69 | + |
| 70 | + //if any of value is null on exisiting cluster, it indicates that cluster came up with following default values assigned by OVNK |
| 71 | + if currentinternalJoinSubnetIPv4Value == "" { |
| 72 | + currentinternalJoinSubnetIPv4Value = "100.64.0.0/16" |
| 73 | + } |
| 74 | + if currentinternalJoinSubnetIPv6Value == "" { |
| 75 | + currentinternalJoinSubnetIPv6Value = "fd98::/64" |
| 76 | + } |
| 77 | + if currentinternalTransitSwSubnetIPv4Value == "" { |
| 78 | + currentinternalTransitSwSubnetIPv4Value = "100.88.0.0/16" |
| 79 | + } |
| 80 | + if currentinternalTransitSwSubnetIPv6Value == "" { |
| 81 | + currentinternalTransitSwSubnetIPv6Value = "fd97::/64" |
| 82 | + } |
| 83 | + |
| 84 | + //vars to patch cluster back to original state |
| 85 | + patchIPv4original := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv4Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv4Value + "\"}}}}}" |
| 86 | + patchIPv6original := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv6\":{\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv6Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv6Value + "\"}}}}}" |
| 87 | + patchDualstackoriginal := "{\"spec\":{\"defaultNetwork\":{\"ovnKubernetesConfig\":{\"ipv4\":{\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv4Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv4Value + "\"},\"ipv6\": {\"internalJoinSubnet\": \"" + currentinternalJoinSubnetIPv6Value + "\",\"internalTransitSwitchSubnet\": \"" + currentinternalTransitSwSubnetIPv6Value + "\"}}}}}" |
| 88 | + |
| 89 | + switch ipStackType { |
| 90 | + case "ipv4single": |
| 91 | + defer func() { |
| 92 | + patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", patchIPv4original) |
| 93 | + err := checkOVNKState(oc) |
| 94 | + o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube didn't trigger or rolled out successfully post oc patch") |
| 95 | + }() |
| 96 | + patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", customPatchIPv4) |
| 97 | + case "ipv6single": |
| 98 | + defer func() { |
| 99 | + patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", patchIPv6original) |
| 100 | + err := checkOVNKState(oc) |
| 101 | + o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube didn't trigger or rolled out successfully post oc patch") |
| 102 | + }() |
| 103 | + patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", customPatchIPv6) |
| 104 | + default: |
| 105 | + defer func() { |
| 106 | + patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", patchDualstackoriginal) |
| 107 | + err := checkOVNKState(oc) |
| 108 | + o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube didn't trigger or rolled out successfully post oc patch") |
| 109 | + }() |
| 110 | + patchResourceAsAdmin(oc, "Network.operator.openshift.io/cluster", customPatchDualstack) |
| 111 | + } |
| 112 | + err = checkOVNKState(oc) |
| 113 | + o.Expect(err).NotTo(o.HaveOccurred(), "OVNkube never trigger or rolled out successfully post oc patch") |
| 114 | + //check usual svc and pod connectivities post migration which also ensures disruption doesn't last post successful rollout |
| 115 | + curlPod2PodPass(oc, oc.Namespace(), pod1Name, oc.Namespace(), pod2Name, serviceTargetPort) |
| 116 | + curlPod2SvcPass(oc, oc.Namespace(), oc.Namespace(), pod1Name, serviceName, servicePort) |
| 117 | + }) |
| 118 | +}) |
0 commit comments