From 060be6d24d8d5a0a477b8c1fdb58f8e6031c30eb Mon Sep 17 00:00:00 2001 From: wojtekt Date: Tue, 26 Nov 2019 13:29:26 +0100 Subject: [PATCH] Immutable field and validation Kubernetes-commit: e612ebfdff22e4bd27ad8345f7c82f074bfedf26 --- pkg/util/hash/hash.go | 20 ++++++++++++++++++-- pkg/util/hash/hash_test.go | 4 ++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/pkg/util/hash/hash.go b/pkg/util/hash/hash.go index de0036245..1b20f384b 100644 --- a/pkg/util/hash/hash.go +++ b/pkg/util/hash/hash.go @@ -56,7 +56,14 @@ func SecretHash(sec *v1.Secret) (string, error) { // Data, Kind, and Name are taken into account. func encodeConfigMap(cm *v1.ConfigMap) (string, error) { // 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 { m["binaryData"] = cm.BinaryData } @@ -70,8 +77,17 @@ func encodeConfigMap(cm *v1.ConfigMap) (string, error) { // encodeSecret encodes a Secret. // Data, Kind, Name, and Type are taken into account. 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 - 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 { return "", err } diff --git a/pkg/util/hash/hash_test.go b/pkg/util/hash/hash_test.go index f527a98a2..455459c3b 100644 --- a/pkg/util/hash/hash_test.go +++ b/pkg/util/hash/hash_test.go @@ -164,8 +164,8 @@ not their metadata (e.g. the Data of a ConfigMap, but nothing in ObjectMeta). obj interface{} expect int }{ - {"ConfigMap", v1.ConfigMap{}, 4}, - {"Secret", v1.Secret{}, 5}, + {"ConfigMap", v1.ConfigMap{}, 5}, + {"Secret", v1.Secret{}, 6}, } for _, c := range cases { val := reflect.ValueOf(c.obj)