Skip to content

Commit

Permalink
handle JSONSchemaProps
Browse files Browse the repository at this point in the history
  • Loading branch information
mingfang committed Nov 5, 2020
1 parent 7657f29 commit 4d97ed3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/extractor/k8s2tf_print_visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (this *K8S2TFPrintVisitor) VisitKind(proto *proto.Kind) {

//fmt.Fprintf(this.buf, "%s//VisitKind %s %s\n", this.indent, this.key, proto.GetPath())
//special handling for JSON data
if proto.GetPath().String() == "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaProps" {
if k8s.IsJSONSchemaProps(proto.GetPath().String()) {
//log.Println("VisitKind JSON:", this.path)
this.handleJSON()
return
Expand Down
2 changes: 1 addition & 1 deletion k8s/k8s2tf_read_visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (this *K8S2TFReadVisitor) VisitKind(proto *proto.Kind) {
}

//special handling for JSON data
if proto.GetPath().String() == "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaProps" {
if IsJSONSchemaProps(proto.GetPath().String()) {
this.handleJSON()
return
}
Expand Down
2 changes: 1 addition & 1 deletion k8s/k8s2tf_schema_visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (this *K8S2TFSchemaVisitor) VisitKind(proto *proto.Kind) {
//log.Println("VisitKind path:", this.path, "GetPath:", proto.GetPath())

//special handling for JSON data
if proto.GetPath().String() == "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaProps" {
if IsJSONSchemaProps(proto.GetPath().String()) {
this.handleJSON()
this.Schema.Description = proto.GetDescription()
return
Expand Down
2 changes: 1 addition & 1 deletion k8s/tf2k8s_visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (this *TF2K8SVisitor) VisitKind(proto *proto.Kind) {
//log.Println("VisitKind keyPath:", this.keyPath)

//special handling for JSON data
if proto.GetPath().String() == "io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaProps" {
if IsJSONSchemaProps(proto.GetPath().String()) {
this.handleJSON()
return
}
Expand Down
13 changes: 13 additions & 0 deletions k8s/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,16 @@ func PrintKeys(data map[string]struct{}) {
func IsDeprecated(schema *tfSchema.Schema) bool {
return strings.Contains(schema.Description, "DEPRECATED")
}

var jsonSchemaPropsPattern = []*regexp.Regexp{
regexp.MustCompile(`k8s\..*\.JSONSchemaProps`),
}

func IsJSONSchemaProps(path string) bool {
for _, pattern := range jsonSchemaPropsPattern {
if pattern.MatchString(path) {
return true
}
}
return false
}

0 comments on commit 4d97ed3

Please sign in to comment.