mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-30 01:46:23 +00:00
Merge branch 'master' into transformer-no-create-arrays
This commit is contained in:
52
pkg/hasher/hasher.go
Normal file
52
pkg/hasher/hasher.go
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package hasher
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// SortArrayAndComputeHash sorts a string array and
|
||||
// returns a hash for it
|
||||
func SortArrayAndComputeHash(s []string) (string, error) {
|
||||
sort.Strings(s)
|
||||
data, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return Encode(Hash(string(data)))
|
||||
}
|
||||
|
||||
// Copied from https://github.com/kubernetes/kubernetes
|
||||
// /blob/master/pkg/kubectl/util/hash/hash.go
|
||||
func Encode(hex string) (string, error) {
|
||||
if len(hex) < 10 {
|
||||
return "", fmt.Errorf(
|
||||
"input length must be at least 10.")
|
||||
}
|
||||
enc := []rune(hex[:10])
|
||||
for i := range enc {
|
||||
switch enc[i] {
|
||||
case '0':
|
||||
enc[i] = 'g'
|
||||
case '1':
|
||||
enc[i] = 'h'
|
||||
case '3':
|
||||
enc[i] = 'k'
|
||||
case 'a':
|
||||
enc[i] = 'm'
|
||||
case 'e':
|
||||
enc[i] = 't'
|
||||
}
|
||||
}
|
||||
return string(enc), nil
|
||||
}
|
||||
|
||||
// Hash returns the hex form of the sha256 of the argument.
|
||||
func Hash(data string) string {
|
||||
return fmt.Sprintf("%x", sha256.Sum256([]byte(data)))
|
||||
}
|
||||
41
pkg/hasher/hasher_test.go
Normal file
41
pkg/hasher/hasher_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package hasher_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "sigs.k8s.io/kustomize/pkg/hasher"
|
||||
)
|
||||
|
||||
func TestSortArrayAndComputeHash(t *testing.T) {
|
||||
array1 := []string{"a", "b", "c", "d"}
|
||||
array2 := []string{"c", "b", "d", "a"}
|
||||
h1, err := SortArrayAndComputeHash(array1)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
if h1 == "" {
|
||||
t.Errorf("failed to hash %v", array1)
|
||||
}
|
||||
h2, err := SortArrayAndComputeHash(array2)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
if h2 == "" {
|
||||
t.Errorf("failed to hash %v", array2)
|
||||
}
|
||||
if h1 != h2 {
|
||||
t.Errorf("hash is not consistent with reordered list: %s %s", h1, h2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHash(t *testing.T) {
|
||||
// hash the empty string to be sure that sha256 is being used
|
||||
expect := "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
sum := Hash("")
|
||||
if expect != sum {
|
||||
t.Errorf("expected hash %q but got %q", expect, sum)
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ kind: Secret
|
||||
metadata:
|
||||
labels:
|
||||
app: release-name-minecraft
|
||||
chart: minecraft-1.0.0
|
||||
chart: minecraft-1.0.1
|
||||
heritage: Tiller
|
||||
release: release-name
|
||||
name: LOOOOOOOONG-release-name-minecraft
|
||||
@@ -72,7 +72,7 @@ kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app: release-name-minecraft
|
||||
chart: minecraft-1.0.0
|
||||
chart: minecraft-1.0.1
|
||||
heritage: Tiller
|
||||
release: release-name
|
||||
name: LOOOOOOOONG-release-name-minecraft
|
||||
@@ -93,7 +93,7 @@ metadata:
|
||||
volume.alpha.kubernetes.io/storage-class: default
|
||||
labels:
|
||||
app: release-name-minecraft
|
||||
chart: minecraft-1.0.0
|
||||
chart: minecraft-1.0.1
|
||||
heritage: Tiller
|
||||
release: release-name
|
||||
name: LOOOOOOOONG-release-name-minecraft-datadir
|
||||
|
||||
@@ -31,24 +31,26 @@ namePrefix: blah-
|
||||
configMapGenerator:
|
||||
- name: bob
|
||||
literals:
|
||||
- fruit=apple
|
||||
- vegetable=broccoli
|
||||
env: foo.env
|
||||
- fruit=apple
|
||||
- vegetable=broccoli
|
||||
envs:
|
||||
- foo.env
|
||||
files:
|
||||
- passphrase=phrase.dat
|
||||
- forces.txt
|
||||
- passphrase=phrase.dat
|
||||
- forces.txt
|
||||
- name: json
|
||||
literals:
|
||||
- 'v2=[{"path": "var/druid/segment-cache"}]'
|
||||
- 'v2=[{"path": "var/druid/segment-cache"}]'
|
||||
secretGenerator:
|
||||
- name: bob
|
||||
literals:
|
||||
- fruit=apple
|
||||
- vegetable=broccoli
|
||||
env: foo.env
|
||||
- fruit=apple
|
||||
- vegetable=broccoli
|
||||
envs:
|
||||
- foo.env
|
||||
files:
|
||||
- passphrase=phrase.dat
|
||||
- forces.txt
|
||||
- passphrase=phrase.dat
|
||||
- forces.txt
|
||||
`)
|
||||
th.WriteF("/app/foo.env", `
|
||||
MOUNTAIN=everest
|
||||
@@ -122,15 +124,15 @@ configMapGenerator:
|
||||
- name: bob
|
||||
behavior: create
|
||||
literals:
|
||||
- bean=pinto
|
||||
- star=wolf-rayet
|
||||
- bean=pinto
|
||||
- star=wolf-rayet
|
||||
literals:
|
||||
- fruit=apple
|
||||
- vegetable=broccoli
|
||||
- fruit=apple
|
||||
- vegetable=broccoli
|
||||
files:
|
||||
- forces.txt
|
||||
- forces.txt
|
||||
files:
|
||||
- nobles=nobility.txt
|
||||
- nobles=nobility.txt
|
||||
`)
|
||||
th.WriteF("/app/forces.txt", `
|
||||
gravitational
|
||||
@@ -177,7 +179,7 @@ configMapGenerator:
|
||||
- name: com1
|
||||
behavior: create
|
||||
literals:
|
||||
- from=base
|
||||
- from=base
|
||||
`)
|
||||
th.WriteK("/app/base2", `
|
||||
namePrefix: p2-
|
||||
@@ -185,7 +187,7 @@ configMapGenerator:
|
||||
- name: com2
|
||||
behavior: create
|
||||
literals:
|
||||
- from=base
|
||||
- from=base
|
||||
`)
|
||||
th.WriteK("/app/overlay/o1", `
|
||||
bases:
|
||||
@@ -194,7 +196,7 @@ configMapGenerator:
|
||||
- name: com1
|
||||
behavior: merge
|
||||
literals:
|
||||
- from=overlay
|
||||
- from=overlay
|
||||
`)
|
||||
th.WriteK("/app/overlay/o2", `
|
||||
bases:
|
||||
@@ -203,7 +205,7 @@ configMapGenerator:
|
||||
- name: com2
|
||||
behavior: merge
|
||||
literals:
|
||||
- from=overlay
|
||||
- from=overlay
|
||||
`)
|
||||
th.WriteK("/app/overlay", `
|
||||
bases:
|
||||
@@ -213,8 +215,8 @@ configMapGenerator:
|
||||
- name: com1
|
||||
behavior: merge
|
||||
literals:
|
||||
- foo=bar
|
||||
- baz=qux
|
||||
- foo=bar
|
||||
- baz=qux
|
||||
`)
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
|
||||
@@ -178,14 +178,14 @@ resources:
|
||||
- deployment.yaml
|
||||
- service.yaml
|
||||
configMapGenerator:
|
||||
- name: configmap-in-base
|
||||
literals:
|
||||
- foo=bar
|
||||
- name: configmap-in-base
|
||||
literals:
|
||||
- foo=bar
|
||||
secretGenerator:
|
||||
- name: secret-in-base
|
||||
literals:
|
||||
- username=admin
|
||||
- password=somepw
|
||||
- username=admin
|
||||
- password=somepw
|
||||
`)
|
||||
th.WriteF("/app/deployment.yaml", `
|
||||
apiVersion: apps/v1beta2
|
||||
@@ -354,18 +354,18 @@ patchesStrategicMerge:
|
||||
bases:
|
||||
- ../app
|
||||
configMapGenerator:
|
||||
- name: configmap-in-overlay
|
||||
literals:
|
||||
- hello=world
|
||||
- name: configmap-in-base
|
||||
behavior: replace
|
||||
literals:
|
||||
- foo=override-bar
|
||||
- name: configmap-in-overlay
|
||||
literals:
|
||||
- hello=world
|
||||
- name: configmap-in-base
|
||||
behavior: replace
|
||||
literals:
|
||||
- foo=override-bar
|
||||
secretGenerator:
|
||||
- name: secret-in-base
|
||||
behavior: merge
|
||||
literals:
|
||||
- proxy=haproxy
|
||||
- proxy=haproxy
|
||||
`)
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
|
||||
@@ -38,9 +38,9 @@ resources:
|
||||
- deployment.yaml
|
||||
- service.yaml
|
||||
configMapGenerator:
|
||||
- name: configmap-in-base
|
||||
literals:
|
||||
- foo=bar
|
||||
- name: configmap-in-base
|
||||
literals:
|
||||
- foo=bar
|
||||
`)
|
||||
th.WriteF("/app/base/deployment.yaml", `
|
||||
apiVersion: apps/v1beta2
|
||||
@@ -93,9 +93,9 @@ patchesStrategicMerge:
|
||||
bases:
|
||||
- ../../base
|
||||
configMapGenerator:
|
||||
- name: configmap-in-overlay
|
||||
literals:
|
||||
- hello=world
|
||||
- name: configmap-in-overlay
|
||||
literals:
|
||||
- hello=world
|
||||
`)
|
||||
}
|
||||
|
||||
|
||||
@@ -42,10 +42,10 @@ secretGenerator:
|
||||
- name: the-non-default-namespace-secret
|
||||
namespace: non-default
|
||||
literals:
|
||||
- password.txt=verySecret
|
||||
- password.txt=verySecret
|
||||
- name: the-secret
|
||||
literals:
|
||||
- password.txt=anotherSecret
|
||||
- password.txt=anotherSecret
|
||||
`)
|
||||
m, err := th.MakeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
|
||||
@@ -32,8 +32,8 @@ resources:
|
||||
configMapGenerator:
|
||||
- name: test-config-map
|
||||
literals:
|
||||
- foo=bar
|
||||
- baz=qux
|
||||
- foo=bar
|
||||
- baz=qux
|
||||
vars:
|
||||
- name: CDB_PUBLIC_SVC
|
||||
objref:
|
||||
|
||||
@@ -252,6 +252,12 @@ nameReference:
|
||||
- path: spec/service/name
|
||||
kind: APIService
|
||||
group: apiregistration.k8s.io
|
||||
- path: webhooks/clientConfig/service/name
|
||||
kind: ValidatingWebhookConfiguration
|
||||
group: admissionregistration.k8s.io
|
||||
- path: webhooks/clientConfig/service/name
|
||||
kind: MutatingWebhookConfiguration
|
||||
group: admissionregistration.k8s.io
|
||||
|
||||
- kind: Role
|
||||
group: rbac.authorization.k8s.io
|
||||
|
||||
Reference in New Issue
Block a user