Merge pull request #344 from mengqiy/namehash

appending name hash only applies to current layer
This commit is contained in:
k8s-ci-robot 2018-03-08 14:01:13 -08:00 committed by GitHub
commit 08f3abb5bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 96 additions and 18 deletions

View File

@ -83,6 +83,16 @@ func (a *applicationImpl) Resources() (types.ResourceCollection, error) {
} else {
resources = append(resources, secrets...)
}
res, err := resourceCollectionFromResources(resources)
if err != nil {
return nil, err
}
// Only append hash for generated configmaps and secrets.
nht := transformers.NewNameHashTransformer()
err = nht.Transform(types.KObject(res))
if err != nil {
return nil, err
}
ps, err := resource.NewFromPaths(a.loader, a.manifest.Patches)
if err != nil {
@ -98,11 +108,7 @@ func (a *applicationImpl) Resources() (types.ResourceCollection, error) {
return nil, errs
}
allResources, err := resourceCollectionFromResources(resources)
if err != nil {
return nil, err
}
err = types.Merge(allResources, raw)
err = types.Merge(res, raw)
if err != nil {
return nil, err
}
@ -111,11 +117,11 @@ func (a *applicationImpl) Resources() (types.ResourceCollection, error) {
if err != nil {
return nil, err
}
err = t.Transform(types.KObject(allResources))
err = t.Transform(types.KObject(res))
if err != nil {
return nil, err
}
return allResources, nil
return res, nil
}
// RawResources computes and returns the raw resources from the manifest.
@ -164,18 +170,14 @@ func (a *applicationImpl) subAppResources() (types.ResourceCollection, *interror
}
// getTransformer generates the following transformers:
// 1) append hash for configmaps ans secrets
// 2) apply overlay
// 3) name prefix
// 4) apply labels
// 5) apply annotations
// 6) update name reference
// 1) apply overlay
// 2) name prefix
// 3) apply labels
// 4) apply annotations
// 5) update name reference
func (a *applicationImpl) getTransformer(patches types.ResourceCollection) (transformers.Transformer, error) {
ts := []transformers.Transformer{}
nht := transformers.NewNameHashTransformer()
ts = append(ts, nht)
ot, err := transformers.NewOverlayTransformer(types.KObject(patches))
if err != nil {
return nil, err

View File

@ -26,7 +26,7 @@ diff -u -N /tmp/noop/apps_v1beta2_Deployment_nginx.yaml /tmp/transformed/apps_v1
org: example.com
team: foo
spec:
@@ -30,5 +33,6 @@
@@ -30,8 +33,12 @@
- mountPath: /tmp/ps
name: nginx-persistent-storage
volumes:
@ -34,6 +34,37 @@ diff -u -N /tmp/noop/apps_v1beta2_Deployment_nginx.yaml /tmp/transformed/apps_v1
+ - gcePersistentDisk:
+ pdName: nginx-persistent-storage
name: nginx-persistent-storage
- configMap:
+ name: staging-configmap-in-overlay-h4hbb8fckf
+ name: configmap-in-overlay
+ - configMap:
name: team-foo-configmap-in-base-72t84tc949
name: configmap-in-base
diff -u -N /tmp/noop/v1_ConfigMap_configmap-in-base.yaml /tmp/transformed/v1_ConfigMap_configmap-in-base.yaml
--- /tmp/noop/v1_ConfigMap_configmap-in-base.yaml YYYY-MM-DD HH:MM:SS
+++ /tmp/transformed/v1_ConfigMap_configmap-in-base.yaml YYYY-MM-DD HH:MM:SS
@@ -8,6 +8,7 @@
creationTimestamp: null
labels:
app: mynginx
+ env: staging
org: example.com
team: foo
- name: team-foo-configmap-in-base-72t84tc949
+ name: staging-team-foo-configmap-in-base-72t84tc949
diff -u -N /tmp/noop/v1_ConfigMap_configmap-in-overlay.yaml /tmp/transformed/v1_ConfigMap_configmap-in-overlay.yaml
--- /tmp/noop/v1_ConfigMap_configmap-in-overlay.yaml YYYY-MM-DD HH:MM:SS
+++ /tmp/transformed/v1_ConfigMap_configmap-in-overlay.yaml YYYY-MM-DD HH:MM:SS
@@ -0,0 +1,9 @@
+apiVersion: v1
+data:
+ hello: world
+kind: ConfigMap
+metadata:
+ creationTimestamp: null
+ labels:
+ env: staging
+ name: staging-configmap-in-overlay-h4hbb8fckf
diff -u -N /tmp/noop/v1_Service_nginx.yaml /tmp/transformed/v1_Service_nginx.yaml
--- /tmp/noop/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS
+++ /tmp/transformed/v1_Service_nginx.yaml YYYY-MM-DD HH:MM:SS

View File

@ -1,4 +1,29 @@
apiVersion: v1
data:
foo: bar
kind: ConfigMap
metadata:
annotations:
note: This is a test annotation
creationTimestamp: null
labels:
app: mynginx
env: staging
org: example.com
team: foo
name: staging-team-foo-configmap-in-base-72t84tc949
---
apiVersion: v1
data:
hello: world
kind: ConfigMap
metadata:
creationTimestamp: null
labels:
env: staging
name: staging-configmap-in-overlay-h4hbb8fckf
---
apiVersion: v1
kind: Service
metadata:
annotations:
@ -56,3 +81,9 @@ spec:
- gcePersistentDisk:
pdName: nginx-persistent-storage
name: nginx-persistent-storage
- configMap:
name: staging-configmap-in-overlay-h4hbb8fckf
name: configmap-in-overlay
- configMap:
name: team-foo-configmap-in-base-72t84tc949
name: configmap-in-base

View File

@ -10,3 +10,7 @@ patches:
- deployment.yaml
packages:
- ../package/
configmaps:
- name: configmap-in-overlay
literals:
- hello=world

View File

@ -10,3 +10,6 @@ spec:
emptyDir: null
gcePersistentDisk:
pdName: nginx-persistent-storage
- configMap:
name: configmap-in-overlay
name: configmap-in-overlay

View File

@ -13,3 +13,7 @@ objectAnnotations:
resources:
- deployment.yaml
- service.yaml
configmaps:
- name: configmap-in-base
literals:
- foo=bar

View File

@ -18,4 +18,7 @@ spec:
mountPath: /tmp/ps
volumes:
- name: nginx-persistent-storage
emptyDir: {}
emptyDir: {}
- configMap:
name: configmap-in-base
name: configmap-in-base