|
| 1 | +//go:build e2e |
| 2 | + |
| 3 | +// Copyright 2024 D2iQ, Inc. All rights reserved. |
| 4 | +// SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +package e2e |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | + "fmt" |
| 11 | + |
| 12 | + . "github.com/onsi/ginkgo/v2" |
| 13 | + appsv1 "k8s.io/api/apps/v1" |
| 14 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 15 | + capiv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 16 | + "sigs.k8s.io/cluster-api/test/framework" |
| 17 | + |
| 18 | + "github.com/d2iq-labs/capi-runtime-extensions/api/v1alpha1" |
| 19 | +) |
| 20 | + |
| 21 | +type WaitForAddonsToBeReadyInWorkloadClusterInput struct { |
| 22 | + AddonsConfig v1alpha1.Addons |
| 23 | + WorkloadCluster *capiv1.Cluster |
| 24 | + ClusterProxy framework.ClusterProxy |
| 25 | + DeploymentIntervals []interface{} |
| 26 | + DaemonSetIntervals []interface{} |
| 27 | + HelmReleaseIntervals []interface{} |
| 28 | + ClusterResourceSetIntervals []interface{} |
| 29 | +} |
| 30 | + |
| 31 | +func WaitForAddonsToBeReadyInWorkloadCluster( |
| 32 | + ctx context.Context, |
| 33 | + input WaitForAddonsToBeReadyInWorkloadClusterInput, //nolint:gocritic // This hugeParam is OK in tests. |
| 34 | +) { |
| 35 | + WaitForCNIToBeReadyInWorkloadCluster( |
| 36 | + ctx, |
| 37 | + WaitForCNIToBeReadyInWorkloadClusterInput{ |
| 38 | + CNI: input.AddonsConfig.CNI, |
| 39 | + WorkloadCluster: input.WorkloadCluster, |
| 40 | + ClusterProxy: input.ClusterProxy, |
| 41 | + DeploymentIntervals: input.DeploymentIntervals, |
| 42 | + DaemonSetIntervals: input.DaemonSetIntervals, |
| 43 | + HelmReleaseIntervals: input.HelmReleaseIntervals, |
| 44 | + ClusterResourceSetIntervals: input.ClusterResourceSetIntervals, |
| 45 | + }, |
| 46 | + ) |
| 47 | +} |
| 48 | + |
| 49 | +type WaitForCNIToBeReadyInWorkloadClusterInput struct { |
| 50 | + CNI *v1alpha1.CNI |
| 51 | + WorkloadCluster *capiv1.Cluster |
| 52 | + ClusterProxy framework.ClusterProxy |
| 53 | + DeploymentIntervals []interface{} |
| 54 | + DaemonSetIntervals []interface{} |
| 55 | + HelmReleaseIntervals []interface{} |
| 56 | + ClusterResourceSetIntervals []interface{} |
| 57 | +} |
| 58 | + |
| 59 | +func WaitForCNIToBeReadyInWorkloadCluster( |
| 60 | + ctx context.Context, |
| 61 | + input WaitForCNIToBeReadyInWorkloadClusterInput, //nolint:gocritic // This hugeParam is OK in tests. |
| 62 | +) { |
| 63 | + if input.CNI == nil { |
| 64 | + return |
| 65 | + } |
| 66 | + |
| 67 | + switch input.CNI.Provider { |
| 68 | + case v1alpha1.CNIProviderCalico: |
| 69 | + waitForCalicoToBeReadyInWorkloadCluster( |
| 70 | + ctx, |
| 71 | + waitForCalicoToBeReadyInWorkloadClusterInput{ |
| 72 | + strategy: input.CNI.Strategy, |
| 73 | + workloadCluster: input.WorkloadCluster, |
| 74 | + clusterProxy: input.ClusterProxy, |
| 75 | + deploymentIntervals: input.DeploymentIntervals, |
| 76 | + daemonSetIntervals: input.DaemonSetIntervals, |
| 77 | + helmReleaseIntervals: input.HelmReleaseIntervals, |
| 78 | + clusterResourceSetIntervals: input.ClusterResourceSetIntervals, |
| 79 | + }, |
| 80 | + ) |
| 81 | + case v1alpha1.CNIProviderCilium: |
| 82 | + waitForCiliumToBeReadyInWorkloadCluster( |
| 83 | + ctx, |
| 84 | + waitForCiliumToBeReadyInWorkloadClusterInput{ |
| 85 | + strategy: input.CNI.Strategy, |
| 86 | + workloadCluster: input.WorkloadCluster, |
| 87 | + clusterProxy: input.ClusterProxy, |
| 88 | + deploymentIntervals: input.DeploymentIntervals, |
| 89 | + daemonSetIntervals: input.DaemonSetIntervals, |
| 90 | + helmReleaseIntervals: input.HelmReleaseIntervals, |
| 91 | + clusterResourceSetIntervals: input.ClusterResourceSetIntervals, |
| 92 | + }, |
| 93 | + ) |
| 94 | + default: |
| 95 | + Fail( |
| 96 | + fmt.Sprintf( |
| 97 | + "Do not know how to wait for CNI provider %s to be ready", |
| 98 | + input.CNI.Provider, |
| 99 | + ), |
| 100 | + ) |
| 101 | + } |
| 102 | +} |
| 103 | + |
| 104 | +type waitForCalicoToBeReadyInWorkloadClusterInput struct { |
| 105 | + strategy v1alpha1.AddonStrategy |
| 106 | + workloadCluster *capiv1.Cluster |
| 107 | + clusterProxy framework.ClusterProxy |
| 108 | + deploymentIntervals []interface{} |
| 109 | + daemonSetIntervals []interface{} |
| 110 | + helmReleaseIntervals []interface{} |
| 111 | + clusterResourceSetIntervals []interface{} |
| 112 | +} |
| 113 | + |
| 114 | +func waitForCalicoToBeReadyInWorkloadCluster( |
| 115 | + ctx context.Context, |
| 116 | + input waitForCalicoToBeReadyInWorkloadClusterInput, //nolint:gocritic // This hugeParam is OK in tests. |
| 117 | +) { |
| 118 | + switch input.strategy { |
| 119 | + case v1alpha1.AddonStrategyClusterResourceSet: |
| 120 | + waitForClusterResourceSetToApplyResourcesInCluster( |
| 121 | + ctx, |
| 122 | + waitForClusterResourceSetToApplyResourcesInClusterInput{ |
| 123 | + name: "calico-cni-installation-" + input.workloadCluster.Name, |
| 124 | + clusterProxy: input.clusterProxy, |
| 125 | + cluster: input.workloadCluster, |
| 126 | + intervals: input.clusterResourceSetIntervals, |
| 127 | + }, |
| 128 | + ) |
| 129 | + case v1alpha1.AddonStrategyHelmAddon: |
| 130 | + WaitForHelmReleaseProxyReadyForCluster( |
| 131 | + ctx, |
| 132 | + WaitForHelmReleaseProxyReadyForClusterInput{ |
| 133 | + GetLister: input.clusterProxy.GetClient(), |
| 134 | + Cluster: input.workloadCluster, |
| 135 | + HelmChartProxyName: "calico-cni-installation-" + input.workloadCluster.Name, |
| 136 | + }, |
| 137 | + input.helmReleaseIntervals..., |
| 138 | + ) |
| 139 | + default: |
| 140 | + Fail( |
| 141 | + fmt.Sprintf( |
| 142 | + "Do not know how to wait for Calico using strategy %s to be ready", |
| 143 | + input.strategy, |
| 144 | + ), |
| 145 | + ) |
| 146 | + } |
| 147 | + |
| 148 | + workloadClusterClient := input.clusterProxy.GetWorkloadCluster( |
| 149 | + ctx, input.workloadCluster.Namespace, input.workloadCluster.Name, |
| 150 | + ).GetClient() |
| 151 | + |
| 152 | + WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{ |
| 153 | + Getter: workloadClusterClient, |
| 154 | + Deployment: &appsv1.Deployment{ |
| 155 | + ObjectMeta: metav1.ObjectMeta{ |
| 156 | + Name: "tigera-operator", |
| 157 | + Namespace: "tigera-operator", |
| 158 | + }, |
| 159 | + }, |
| 160 | + }, input.deploymentIntervals...) |
| 161 | + WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{ |
| 162 | + Getter: workloadClusterClient, |
| 163 | + Deployment: &appsv1.Deployment{ |
| 164 | + ObjectMeta: metav1.ObjectMeta{ |
| 165 | + Name: "calico-typha", |
| 166 | + Namespace: "calico-system", |
| 167 | + }, |
| 168 | + }, |
| 169 | + }, input.deploymentIntervals...) |
| 170 | + WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{ |
| 171 | + Getter: workloadClusterClient, |
| 172 | + Deployment: &appsv1.Deployment{ |
| 173 | + ObjectMeta: metav1.ObjectMeta{ |
| 174 | + Name: "calico-kube-controllers", |
| 175 | + Namespace: "calico-system", |
| 176 | + }, |
| 177 | + }, |
| 178 | + }, input.deploymentIntervals...) |
| 179 | + WaitForDaemonSetsAvailable(ctx, WaitForDaemonSetsAvailableInput{ |
| 180 | + Getter: workloadClusterClient, |
| 181 | + DaemonSet: &appsv1.DaemonSet{ |
| 182 | + ObjectMeta: metav1.ObjectMeta{ |
| 183 | + Name: "calico-node", |
| 184 | + Namespace: "calico-system", |
| 185 | + }, |
| 186 | + }, |
| 187 | + }, input.daemonSetIntervals...) |
| 188 | + WaitForDaemonSetsAvailable(ctx, WaitForDaemonSetsAvailableInput{ |
| 189 | + Getter: workloadClusterClient, |
| 190 | + DaemonSet: &appsv1.DaemonSet{ |
| 191 | + ObjectMeta: metav1.ObjectMeta{ |
| 192 | + Name: "csi-node-driver", |
| 193 | + Namespace: "calico-system", |
| 194 | + }, |
| 195 | + }, |
| 196 | + }, input.daemonSetIntervals...) |
| 197 | + WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{ |
| 198 | + Getter: workloadClusterClient, |
| 199 | + Deployment: &appsv1.Deployment{ |
| 200 | + ObjectMeta: metav1.ObjectMeta{ |
| 201 | + Name: "calico-apiserver", |
| 202 | + Namespace: "calico-apiserver", |
| 203 | + }, |
| 204 | + }, |
| 205 | + }, input.deploymentIntervals...) |
| 206 | +} |
| 207 | + |
| 208 | +type waitForCiliumToBeReadyInWorkloadClusterInput struct { |
| 209 | + strategy v1alpha1.AddonStrategy |
| 210 | + workloadCluster *capiv1.Cluster |
| 211 | + clusterProxy framework.ClusterProxy |
| 212 | + deploymentIntervals []interface{} |
| 213 | + daemonSetIntervals []interface{} |
| 214 | + helmReleaseIntervals []interface{} |
| 215 | + clusterResourceSetIntervals []interface{} |
| 216 | +} |
| 217 | + |
| 218 | +func waitForCiliumToBeReadyInWorkloadCluster( |
| 219 | + ctx context.Context, |
| 220 | + input waitForCiliumToBeReadyInWorkloadClusterInput, //nolint:gocritic // This hugeParam is OK in tests. |
| 221 | +) { |
| 222 | + switch input.strategy { |
| 223 | + case v1alpha1.AddonStrategyClusterResourceSet: |
| 224 | + waitForClusterResourceSetToApplyResourcesInCluster( |
| 225 | + ctx, |
| 226 | + waitForClusterResourceSetToApplyResourcesInClusterInput{ |
| 227 | + name: "cilium-cni-installation-" + input.workloadCluster.Name, |
| 228 | + clusterProxy: input.clusterProxy, |
| 229 | + cluster: input.workloadCluster, |
| 230 | + intervals: input.clusterResourceSetIntervals, |
| 231 | + }, |
| 232 | + ) |
| 233 | + case v1alpha1.AddonStrategyHelmAddon: |
| 234 | + WaitForHelmReleaseProxyReadyForCluster( |
| 235 | + ctx, |
| 236 | + WaitForHelmReleaseProxyReadyForClusterInput{ |
| 237 | + GetLister: input.clusterProxy.GetClient(), |
| 238 | + Cluster: input.workloadCluster, |
| 239 | + HelmChartProxyName: "cilium-cni-installation-" + input.workloadCluster.Name, |
| 240 | + }, |
| 241 | + input.helmReleaseIntervals..., |
| 242 | + ) |
| 243 | + default: |
| 244 | + Fail( |
| 245 | + fmt.Sprintf( |
| 246 | + "Do not know how to wait for Cilium using strategy %s to be ready", |
| 247 | + input.strategy, |
| 248 | + ), |
| 249 | + ) |
| 250 | + } |
| 251 | + |
| 252 | + workloadClusterClient := input.clusterProxy.GetWorkloadCluster( |
| 253 | + ctx, input.workloadCluster.Namespace, input.workloadCluster.Name, |
| 254 | + ).GetClient() |
| 255 | + |
| 256 | + WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{ |
| 257 | + Getter: workloadClusterClient, |
| 258 | + Deployment: &appsv1.Deployment{ |
| 259 | + ObjectMeta: metav1.ObjectMeta{ |
| 260 | + Name: "cilium-operator", |
| 261 | + Namespace: "kube-system", |
| 262 | + }, |
| 263 | + }, |
| 264 | + }, input.deploymentIntervals...) |
| 265 | + |
| 266 | + WaitForDaemonSetsAvailable(ctx, WaitForDaemonSetsAvailableInput{ |
| 267 | + Getter: workloadClusterClient, |
| 268 | + DaemonSet: &appsv1.DaemonSet{ |
| 269 | + ObjectMeta: metav1.ObjectMeta{ |
| 270 | + Name: "cilium", |
| 271 | + Namespace: "kube-system", |
| 272 | + }, |
| 273 | + }, |
| 274 | + }, input.daemonSetIntervals...) |
| 275 | +} |
0 commit comments