cluster-api-provider-gcp
cluster-api-provider-gcp copied to clipboard
Fix Cluster Creation in User Provided Subnet
What type of PR is this? /kind bug
What this PR does / why we need it: This PR enables the creation of clusters in user-provided subnets. It also adds validation for user-provided subnets to ensure that at least one subnet is in the same region where the cluster will be created. The user-provided subnets are created in the intended region rather than the default region.
Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):
Fixes #896
Special notes for your reviewer:
Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.
TODOs:
- [x] squashed commits
- [ ] includes documentation
- [x] adds unit tests
Release note:
Fix bug for the creation of clusters in user-provided subnets
Hi @Shaad7. Thanks for your PR.
I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test
on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.
Once the patch is verified, the new status will be reflected by the ok-to-test
label.
I understand the commands that are listed here.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
/ok-to-test
@Shaad7 - how would you feel about adding an e2e test to cover this scenario?
@richardcase I have looked the e2e test codes. The cluster template is generated using clusterctl
commands. There is not flag or export using which I can add a custom subnet. Any idea how can I add e2e test for this ?
@richardcase I have looked the e2e test codes. The cluster template is generated using
clusterctl
commands. There is not flag or export using which I can add a custom subnet. Any idea how can I add e2e test for this ?
It can be quite time-consuming adding e2e tests, but there is lots of value as it prevents regressions.
If i was doing the work i would probably do this:
- create a new template specifically for use in the e2e tests here
- Add a envsubst variable for the subnet so that you can replace the token later
- Add the new template after this entry so clusterctl picks it up: https://github.com/kubernetes-sigs/cluster-api-provider-gcp/blob/5e7fc149ad3c9996499eba8c91e9dc2aeee4b6ef/test/e2e/config/gcp-ci.yaml#L73
- Then in the e2e_test.go test file i would create a new It under
Context("Creating a single control-plane cluster", func()
and use the new template created earlier, so something like this:
It("Should create a cluster with 1 worker node with user provided subnets", func() {
By("Creating subnets")
// Add code to create or get existing subnets in GCP
By("Initializes with 1 worker node")
clusterctl.ApplyClusterTemplateAndWait(ctx, clusterctl.ApplyClusterTemplateAndWaitInput{
ClusterProxy: bootstrapClusterProxy,
ConfigCluster: clusterctl.ConfigClusterInput{
LogFolder: clusterctlLogFolder,
ClusterctlConfigPath: clusterctlConfigPath,
KubeconfigPath: bootstrapClusterProxy.GetKubeconfigPath(),
InfrastructureProvider: clusterctl.DefaultInfrastructureProvider,
Flavor: "newtemplateflavour", // <- this is where we specify the new template
Namespace: namespace.Name,
ClusterName: clusterName,
KubernetesVersion: e2eConfig.GetVariable(KubernetesVersion),
ControlPlaneMachineCount: pointer.Int64Ptr(1),
WorkerMachineCount: pointer.Int64Ptr(1),
ClusterctlVariables: map[string]string{
"SUBNET": subnetid,
},
},
WaitForClusterIntervals: e2eConfig.GetIntervals(specName, "wait-cluster"),
WaitForControlPlaneIntervals: e2eConfig.GetIntervals(specName, "wait-control-plane"),
WaitForMachineDeployments: e2eConfig.GetIntervals(specName, "wait-worker-nodes"),
}, result)
})
})
Thank you @richardcase . I have added e2e test for the scenario. Can you have a look ?
/test pull-cluster-api-provider-gcp-e2e-test
Deploy Preview for kubernetes-sigs-cluster-api-gcp ready!
Name | Link |
---|---|
Latest commit | d6cf2e1faa77926e2e7521e68a023e0cddb0e728 |
Latest deploy log | https://app.netlify.com/sites/kubernetes-sigs-cluster-api-gcp/deploys/65e69a89b5e6770007728e6e |
Deploy Preview | https://deploy-preview-961--kubernetes-sigs-cluster-api-gcp.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
/test ls
@cpanato: The specified target(s) for /test
were not found.
The following commands are available to trigger required jobs:
-
/test pull-cluster-api-provider-gcp-build
-
/test pull-cluster-api-provider-gcp-e2e-test
-
/test pull-cluster-api-provider-gcp-make
-
/test pull-cluster-api-provider-gcp-test
-
/test pull-cluster-api-provider-gcp-verify
The following commands are available to trigger optional jobs:
-
/test pull-cluster-api-provider-gcp-apidiff
-
/test pull-cluster-api-provider-gcp-capi-e2e
-
/test pull-cluster-api-provider-gcp-conformance
-
/test pull-cluster-api-provider-gcp-conformance-ci-artifacts
-
/test pull-cluster-api-provider-gcp-coverage
-
/test pull-cluster-api-provider-gcp-e2e-workload-upgrade
Use /test all
to run the following jobs that were automatically triggered:
-
pull-cluster-api-provider-gcp-apidiff
-
pull-cluster-api-provider-gcp-build
-
pull-cluster-api-provider-gcp-e2e-test
-
pull-cluster-api-provider-gcp-make
-
pull-cluster-api-provider-gcp-test
-
pull-cluster-api-provider-gcp-verify
In response to this:
/test ls
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
/test pull-cluster-api-provider-gcp-capi-e2e /test pull-cluster-api-provider-gcp-conformance
Thanks @AbdullahAlShaad . From my side:
/approve
For final eyes and lgtm
/assign cpanato
[APPROVALNOTIFIER] This PR is APPROVED
This pull-request has been approved by: AbdullahAlShaad, cpanato, richardcase
The full list of commands accepted by this bot can be found here.
The pull request process is described here
- ~~OWNERS~~ [cpanato,richardcase]
Approvers can indicate their approval by writing /approve
in a comment
Approvers can cancel approval by writing /approve cancel
in a comment