1
0
mirror of https://github.com/rancher/types.git synced 2025-09-01 13:18:20 +00:00

make update false for immutable fields of persistentVolume

This commit is contained in:
kinarashah
2019-05-23 14:46:23 -07:00
committed by Alena Prokharchyk
parent 4bcdbf3103
commit 2361355c4c

View File

@@ -1,6 +1,9 @@
package schema
import (
"reflect"
"strings"
"github.com/rancher/norman/types"
m "github.com/rancher/norman/types/mapper"
"github.com/rancher/types/apis/cluster.cattle.io/v3"
@@ -78,7 +81,24 @@ func persistentVolumeTypes(schemas *types.Schemas) *types.Schemas {
}{}).
MustImport(&Version, v1.PersistentVolume{}, struct {
Description string `json:"description"`
}{})
}{}).
MustImportAndCustomize(&Version, v1.PersistentVolume{}, func(schema *types.Schema) {
schema.MustCustomizeField("volumeMode", func(field types.Field) types.Field {
field.Update = false
return field
})
// All fields of PersistentVolumeSource are immutable
val := reflect.ValueOf(v1.PersistentVolumeSource{})
for i := 0; i < val.Type().NumField(); i++ {
if tag, ok := val.Type().Field(i).Tag.Lookup("json"); ok {
name := strings.Split(tag, ",")[0]
schema.MustCustomizeField(name, func(field types.Field) types.Field {
field.Update = false
return field
})
}
}
})
}
func storageClassTypes(schemas *types.Schemas) *types.Schemas {