Skip to content

Commit

Permalink
Preserve previous default versions in v3 (#3748)
Browse files Browse the repository at this point in the history
Fixes #3424

Before considering the resources marked for removal, if the resource
version was in the previous default version, ensure we include it.

Only fix this for v3 onwards so we don't introduce schema changes now.

Bonus:
- Fix handling of "-beta" versions when converting back from SDK version
to API version.

Stacked on top of #3753
  • Loading branch information
danielrbradley authored Dec 6, 2024
1 parent 04edaa3 commit a8e5e1c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
13 changes: 12 additions & 1 deletion provider/pkg/openapi/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,18 @@ func NewVersionResources() VersionResources {
type ProviderVersionList = map[ProviderName][]ApiVersion

// DefaultVersionLock is an amalgamation of multiple API versions
type DefaultVersionLock = map[ProviderName]map[DefinitionName]ApiVersion
type DefaultVersionLock map[ProviderName]map[DefinitionName]ApiVersion

func (lock DefaultVersionLock) IsAtVersion(provider ProviderName, typeName DefinitionName, version ApiVersion) bool {
if resources, ok := lock[provider]; ok {
if resourceVersion, ok := resources[typeName]; ok {
if resourceVersion == version {
return true
}
}
}
return false
}

func (v VersionResources) All() map[string]*ResourceSpec {
specs := map[string]*ResourceSpec{}
Expand Down
23 changes: 12 additions & 11 deletions provider/pkg/versioning/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func (v VersionMetadata) ShouldInclude(provider string, version *openapi.ApiVers
return true
}
// Keep any resources in the default version lock
if resources, ok := v.Lock[provider]; ok {
if defaultResourceVersion, ok := resources[typeName]; ok {
if defaultResourceVersion == *version {
return true
}
}
if v.Lock.IsAtVersion(provider, typeName, *version) {
return true
}
// Keep any resources in the previous version lock for easier migration
if v.MajorVersion >= 3 && v.PreviousLock.IsAtVersion(provider, typeName, *version) {
return true
}
// Exclude versions from removed versions
if versions, ok := v.RemovedVersions[provider]; ok {
Expand Down Expand Up @@ -136,11 +136,12 @@ type VersionSources struct {
MajorVersion int
ProviderList providerlist.ProviderList
requiredExplicitResources []string
PreviousLock openapi.DefaultVersionLock
RemovedVersions openapi.ProviderVersionList
Spec Spec
Config Curations
ConfigPath string
// map[ProviderName]map[DefinitionName]ApiVersion
PreviousLock openapi.DefaultVersionLock
RemovedVersions openapi.ProviderVersionList
Spec Spec
Config Curations
ConfigPath string
// provider->version->[]resource
AllResourcesByVersion ProvidersVersionResources
// map[TokenToRemove]TokenReplacedWith
Expand Down

0 comments on commit a8e5e1c

Please sign in to comment.