|
| 1 | +package manager |
| 2 | + |
| 3 | +import ( |
| 4 | + . "github.com/onsi/ginkgo" |
| 5 | + . "github.com/onsi/gomega" |
| 6 | + |
| 7 | + "sigs.k8s.io/controller-runtime/pkg/config" |
| 8 | + |
| 9 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 10 | + "k8s.io/apimachinery/pkg/runtime" |
| 11 | + configv1alpha1 "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" |
| 12 | +) |
| 13 | + |
| 14 | +var _ = Describe("manager.Options", func() { |
| 15 | + Describe("AndFrom", func() { |
| 16 | + Describe("reading custom type using OfKind", func() { |
| 17 | + var ( |
| 18 | + o Options |
| 19 | + c customConfig |
| 20 | + err error |
| 21 | + ) |
| 22 | + |
| 23 | + JustBeforeEach(func() { |
| 24 | + s := runtime.NewScheme() |
| 25 | + o = Options{Scheme: s} |
| 26 | + c = customConfig{} |
| 27 | + |
| 28 | + _, err = o.AndFrom(config.File().AtPath("./testdata/custom-config.yaml").OfKind(&c)) |
| 29 | + }) |
| 30 | + |
| 31 | + It("should not panic or fail", func() { |
| 32 | + Expect(err).To(Succeed()) |
| 33 | + }) |
| 34 | + It("should set custom properties", func() { |
| 35 | + Expect(c.CustomValue).To(Equal("foo")) |
| 36 | + }) |
| 37 | + }) |
| 38 | + }) |
| 39 | +}) |
| 40 | + |
| 41 | +type customConfig struct { |
| 42 | + metav1.TypeMeta `json:",inline"` |
| 43 | + configv1alpha1.ControllerManagerConfigurationSpec `json:",inline"` |
| 44 | + CustomValue string `json:"customValue"` |
| 45 | +} |
| 46 | + |
| 47 | +func (in *customConfig) DeepCopyObject() runtime.Object { |
| 48 | + out := &customConfig{} |
| 49 | + *out = *in |
| 50 | + |
| 51 | + in.ControllerManagerConfigurationSpec.DeepCopyInto(&out.ControllerManagerConfigurationSpec) |
| 52 | + |
| 53 | + return out |
| 54 | +} |
0 commit comments