-
Notifications
You must be signed in to change notification settings - Fork 55
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
(Outdated) Showing Fleets in the Treeview #1220
Conversation
@Tatsinnit please review carefully the merge commit 7259407 probably best evaluated by reading the overall code in in short, most of the work in this PR was to change the resource fetching in the subscriptionTree implementation. There is still a gap to apply the same filtering on members under the fleet items. |
const name = bits[bits.length - 1]; | ||
return { resourceGroupName, name }; | ||
const parentResourceId = `/${bits.slice(0, bits.length - 2).join("/")}`; | ||
return { parentResourceId, subscriptionId, resourceGroupName, name }; | ||
} | ||
|
||
export function parseSubId(armId: string): { subId: string } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this func was added in your PR @Tatsinnit
follow-up refactoring might be to delete it, and reuse the parseResource that allows extracting more parts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 First pass looks fine, share away the VSIX, we can all shake down a little and if all looks good, lets enable Junyu for his intern work and we can all chip in.
Thanks heaps, fyi @tejhan and @ReinierCC as well please ❤️
src/commands/utils/clusterfilter.ts
Outdated
...validClusters.map((c) => ({ label: c.name!, name: c.name!, id: c.id!, location: c.location! })), | ||
); | ||
} | ||
const aksClusters = await fetchAksClusters(graphServiceClient, subscriptionNode.result.subscriptionId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Note to other readers, this is Graph API use, I've added this last night and its way more faster. In case anyone else ponders this, after nice cahtup with Junyu and Stephane, Thanks heaps
|
||
this.iconPath = assetUri("resources/aks-tools.png"); | ||
this.subscriptionTreeNode = parent; | ||
if (parent.nodeType === "subscription") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡Note only please: This part of the code is something we can nicely verify in our quick shakedown please @tejhan
Hi @Tatsinnit @tejhan @ReinierCC, sorry for the delay and here is the VSIX file :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stephane's commits are not verified. I remember this was a problem before, will it make it hard to merge again now?
src/commands/utils/azureResources.ts
Outdated
try { | ||
const response = await client.resources(query); | ||
|
||
const aksClusters: AksCluster[] = response.data.map((resource: AksCluster) => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get what this is doing? It looks like it's mapping over a list of AksClusters to produce the exact same list of AksClusters. Why can't you just pass response.data
directly into the errmap
constructor?
|
||
function asFleetMemberWithGroup(member: FleetMember): DefinedFleetMemberWithGroup { | ||
return { | ||
resourceGroup: parseResource(member.id!).resourceGroupName!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using the non-null assertions here, it'd be safer to check for nulls explicitly. You can pass null back to the caller in that case, and in getFleetMembers
, handle the error properly. You already use Errorable
there, so it'll fit in to the type there.
src/commands/utils/azureResources.ts
Outdated
subscriptionId: resource.subscriptionId, | ||
type: resource.type, | ||
})); | ||
return errmap({ succeeded: true, result: aksClusters }, (resources) => resources); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're not doing any mapping here. You could just return success(aksClusters)
.
): Promise<Errorable<AksCluster[]>> { | ||
const client = getGraphResourceClient(sessionProvider); | ||
const query = { | ||
query: `Resources | where type =~ '${clusterResourceType}' or type =~ '${fleetResourceType}' | project id, name, location, resourceGroup, subscriptionId, type`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You retrieve Fleets here as well, but you return a list of AksClusters. Maybe rename that AksCluster
type so it's clear that it encompasses multiple Azure resource types.
src/commands/utils/clusterfilter.ts
Outdated
@@ -79,6 +73,34 @@ export default async function aksClusterFilter(_context: IActionContext, target: | |||
await setFilteredClusters(newFilteredClusters); | |||
} | |||
|
|||
async function fetchAksClusters( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks the same as getClusterAndFleetResourcesFromGraphAPI
in azureResources.ts. Can you factor them out, e.g. by having 1 function that takes in the query string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ most of these comments are catered for your PR @JunyuQian here: https://github.com/JunyuQian/vscode-aks-tools/pull/4/files
Thank you!
e284bbd
to
cf0e54d
Compare
cf0e54d
to
8e3240d
Compare
* Use arm resrource graph api, which is way faster then iterator api. * Remove unused import types. * Optimise mulitple call to 1 call and add getClusterAndFleetResourcesFromGraphAPI. * Help Junyu for recommended cahnges. * prettier fix.
👮 Closing this in favour of #1237 because its a more re-work, with fixes rebase issues. Thanks, (If this is a mistake we can always reopen) |
Showing Fleets in the Treeview
This PR adds the Fleet resource to the treeview, based on @serbrech's initial work. The image below shows the final result of the treeview.
![treeview](https://private-user-images.githubusercontent.com/153477667/410351979-0245100d-60c9-437f-810e-99ff9e16c77c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjAzMjYsIm5iZiI6MTczOTQ2MDAyNiwicGF0aCI6Ii8xNTM0Nzc2NjcvNDEwMzUxOTc5LTAyNDUxMDBkLTYwYzktNDM3Zi04MTBlLTk5ZmY5ZTE2Yzc3Yy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjEzJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxM1QxNTIwMjZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1iZmNhOTM4Y2JhN2NmZTVlNGVkNmIzMjE3ZDdmNzg0NzZhMjI5MTY0YjI0YWZmOTA2OTA3ZDc4YmRjNmIxNmE0JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.ckrVMYYL6lCNrYPiPG7ftdjnffLzBShaRnKw2E9Hl-w)
Due to the special characteristics that a Fleet can have member clusters from different subscriptions, the initial treeview design, which classifies clusters based on subscriptions, does not quite fit Fleets. The current design can be summarized into three cases below:
![design](https://private-user-images.githubusercontent.com/153477667/410352030-ec81ce96-febe-429e-afb9-676f7ce86602.jpeg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NjAzMjYsIm5iZiI6MTczOTQ2MDAyNiwicGF0aCI6Ii8xNTM0Nzc2NjcvNDEwMzUyMDMwLWVjODFjZTk2LWZlYmUtNDI5ZS1hZmI5LTY3NmY3Y2U4NjYwMi5qcGVnP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTNUMTUyMDI2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZWJkNDY0ZTZkMGI0YmNkYzZiNTU1YTViZDMyNWIwNmE0NGFkNDdiNmQ3MWUyOTI0N2ZjMmJmYWUzMzJjYmM4OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ._LI1d0uGG7gpK067nVGWAInE2TBa6bwo6yHqZkHzBwI)
Key Changes
New Files
fleet-tree-icon.png
: The fleet icon displayed in the treeview.fleetTreeItem.ts
: The class responsible for the Fleet node in the treeview. It includes thecreateFleetTreeNode
function and all necessary properties.Modified Files
azure-api-util.ts
: Modified theparseResource
function to enable parsing a member cluster to a cluster resource.azureResources.ts
: Defined theDefinedFleetMemberWithGroup
type, added Fleet-related resource types, and added functions to retrieve Fleet members and convert a FleetMember to a DefinedFleetMemberWithGroup.config.ts
: Refactored and added the cluster filtering function implemented in this PR #1208.aksClusterTreeItem.ts
: Deleted thesubscriptionId
field and used theclusterResource
's id to get thesubscriptionId
for more concise code. Modified the parent node type so that the parent node of a cluster can be either a subscription or a Fleet.subscriptionTreeItem.ts
: Merged the cluster filter into the current PR by refactoring and moving the related code intoconfig.ts
. Added the process of fetching fleets and mapping members to their corresponding fleets before loading.Conflict Resolution (with cluster-filter PR #1208)
This PR also resolves conflicts with the cluster-filter PR by refactoring the filter-related code (mentioned in
config.ts
andsubscriptionTreeItem.ts
in the Modified Files section above). However, further integration testing is needed to ensure both functionalities work well together.Some known issues are:
Next Steps
loadMoreChildrenImpl
function insubscriptionTreeItem.ts
, as mentioned in this comment #1219.hasMoreChildren
function infleetTreeItems.ts
, so that the resources will be loaded gradually (e.g., load 10 lines, and display the "load more" button), rather than load them all at once. Currently, in the testing environment, the number of resources is not quite big. But in reality, it should have the ability to handle a large amount of resources.Last but not least, a huge thank-you to @serbrech, who provided immense assistance to this PR and spent hours peer-programming with me. Also, a big thank-you to @Tatsinnit for your support and the discussion this afternoon, where we could finalize this PR ❤️
Looking forward to moving on to the next feature, where we can add a member to a Fleet!