|
| 1 | +package capi |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + |
| 7 | + . "github.com/onsi/ginkgo/v2" |
| 8 | + . "github.com/onsi/gomega" |
| 9 | + configv1 "github.com/openshift/api/config/v1" |
| 10 | + mapiv1 "github.com/openshift/api/machine/v1beta1" |
| 11 | + framework "github.com/openshift/cluster-api-actuator-pkg/pkg/framework" |
| 12 | + corev1 "k8s.io/api/core/v1" |
| 13 | + apierrors "k8s.io/apimachinery/pkg/api/errors" |
| 14 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 15 | + gcpv1 "sigs.k8s.io/cluster-api-provider-gcp/api/v1beta1" |
| 16 | + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" |
| 17 | + "sigs.k8s.io/controller-runtime/pkg/client" |
| 18 | + "sigs.k8s.io/controller-runtime/pkg/envtest/komega" |
| 19 | + yaml "sigs.k8s.io/yaml" |
| 20 | +) |
| 21 | + |
| 22 | +const ( |
| 23 | + infraAPIVersion = "infrastructure.cluster.x-k8s.io/v1beta1" |
| 24 | + gcpMachineTemplateName = "gcp-machine-template" |
| 25 | + OnHostMaintenanceTerminate = "Terminate" |
| 26 | + OnHostMaintenanceMigrate = "Migrate" |
| 27 | +) |
| 28 | + |
| 29 | +var ( |
| 30 | + clusterName string |
| 31 | + cl client.Client |
| 32 | +) |
| 33 | + |
| 34 | +var _ = Describe("Cluster API GCP MachineSet", framework.LabelCAPI, framework.LabelDisruptive, Ordered, func() { |
| 35 | + var gcpMachineTemplate *gcpv1.GCPMachineTemplate |
| 36 | + var machineSet *clusterv1.MachineSet |
| 37 | + var mapiMachineSpec *mapiv1.GCPMachineProviderSpec |
| 38 | + var ctx context.Context |
| 39 | + var platform configv1.PlatformType |
| 40 | + var clusterName string |
| 41 | + var err error |
| 42 | + |
| 43 | + BeforeAll(func() { |
| 44 | + cl, err = framework.LoadClient() |
| 45 | + Expect(err).NotTo(HaveOccurred(), "Failed to create Kubernetes client for test") |
| 46 | + komega.SetClient(cl) |
| 47 | + ctx = framework.GetContext() |
| 48 | + platform, err = framework.GetPlatform(ctx, cl) |
| 49 | + Expect(err).ToNot(HaveOccurred(), "Failed to get platform") |
| 50 | + if platform != configv1.GCPPlatformType { |
| 51 | + Skip("Skipping GCP E2E tests") |
| 52 | + } |
| 53 | + oc, _ := framework.NewCLI() |
| 54 | + framework.SkipIfNotTechPreviewNoUpgrade(oc, cl) |
| 55 | + |
| 56 | + infra, err := framework.GetInfrastructure(ctx, cl) |
| 57 | + Expect(err).NotTo(HaveOccurred(), "Failed to get cluster infrastructure object") |
| 58 | + Expect(infra.Status.InfrastructureName).ShouldNot(BeEmpty(), "infrastructure name was empty on Infrastructure.Status.") |
| 59 | + clusterName = infra.Status.InfrastructureName |
| 60 | + |
| 61 | + framework.CreateCoreCluster(ctx, cl, clusterName, "GCPCluster") |
| 62 | + mapiMachineSpec = getGCPMAPIProviderSpec(cl) |
| 63 | + }) |
| 64 | + AfterEach(func() { |
| 65 | + if platform != configv1.GCPPlatformType { |
| 66 | + // Because AfterEach always runs, even when tests are skipped, we have to |
| 67 | + // explicitly skip it here for other platforms. |
| 68 | + Skip("Skipping GCP E2E tests") |
| 69 | + } |
| 70 | + framework.DeleteCAPIMachineSets(ctx, cl, machineSet) |
| 71 | + framework.WaitForCAPIMachineSetsDeleted(ctx, cl, machineSet) |
| 72 | + framework.DeleteObjects(ctx, cl, gcpMachineTemplate) |
| 73 | + }) |
| 74 | + // OCP-77825 capi created instances support disks pd-ssd and pd-standard |
| 75 | + |
| 76 | + DescribeTable("should be able to run a machine with disk types", |
| 77 | + func(expectedDiskType gcpv1.DiskType) { |
| 78 | + mapiProviderSpec := getGCPMAPIProviderSpec(cl) |
| 79 | + Expect(mapiProviderSpec).ToNot(BeNil()) |
| 80 | + gcpMachineTemplate = createGCPMachineTemplate(mapiProviderSpec) |
| 81 | + gcpMachineTemplate.Spec.Template.Spec.RootDeviceType = &expectedDiskType |
| 82 | + mapiProviderSpec.OnHostMaintenance = OnHostMaintenanceTerminate |
| 83 | + gcpMachineTemplate.Spec.Template.Spec.OnHostMaintenance = (*gcpv1.HostMaintenancePolicy)(&mapiProviderSpec.OnHostMaintenance) |
| 84 | + |
| 85 | + if err := cl.Create(ctx, gcpMachineTemplate); err != nil && !apierrors.IsAlreadyExists(err) { |
| 86 | + Expect(err).ToNot(HaveOccurred()) |
| 87 | + } |
| 88 | + |
| 89 | + machineSet, _ = framework.CreateCAPIMachineSet(ctx, cl, framework.NewCAPIMachineSetParams( |
| 90 | + "gcp-machineset-77825", |
| 91 | + clusterName, |
| 92 | + mapiMachineSpec.Zone, |
| 93 | + 1, |
| 94 | + corev1.ObjectReference{ |
| 95 | + Kind: "GCPMachineTemplate", |
| 96 | + APIVersion: infraAPIVersion, |
| 97 | + Name: gcpMachineTemplateName, |
| 98 | + }, |
| 99 | + )) |
| 100 | + Expect(err).ToNot(HaveOccurred(), "Failed to create CAPI machineset") |
| 101 | + framework.WaitForCAPIMachinesRunning(framework.GetContext(), cl, machineSet.Name) |
| 102 | + }, |
| 103 | + Entry("Disk type pd-standard", gcpv1.PdStandardDiskType), |
| 104 | + Entry("Disk type pd-ssd", gcpv1.PdSsdDiskType), |
| 105 | + ) |
| 106 | + // OCP-74795 - add support for shielded VMs - It takes defaults if configs are not supported; eg-vtpm alone set to Enabled will result in IntergrityMonitoring also as Enabled |
| 107 | + // doesn't matter what we pass - all enabled/secureboot only disabled(default) are valid changes which we can apply |
| 108 | + |
| 109 | + DescribeTable("should configure Shielded VM options correctly", |
| 110 | + func(enableSecureBoot gcpv1.SecureBootPolicy, enableVtpm gcpv1.VirtualizedTrustedPlatformModulePolicy, enableIntegrityMonitoring gcpv1.IntegrityMonitoringPolicy) { |
| 111 | + mapiProviderSpec := getGCPMAPIProviderSpec(cl) |
| 112 | + Expect(mapiProviderSpec).ToNot(BeNil()) |
| 113 | + gcpMachineTemplate = createGCPMachineTemplate(mapiProviderSpec) |
| 114 | + mapiProviderSpec.OnHostMaintenance = OnHostMaintenanceMigrate |
| 115 | + gcpMachineTemplate.Spec.Template.Spec.OnHostMaintenance = (*gcpv1.HostMaintenancePolicy)(&mapiProviderSpec.OnHostMaintenance) |
| 116 | + gcpMachineTemplate.Spec.Template.Spec.ShieldedInstanceConfig = &gcpv1.GCPShieldedInstanceConfig{ |
| 117 | + SecureBoot: enableSecureBoot, |
| 118 | + VirtualizedTrustedPlatformModule: enableVtpm, |
| 119 | + IntegrityMonitoring: enableIntegrityMonitoring, |
| 120 | + } |
| 121 | + if err := cl.Create(ctx, gcpMachineTemplate); err != nil && !apierrors.IsAlreadyExists(err) { |
| 122 | + Expect(err).ToNot(HaveOccurred()) |
| 123 | + } |
| 124 | + |
| 125 | + machineSet, err = framework.CreateCAPIMachineSet(ctx, cl, framework.NewCAPIMachineSetParams( |
| 126 | + "gcp-machineset-shieldedvm-74795", |
| 127 | + clusterName, |
| 128 | + mapiMachineSpec.Zone, |
| 129 | + 1, |
| 130 | + corev1.ObjectReference{ |
| 131 | + Kind: "GCPMachineTemplate", |
| 132 | + APIVersion: infraAPIVersion, |
| 133 | + Name: gcpMachineTemplateName, |
| 134 | + }, |
| 135 | + )) |
| 136 | + Expect(err).ToNot(HaveOccurred(), "Failed to create CAPI machineset with Shielded VM config") |
| 137 | + |
| 138 | + framework.WaitForCAPIMachinesRunning(framework.GetContext(), cl, machineSet.Name) |
| 139 | + |
| 140 | + By("Verifying the Shielded VM configuration on the created GCP MachineTemplate") |
| 141 | + createdTemplate := &gcpv1.GCPMachineTemplate{} |
| 142 | + Expect(cl.Get(ctx, client.ObjectKey{ |
| 143 | + Namespace: framework.ClusterAPINamespace, |
| 144 | + Name: gcpMachineTemplateName, |
| 145 | + }, createdTemplate)).To(Succeed()) |
| 146 | + Expect(createdTemplate.Spec.Template.Spec.ShieldedInstanceConfig).ToNot(BeNil()) |
| 147 | + Expect(fmt.Sprintf("%v", createdTemplate.Spec.Template.Spec.ShieldedInstanceConfig.SecureBoot)).To(Equal(fmt.Sprintf("%v", enableSecureBoot))) |
| 148 | + Expect(fmt.Sprintf("%v", createdTemplate.Spec.Template.Spec.ShieldedInstanceConfig.VirtualizedTrustedPlatformModule)).To(Equal(fmt.Sprintf("%v", enableVtpm))) |
| 149 | + Expect(fmt.Sprintf("%v", createdTemplate.Spec.Template.Spec.ShieldedInstanceConfig.IntegrityMonitoring)).To(Equal(fmt.Sprintf("%v", enableIntegrityMonitoring))) |
| 150 | + }, |
| 151 | + Entry("all Shielded VM options enabled", gcpv1.SecureBootPolicyEnabled, gcpv1.VirtualizedTrustedPlatformModulePolicyEnabled, gcpv1.IntegrityMonitoringPolicyEnabled), |
| 152 | + Entry("only SecureBoot enabled", gcpv1.SecureBootPolicyEnabled, gcpv1.VirtualizedTrustedPlatformModulePolicyDisabled, gcpv1.IntegrityMonitoringPolicyDisabled), |
| 153 | + /*Below configs doesn't make difference due to defaulting conditions of shielded VMs |
| 154 | + Entry("only Vtpm enabled", gcpv1.SecureBootPolicyDisabled, gcpv1.VirtualizedTrustedPlatformModulePolicyEnabled, gcpv1.IntegrityMonitoringPolicyDisabled), |
| 155 | + Entry("only IntegrityMonitoring enabled", gcpv1.SecureBootPolicyDisabled, gcpv1.VirtualizedTrustedPlatformModulePolicyDisabled, gcpv1.IntegrityMonitoringPolicyEnabled), |
| 156 | + Entry("SecureBoot and Vtpm enabled", gcpv1.SecureBootPolicyEnabled, mapiv1.VirtualizedTrustedPlatformModulePolicyEnabled, gcpv1.IntegrityMonitoringPolicyDisabled), |
| 157 | + Entry("SecureBoot and IntegrityMonitoring enabled", gcpv1.SecureBootPolicyEnabled, gcpv1.VirtualizedTrustedPlatformModulePolicyDisabled, gcpv1.IntegrityMonitoringPolicyEnabled), |
| 158 | + Entry("all Shielded VM options disabled", gcpv1.SecureBootPolicyDisabled, gcpv1.VirtualizedTrustedPlatformModulePolicyDisabled, gcpv1.IntegrityMonitoringPolicyDisabled), |
| 159 | + */ |
| 160 | + ) |
| 161 | + // OCP-74703 - Create confidential compute VMs on gcp |
| 162 | + |
| 163 | + // Define constants as variable for this case to pass values properly |
| 164 | + confidentialComputeEnabled := gcpv1.ConfidentialComputePolicyEnabled |
| 165 | + confidentialComputeDisabled := gcpv1.ConfidentialComputePolicyDisabled |
| 166 | + DescribeTable("should configure Confidential VM correctly", |
| 167 | + func(confidentialCompute *gcpv1.ConfidentialComputePolicy) { |
| 168 | + mapiProviderSpec := getGCPMAPIProviderSpec(cl) |
| 169 | + Expect(mapiProviderSpec).ToNot(BeNil()) |
| 170 | + gcpMachineTemplate = createGCPMachineTemplate(mapiProviderSpec) |
| 171 | + gcpMachineTemplate.Spec.Template.Spec.ConfidentialCompute = confidentialCompute |
| 172 | + gcpMachineTemplate.Spec.Template.Spec.InstanceType = "n2d-standard-4" |
| 173 | + |
| 174 | + if *confidentialCompute == gcpv1.ConfidentialComputePolicyEnabled { |
| 175 | + mapiProviderSpec.OnHostMaintenance = OnHostMaintenanceTerminate |
| 176 | + gcpMachineTemplate.Spec.Template.Spec.OnHostMaintenance = (*gcpv1.HostMaintenancePolicy)(&mapiProviderSpec.OnHostMaintenance) |
| 177 | + } else { |
| 178 | + mapiProviderSpec.OnHostMaintenance = "Migrate" |
| 179 | + gcpMachineTemplate.Spec.Template.Spec.OnHostMaintenance = (*gcpv1.HostMaintenancePolicy)(&mapiProviderSpec.OnHostMaintenance) |
| 180 | + } |
| 181 | + |
| 182 | + if err := cl.Create(ctx, gcpMachineTemplate); err != nil && !apierrors.IsAlreadyExists(err) { |
| 183 | + Expect(err).ToNot(HaveOccurred()) |
| 184 | + } |
| 185 | + |
| 186 | + By("Creating a MachineSet for Confidential VM") |
| 187 | + machineSet, err = framework.CreateCAPIMachineSet(ctx, cl, framework.NewCAPIMachineSetParams( |
| 188 | + "gcp-machineset-confidential-74703", |
| 189 | + clusterName, |
| 190 | + mapiProviderSpec.Zone, |
| 191 | + 1, |
| 192 | + corev1.ObjectReference{ |
| 193 | + Kind: "GCPMachineTemplate", |
| 194 | + APIVersion: infraAPIVersion, |
| 195 | + Name: gcpMachineTemplateName, |
| 196 | + }, |
| 197 | + )) |
| 198 | + Expect(err).ToNot(HaveOccurred(), "Failed to create CAPI MachineSet with Confidential VM configuration") |
| 199 | + |
| 200 | + framework.WaitForCAPIMachinesRunning(ctx, cl, machineSet.Name) |
| 201 | + |
| 202 | + By("Verifying the Confidential VM configuration on the created GCP MachineTemplate") |
| 203 | + createdTemplate := &gcpv1.GCPMachineTemplate{} |
| 204 | + Expect(cl.Get(framework.GetContext(), client.ObjectKey{ |
| 205 | + Namespace: framework.ClusterAPINamespace, |
| 206 | + Name: gcpMachineTemplateName, |
| 207 | + }, createdTemplate)).To(Succeed()) |
| 208 | + var confidentialComputevalue = *createdTemplate.Spec.Template.Spec.ConfidentialCompute |
| 209 | + Expect(fmt.Sprintf("%v", confidentialComputevalue)).To(Equal(fmt.Sprintf("%v", *confidentialCompute))) |
| 210 | + }, |
| 211 | + Entry("Confidential Compute enabled", &confidentialComputeEnabled), |
| 212 | + Entry("Confidential Compute disabled", &confidentialComputeDisabled), |
| 213 | + ) |
| 214 | + // OCP-74732 GPU machine can be provisioned successfully by capi machineset |
| 215 | + |
| 216 | + It("should provision GPU machine successfully", func() { |
| 217 | + mapiProviderSpec := getGCPMAPIProviderSpec(cl) |
| 218 | + Expect(mapiProviderSpec).ToNot(BeNil()) |
| 219 | + gcpMachineTemplate = createGCPMachineTemplate(mapiProviderSpec) |
| 220 | + gcpMachineTemplate.Spec.Template.Spec.InstanceType = "a2-highgpu-1g" |
| 221 | + mapiProviderSpec.OnHostMaintenance = OnHostMaintenanceTerminate |
| 222 | + gcpMachineTemplate.Spec.Template.Spec.OnHostMaintenance = (*gcpv1.HostMaintenancePolicy)(&mapiProviderSpec.OnHostMaintenance) |
| 223 | + |
| 224 | + if err := cl.Create(ctx, gcpMachineTemplate); err != nil && !apierrors.IsAlreadyExists(err) { |
| 225 | + Expect(err).ToNot(HaveOccurred()) |
| 226 | + } |
| 227 | + |
| 228 | + By("Creating a MachineSet for GPU machine") |
| 229 | + machineSet, err = framework.CreateCAPIMachineSet(ctx, cl, framework.NewCAPIMachineSetParams( |
| 230 | + "gcp-machineset-gpu-74732", |
| 231 | + clusterName, |
| 232 | + mapiProviderSpec.Zone, |
| 233 | + 1, |
| 234 | + corev1.ObjectReference{ |
| 235 | + Kind: "GCPMachineTemplate", |
| 236 | + APIVersion: infraAPIVersion, |
| 237 | + Name: gcpMachineTemplateName, |
| 238 | + }, |
| 239 | + )) |
| 240 | + Expect(err).ToNot(HaveOccurred(), "Failed to create CAPI MachineSet with GPU instanceType") |
| 241 | + |
| 242 | + framework.WaitForCAPIMachinesRunning(ctx, cl, machineSet.Name) |
| 243 | + |
| 244 | + By("Verifying the GPU machinetype configuration on the created GCP MachineTemplate") |
| 245 | + createdTemplate := &gcpv1.GCPMachineTemplate{} |
| 246 | + Expect(cl.Get(framework.GetContext(), client.ObjectKey{ |
| 247 | + Namespace: framework.ClusterAPINamespace, |
| 248 | + Name: gcpMachineTemplateName, |
| 249 | + }, createdTemplate)).To(Succeed()) |
| 250 | + var machineType = createdTemplate.Spec.Template.Spec.InstanceType |
| 251 | + Expect(machineType).To(Equal("a2-highgpu-1g")) |
| 252 | + }, |
| 253 | + ) |
| 254 | + // OCP-75792 Preemptible machines can be provisioned successfully by capi machineset |
| 255 | + |
| 256 | + It("should provision Preemptible machine successfully", func() { |
| 257 | + mapiProviderSpec := getGCPMAPIProviderSpec(cl) |
| 258 | + Expect(mapiProviderSpec).ToNot(BeNil()) |
| 259 | + gcpMachineTemplate = createGCPMachineTemplate(mapiProviderSpec) |
| 260 | + gcpMachineTemplate.Spec.Template.Spec.Preemptible = true |
| 261 | + mapiProviderSpec.OnHostMaintenance = OnHostMaintenanceTerminate |
| 262 | + gcpMachineTemplate.Spec.Template.Spec.OnHostMaintenance = (*gcpv1.HostMaintenancePolicy)(&mapiProviderSpec.OnHostMaintenance) |
| 263 | + |
| 264 | + if err := cl.Create(ctx, gcpMachineTemplate); err != nil && !apierrors.IsAlreadyExists(err) { |
| 265 | + Expect(err).ToNot(HaveOccurred()) |
| 266 | + } |
| 267 | + |
| 268 | + By("Creating a MachineSet for preeemptible machine") |
| 269 | + machineSet, err = framework.CreateCAPIMachineSet(ctx, cl, framework.NewCAPIMachineSetParams( |
| 270 | + "gcp-machineset-preemptible-75792", |
| 271 | + clusterName, |
| 272 | + mapiProviderSpec.Zone, |
| 273 | + 1, |
| 274 | + corev1.ObjectReference{ |
| 275 | + Kind: "GCPMachineTemplate", |
| 276 | + APIVersion: infraAPIVersion, |
| 277 | + Name: gcpMachineTemplateName, |
| 278 | + }, |
| 279 | + )) |
| 280 | + Expect(err).ToNot(HaveOccurred(), "Failed to create CAPI MachineSet with preemptible instanceType") |
| 281 | + |
| 282 | + framework.WaitForCAPIMachinesRunning(ctx, cl, machineSet.Name) |
| 283 | + |
| 284 | + By("Verifying the preemptible machinetype configuration on the created GCP MachineTemplate") |
| 285 | + createdTemplate := &gcpv1.GCPMachineTemplate{} |
| 286 | + Expect(cl.Get(framework.GetContext(), client.ObjectKey{ |
| 287 | + Namespace: framework.ClusterAPINamespace, |
| 288 | + Name: gcpMachineTemplateName, |
| 289 | + }, createdTemplate)).To(Succeed()) |
| 290 | + var preemptible = createdTemplate.Spec.Template.Spec.Preemptible |
| 291 | + Expect(preemptible).To(Equal(true)) |
| 292 | + }) |
| 293 | + |
| 294 | +}) |
| 295 | + |
| 296 | +func getGCPMAPIProviderSpec(cl client.Client) *mapiv1.GCPMachineProviderSpec { |
| 297 | + machineSetList := &mapiv1.MachineSetList{} |
| 298 | + |
| 299 | + Eventually(func() error { |
| 300 | + return cl.List(framework.GetContext(), machineSetList, client.InNamespace(framework.MachineAPINamespace)) |
| 301 | + }, framework.WaitShort, framework.RetryShort).Should(Succeed(), "it should be able to list the MAPI machinesets") |
| 302 | + Expect(machineSetList.Items).ToNot(HaveLen(0), "expected the MAPI machinesets to be present") |
| 303 | + |
| 304 | + machineSet := machineSetList.Items[0] |
| 305 | + Expect(machineSet.Spec.Template.Spec.ProviderSpec.Value).ToNot(BeNil()) |
| 306 | + |
| 307 | + providerSpec := &mapiv1.GCPMachineProviderSpec{} |
| 308 | + Expect(yaml.Unmarshal(machineSet.Spec.Template.Spec.ProviderSpec.Value.Raw, providerSpec)).To(Succeed()) |
| 309 | + |
| 310 | + return providerSpec |
| 311 | +} |
| 312 | + |
| 313 | +func createGCPMachineTemplate(mapiProviderSpec *mapiv1.GCPMachineProviderSpec) *gcpv1.GCPMachineTemplate { |
| 314 | + By("Creating GCP machine template") |
| 315 | + |
| 316 | + Expect(mapiProviderSpec).ToNot(BeNil()) |
| 317 | + Expect(mapiProviderSpec.Disks).ToNot(BeNil()) |
| 318 | + Expect(len(mapiProviderSpec.Disks)).To(BeNumerically(">", 0)) |
| 319 | + Expect(mapiProviderSpec.Disks[0].Type).ToNot(BeEmpty()) |
| 320 | + Expect(mapiProviderSpec.MachineType).ToNot(BeEmpty()) |
| 321 | + Expect(mapiProviderSpec.NetworkInterfaces).ToNot(BeNil()) |
| 322 | + Expect(len(mapiProviderSpec.NetworkInterfaces)).To(BeNumerically(">", 0)) |
| 323 | + Expect(mapiProviderSpec.NetworkInterfaces[0].Subnetwork).ToNot(BeEmpty()) |
| 324 | + Expect(mapiProviderSpec.ServiceAccounts).ToNot(BeNil()) |
| 325 | + Expect(mapiProviderSpec.ServiceAccounts[0].Email).ToNot(BeEmpty()) |
| 326 | + Expect(mapiProviderSpec.ServiceAccounts[0].Scopes).ToNot(BeNil()) |
| 327 | + Expect(len(mapiProviderSpec.ServiceAccounts)).To(BeNumerically(">", 0)) |
| 328 | + Expect(mapiProviderSpec.Tags).ToNot(BeNil()) |
| 329 | + Expect(len(mapiProviderSpec.Tags)).To(BeNumerically(">", 0)) |
| 330 | + |
| 331 | + ipForwardingDisabled := gcpv1.IPForwardingDisabled |
| 332 | + |
| 333 | + gcpMachineSpec := gcpv1.GCPMachineSpec{ |
| 334 | + RootDeviceSize: mapiProviderSpec.Disks[0].SizeGB, |
| 335 | + InstanceType: mapiProviderSpec.MachineType, |
| 336 | + Image: &mapiProviderSpec.Disks[0].Image, |
| 337 | + Subnet: &mapiProviderSpec.NetworkInterfaces[0].Subnetwork, |
| 338 | + ServiceAccount: &gcpv1.ServiceAccount{ |
| 339 | + Email: mapiProviderSpec.ServiceAccounts[0].Email, |
| 340 | + Scopes: mapiProviderSpec.ServiceAccounts[0].Scopes, |
| 341 | + }, |
| 342 | + |
| 343 | + AdditionalNetworkTags: mapiProviderSpec.Tags, |
| 344 | + AdditionalLabels: gcpv1.Labels{fmt.Sprintf("kubernetes-io-cluster-%s", clusterName): "owned"}, |
| 345 | + IPForwarding: &ipForwardingDisabled, |
| 346 | + } |
| 347 | + |
| 348 | + gcpMachineTemplate := &gcpv1.GCPMachineTemplate{ |
| 349 | + ObjectMeta: metav1.ObjectMeta{ |
| 350 | + Name: gcpMachineTemplateName, |
| 351 | + Namespace: framework.ClusterAPINamespace, |
| 352 | + }, |
| 353 | + Spec: gcpv1.GCPMachineTemplateSpec{ |
| 354 | + Template: gcpv1.GCPMachineTemplateResource{ |
| 355 | + Spec: gcpMachineSpec, |
| 356 | + }, |
| 357 | + }, |
| 358 | + } |
| 359 | + |
| 360 | + return gcpMachineTemplate |
| 361 | +} |
0 commit comments