Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Cluster Creation in User Provided Subnet #961

Merged

Conversation

AbdullahAlShaad
Copy link
Contributor

@AbdullahAlShaad AbdullahAlShaad commented Jun 22, 2023

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:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

Fix bug for the creation of clusters in user-provided subnets

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 22, 2023
@k8s-ci-robot
Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jun 22, 2023
@cpanato
Copy link
Member

cpanato commented Jun 22, 2023

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 22, 2023
@AbdullahAlShaad AbdullahAlShaad changed the title Add CustomSubnet feature @Shaad7 Fix Cluster Creation in User Provided Subnet Jun 22, 2023
@k8s-ci-robot k8s-ci-robot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jun 22, 2023
@AbdullahAlShaad AbdullahAlShaad changed the title @Shaad7 Fix Cluster Creation in User Provided Subnet Fix Cluster Creation in User Provided Subnet Jun 22, 2023
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jun 22, 2023
@richardcase
Copy link
Member

@shaad7 - how would you feel about adding an e2e test to cover this scenario?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 16, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 16, 2023
@AbdullahAlShaad
Copy link
Contributor Author

@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
Copy link
Member

@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:
    - sourcePath: "${PWD}/test/e2e/data/infrastructure-gcp/cluster-template-ci-gke-autopilot.yaml"
  • 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)
              })
     })

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 17, 2023
@AbdullahAlShaad
Copy link
Contributor Author

Thank you @richardcase . I have added e2e test for the scenario. Can you have a look ?

Copy link
Member

@richardcase richardcase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shaad7 - thanks for adding the e2e test. A coupld of comments on it. Currently the test isn't using the new template you added.

test/e2e/e2e_test.go Outdated Show resolved Hide resolved
test/e2e/e2e_test.go Outdated Show resolved Hide resolved
@AbdullahAlShaad AbdullahAlShaad force-pushed the feature/custom-subnet branch 3 times, most recently from 07c51f9 to 0f85590 Compare August 23, 2023 09:49
@richardcase
Copy link
Member

/test pull-cluster-api-provider-gcp-e2e-test

Copy link

netlify bot commented Mar 4, 2024

Deploy Preview for kubernetes-sigs-cluster-api-gcp ready!

Name Link
🔨 Latest commit d6cf2e1
🔍 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...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@AbdullahAlShaad AbdullahAlShaad force-pushed the feature/custom-subnet branch 2 times, most recently from 99eefe6 to 7a0db02 Compare March 5, 2024 03:49
Signed-off-by: Shaad7 <[email protected]>
Signed-off-by: AbdullahAlShaad <[email protected]>
@cpanato
Copy link
Member

cpanato commented Mar 5, 2024

/test ls

@k8s-ci-robot
Copy link
Contributor

@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.

@cpanato
Copy link
Member

cpanato commented Mar 5, 2024

/test pull-cluster-api-provider-gcp-capi-e2e
/test pull-cluster-api-provider-gcp-conformance

@richardcase
Copy link
Member

Thanks @AbdullahAlShaad . From my side:

/approve

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 27, 2024
@richardcase
Copy link
Member

For final eyes and lgtm

/assign cpanato

Copy link
Member

@cpanato cpanato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 27, 2024
@k8s-ci-robot
Copy link
Contributor

[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

Needs approval from an approver in each of these files:
  • 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

@k8s-ci-robot k8s-ci-robot merged commit 75eae02 into kubernetes-sigs:main Mar 27, 2024
19 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.1.0 milestone Mar 27, 2024
@AbdullahAlShaad AbdullahAlShaad deleted the feature/custom-subnet branch March 27, 2024 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GCPManagedControlPlane does not come up and requires "Subnet"
4 participants