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

Completely disable typeCache in getTypeFromSchema #2646

Closed
wants to merge 1 commit into from
Closed
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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ require (
github.com/hashicorp/terraform-plugin-testing v1.11.0
github.com/jinzhu/copier v0.3.5
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/hashstructure v1.1.0
github.com/robfig/cron v1.2.0
github.com/stretchr/testify v1.8.3
golang.org/x/mod v0.21.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJ
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/mitchellh/hashstructure v1.1.0 h1:P6P1hdjqAAknpY/M1CGipelZgp+4y9ja9kmUZPXP+H0=
github.com/mitchellh/hashstructure v1.1.0/go.mod h1:xUDAozZz0Wmdiufv0uyhnHkUTN6/6d8ulp4AwfLKrmA=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
Expand Down
32 changes: 18 additions & 14 deletions manifest/openapi/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/hashicorp/terraform-plugin-go/tftypes"
"github.com/hashicorp/terraform-provider-kubernetes/manifest"
"github.com/mitchellh/hashstructure"
)

func resolveSchemaRef(ref *openapi3.SchemaRef, defs map[string]*openapi3.SchemaRef) (*openapi3.Schema, error) {
Expand Down Expand Up @@ -60,7 +59,6 @@ func getTypeFromSchema(elem *openapi3.Schema, stackdepth uint64, typeCache *sync
return nil, errors.New("cannot convert OpenAPI type (nil)")
}

h, herr := hashstructure.Hash(elem, nil)

var t tftypes.Type

Expand All @@ -80,6 +78,8 @@ func getTypeFromSchema(elem *openapi3.Schema, stackdepth uint64, typeCache *sync

// check if type is in cache
// HACK: this is temporarily disabled to diagnose a cache corruption issue.
// At the time of removal hashstructure v1 ("github.com/mitchellh/hashstructure") was in use.
// h, herr := hashstructure.Hash(elem, nil)
// if herr == nil {
// if t, ok := typeCache.Load(h); ok {
// return t.(tftypes.Type), nil
Expand Down Expand Up @@ -133,9 +133,10 @@ func getTypeFromSchema(elem *openapi3.Schema, stackdepth uint64, typeCache *sync
} else {
t = tftypes.List{ElementType: et}
}
if herr == nil {
typeCache.Store(h, t)
}
// See above HACK
// if herr == nil {
// typeCache.Store(h, t)
// }
return t, nil
case elem.AdditionalProperties != nil && elem.Items == nil: // "overriden" array - translates to a tftypes.Tuple
it, err := resolveSchemaRef(elem.AdditionalProperties, defs)
Expand Down Expand Up @@ -170,9 +171,10 @@ func getTypeFromSchema(elem *openapi3.Schema, stackdepth uint64, typeCache *sync
atts[p] = pType
}
t = tftypes.Object{AttributeTypes: atts}
if herr == nil {
typeCache.Store(h, t)
}
// See above HACK
// if herr == nil {
// typeCache.Store(h, t)
// }
return t, nil

case elem.Properties == nil && elem.AdditionalProperties != nil:
Expand All @@ -187,17 +189,19 @@ func getTypeFromSchema(elem *openapi3.Schema, stackdepth uint64, typeCache *sync
return nil, err
}
t = tftypes.Map{ElementType: pt}
if herr == nil {
typeCache.Store(h, t)
}
// See above HACK
// if herr == nil {
// typeCache.Store(h, t)
// }
return t, nil

case elem.Properties == nil && elem.AdditionalProperties == nil:
// this is a strange case, encountered with io.k8s.apimachinery.pkg.apis.meta.v1.FieldsV1 and also io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1.CustomResourceSubresourceStatus
t = tftypes.DynamicPseudoType
if herr == nil {
typeCache.Store(h, t)
}
// See above HACK
// if herr == nil {
// typeCache.Store(h, t)
// }
return t, nil

}
Expand Down
Loading