-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configmap support for eventing operator and update the manifest o…
…f eventing (#25) (#28) * Add support of configuring ConfigMaps with CR * Update the manifest of eventing
- Loading branch information
Vincent
authored
Apr 23, 2020
1 parent
755bf3b
commit a115cb1
Showing
10 changed files
with
358 additions
and
154 deletions.
There are no files selected for viewing
284 changes: 140 additions & 144 deletions
284
cmd/eventing-operator/kodata/knative-eventing/1-eventing.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package common | ||
|
||
import ( | ||
mf "github.com/manifestival/manifestival" | ||
"go.uber.org/zap" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
eventingv1alpha1 "knative.dev/operator/pkg/apis/operator/v1alpha1" | ||
) | ||
|
||
// ConfigMapTransform updates the ConfigMap with the values specified in operator CR | ||
func ConfigMapTransform(instance *eventingv1alpha1.KnativeEventing, log *zap.SugaredLogger) mf.Transformer { | ||
return func(u *unstructured.Unstructured) error { | ||
// Let any config in instance override everything else | ||
if u.GetKind() == "ConfigMap" { | ||
if data, ok := instance.Spec.Config[u.GetName()[len(`config-`):]]; ok { | ||
UpdateConfigMap(u, data, log) | ||
} | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
// UpdateConfigMap set some data in a configmap, only overwriting common keys if they differ | ||
func UpdateConfigMap(cm *unstructured.Unstructured, data map[string]string, log *zap.SugaredLogger) { | ||
for k, v := range data { | ||
message := []interface{}{"map", cm.GetName(), k, v} | ||
if x, found, _ := unstructured.NestedFieldNoCopy(cm.Object, "data", k); found { | ||
if v == x { | ||
continue | ||
} | ||
message = append(message, "previous", x) | ||
} | ||
log.Infow("Setting", message...) | ||
unstructured.SetNestedField(cm.Object, v, "data", k) | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
pkg/reconciler/knativeeventing/common/config_maps_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
Copyright 2020 The Knative Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
eventingv1alpha1 "knative.dev/operator/pkg/apis/operator/v1alpha1" | ||
) | ||
|
||
type configMapData struct { | ||
name string | ||
data map[string]string | ||
} | ||
|
||
type updateConfigMapTest struct { | ||
name string | ||
config configMapData | ||
configMap corev1.ConfigMap | ||
expected corev1.ConfigMap | ||
} | ||
|
||
func makeconfigMapData(name string, data map[string]string) configMapData { | ||
return configMapData{ | ||
name: name, | ||
data: data, | ||
} | ||
} | ||
|
||
func createConfigMapTests(t *testing.T) []updateConfigMapTest { | ||
return []updateConfigMapTest{ | ||
{ | ||
name: "change-config-logging", | ||
config: makeconfigMapData("logging", map[string]string{ | ||
"loglevel.controller": "debug", | ||
"loglevel.webhook": "debug", | ||
}), | ||
configMap: createConfigMap("config-logging", map[string]string{ | ||
"loglevel.controller": "info", | ||
"loglevel.webhook": "info", | ||
}), | ||
expected: createConfigMap("config-logging", map[string]string{ | ||
"loglevel.controller": "debug", | ||
"loglevel.webhook": "debug", | ||
}), | ||
}, | ||
{ | ||
name: "change-config-logging-empty-data", | ||
config: makeconfigMapData("logging", map[string]string{ | ||
"loglevel.controller": "debug", | ||
"loglevel.webhook": "debug", | ||
}), | ||
configMap: createConfigMap("config-logging", nil), | ||
expected: createConfigMap("config-logging", map[string]string{ | ||
"loglevel.controller": "debug", | ||
"loglevel.webhook": "debug", | ||
}), | ||
}, | ||
} | ||
} | ||
|
||
func createConfigMap(name string, data map[string]string) corev1.ConfigMap { | ||
return corev1.ConfigMap{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "ConfigMap", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
}, | ||
Data: data, | ||
} | ||
} | ||
|
||
func TestConfigMapTransform(t *testing.T) { | ||
for _, tt := range createConfigMapTests(t) { | ||
t.Run(tt.name, func(t *testing.T) { | ||
runConfigMapTransformTest(t, &tt) | ||
}) | ||
} | ||
} | ||
|
||
func runConfigMapTransformTest(t *testing.T, tt *updateConfigMapTest) { | ||
unstructuredConfigMap := makeUnstructured(t, &tt.configMap) | ||
instance := &eventingv1alpha1.KnativeEventing{ | ||
Spec: eventingv1alpha1.KnativeEventingSpec{ | ||
Config: map[string]map[string]string{ | ||
tt.config.name: tt.config.data, | ||
}, | ||
}, | ||
} | ||
|
||
configMapTransform := ConfigMapTransform(instance, log) | ||
configMapTransform(&unstructuredConfigMap) | ||
validateConfigMapChanged(t, tt, &unstructuredConfigMap) | ||
} | ||
|
||
func validateConfigMapChanged(t *testing.T, tt *updateConfigMapTest, u *unstructured.Unstructured) { | ||
var configMap = &corev1.ConfigMap{} | ||
err := scheme.Scheme.Convert(u, configMap, nil) | ||
assertEqual(t, err, nil) | ||
assertDeepEqual(t, configMap.Data, tt.expected.Data) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package version | ||
|
||
var ( | ||
// Version is the version that will be applied to the KnativeServing resource. | ||
// ServingVersion is the version that will be applied to the KnativeServing resource. | ||
ServingVersion = "0.14.0" | ||
EventingVersion = "0.14.0" | ||
|
||
// EventingVersion is the version that will be applied to the KnativeEventing resource. | ||
EventingVersion = "0.14.1" | ||
) |