mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-24 08:36:46 +00:00
feat: make image ref parsing a static function (#12374)
* feat: make image ref parsing a static function Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * typo Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
b5b1287282
commit
0d43a2d997
5 changed files with 9 additions and 12 deletions
|
@ -191,9 +191,7 @@ func Test_impl_parse_image_ref_string(t *testing.T) {
|
|||
data := map[string]any{
|
||||
"context": Context{&MockCtx{
|
||||
ParseImageReferenceFunc: func(image string) (imagedataloader.ImageReference, error) {
|
||||
idl, err := imagedataloader.New(nil)
|
||||
assert.NoError(t, err)
|
||||
return idl.ParseImageReference(image)
|
||||
return imagedataloader.ParseImageReference(image)
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -225,7 +223,7 @@ func Test_impl_get_resource_string_string_string_string(t *testing.T) {
|
|||
assert.NotNil(t, prog)
|
||||
data := map[string]any{
|
||||
"context": Context{&MockCtx{
|
||||
GetResourcesFunc: func(apiVersion, resource, namespace, name string) (*unstructured.Unstructured, error) {
|
||||
GetResourceFunc: func(apiVersion, resource, namespace, name string) (*unstructured.Unstructured, error) {
|
||||
return &unstructured.Unstructured{
|
||||
Object: map[string]any{
|
||||
"apiVersion": "apps/v1",
|
||||
|
|
|
@ -13,7 +13,7 @@ type MockCtx struct {
|
|||
GetImageDataFunc func(string) (*imagedataloader.ImageData, error)
|
||||
ParseImageReferenceFunc func(string) (imagedataloader.ImageReference, error)
|
||||
ListResourcesFunc func(string, string, string) (*unstructured.UnstructuredList, error)
|
||||
GetResourcesFunc func(string, string, string, string) (*unstructured.Unstructured, error)
|
||||
GetResourceFunc func(string, string, string, string) (*unstructured.Unstructured, error)
|
||||
}
|
||||
|
||||
func (mock *MockCtx) GetConfigMap(ns string, n string) (*unstructured.Unstructured, error) {
|
||||
|
@ -37,7 +37,7 @@ func (mock *MockCtx) ListResources(apiVersion, resource, namespace string) (*uns
|
|||
}
|
||||
|
||||
func (mock *MockCtx) GetResource(apiVersion, resource, namespace, name string) (*unstructured.Unstructured, error) {
|
||||
return mock.GetResourcesFunc(apiVersion, resource, namespace, name)
|
||||
return mock.GetResourceFunc(apiVersion, resource, namespace, name)
|
||||
}
|
||||
|
||||
type mockGctxStore struct {
|
||||
|
|
|
@ -151,5 +151,5 @@ func (cp *contextProvider) GetResource(apiVersion, resource, namespace, name str
|
|||
}
|
||||
|
||||
func (cp *contextProvider) ParseImageReference(image string) (imagedataloader.ImageReference, error) {
|
||||
return cp.imagedata.ParseImageReference(image)
|
||||
return imagedataloader.ParseImageReference(image)
|
||||
}
|
||||
|
|
|
@ -50,8 +50,8 @@ func (cp *FakeContextProvider) GetImageData(string) (*imagedataloader.ImageData,
|
|||
panic("not implemented")
|
||||
}
|
||||
|
||||
func (cp *FakeContextProvider) ParseImageReference(string) (imagedataloader.ImageReference, error) {
|
||||
panic("not implemented")
|
||||
func (cp *FakeContextProvider) ParseImageReference(image string) (imagedataloader.ImageReference, error) {
|
||||
return imagedataloader.ParseImageReference(image)
|
||||
}
|
||||
|
||||
func (cp *FakeContextProvider) ListResources(apiVersion, resource, namespace string) (*unstructured.UnstructuredList, error) {
|
||||
|
|
|
@ -26,7 +26,6 @@ type imagedatafetcher struct {
|
|||
|
||||
type Fetcher interface {
|
||||
FetchImageData(ctx context.Context, image string, options ...Option) (*ImageData, error)
|
||||
ParseImageReference(image string, options ...Option) (ImageReference, error)
|
||||
}
|
||||
|
||||
func New(lister k8scorev1.SecretInterface, opts ...Option) (*imagedatafetcher, error) {
|
||||
|
@ -41,7 +40,7 @@ func New(lister k8scorev1.SecretInterface, opts ...Option) (*imagedatafetcher, e
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (i *imagedatafetcher) ParseImageReference(image string, options ...Option) (ImageReference, error) {
|
||||
func ParseImageReference(image string, options ...Option) (ImageReference, error) {
|
||||
var img ImageReference
|
||||
nameOpts := nameOptions(options...)
|
||||
ref, err := name.ParseReference(image, nameOpts...)
|
||||
|
@ -74,7 +73,7 @@ func (i *imagedatafetcher) FetchImageData(ctx context.Context, image string, opt
|
|||
return nil, err
|
||||
}
|
||||
|
||||
img.ImageReference, err = i.ParseImageReference(image, options...)
|
||||
img.ImageReference, err = ParseImageReference(image, options...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue