Skip to content

Commit

Permalink
Support arbitrary data for rekt configmap package (#7991)
Browse files Browse the repository at this point in the history
This will help with testing the CA trust bundle rotation.

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
  • Loading branch information
pierDipi committed Jun 11, 2024
1 parent 834d833 commit 0bce743
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/rekt/resources/configmap/config-features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,28 @@ kind: ConfigMap
metadata:
name: {{ .name }}
namespace: {{ .namespace }}
{{ if .labels }}
labels:
{{ range $key, $value := .labels }}
{{ $key }}: "{{ $value }}"
{{ end }}
{{ else }}
labels:
knative.dev/config-propagation: original
knative.dev/config-category: eventing
{{ end }}
data:
{{ if .data }}
{{ range $key, $value := .data }}
{{ $key }}: |-
{{ $value }}
{{ end }}
{{ else }}
_example: |
my-enabled-flag: "enabled"
my-disabled-flag: "disabled"
my-allowed-flag: "allowed"
apiserversources-nodeselector-testkey: testvalue
apiserversources-nodeselector-testkey1: testvalue1
apiserversources-nodeselector-testkey2: testvalue2
{{ end }}
13 changes: 13 additions & 0 deletions test/rekt/resources/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package configmap
import (
"context"
"embed"
"strings"

"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/manifest"
Expand All @@ -44,3 +45,15 @@ func Install(name string, ns string, opts ...manifest.CfgFn) feature.StepFn {
}
}
}

var WithLabels = manifest.WithLabels

func WithData(key, value string) manifest.CfgFn {
return func(m map[string]interface{}) {
if _, ok := m["data"]; !ok {
m["data"] = map[string]string{}
}
value = strings.ReplaceAll(value, "\n", "\n ")
m["data"].(map[string]string)[key] = value
}
}
55 changes: 55 additions & 0 deletions test/rekt/resources/configmap/configmap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2024 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 configmap

import (
"os"

testlog "knative.dev/reconciler-test/pkg/logging"
"knative.dev/reconciler-test/pkg/manifest"
)

func Example_withData() {
ctx := testlog.NewContext()
images := map[string]string{}
cfg := map[string]interface{}{
"name": "foo",
"namespace": "bar",
}

WithData("ca.crt", "x\nx")(cfg)
WithLabels(map[string]string{"a": "b"})(cfg)

files, err := manifest.ExecuteYAML(ctx, yaml, images, cfg)
if err != nil {
panic(err)
}

manifest.OutputYAML(os.Stdout, files)
// Output:
// apiVersion: v1
// kind: ConfigMap
// metadata:
// name: foo
// namespace: bar
// labels:
// a: "b"
// data:
// ca.crt: |-
// x
// x
}

0 comments on commit 0bce743

Please sign in to comment.