-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Avoid nilref when copying leader election options from custom config (
#1889) * Avoid nilref when copying leader election options from custom config * Add regression test
- Loading branch information
1 parent
26c95ad
commit 2f77235
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package manager | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/config" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
configv1alpha1 "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" | ||
) | ||
|
||
var _ = Describe("manager.Options", func() { | ||
Describe("AndFrom", func() { | ||
Describe("reading custom type using OfKind", func() { | ||
var ( | ||
o Options | ||
c customConfig | ||
err error | ||
) | ||
|
||
JustBeforeEach(func() { | ||
s := runtime.NewScheme() | ||
o = Options{Scheme: s} | ||
c = customConfig{} | ||
|
||
_, err = o.AndFrom(config.File().AtPath("./testdata/custom-config.yaml").OfKind(&c)) | ||
}) | ||
|
||
It("should not panic or fail", func() { | ||
Expect(err).To(Succeed()) | ||
}) | ||
It("should set custom properties", func() { | ||
Expect(c.CustomValue).To(Equal("foo")) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
type customConfig struct { | ||
metav1.TypeMeta `json:",inline"` | ||
configv1alpha1.ControllerManagerConfigurationSpec `json:",inline"` | ||
CustomValue string `json:"customValue"` | ||
} | ||
|
||
func (in *customConfig) DeepCopyObject() runtime.Object { | ||
out := &customConfig{} | ||
*out = *in | ||
|
||
in.ControllerManagerConfigurationSpec.DeepCopyInto(&out.ControllerManagerConfigurationSpec) | ||
|
||
return out | ||
} |
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,3 @@ | ||
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1 | ||
kind: CustomControllerManagerConfiguration | ||
customValue: foo |