Skip to content

Scheduled labeling does not work in projects in folders unless one specifies projects. #23

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

Closed
JoshuaFox opened this issue Nov 1, 2023 · 3 comments

Comments

@JoshuaFox
Copy link
Contributor

JoshuaFox commented Nov 1, 2023

There is a failure to label where all these are true:

  • The resource is in a project is in a folder (i.e, the bug does not occur if the project is directly in the org)
    and
  • The labeling is scheduled (by Cloud Scheduler) (i.e., the bug does not occur with labeling that occurs on creation of resources).
    and
  • the projects config key (in config.yaml is empty projects: [] (i.e., the bug does not occur if you have projects: ['myproject']

Looking at the code for listing projects, we see that if projects are not explicitly listed, all_projects() finds the projects with list_projects(parent=org_name), which lists only the "projects that are direct children of the specified folder or organization resource".

(As to why this issue was not earlier caught: It is probably because most labeling occurs on-creation, not with Cloud Scheduler. So, this issue would only be seen for projects in a folder, and for existing resources labeled for the first time after Iris has been launched, or for Cloud SQL, or for disks whose attachment state has changed.)

The solution would be to use a combination of list_folders and the above-mentioned list_projects to recursively walk the organization. It might make sense to parallelize the tree-walking algo. It might be best to return a Generator and have get_enabled_projects return a generator to better support cases with a huge number of projetcs, though if so, sorting will need to be removed -- and if we really have such a huge number of projects, we probably have bigger headaches.

@geekflyer
Copy link

heyho, wouldn't it be better/simpler to use Cloud Asset Inventory instead to get the list of projects? Afaik that automatically allows to recursively get the list of descendent projects within an organization or folder.

@JoshuaFox
Copy link
Contributor Author

Great idea! I gave this a try and it seems to give both projects in a folder and not.

    --scope=organizations/<ORGID> \
    --asset-types=cloudresourcemanager.googleapis.com/Project

@JoshuaFox
Copy link
Contributor Author

@geekflyer I have implemented the feature. I used the Organizations/Folders API rather than Asset Inventory because Asset Inventory has a lag (and because it was not too hard to walk the folder tree)

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

No branches or pull requests

2 participants