Immutable field and validation
Kubernetes-commit: e612ebfdff22e4bd27ad8345f7c82f074bfedf26
This commit is contained in:
parent
7280c03866
commit
060be6d24d
|
|
@ -56,7 +56,14 @@ func SecretHash(sec *v1.Secret) (string, error) {
|
||||||
// Data, Kind, and Name are taken into account.
|
// Data, Kind, and Name are taken into account.
|
||||||
func encodeConfigMap(cm *v1.ConfigMap) (string, error) {
|
func encodeConfigMap(cm *v1.ConfigMap) (string, error) {
|
||||||
// json.Marshal sorts the keys in a stable order in the encoding
|
// json.Marshal sorts the keys in a stable order in the encoding
|
||||||
m := map[string]interface{}{"kind": "ConfigMap", "name": cm.Name, "data": cm.Data}
|
m := map[string]interface{}{
|
||||||
|
"kind": "ConfigMap",
|
||||||
|
"name": cm.Name,
|
||||||
|
"data": cm.Data,
|
||||||
|
}
|
||||||
|
if cm.Immutable != nil {
|
||||||
|
m["immutable"] = *cm.Immutable
|
||||||
|
}
|
||||||
if len(cm.BinaryData) > 0 {
|
if len(cm.BinaryData) > 0 {
|
||||||
m["binaryData"] = cm.BinaryData
|
m["binaryData"] = cm.BinaryData
|
||||||
}
|
}
|
||||||
|
|
@ -70,8 +77,17 @@ func encodeConfigMap(cm *v1.ConfigMap) (string, error) {
|
||||||
// encodeSecret encodes a Secret.
|
// encodeSecret encodes a Secret.
|
||||||
// Data, Kind, Name, and Type are taken into account.
|
// Data, Kind, Name, and Type are taken into account.
|
||||||
func encodeSecret(sec *v1.Secret) (string, error) {
|
func encodeSecret(sec *v1.Secret) (string, error) {
|
||||||
|
m := map[string]interface{}{
|
||||||
|
"kind": "Secret",
|
||||||
|
"type": sec.Type,
|
||||||
|
"name": sec.Name,
|
||||||
|
"data": sec.Data,
|
||||||
|
}
|
||||||
|
if sec.Immutable != nil {
|
||||||
|
m["immutable"] = *sec.Immutable
|
||||||
|
}
|
||||||
// json.Marshal sorts the keys in a stable order in the encoding
|
// json.Marshal sorts the keys in a stable order in the encoding
|
||||||
data, err := json.Marshal(map[string]interface{}{"kind": "Secret", "type": sec.Type, "name": sec.Name, "data": sec.Data})
|
data, err := json.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -164,8 +164,8 @@ not their metadata (e.g. the Data of a ConfigMap, but nothing in ObjectMeta).
|
||||||
obj interface{}
|
obj interface{}
|
||||||
expect int
|
expect int
|
||||||
}{
|
}{
|
||||||
{"ConfigMap", v1.ConfigMap{}, 4},
|
{"ConfigMap", v1.ConfigMap{}, 5},
|
||||||
{"Secret", v1.Secret{}, 5},
|
{"Secret", v1.Secret{}, 6},
|
||||||
}
|
}
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
val := reflect.ValueOf(c.obj)
|
val := reflect.ValueOf(c.obj)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue