mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-24 08:36:46 +00:00
fix: use pointer in context config map getter (#12365)
This commit is contained in:
parent
456218952b
commit
c655ba72c2
4 changed files with 11 additions and 15 deletions
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ctx struct {
|
type ctx struct {
|
||||||
GetConfigMapFunc func(string, string) (unstructured.Unstructured, error)
|
GetConfigMapFunc func(string, string) (*unstructured.Unstructured, error)
|
||||||
GetGlobalReferenceFunc func(string, string) (any, error)
|
GetGlobalReferenceFunc func(string, string) (any, error)
|
||||||
GetImageDataFunc func(string) (*imagedataloader.ImageData, error)
|
GetImageDataFunc func(string) (*imagedataloader.ImageData, error)
|
||||||
ParseImageReferenceFunc func(string) (imagedataloader.ImageReference, error)
|
ParseImageReferenceFunc func(string) (imagedataloader.ImageReference, error)
|
||||||
|
@ -22,7 +22,7 @@ type ctx struct {
|
||||||
GetResourcesFunc func(string, string, string, string) (*unstructured.Unstructured, error)
|
GetResourcesFunc func(string, string, string, string) (*unstructured.Unstructured, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mock *ctx) GetConfigMap(ns string, n string) (unstructured.Unstructured, error) {
|
func (mock *ctx) GetConfigMap(ns string, n string) (*unstructured.Unstructured, error) {
|
||||||
return mock.GetConfigMapFunc(ns, n)
|
return mock.GetConfigMapFunc(ns, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,9 +66,9 @@ func Test_impl_get_configmap_string_string(t *testing.T) {
|
||||||
called := false
|
called := false
|
||||||
data := map[string]any{
|
data := map[string]any{
|
||||||
"context": Context{&ctx{
|
"context": Context{&ctx{
|
||||||
GetConfigMapFunc: func(string, string) (unstructured.Unstructured, error) {
|
GetConfigMapFunc: func(string, string) (*unstructured.Unstructured, error) {
|
||||||
called = true
|
called = true
|
||||||
return unstructured.Unstructured{}, nil
|
return &unstructured.Unstructured{}, nil
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContextInterface interface {
|
type ContextInterface interface {
|
||||||
GetConfigMap(string, string) (unstructured.Unstructured, error)
|
GetConfigMap(string, string) (*unstructured.Unstructured, error)
|
||||||
GetGlobalReference(string, string) (any, error)
|
GetGlobalReference(string, string) (any, error)
|
||||||
GetImageData(string) (*imagedataloader.ImageData, error)
|
GetImageData(string) (*imagedataloader.ImageData, error)
|
||||||
ParseImageReference(string) (imagedataloader.ImageReference, error)
|
ParseImageReference(string) (imagedataloader.ImageReference, error)
|
||||||
|
|
|
@ -45,16 +45,16 @@ func NewContextProvider(
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *contextProvider) GetConfigMap(namespace string, name string) (unstructured.Unstructured, error) {
|
func (cp *contextProvider) GetConfigMap(namespace string, name string) (*unstructured.Unstructured, error) {
|
||||||
cm, err := cp.client.CoreV1().ConfigMaps(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
cm, err := cp.client.CoreV1().ConfigMaps(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return unstructured.Unstructured{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
out, err := kubeutils.ObjToUnstructured(cm)
|
out, err := kubeutils.ObjToUnstructured(cm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return unstructured.Unstructured{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return *out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *contextProvider) GetGlobalReference(name, projection string) (any, error) {
|
func (cp *contextProvider) GetGlobalReference(name, projection string) (any, error) {
|
||||||
|
|
|
@ -38,12 +38,8 @@ func (cp *FakeContextProvider) AddResource(gvr schema.GroupVersionResource, obj
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *FakeContextProvider) GetConfigMap(ns, n string) (unstructured.Unstructured, error) {
|
func (cp *FakeContextProvider) GetConfigMap(ns, n string) (*unstructured.Unstructured, error) {
|
||||||
cm, err := cp.GetResource("v1", "configmaps", ns, n)
|
return cp.GetResource("v1", "configmaps", ns, n)
|
||||||
if err != nil {
|
|
||||||
return unstructured.Unstructured{}, err
|
|
||||||
}
|
|
||||||
return *cm, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cp *FakeContextProvider) GetGlobalReference(string, string) (any, error) {
|
func (cp *FakeContextProvider) GetGlobalReference(string, string) (any, error) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue