Skip to content

Commit

Permalink
Merge pull request #349 from Kuadrant/fix/bootstrap-count
Browse files Browse the repository at this point in the history
[Bugfix] Only bootstrap AuthConfigs in scope
  • Loading branch information
guicassolato authored Aug 30, 2022
2 parents 77b8032 + 611a22a commit 5b525c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 5 additions & 1 deletion controllers/auth_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,11 @@ func (r *AuthConfigReconciler) bootstrapIndex(ctx context.Context) error {
}

authConfigList := api.AuthConfigList{}
if err := r.List(ctx, &authConfigList); err != nil {
listOptions := []client.ListOption{}
if r.LabelSelector != nil {
listOptions = append(listOptions, client.MatchingLabelsSelector{Selector: r.LabelSelector})
}
if err := r.List(ctx, &authConfigList, listOptions...); err != nil {
return err
}

Expand Down
18 changes: 16 additions & 2 deletions controllers/auth_config_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,12 @@ func TestEmptyAuthConfigIdentitiesDefaultsToAnonymousAccess(t *testing.T) {
assert.Equal(t, len(config.IdentityConfigs), 1)
}

func TestEmptyIndex(t *testing.T) {
func TestBootstrapIndex(t *testing.T) {
mockController := gomock.NewController(t)
defer mockController.Finish()
indexMock := mock_index.NewMockIndex(mockController)

authConfig := newTestAuthConfig(map[string]string{})
authConfig := newTestAuthConfig(map[string]string{"scope": "in"})
authConfig.Status.Summary = api.Summary{
Ready: true,
HostsReady: authConfig.Spec.Hosts,
Expand All @@ -334,11 +334,25 @@ func TestEmptyIndex(t *testing.T) {
NumResponseItems: int64(len(authConfig.Spec.Response)),
FestivalWristbandEnabled: false,
}

authConfigOutOfScope := newTestAuthConfig(map[string]string{"scope": "out"})
authConfigOutOfScope.Status.Summary = api.Summary{
Ready: true,
HostsReady: authConfig.Spec.Hosts,
NumHostsReady: fmt.Sprintf("%d/%d", len(authConfig.Spec.Hosts), len(authConfig.Spec.Hosts)),
NumIdentitySources: int64(len(authConfig.Spec.Identity)),
NumMetadataSources: int64(len(authConfig.Spec.Metadata)),
NumAuthorizationPolicies: int64(len(authConfig.Spec.Authorization)),
NumResponseItems: int64(len(authConfig.Spec.Response)),
FestivalWristbandEnabled: false,
}

authConfigName := types.NamespacedName{Name: authConfig.Name, Namespace: authConfig.Namespace}
resourceId := authConfigName.String()
secret := newTestOAuthClientSecret()
client := newTestK8sClient(&authConfig, &secret)
reconciler := newTestAuthConfigReconciler(client, indexMock)
reconciler.LabelSelector = ToLabelSelector("scope=in")

indexMock.EXPECT().Empty().Return(true)
indexMock.EXPECT().FindKeys(resourceId).Return([]string{}).AnyTimes()
Expand Down

0 comments on commit 5b525c2

Please sign in to comment.