-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change logic to check prefix of image url
add install instructions add in unit tests Signed-off-by: craig <[email protected]> rh-pre-commit.version: 2.2.0 rh-pre-commit.check-secrets: ENABLED
- Loading branch information
Showing
6 changed files
with
173 additions
and
5 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
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,136 @@ | ||
//go:build unit | ||
|
||
package controllers | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
envoygatewayv1alpha1 "github.com/envoyproxy/gateway/api/v1alpha1" | ||
"github.com/kuadrant/kuadrant-operator/pkg/wasm" | ||
"github.com/kuadrant/policy-machinery/machinery" | ||
istioclientgoextensionv1alpha1 "istio.io/client-go/pkg/apis/extensions/v1alpha1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
v1 "sigs.k8s.io/gateway-api/apis/v1" | ||
) | ||
|
||
var ( | ||
defaultWasmImage = WASMFilterImageURL | ||
registry = "protected.registry.io" | ||
protectedRegImage = fmt.Sprintf("oci://%s/kuadrant/wasm-shim:latest", registry) | ||
testGateway = &machinery.Gateway{ | ||
Gateway: &v1.Gateway{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test", | ||
Namespace: "test", | ||
}, | ||
}, | ||
} | ||
testWasmConfig = wasm.Config{ | ||
ActionSets: []wasm.ActionSet{ | ||
{ | ||
Name: "test", | ||
}, | ||
}, | ||
} | ||
) | ||
|
||
func Test_buildIstioWasmPluginForGateway(t *testing.T) { | ||
testCases := []struct { | ||
Name string | ||
setWASMImageURL func() | ||
ProtectedRegistryPrefix string | ||
Assert func(t *testing.T, plugin *istioclientgoextensionv1alpha1.WasmPlugin) | ||
}{ | ||
{ | ||
Name: "ensure image pull secret is set in wasmPlugin for protected registry", | ||
setWASMImageURL: func() { | ||
WASMFilterImageURL = protectedRegImage | ||
}, | ||
ProtectedRegistryPrefix: registry, | ||
Assert: func(t *testing.T, plugin *istioclientgoextensionv1alpha1.WasmPlugin) { | ||
if plugin == nil { | ||
t.Fatalf("Expected a wasmplugin") | ||
} | ||
if plugin.Spec.ImagePullSecret != RegistryPullSecretName { | ||
t.Fatalf("Expected wasm plugin to have imagePullSecret %s but got %s", RegistryPullSecretName, plugin.Spec.ImagePullSecret) | ||
} | ||
}, | ||
}, | ||
{ | ||
Name: "ensure image pull secret is NOT set in wasmPlugin for unprotected registry", | ||
setWASMImageURL: func() { | ||
WASMFilterImageURL = defaultWasmImage | ||
}, | ||
Assert: func(t *testing.T, plugin *istioclientgoextensionv1alpha1.WasmPlugin) { | ||
if plugin == nil { | ||
t.Fatalf("Expected a wasmplugin") | ||
} | ||
if plugin.Spec.ImagePullSecret != "" { | ||
t.Fatalf("Expected wasm plugin to have not imagePullSecret %s", plugin.Spec.ImagePullSecret) | ||
} | ||
}, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.Name, func(t *testing.T) { | ||
testCase.setWASMImageURL() | ||
plugin := buildIstioWasmPluginForGateway(testGateway, testWasmConfig, testCase.ProtectedRegistryPrefix) | ||
testCase.Assert(t, plugin) | ||
}) | ||
} | ||
|
||
} | ||
|
||
func Test_buildEnvoyExtensionPolicyForGateway(t *testing.T) { | ||
testCases := []struct { | ||
Name string | ||
setWASMImageURL func() | ||
ProtectedRegistryPrefix string | ||
Assert func(t *testing.T, policy *envoygatewayv1alpha1.EnvoyExtensionPolicy) | ||
}{ | ||
{ | ||
Name: "ensure image pull secret is set in ExtensionPolicy for protected registry", | ||
setWASMImageURL: func() { | ||
WASMFilterImageURL = protectedRegImage | ||
}, | ||
ProtectedRegistryPrefix: registry, | ||
Assert: func(t *testing.T, policy *envoygatewayv1alpha1.EnvoyExtensionPolicy) { | ||
if policy == nil { | ||
t.Fatalf("Expected a wasmplugin") | ||
} | ||
for _, w := range policy.Spec.Wasm { | ||
if w.Code.Image.PullSecretRef == nil { | ||
t.Fatalf("Expected extension to have imagePullSecret %s but no pullSecretRef", RegistryPullSecretName) | ||
} | ||
if w.Code.Image.PullSecretRef.Name != v1.ObjectName(RegistryPullSecretName) { | ||
t.Fatalf("expected the pull secret name to be %s but got %v", RegistryPullSecretName, w.Code.Image.PullSecretRef.Name) | ||
} | ||
} | ||
}, | ||
}, | ||
{ | ||
Name: "ensure image pull secret is NOT set in wasmPlugin for unprotected registry", | ||
setWASMImageURL: func() { | ||
WASMFilterImageURL = defaultWasmImage | ||
}, | ||
Assert: func(t *testing.T, policy *envoygatewayv1alpha1.EnvoyExtensionPolicy) { | ||
if policy == nil { | ||
t.Fatalf("Expected a wasmplugin") | ||
} | ||
for _, w := range policy.Spec.Wasm { | ||
if w.Code.Image.PullSecretRef != nil { | ||
t.Fatalf("Expected extension to have not imagePullSecret but got %v", w.Code.Image.PullSecretRef) | ||
} | ||
} | ||
}, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
testCase.setWASMImageURL() | ||
policy := buildEnvoyExtensionPolicyForGateway(testGateway, testWasmConfig, testCase.ProtectedRegistryPrefix) | ||
testCase.Assert(t, policy) | ||
} | ||
} |
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
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