Skip to content

Commit

Permalink
Merge pull request #420 from vmware/cluster-import-fix
Browse files Browse the repository at this point in the history
Handle x-kubernetes-preserve-unknown-fields in import
  • Loading branch information
ankitsny authored Oct 23, 2024
2 parents 74e8faa + 25b6863 commit 589598f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
PropertiesKey OpenAPIV3Key = "properties"
TypeKey OpenAPIV3Key = "type"
AdditionalPropertiesKey OpenAPIV3Key = "additionalProperties"
PreserveUnknownFieldKey OpenAPIV3Key = "x-kubernetes-preserve-unknown-fields"
ItemsKey OpenAPIV3Key = "items"
PatternKey OpenAPIV3Key = "pattern"
MinLengthKey OpenAPIV3Key = "minLength"
Expand Down
17 changes: 11 additions & 6 deletions internal/resources/tanzukubernetescluster/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,20 @@ func removeModelVariable(clusterClassSchema interface{}, modelVariable interface
}
}
} else {
modelVarAdditionalProperties := clusterClassSchema.(map[string]interface{})[string(openapiv3.AdditionalPropertiesKey)]
_, propertiesExist := modelVarAdditionalProperties.(map[string]interface{})[string(openapiv3.PropertiesKey)]
modelVarAdditionalProperties, additionalPropertiesExist := clusterClassSchema.(map[string]interface{})[string(openapiv3.AdditionalPropertiesKey)]
preserve, preserveExists := clusterClassSchema.(map[string]interface{})[string(openapiv3.PreserveUnknownFieldKey)]
if additionalPropertiesExist {
_, propertiesExist := modelVarAdditionalProperties.(map[string]interface{})[string(openapiv3.PropertiesKey)]

if propertiesExist {
modelVariable = make(map[string]interface{})
if propertiesExist {
modelVariable = make(map[string]interface{})

for k, v := range modelVariableMap {
modelVariable.(map[string]interface{})[k] = removeModelVariable(modelVarAdditionalProperties, v)
for k, v := range modelVariableMap {
modelVariable.(map[string]interface{})[k] = removeModelVariable(modelVarAdditionalProperties, v)
}
}
} else if !preserveExists || !preserve.(bool) {
modelVariable = make(map[string]interface{})
}
}
}
Expand Down

0 comments on commit 589598f

Please sign in to comment.