Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests and changelog #1

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ Here is an overview of all new **experimental** features:

### Fixes

- **GCP PubSub**: Fix GCP PodIdentity not considered with WorkloadIdentity ([#5021](https://github.com/kedacore/keda/issues/5021))
- **General**: Fix CVE-2023-39325 in golang.org/x/net ([#5122](https://github.com/kedacore/keda/issues/5122))
- **General**: Fix otelgrpc DoS vulnerability ([#5208](https://github.com/kedacore/keda/issues/5208))
- **General**: Prevented stuck status due to timeouts during scalers generation ([#5083](https://github.com/kedacore/keda/issues/5083))
- **Azure Pipelines**: No more HTTP 400 errors produced by poolName with spaces ([#5107](https://github.com/kedacore/keda/issues/5107))
- **GCP PubSub**: Fix GCP PodIdentity not considered with WorkloadIdentity ([#5021](https://github.com/kedacore/keda/issues/5021))
- **GCP pubsub scaler**: Missing use of default value of `value` added ([#5093](https://github.com/kedacore/keda/issues/5093))
- **ScaledJobs**: Copy ScaledJob annotations to child Jobs ([#4594](https://github.com/kedacore/keda/issues/4594))

Expand Down
79 changes: 67 additions & 12 deletions pkg/scaling/resolver/scale_resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,56 @@ func TestResolveNonExistingConfigMapsOrSecretsEnv(t *testing.T) {
}
}

func TestResolveAuthRefAndPodIdentity(t *testing.T) {
if err := corev1.AddToScheme(scheme.Scheme); err != nil {
t.Errorf("Expected Error because: %v", err)
}
if err := kedav1alpha1.AddToScheme(scheme.Scheme); err != nil {
t.Errorf("Expected Error because: %v", err)
}
tests := []struct {
name string
existing []runtime.Object
soar *kedav1alpha1.AuthenticationRef
podTemplateSpec *corev1.PodTemplateSpec
expected map[string]string
expectedPodIdentity kedav1alpha1.AuthPodIdentity
expectedError error
}{
// ensure podIdentity is returned
{
name: "foo",
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
}
var secretsLister corev1listers.SecretLister
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
ctx := context.Background()
os.Setenv("KEDA_CLUSTER_OBJECT_NAMESPACE", clusterNamespace) // Inject test cluster namespace.
gotMap, gotPodIdentity, err := ResolveAuthRefAndPodIdentity(
ctx,
fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(test.existing...).Build(),
logf.Log.WithName("test"),
test.soar,
test.podTemplateSpec,
namespace,
secretsLister)
if diff := cmp.Diff(gotMap, test.expected); diff != "" {
t.Errorf("Returned authParams are different: %s", diff)
}
if gotPodIdentity != test.expectedPodIdentity {
t.Errorf("Unexpected podidentity, wanted: %q got: %q", test.expectedPodIdentity.Provider, gotPodIdentity.Provider)
}
if diff := cmp.Diff(err, test.expectedError); diff != "" {
t.Errorf("Returned error is different: %s", diff)
}
})
}
}

func TestResolveAuthRef(t *testing.T) {
if err := corev1.AddToScheme(scheme.Scheme); err != nil {
t.Errorf("Expected Error because: %v", err)
Expand All @@ -256,18 +306,21 @@ func TestResolveAuthRef(t *testing.T) {
expectedPodIdentity kedav1alpha1.AuthPodIdentity
}{
{
name: "foo",
expected: make(map[string]string),
name: "foo",
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "triggerauth exists, podidentity nil",
Expand All @@ -288,8 +341,9 @@ func TestResolveAuthRef(t *testing.T) {
},
},
},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName},
expected: map[string]string{"host": ""},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
expected: map[string]string{"host": ""},
},
{
name: "triggerauth exists and secret",
Expand Down Expand Up @@ -421,8 +475,9 @@ func TestResolveAuthRef(t *testing.T) {
},
},
},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName, Kind: "ClusterTriggerAuthentication"},
expected: map[string]string{"host": ""},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName, Kind: "ClusterTriggerAuthentication"},
expected: map[string]string{"host": ""},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "clustertriggerauth exists and secret",
Expand Down