@@ -19,17 +19,64 @@ package rabbitmqvhost
1919import (
2020 "context"
2121 "embed"
22+ "log"
2223
24+ "github.com/kelseyhightower/envconfig"
2325 "knative.dev/reconciler-test/pkg/feature"
2426 "knative.dev/reconciler-test/pkg/manifest"
2527)
2628
2729//go:embed "*.yaml"
2830var yamls embed.FS
2931
30- func Install () feature.StepFn {
32+ var EnvCfg EnvConfig
33+
34+ type EnvConfig struct {
35+ RabbitmqServerImage string `envconfig:"RABBITMQ_SERVER_IMAGE"`
36+ RabbitmqImagePullSecret string `envconfig:"RABBITMQ_IMAGE_PULL_SECRET"`
37+ }
38+
39+ func init () {
40+ // Process EventingGlobal.
41+ if err := envconfig .Process ("" , & EnvCfg ); err != nil {
42+ log .Fatal ("Failed to process env var" , err )
43+ }
44+ }
45+
46+ func WithEnvConfig () []manifest.CfgFn {
47+ cfg := []manifest.CfgFn {}
48+
49+ if EnvCfg .RabbitmqServerImage != "" {
50+ cfg = append (cfg , WithRabbitmqServerImage (EnvCfg .RabbitmqServerImage ))
51+ }
52+
53+ if EnvCfg .RabbitmqImagePullSecret != "" {
54+ cfg = append (cfg , WithRabbitmqImagePullSecret (EnvCfg .RabbitmqImagePullSecret ))
55+ }
56+
57+ return cfg
58+ }
59+
60+ func WithRabbitmqServerImage (name string ) manifest.CfgFn {
61+ return func (cfg map [string ]interface {}) {
62+ cfg ["rabbitmqServerImage" ] = name
63+ }
64+ }
65+
66+ func WithRabbitmqImagePullSecret (name string ) manifest.CfgFn {
67+ return func (cfg map [string ]interface {}) {
68+ cfg ["rabbitmqImagePullSecretName" ] = name
69+ }
70+ }
71+
72+ func Install (opts ... manifest.CfgFn ) feature.StepFn {
73+ cfg := map [string ]interface {}{}
74+ for _ , fn := range opts {
75+ fn (cfg )
76+ }
77+
3178 return func (ctx context.Context , t feature.T ) {
32- if _ , err := manifest .InstallYamlFS (ctx , yamls , nil ); err != nil {
79+ if _ , err := manifest .InstallYamlFS (ctx , yamls , cfg ); err != nil {
3380 t .Fatal (err )
3481 }
3582 }
0 commit comments