|
| 1 | +//go:build e2e |
| 2 | +// +build e2e |
| 3 | + |
| 4 | +/* |
| 5 | +Copyright 2023 The Kubernetes Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +*/ |
| 19 | + |
| 20 | +package e2e |
| 21 | + |
| 22 | +import ( |
| 23 | + "os" |
| 24 | + |
| 25 | + . "github.com/onsi/ginkgo/v2" |
| 26 | + . "github.com/onsi/gomega" |
| 27 | + appsv1 "k8s.io/api/apps/v1" |
| 28 | + corev1 "k8s.io/api/core/v1" |
| 29 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 30 | + operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha1" |
| 31 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 32 | + "sigs.k8s.io/yaml" |
| 33 | +) |
| 34 | + |
| 35 | +const ( |
| 36 | + customManifestsFolder = "resources/" |
| 37 | +) |
| 38 | + |
| 39 | +var _ = Describe("Install Core Provider in an air-gapped environment", func() { |
| 40 | + It("should successfully create config maps with Core Provider manifests", func() { |
| 41 | + k8sclient := bootstrapClusterProxy.GetClient() |
| 42 | + |
| 43 | + configMaps := []corev1.ConfigMap{} |
| 44 | + |
| 45 | + for _, fileName := range []string{"core-cluster-api-v1.4.2.yaml", "core-cluster-api-v1.4.3.yaml"} { |
| 46 | + coreProviderComponents, err := os.ReadFile(customManifestsFolder + fileName) |
| 47 | + Expect(err).ToNot(HaveOccurred(), "Failed to read the core provider manifests file") |
| 48 | + |
| 49 | + var configMap corev1.ConfigMap |
| 50 | + |
| 51 | + Expect(yaml.Unmarshal(coreProviderComponents, &configMap)).To(Succeed()) |
| 52 | + |
| 53 | + configMaps = append(configMaps, configMap) |
| 54 | + } |
| 55 | + |
| 56 | + By("Applying core provider manifests to the cluster") |
| 57 | + for _, cm := range configMaps { |
| 58 | + Expect(k8sclient.Create(ctx, &cm)).To(Succeed()) |
| 59 | + } |
| 60 | + }) |
| 61 | + |
| 62 | + It("should successfully create a CoreProvider from a config map", func() { |
| 63 | + k8sclient := bootstrapClusterProxy.GetClient() |
| 64 | + coreProvider := &operatorv1.CoreProvider{ |
| 65 | + ObjectMeta: metav1.ObjectMeta{ |
| 66 | + Name: coreProviderName, |
| 67 | + Namespace: operatorNamespace, |
| 68 | + }, |
| 69 | + Spec: operatorv1.CoreProviderSpec{ |
| 70 | + ProviderSpec: operatorv1.ProviderSpec{ |
| 71 | + FetchConfig: &operatorv1.FetchConfiguration{ |
| 72 | + Selector: &metav1.LabelSelector{ |
| 73 | + MatchLabels: map[string]string{ |
| 74 | + "provider.cluster.x-k8s.io/name": "cluster-api", |
| 75 | + "provider.cluster.x-k8s.io/type": "core", |
| 76 | + }, |
| 77 | + }, |
| 78 | + }, |
| 79 | + }, |
| 80 | + }, |
| 81 | + } |
| 82 | + |
| 83 | + Expect(k8sclient.Create(ctx, coreProvider)).To(Succeed()) |
| 84 | + |
| 85 | + By("Waiting for the core provider deployment to be ready") |
| 86 | + Eventually(func() bool { |
| 87 | + isReady, err := waitForDeployment(k8sclient, ctx, coreProviderDeploymentName) |
| 88 | + if err != nil { |
| 89 | + return false |
| 90 | + } |
| 91 | + return isReady |
| 92 | + }, timeout).Should(Equal(true)) |
| 93 | + |
| 94 | + By("Waiting for core provider to be ready") |
| 95 | + Eventually(func() bool { |
| 96 | + coreProvider := &operatorv1.CoreProvider{} |
| 97 | + key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName} |
| 98 | + if err := k8sclient.Get(ctx, key, coreProvider); err != nil { |
| 99 | + return false |
| 100 | + } |
| 101 | + |
| 102 | + for _, c := range coreProvider.Status.Conditions { |
| 103 | + if c.Type == operatorv1.ProviderInstalledCondition && c.Status == corev1.ConditionTrue { |
| 104 | + return true |
| 105 | + } |
| 106 | + } |
| 107 | + return false |
| 108 | + }, timeout).Should(Equal(true)) |
| 109 | + |
| 110 | + By("Waiting for status.IntalledVersion to be set") |
| 111 | + Eventually(func() bool { |
| 112 | + coreProvider := &operatorv1.CoreProvider{} |
| 113 | + key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName} |
| 114 | + if err := k8sclient.Get(ctx, key, coreProvider); err != nil { |
| 115 | + return false |
| 116 | + } |
| 117 | + |
| 118 | + if coreProvider.Status.InstalledVersion != nil && *coreProvider.Status.InstalledVersion == coreProvider.Spec.Version { |
| 119 | + return true |
| 120 | + } |
| 121 | + return false |
| 122 | + }, timeout).Should(Equal(true)) |
| 123 | + }) |
| 124 | + |
| 125 | + It("should successfully downgrade a CoreProvider (latest -> v1.4.2)", func() { |
| 126 | + k8sclient := bootstrapClusterProxy.GetClient() |
| 127 | + coreProvider := &operatorv1.CoreProvider{} |
| 128 | + key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName} |
| 129 | + Expect(k8sclient.Get(ctx, key, coreProvider)).To(Succeed()) |
| 130 | + |
| 131 | + coreProvider.Spec.Version = previousCAPIVersion |
| 132 | + |
| 133 | + Expect(k8sclient.Update(ctx, coreProvider)).To(Succeed()) |
| 134 | + |
| 135 | + By("Waiting for the core provider deployment to be ready") |
| 136 | + Eventually(func() bool { |
| 137 | + isReady, err := waitForDeployment(k8sclient, ctx, coreProviderDeploymentName) |
| 138 | + if err != nil { |
| 139 | + return false |
| 140 | + } |
| 141 | + return isReady |
| 142 | + }, timeout).Should(Equal(true)) |
| 143 | + |
| 144 | + By("Waiting for core provider to be ready") |
| 145 | + Eventually(func() bool { |
| 146 | + coreProvider := &operatorv1.CoreProvider{} |
| 147 | + key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName} |
| 148 | + if err := k8sclient.Get(ctx, key, coreProvider); err != nil { |
| 149 | + return false |
| 150 | + } |
| 151 | + |
| 152 | + for _, c := range coreProvider.Status.Conditions { |
| 153 | + if c.Type == operatorv1.ProviderInstalledCondition && c.Status == corev1.ConditionTrue { |
| 154 | + return true |
| 155 | + } |
| 156 | + } |
| 157 | + return false |
| 158 | + }, timeout).Should(Equal(true)) |
| 159 | + |
| 160 | + By("Waiting for status.IntalledVersion to be set") |
| 161 | + Eventually(func() bool { |
| 162 | + coreProvider := &operatorv1.CoreProvider{} |
| 163 | + key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName} |
| 164 | + if err := k8sclient.Get(ctx, key, coreProvider); err != nil { |
| 165 | + return false |
| 166 | + } |
| 167 | + |
| 168 | + if coreProvider.Status.InstalledVersion != nil && *coreProvider.Status.InstalledVersion == previousCAPIVersion { |
| 169 | + return true |
| 170 | + } |
| 171 | + return false |
| 172 | + }, timeout).Should(Equal(true)) |
| 173 | + }) |
| 174 | + |
| 175 | + It("should successfully upgrade a CoreProvider (v1.4.2 -> latest)", func() { |
| 176 | + k8sclient := bootstrapClusterProxy.GetClient() |
| 177 | + coreProvider := &operatorv1.CoreProvider{} |
| 178 | + key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName} |
| 179 | + Expect(k8sclient.Get(ctx, key, coreProvider)).To(Succeed()) |
| 180 | + |
| 181 | + coreProvider.Spec.Version = "" |
| 182 | + |
| 183 | + Expect(k8sclient.Update(ctx, coreProvider)).To(Succeed()) |
| 184 | + |
| 185 | + By("Waiting for the core provider deployment to be ready") |
| 186 | + Eventually(func() bool { |
| 187 | + isReady, err := waitForDeployment(k8sclient, ctx, coreProviderDeploymentName) |
| 188 | + if err != nil { |
| 189 | + return false |
| 190 | + } |
| 191 | + return isReady |
| 192 | + }, timeout).Should(Equal(true)) |
| 193 | + |
| 194 | + By("Waiting for core provider to be ready") |
| 195 | + Eventually(func() bool { |
| 196 | + coreProvider := &operatorv1.CoreProvider{} |
| 197 | + key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName} |
| 198 | + if err := k8sclient.Get(ctx, key, coreProvider); err != nil { |
| 199 | + return false |
| 200 | + } |
| 201 | + |
| 202 | + for _, c := range coreProvider.Status.Conditions { |
| 203 | + if c.Type == operatorv1.ProviderInstalledCondition && c.Status == corev1.ConditionTrue { |
| 204 | + return true |
| 205 | + } |
| 206 | + } |
| 207 | + return false |
| 208 | + }, timeout).Should(Equal(true)) |
| 209 | + |
| 210 | + By("Waiting for status.IntalledVersion to be set") |
| 211 | + Eventually(func() bool { |
| 212 | + coreProvider := &operatorv1.CoreProvider{} |
| 213 | + key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderName} |
| 214 | + if err := k8sclient.Get(ctx, key, coreProvider); err != nil { |
| 215 | + return false |
| 216 | + } |
| 217 | + |
| 218 | + if coreProvider.Status.InstalledVersion != nil && *coreProvider.Status.InstalledVersion == coreProvider.Spec.Version { |
| 219 | + return true |
| 220 | + } |
| 221 | + return false |
| 222 | + }, timeout).Should(Equal(true)) |
| 223 | + }) |
| 224 | + |
| 225 | + It("should successfully delete a CoreProvider", func() { |
| 226 | + k8sclient := bootstrapClusterProxy.GetClient() |
| 227 | + coreProvider := &operatorv1.CoreProvider{ |
| 228 | + ObjectMeta: metav1.ObjectMeta{ |
| 229 | + Name: coreProviderName, |
| 230 | + Namespace: operatorNamespace, |
| 231 | + }, |
| 232 | + Spec: operatorv1.CoreProviderSpec{ |
| 233 | + ProviderSpec: operatorv1.ProviderSpec{}, |
| 234 | + }, |
| 235 | + } |
| 236 | + |
| 237 | + Expect(k8sclient.Delete(ctx, coreProvider)).To(Succeed()) |
| 238 | + |
| 239 | + By("Waiting for the core provider deployment to be deleted") |
| 240 | + Eventually(func() bool { |
| 241 | + deployment := &appsv1.Deployment{} |
| 242 | + key := client.ObjectKey{Namespace: operatorNamespace, Name: coreProviderDeploymentName} |
| 243 | + isReady, err := waitForObjectToBeDeleted(k8sclient, ctx, key, deployment) |
| 244 | + if err != nil { |
| 245 | + return false |
| 246 | + } |
| 247 | + return isReady |
| 248 | + }, timeout).Should(Equal(true)) |
| 249 | + }) |
| 250 | +}) |
0 commit comments