Skip to content

Feat: Added functionalities to remove duplicate parameters and overwrite existing ones. #527

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

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from

Conversation

DannyLiCom
Copy link
Collaborator

Fixes / Features

  • Added functionality to delete conflicting parameters and overwrite duplicate ones, ensuring user-defined settings take precedence.

Testing / Documentation

Can be tested when creating a cluster using XPK.

  • [ y/n ] Tests pass
  • [ y/n ] Appropriate changes to documentation are included in the PR

@pawloch00
Copy link
Collaborator

@sharabiani ptal

@DannyLiCom
Copy link
Collaborator Author

This PR is from #506 . @SujeethJinesh These errors likely aren't related to my modifications. They seem to be primarily about IP conflicts and the inability to get-credentials for the cluster.

@pawloch00
Copy link
Collaborator

The tests are failing and I don't think fault is on the tests side this time @DannyLiCom

@DannyLiCom
Copy link
Collaborator Author

@SujeethJinesh This issue likely stems from conflicts caused by the default network and IP. To pass the checks, we might need to include the creation of networks, subnetworks, firewalls, and so on, and then change the defaults to the new network.(Refer to here) This would involve a lot of related changes and modifications.

@DannyLiCom
Copy link
Collaborator Author

@wstcliyu Might need to help Sujeeth discuss this with Piotr. Thanks!

# After shlex.split: Print the tokens list
xpk_print(f'Shlex-split tokens: {tokens}')
i = 0
while i < len(tokens):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking again at this, this is custom loop, handling string with arguments. I find it hard to mantain and debug. It should be replaced with usage of some library is possible

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried to modify argparse before, but I don't think it's flexible enough. You have to pre-define all the parameters it needs to parse.
https://screenshot.googleplex.com/8fpLsUdZMrouXXt

del final_gcloud_args[opposite_key]
final_gcloud_args[key] = True
elif key.startswith('--enable-'):
opposite_key = f'--no-{key[2:]}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

how are we guaranteed that the only keys which will have opposite effect are formed with disable or no prefixes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Our current processing logic is indeed based on the observed gcloud and our custom argument conventions, meaning keys with opposite effects use prefixes like --no-, --enable-, or --disable-. However, it is indeed a potential risk point.
https://screenshot.googleplex.com/dhSjkYf9LWhGupu
Currently, I'm only referring to this source.
https://cloud.google.com/sdk/gcloud/reference/container/clusters/create

command += f' --addons={addons_str}'
conditional_params['--addons'] = ','.join(addons)

for key, value in conditional_params.items():
Copy link
Collaborator

Choose a reason for hiding this comment

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

this loop could be separate function

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added merge_conditional_params function.

process_gcloud_args(user_parsed_args, final_gcloud_args)

command_parts = ['gcloud beta container clusters create', args.cluster]
for key, value in final_gcloud_args.items():
Copy link
Collaborator

Choose a reason for hiding this comment

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

this loop could be separate function

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added construct_gcloud_command_string function.

final_gcloud_args['--master-ipv4-cidr'] = '172.16.0.32/28'
# This value is from here https://cloud.google.com/vpc/docs/subnets
final_gcloud_args['--cluster-ipv4-cidr'] = '10.224.0.0/12'
final_gcloud_args['--enable-private-nodes'] = True
Copy link
Collaborator

Choose a reason for hiding this comment

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

shouldn't this be False?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you want to use --master-ipv4-cidr, you must also include --enable-private-nodes, otherwise an error will occur.

error: ERROR: (gcloud.beta.container.clusters.create) Cannot specify --master-ipv4-cidr without --enable-private-nodes. It seems I might need to add --enable-private-nodes to execute python3 xpk/xpk.py cluster create-pathways.

@pawloch00
Copy link
Collaborator

What is the exact reason for this PR?

@DannyLiCom
Copy link
Collaborator Author

What is the exact reason for this PR?

This is a task @SujeethJinesh assigned to me. Here are Sujeeth's objectives.
https://b.corp.google.com/issues/423650971

@DannyLiCom
Copy link
Collaborator Author

@SujeethJinesh This issue likely stems from conflicts caused by the default network and IP. To pass the checks, we might need to include the creation of networks, subnetworks, firewalls, and so on, and then change the defaults to the new network.(Refer to here) This would involve a lot of related changes and modifications.

@SujeethJinesh This issue still exists.

@DannyLiCom DannyLiCom requested a review from scaliby as a code owner August 8, 2025 01:40
else:
parsed_args[token] = True
elif token.startswith('-'):
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

This if branch could be removed.

final_gcloud_args[key] = value


def merge_conditional_params(conditional_params, final_gcloud_args):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please refactor this to not modify the final_gcloud_args input parameter, but copy it and return a copy.

return parsed_args


def process_gcloud_args(user_parsed_args, final_gcloud_args):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please refactor this to not modify the final_gcloud_args input parameter, but copy it and return a copy.

@DannyLiCom
Copy link
Collaborator Author

DannyLiCom commented Aug 13, 2025

@SujeethJinesh @pawloch00
Main task: https://b.corp.google.com/issues/423650971
The current problem is a conflict caused by the default network of the test environment and IP.

The reason my manual tests had no issues is that I would first create the network, subnetwork, firewall and so on as a prerequisite before running the test.
https://screenshot.googleplex.com/4BGSx4yGJqz6Xdh
Sources: https://docs.google.com/document/d/1gpcNDkqCgWAQYN_KOb7M5eiXd_bquSvLeKjA966LJbk/edit?tab=t.0#heading=h.glahk2wkse7w

But if I were to put the creation of networks, etc., inside the xpk code, it feels a bit illogical, and it would likely require a lot of modifications.

The solutions I can think of are to either change the original default network or, as we just discussed, to add a method for creating networks inside the code.

I might need some advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants