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

Support master authorized network config #1004

Conversation

yuecong
Copy link
Contributor

@yuecong yuecong commented Aug 15, 2023

What type of PR is this?
/kind feature

What this PR does / why we need it:
This PR is to add CAPG to add authorized networks for the control plane access feature provided by GKE.

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 ##1003

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:

Add  authorized network support for the control plane access feature provided by GKE.

@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/feature Categorizes issue or PR as related to a new feature. labels Aug 15, 2023
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Aug 15, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: yuecong / name: Cong Yue (682457a)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Aug 15, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @yuecong!

It looks like this is your first PR to kubernetes-sigs/cluster-api-provider-gcp 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cluster-api-provider-gcp has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @yuecong. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 15, 2023
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 15, 2023
@yuecong yuecong changed the title Support master authorized network config (#65) Support master authorized network config Aug 15, 2023
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.

please sign the CLA

/ok-to-test

thanks for this PR :D

@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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 15, 2023
@yuecong
Copy link
Contributor Author

yuecong commented Aug 15, 2023

please sign the CLA

/ok-to-test

thanks for this PR :D

Thanks and I just signed the CLA

@cpanato
Copy link
Member

cpanato commented Aug 16, 2023

/assign @richardcase

@@ -91,6 +91,35 @@ spec:
description: Location represents the location (region or zone) in
which the GKE cluster will be created.
type: string
master_authorized_networks_config:
description: MasterAuthorizedNetworksConfig repsesents configuration
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description: MasterAuthorizedNetworksConfig repsesents configuration
description: MasterAuthorizedNetworksConfig represents configuration

@@ -53,6 +53,9 @@ type GCPManagedControlPlaneSpec struct {
// Endpoint represents the endpoint used to communicate with the control plane.
// +optional
Endpoint clusterv1.APIEndpoint `json:"endpoint"`
// MasterAuthorizedNetworksConfig repsesents configuration options for master authorized networks feature of the GKE cluster.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// MasterAuthorizedNetworksConfig repsesents configuration options for master authorized networks feature of the GKE cluster.
// MasterAuthorizedNetworksConfig represents configuration options for master authorized networks feature of the GKE cluster.


// MasterAuthorizedNetworksConfigCidrBlock contains an optional name and one CIDR block.
type MasterAuthorizedNetworksConfigCidrBlock struct {

Copy link
Member

Choose a reason for hiding this comment

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

nit: can remove this empty line

@yuecong yuecong requested a review from cpanato August 16, 2023 17:50
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.

Great work @yuecong , thank you.

}

return &containerpb.MasterAuthorizedNetworksConfig{
// Enabled specifies whether master authorized networks is enabled.
Copy link
Member

Choose a reason for hiding this comment

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

nit: not sure you really need these comments when creating an instance of the struct.

// When desiredMasterAuthorizedNetworksConfig is nil, we will not update the existing config because this will casuse always reconcile.
// The GCP SDK is not allowed to pass nil to the update request either.
desiredMasterAuthorizedNetworksConfig := convertToSdkMasterAuthorizedNetworksConfig(s.scope.GCPManagedControlPlane.Spec.MasterAuthorizedNetworksConfig)
if desiredMasterAuthorizedNetworksConfig != nil && !reflect.DeepEqual(desiredMasterAuthorizedNetworksConfig, existingCluster.MasterAuthorizedNetworksConfig) {
Copy link
Member

Choose a reason for hiding this comment

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

Could we use cmp.Equal instead of reflect.DeepEqual?

// Google Compute Engine Public IPs and Google Prod IPs.
type MasterAuthorizedNetworksConfig struct {
// Whether or not master authorized networks is enabled.
Enabled bool `json:"enabled,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

As MasterAuthorizedNetworksConfig is optional on GCPManagedControlPlaneSpec then i would say that if someone specifies a non-nil MasterAuthorizedNetworksConfig then this means they want to enable master authorized networks. So i feel that the Enabled field is not needed.

Copy link
Member

Choose a reason for hiding this comment

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

wdyt @cpanato ?

Copy link
Contributor Author

@yuecong yuecong Aug 17, 2023

Choose a reason for hiding this comment

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

Good question and I agree we should decide the behavior here.
Right now, MasterAuthorizedNetworksConfig == nil means we will not reconcile it from CAPG. This means even if the users somehow manually changed the config for their cluster, we will not change it. So we would need this enabled field to let the users explicitly disable this feature.

If we want to make MasterAuthorizedNetworksConfig == nil means disable, we would need to also make sure do not to reconcile if MasterAuthorizedNetworksConfig == nil and the existing config is false.

I agree with both of the options here. :)

Copy link
Member

Choose a reason for hiding this comment

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

Personally I would prefer that we make MasterAuthorizedNetworksConfig == nil to mean disabled.

Comment on lines +331 to +332
CidrBlocks: []*containerpb.MasterAuthorizedNetworksConfig_CidrBlock{},
GcpPublicCidrsAccessEnabled: new(bool),
Copy link
Member

Choose a reason for hiding this comment

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

nit: could we just omit these and leave Enabled: false ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it does not work per my test. for GcpPublicCidrsAccessEnabled, it will be Nil instead of false as it is a *bool rather than bool in the GKE SDK. similarly to CidrBlocks, it will be Nil if we do not put some empty values. And it is a Nil to the GKE SDK, it will not overwrite current values and cause us to always have diff on those two fields when reconciling. Let me know if you have different opinions on this.

if a.Enabled != b.Enabled {
return false
}
if *a.GcpPublicCidrsAccessEnabled != *b.GcpPublicCidrsAccessEnabled {
Copy link
Member

Choose a reason for hiding this comment

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

If either of the GcpPublicCidrsAccessEnabled is nil then this will panic. Do we need to do some additional checks on this (or is this handled elsewhere)?

@richardcase
Copy link
Member

This looks good to me, thanks for looking at the feedback @yuecong ❤️

Can you squash the commits? Then i think we are good to merge.

* add MasterAuthorizedNetworksConfig filed into GCPManagedControlPlane CRD

* fix

* disable it if no desired specified in CR

* change to do not reconcile if the desired CR is nil

* add comment

add nil handling fo GcpPublicCidrsAccessEnabled

change nil as enabled

fix display_name not to be optional

address comments

fix typo and remove empty line
@yuecong yuecong force-pushed the support-master-authorized-network-config branch from 4b5ebde to 682457a Compare August 31, 2023 16:57
@richardcase
Copy link
Member

Thanks for squashing the commits. From my side:

/approve

For the lgtm:

/assign cpanato

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: richardcase, yuecong

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:

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 1, 2023
@richardcase
Copy link
Member

richardcase commented Sep 1, 2023

Actually it doesn't require both (just lgtm), so:

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 1, 2023
@k8s-ci-robot k8s-ci-robot merged commit 01af3be into kubernetes-sigs:main Sep 1, 2023
5 checks passed
@k8s-ci-robot k8s-ci-robot added this to the v1.1.0 milestone Sep 1, 2023
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/feature Categorizes issue or PR as related to a new feature. 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.

4 participants