Skip to content

Commit a115cb1

Browse files
author
Vincent
authored
Add configmap support for eventing operator and update the manifest of eventing (#25) (#28)
* Add support of configuring ConfigMaps with CR * Update the manifest of eventing
1 parent 755bf3b commit a115cb1

File tree

10 files changed

+358
-154
lines changed

10 files changed

+358
-154
lines changed

cmd/eventing-operator/kodata/knative-eventing/1-eventing.yaml

Lines changed: 140 additions & 144 deletions
Large diffs are not rendered by default.

cmd/eventing-operator/kodata/knative-eventing/2-upgrade-to-v0.14.0.yaml renamed to cmd/eventing-operator/kodata/knative-eventing/2-upgrade-to-v0.14.1.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ metadata:
44
name: v0.14.0-upgrade
55
namespace: knative-eventing
66
labels:
7-
eventing.knative.dev/release: "v0.14.0"
7+
eventing.knative.dev/release: "v0.14.1"
88
spec:
99
template:
10+
metadata:
11+
annotations:
12+
sidecar.istio.io/inject: "false"
1013
spec:
1114
serviceAccountName: eventing-controller
1215
restartPolicy: Never
1316
containers:
1417
- name: upgrade-brokers
15-
image: gcr.io/knative-releases/knative.dev/eventing/cmd/upgrade/v0.14.0@sha256:3f796b810f763325678730849021bf53ce7b6016848f880f27298e4db9112d0f
18+
image: gcr.io/knative-releases/knative.dev/eventing/cmd/upgrade/v0.14.0@sha256:574b61b38c5bba600c6a00de39eb7d8b75bb38f551755c21eda938653b74bef3
1619

1720
---

config/300-operator-v1alpha1-knative-crd.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ spec:
258258
spec:
259259
description: Spec defines the desired state of KnativeEventing
260260
properties:
261+
config:
262+
additionalProperties:
263+
additionalProperties:
264+
type: string
265+
type: object
266+
description: A means to override the corresponding entries in the upstream
267+
configmaps
268+
type: object
261269
registry:
262270
description: A means to override the corresponding deployment images in the upstream.
263271
This affects both apps/v1.Deployment and caching.internal.knative.dev/v1alpha1.Image.

pkg/apis/operator/v1alpha1/knativeeventing_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ type KnativeEventing struct {
3838
// KnativeEventingSpec defines the desired state of KnativeEventing
3939
// +k8s:openapi-gen=true
4040
type KnativeEventingSpec struct {
41+
// A means to override the corresponding entries in the upstream configmaps
42+
// +optional
43+
Config map[string]map[string]string `json:"config,omitempty"`
44+
4145
// A means to override the corresponding deployment images in the upstream.
4246
// If no registry is provided, the knative release images will be used.
4347
// +optional

pkg/apis/operator/v1alpha1/zz_generated.deepcopy.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
Copyright 2020 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package common
18+
19+
import (
20+
mf "github.com/manifestival/manifestival"
21+
"go.uber.org/zap"
22+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
23+
eventingv1alpha1 "knative.dev/operator/pkg/apis/operator/v1alpha1"
24+
)
25+
26+
// ConfigMapTransform updates the ConfigMap with the values specified in operator CR
27+
func ConfigMapTransform(instance *eventingv1alpha1.KnativeEventing, log *zap.SugaredLogger) mf.Transformer {
28+
return func(u *unstructured.Unstructured) error {
29+
// Let any config in instance override everything else
30+
if u.GetKind() == "ConfigMap" {
31+
if data, ok := instance.Spec.Config[u.GetName()[len(`config-`):]]; ok {
32+
UpdateConfigMap(u, data, log)
33+
}
34+
}
35+
return nil
36+
}
37+
}
38+
39+
// UpdateConfigMap set some data in a configmap, only overwriting common keys if they differ
40+
func UpdateConfigMap(cm *unstructured.Unstructured, data map[string]string, log *zap.SugaredLogger) {
41+
for k, v := range data {
42+
message := []interface{}{"map", cm.GetName(), k, v}
43+
if x, found, _ := unstructured.NestedFieldNoCopy(cm.Object, "data", k); found {
44+
if v == x {
45+
continue
46+
}
47+
message = append(message, "previous", x)
48+
}
49+
log.Infow("Setting", message...)
50+
unstructured.SetNestedField(cm.Object, v, "data", k)
51+
}
52+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
Copyright 2020 The Knative Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package common
18+
19+
import (
20+
"testing"
21+
22+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
23+
24+
corev1 "k8s.io/api/core/v1"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26+
"k8s.io/client-go/kubernetes/scheme"
27+
eventingv1alpha1 "knative.dev/operator/pkg/apis/operator/v1alpha1"
28+
)
29+
30+
type configMapData struct {
31+
name string
32+
data map[string]string
33+
}
34+
35+
type updateConfigMapTest struct {
36+
name string
37+
config configMapData
38+
configMap corev1.ConfigMap
39+
expected corev1.ConfigMap
40+
}
41+
42+
func makeconfigMapData(name string, data map[string]string) configMapData {
43+
return configMapData{
44+
name: name,
45+
data: data,
46+
}
47+
}
48+
49+
func createConfigMapTests(t *testing.T) []updateConfigMapTest {
50+
return []updateConfigMapTest{
51+
{
52+
name: "change-config-logging",
53+
config: makeconfigMapData("logging", map[string]string{
54+
"loglevel.controller": "debug",
55+
"loglevel.webhook": "debug",
56+
}),
57+
configMap: createConfigMap("config-logging", map[string]string{
58+
"loglevel.controller": "info",
59+
"loglevel.webhook": "info",
60+
}),
61+
expected: createConfigMap("config-logging", map[string]string{
62+
"loglevel.controller": "debug",
63+
"loglevel.webhook": "debug",
64+
}),
65+
},
66+
{
67+
name: "change-config-logging-empty-data",
68+
config: makeconfigMapData("logging", map[string]string{
69+
"loglevel.controller": "debug",
70+
"loglevel.webhook": "debug",
71+
}),
72+
configMap: createConfigMap("config-logging", nil),
73+
expected: createConfigMap("config-logging", map[string]string{
74+
"loglevel.controller": "debug",
75+
"loglevel.webhook": "debug",
76+
}),
77+
},
78+
}
79+
}
80+
81+
func createConfigMap(name string, data map[string]string) corev1.ConfigMap {
82+
return corev1.ConfigMap{
83+
TypeMeta: metav1.TypeMeta{
84+
Kind: "ConfigMap",
85+
},
86+
ObjectMeta: metav1.ObjectMeta{
87+
Name: name,
88+
},
89+
Data: data,
90+
}
91+
}
92+
93+
func TestConfigMapTransform(t *testing.T) {
94+
for _, tt := range createConfigMapTests(t) {
95+
t.Run(tt.name, func(t *testing.T) {
96+
runConfigMapTransformTest(t, &tt)
97+
})
98+
}
99+
}
100+
101+
func runConfigMapTransformTest(t *testing.T, tt *updateConfigMapTest) {
102+
unstructuredConfigMap := makeUnstructured(t, &tt.configMap)
103+
instance := &eventingv1alpha1.KnativeEventing{
104+
Spec: eventingv1alpha1.KnativeEventingSpec{
105+
Config: map[string]map[string]string{
106+
tt.config.name: tt.config.data,
107+
},
108+
},
109+
}
110+
111+
configMapTransform := ConfigMapTransform(instance, log)
112+
configMapTransform(&unstructuredConfigMap)
113+
validateConfigMapChanged(t, tt, &unstructuredConfigMap)
114+
}
115+
116+
func validateConfigMapChanged(t *testing.T, tt *updateConfigMapTest, u *unstructured.Unstructured) {
117+
var configMap = &corev1.ConfigMap{}
118+
err := scheme.Scheme.Convert(u, configMap, nil)
119+
assertEqual(t, err, nil)
120+
assertDeepEqual(t, configMap.Data, tt.expected.Data)
121+
}

pkg/reconciler/knativeeventing/common/extensions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func (platforms Platforms) Transformers(kubeClientSet kubernetes.Interface, inst
3434
mf.InjectNamespace(instance.GetNamespace()),
3535
DeploymentTransform(instance, log),
3636
DefaultBrokerConfigMapTransform(instance, log),
37+
ConfigMapTransform(instance, log),
3738
}
3839
for _, fn := range platforms {
3940
transformer, err := fn(kubeClientSet, log)

pkg/reconciler/knativeeventing/common/extensions_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,20 @@ func TestTransformers(t *testing.T) {
6161

6262
results, err := platform.Transformers(kubeclient.Get(ctx), ke, logger)
6363
assertEqual(t, err, nil)
64-
// By default, there are 4 functions.
65-
assertEqual(t, len(results), 4)
64+
// By default, there are 5 functions.
65+
assertEqual(t, len(results), 5)
6666

6767
platform = append(platform, fakePlatform)
6868
results, err = platform.Transformers(kubeclient.Get(ctx), ke, logger)
6969
assertEqual(t, err, nil)
70-
// There is one function in existing platform, so there will be 5 functions in total.
71-
assertEqual(t, len(results), 5)
70+
// There is one function in existing platform, so there will be 6 functions in total.
71+
assertEqual(t, len(results), 6)
7272

7373
platformErr = append(platformErr, fakePlatformErr)
7474
results, err = platformErr.Transformers(kubeclient.Get(ctx), ke, logger)
7575
assertEqual(t, err.Error(), "Test Error")
76-
// By default, there are 4 functions.
77-
assertEqual(t, len(results), 4)
76+
// By default, there are 5 functions.
77+
assertEqual(t, len(results), 5)
7878
}
7979

8080
func fakePlatformErr(kubeClient kubernetes.Interface, logger *zap.SugaredLogger) (mf.Transformer, error) {

version/version.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package version
22

33
var (
4-
// Version is the version that will be applied to the KnativeServing resource.
4+
// ServingVersion is the version that will be applied to the KnativeServing resource.
55
ServingVersion = "0.14.0"
6-
EventingVersion = "0.14.0"
6+
7+
// EventingVersion is the version that will be applied to the KnativeEventing resource.
8+
EventingVersion = "0.14.1"
79
)

0 commit comments

Comments
 (0)