Search code examples
azure-service-fabric

Removing unused app type versions but leaving last few


The Publish-UpgradedServiceFabricApplication powershell cmdlet that comes with the SF SDK has an $UnregisterUnusedVersions option that when set to $true will remove all unused app type versions. This is great as I don't want clutter building up on my clusters.

BUT, what I really want is to keep the last 3 or so versions so I have some flexibility to rollback if needed. Is there any way of doing this short of re-creating that cmdlet? I'm gonna guess the challenge is for the cmdlet knowing which ones to leave and which to remove. Perhaps using semver logic it could remove all but the most recent 3 versions?

Is this a pipe-dream? Feels like something I should be able to configure my cluster to do. Periodically purge all but the latest X versions.


Solution

  • The problem with this is that the type version can be any string. From SF's point of view, there is no ordering to it other than the date/time it was registered. You get to assign meaning to it in whatever way works for your applications.

    Should be easy enough to script though. Use FabricClient to figure out which types have instances running and which ones you want to purge. Then turn that script into a service so it's always running and periodically purging old types.