Improvements to kyaml fn framework

This commit creates a new version of the alpha configuration functions framework. Goals include:
- Make it easy to build multi-version APIs with the framework (not previously facilitated at all).
- Simplify the framework's APIs where redundant configuration options exist (leaving the most powerful, replacing others with helpers to maintain usability they provided).
- Make the Framework's APIs more consistent (e.g. between the various template types, usage of kio.Filter, field names)
- Decouple responsibilities (e.g. command creation, resource list processing, generation of templating functions).
- Make the framework even more powerfully pluggable (e.g. any kio.Filter can be a selector, and the selector the framework provides is itself a filter built from reusable abstractions).
- Improve documentation.
- Make container patches merge fields (notably list fields like `env`) correctly.
This commit is contained in:
Katrina Verey
2021-01-21 17:52:45 -08:00
parent 1d524b6fbe
commit 5c4b5b1bf0
61 changed files with 4059 additions and 2624 deletions

View File

@@ -0,0 +1,10 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: example.com/v1alpha1
kind: patcher
selector:
annotations:
foo: bar
a: a
b: b

View File

@@ -0,0 +1,23 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
annotations:
foo: bar
patched: 'a'
spec:
template:
spec:
containers:
- name: foo
image: example/sidecar:b

View File

@@ -4,17 +4,13 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: bar2
namespace: default
name: test-1
annotations:
foo: bar2
a: 'b'
baz: foo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: bar1
namespace: default
name: test-2
annotations:
foo: bar1
a: 'b'
foo: bar

View File

@@ -0,0 +1,9 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: example.com/v1alpha1
kind: patcher
selector:
apiVersions: ["apps/v1alpha1"]
a: a
b: b

View File

@@ -0,0 +1,23 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1alpha1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
patched: 'a'
spec:
template:
spec:
containers:
- name: foo
image: example/sidecar:b
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
annotations:
foo: bar

View File

@@ -0,0 +1,16 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1alpha1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
annotations:
foo: bar

View File

@@ -2,5 +2,7 @@
# SPDX-License-Identifier: Apache-2.0
apiVersion: example.com/v1alpha1
kind: Foo
a: b
kind: patcher
a: a
b: b
special: bar

View File

@@ -0,0 +1,32 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
patched: 'a'
spec:
template:
spec:
containers:
- name: foo
image: example/sidecar:b
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
namespace: test
annotations:
foo: bar
patched: 'a'
filterPatched: 'a'
spec:
template:
spec:
containers:
- name: foo
image: example/sidecar:b

View File

@@ -0,0 +1,17 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
namespace: test
annotations:
foo: bar

View File

@@ -0,0 +1,9 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: example.com/v1alpha1
kind: patcher
selector:
kinds: ["Deployment"]
a: a
b: b

View File

@@ -0,0 +1,23 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
patched: 'a'
spec:
template:
spec:
containers:
- name: foo
image: example/sidecar:b
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: test-2
annotations:
foo: bar

View File

@@ -0,0 +1,16 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: test-2
annotations:
foo: bar

View File

@@ -0,0 +1,10 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: example.com/v1alpha1
kind: patcher
selector:
labels:
foo: bar
a: a
b: b

View File

@@ -0,0 +1,24 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
labels:
baz: foo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
labels:
foo: bar
annotations:
patched: 'a'
spec:
template:
spec:
containers:
- name: foo
image: example/sidecar:b

View File

@@ -0,0 +1,16 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
labels:
baz: foo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
labels:
foo: bar

View File

@@ -0,0 +1,9 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: example.com/v1alpha1
kind: patcher
selector:
kinds: ["Deployment"]
a: a
b: b

View File

@@ -0,0 +1,39 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
long: 'true'
patched: 'a'
spec:
template:
spec:
containers:
- name: foo
image: example/sidecar:b
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: test-2
annotations:
foo: bar
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-3
annotations:
foo: bar
long: 'true'
patched: 'a'
spec:
template:
spec:
containers:
- name: foo
image: example/sidecar:b

View File

@@ -0,0 +1,23 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: test-2
annotations:
foo: bar
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-3
annotations:
foo: bar

View File

@@ -0,0 +1,9 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: example.com/v1alpha1
kind: patcher
selector:
names: ["test-2"]
a: a
b: b

View File

@@ -0,0 +1,23 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
annotations:
foo: bar
patched: 'a'
spec:
template:
spec:
containers:
- name: foo
image: example/sidecar:b

View File

@@ -4,7 +4,13 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: bar2
namespace: default
name: test-1
annotations:
foo: bar2
baz: foo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
annotations:
foo: bar

View File

@@ -0,0 +1,9 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: example.com/v1alpha1
kind: patcher
selector:
namespaces: ["test"]
a: a
b: b

View File

@@ -0,0 +1,24 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
namespace: test
annotations:
foo: bar
patched: 'a'
spec:
template:
spec:
containers:
- name: foo
image: example/sidecar:b

View File

@@ -0,0 +1,17 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-1
annotations:
baz: foo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-2
namespace: test
annotations:
foo: bar

View File

@@ -0,0 +1,6 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
env:
- name: {{ .Spec.Key }}
value: {{ .Spec.Value }}

View File

@@ -0,0 +1,5 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
spec:
replicas: {{ .Spec.Replicas }}

View File

@@ -0,0 +1,14 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
apiVersion: apps/v1
kind: Deployment
metadata:
name: foo
namespace: bar
spec:
template:
spec:
containers:
- name: foo
image: {{ .Image }}