diff --git a/types/mapper/object.go b/types/mapper/object.go index f31e478dc..ec12297e0 100644 --- a/types/mapper/object.go +++ b/types/mapper/object.go @@ -13,7 +13,7 @@ func NewObject(mappers ...types.Mapper) Object { Mappers: append([]types.Mapper{ &Embed{Field: "metadata"}, &Embed{Field: "spec", Optional: true}, - &ReadOnly{Field: "status", Optional: true}, + &ReadOnly{Field: "status", Optional: true, SubFields: true}, Drop{"kind"}, Drop{"apiVersion"}, &Scope{ diff --git a/types/mapper/read_only.go b/types/mapper/read_only.go index 311e933ba..69da7589c 100644 --- a/types/mapper/read_only.go +++ b/types/mapper/read_only.go @@ -5,8 +5,9 @@ import ( ) type ReadOnly struct { - Field string - Optional bool + Field string + Optional bool + SubFields bool } func (r ReadOnly) FromInternal(data map[string]interface{}) { @@ -15,12 +16,28 @@ func (r ReadOnly) FromInternal(data map[string]interface{}) { func (r ReadOnly) ToInternal(data map[string]interface{}) { } +func (r ReadOnly) readOnly(field types.Field, schema *types.Schema, schemas *types.Schemas) types.Field { + field.Create = false + field.Update = false + + if r.SubFields { + subSchema := schemas.Schema(&schema.Version, field.Type) + if subSchema != nil { + for name, field := range subSchema.ResourceFields { + field.Create = false + field.Update = false + subSchema.ResourceFields[name] = field + } + } + } + + return field +} + func (r ReadOnly) ModifySchema(schema *types.Schema, schemas *types.Schemas) error { if r.Field == "*" { for name, field := range schema.ResourceFields { - field.Create = false - field.Update = false - schema.ResourceFields[name] = field + schema.ResourceFields[name] = r.readOnly(field, schema, schemas) } return nil } @@ -33,9 +50,7 @@ func (r ReadOnly) ModifySchema(schema *types.Schema, schemas *types.Schemas) err } field := schema.ResourceFields[r.Field] - field.Create = false - field.Update = false - schema.ResourceFields[r.Field] = field + schema.ResourceFields[r.Field] = r.readOnly(field, schema, schemas) return nil }