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

A new report listing API versions that are old enough to be removed #3899

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions provider/pkg/versioning/build_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type BuildSchemaReports struct {
FlattenedPropertyConflicts map[string]map[string]any
AllEndpoints map[openapi.ModuleName]map[openapi.ResourceName]map[string]*openapi.Endpoint
InactiveDefaultVersions map[openapi.ModuleName][]openapi.ApiVersion
OldApiVersions map[openapi.ModuleName][]openapi.ApiVersion
}

func (r BuildSchemaReports) WriteTo(outputDir string) ([]string, error) {
Expand All @@ -65,6 +66,7 @@ func (r BuildSchemaReports) WriteTo(outputDir string) ([]string, error) {
"moduleNameErrors.json": r.ModuleNameErrors,
"skippedPOSTEndpoints.json": r.SkippedPOSTEndpoints,
"typeCaseConflicts.json": r.TypeCaseConflicts,
"oldApiVersions.json": r.OldApiVersions,
})
}

Expand Down Expand Up @@ -122,6 +124,7 @@ func BuildSchema(args BuildSchemaArgs) (*BuildSchemaResult, error) {
CurationViolations: versionMetadata.CurationViolations,
AllEndpoints: diagnostics.Endpoints,
InactiveDefaultVersions: versionMetadata.InactiveDefaultVersions,
OldApiVersions: versionMetadata.GetOldApiVersionsPerModule(),
}

generationResult, err := gen.PulumiSchema(args.RootDir, modules, versionMetadata, providerVersion)
Expand Down
46 changes: 46 additions & 0 deletions provider/pkg/versioning/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (
"os"
"path"
"path/filepath"
"slices"
"strings"

"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/gen"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/openapi"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/openapi/paths"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/providerlist"
"github.com/pulumi/pulumi-azure-native/v2/provider/pkg/util"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -85,6 +87,50 @@ func (v VersionMetadata) GetAllVersions(moduleName openapi.ModuleName, resource
return v.AllResourceVersionsByResource[moduleName][resource]
}

// Collect, for each module, the API versions that are older than any _previous_ default version and that weren't
// explicitly removed.
func (v VersionMetadata) GetOldApiVersionsPerModule() map[openapi.ModuleName][]openapi.ApiVersion {
result := map[openapi.ModuleName][]openapi.ApiVersion{}
for moduleName, resourceVersions := range v.AllResourceVersionsByResource {
// Collect the explicitly removed versions in a set for easy lookup. We don't want to list them as removable
// when they're already removed.
removedFromModule := map[openapi.ApiVersion]struct{}{}
for _, version := range v.RemovedVersions[moduleName] {
removedFromModule[version] = struct{}{}
}

// API versions can be removed by module, not by resource. Determine the oldest previous default version for
// this module. It's the cut-off below which we can safely remove versions.
previousDefaultVersions := []openapi.ApiVersion{}
for _, version := range v.PreviousDefaultVersions[moduleName] {
previousDefaultVersions = append(previousDefaultVersions, version.ApiVersion)
}
if len(previousDefaultVersions) == 0 {
continue
}
oldestPreviousDefaultVersion := slices.MinFunc(previousDefaultVersions, openapi.CompareApiVersions)

// With oldestPreviousDefaultVersion as cut-off, iterate over all resources and their versions and collect the
// versions that are older than the cut-off.
oldVersionsSet := map[openapi.ApiVersion]struct{}{}
for _, versions := range resourceVersions {
for _, version := range versions {
if _, ok := removedFromModule[version]; !ok && openapi.CompareApiVersions(version, oldestPreviousDefaultVersion) < 0 {
oldVersionsSet[version] = struct{}{}
}
}
}

// If there are any old versions, sort them and add them to the result.
if len(oldVersionsSet) > 0 {
oldVersions := util.UnsortedKeys(oldVersionsSet)
slices.SortStableFunc(oldVersions, openapi.CompareApiVersions)
result[moduleName] = oldVersions
}
}
return result
}

func LoadVersionMetadata(rootDir string, modules openapi.AzureModules, majorVersion int) (VersionMetadata, error) {
versionSources, err := ReadVersionSources(rootDir, modules, majorVersion)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion reports/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ This, most likely very unelegant, `jq` query filters the endpoints to only those

```jq
jq '[ keys[] as $rp | .[$rp] | keys[] as $path | .[$path][] ] | map(select(.HttpVerbs != null) | select(.HttpVerbs | contains(["POST"])))' allEndpoints.json
```
```

## `oldApiVersions.json`

This file contains a list of all API versions that are older than the oldest previous default version for each resource provider. These API versions are good candidates for removal. Versions that are already explicitly removed via `vN-removed.json` are not included.
81 changes: 81 additions & 0 deletions reports/oldApiVersions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"AadIam": [
"2017-04-01-preview"
],
"AnalysisServices": [
"2017-08-01-beta"
],
"App": [
"2022-01-01-preview"
],
"Communication": [
"2020-08-20-preview"
],
"Confluent": [
"2020-03-01-preview"
],
"DBforMariaDB": [
"2018-06-01-privatepreview",
"2018-06-01-preview"
],
"DBforMySQL": [
"2017-12-01-preview"
],
"DBforPostgreSQL": [
"2017-12-01-preview"
],
"Dashboard": [
"2021-09-01-preview"
],
"DesktopVirtualization": [
"2021-01-14-preview"
],
"DevCenter": [
"2022-08-01-preview"
],
"DocumentDB": [
"2021-01-15"
],
"Elastic": [
"2020-07-01-preview"
],
"HealthBot": [
"2020-12-08-preview"
],
"HealthcareApis": [
"2021-01-11",
"2021-06-01-preview",
"2021-11-01",
"2022-01-31-preview"
],
"HybridConnectivity": [
"2021-10-06-preview"
],
"Intune": [
"2015-01-14-privatepreview"
],
"Logz": [
"2020-10-01-preview"
],
"MobileNetwork": [
"2022-03-01-preview"
],
"NetworkFunction": [
"2021-09-01-preview"
],
"OpenEnergyPlatform": [
"2021-06-01-preview"
],
"Portal": [
"2018-10-01-preview"
],
"Search": [
"2020-08-01-preview"
],
"SecurityAndCompliance": [
"2021-01-11"
],
"Storage": [
"2021-01-01"
]
}
Loading