Skip to content

Commit

Permalink
Org/space delete job uses an uncached client
Browse files Browse the repository at this point in the history
- The cached client would sometimes return a resource without the
  deletion timestamp when the job endpoint was called immediately after
  deleting the resource.
- Consolidate CFSpaceRepository and SpaceRepository interfaces.

[#2604]
[#2605]

Co-authored-by: Dave Walter <walterda@vmware.com>
  • Loading branch information
akrishna90 and davewalter committed Jun 30, 2023
1 parent 9b4ff9f commit 2340c78
Show file tree
Hide file tree
Showing 21 changed files with 531 additions and 541 deletions.
35 changes: 35 additions & 0 deletions api/authorization/user_client_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -22,6 +23,7 @@ import (
type UserK8sClientFactory interface {
BuildClient(Info) (client.WithWatch, error)
BuildK8sClient(info Info) (k8sclient.Interface, error)
BuildDynamicClient(info Info) (dynamic.Interface, error)
}

type UnprivilegedClientFactory struct {
Expand Down Expand Up @@ -122,3 +124,36 @@ func (f UnprivilegedClientFactory) BuildK8sClient(authInfo Info) (k8sclient.Inte

return userK8sClient, nil
}

func (f UnprivilegedClientFactory) BuildDynamicClient(authInfo Info) (dynamic.Interface, error) {
config := rest.CopyConfig(f.config)

switch strings.ToLower(authInfo.Scheme()) {
case BearerScheme:
config.BearerToken = authInfo.Token

case CertScheme:
certBlock, rst := pem.Decode(authInfo.CertData)
if certBlock == nil {
return nil, fmt.Errorf("failed to decode cert PEM")
}

keyBlock, _ := pem.Decode(rst)
if keyBlock == nil {
return nil, fmt.Errorf("failed to decode key PEM")
}

config.CertData = pem.EncodeToMemory(certBlock)
config.KeyData = pem.EncodeToMemory(keyBlock)

default:
return nil, apierrors.NewNotAuthenticatedError(errors.New("unsupported Authorization header scheme"))
}

userDynamicClient, err := dynamic.NewForConfig(config)
if err != nil {
return nil, apierrors.FromK8sError(err, "")
}

return userDynamicClient, nil
}
4 changes: 2 additions & 2 deletions api/handlers/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type App struct {
processRepo CFProcessRepository
routeRepo CFRouteRepository
domainRepo CFDomainRepository
spaceRepo SpaceRepository
spaceRepo CFSpaceRepository
packageRepo CFPackageRepository
requestValidator RequestValidator
}
Expand All @@ -73,7 +73,7 @@ func NewApp(
processRepo CFProcessRepository,
routeRepo CFRouteRepository,
domainRepo CFDomainRepository,
spaceRepo SpaceRepository,
spaceRepo CFSpaceRepository,
packageRepo CFPackageRepository,
requestValidator RequestValidator,
) *App {
Expand Down
4 changes: 2 additions & 2 deletions api/handlers/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = Describe("App", func() {
processRepo *fake.CFProcessRepository
routeRepo *fake.CFRouteRepository
domainRepo *fake.CFDomainRepository
spaceRepo *fake.SpaceRepository
spaceRepo *fake.CFSpaceRepository
packageRepo *fake.CFPackageRepository
requestValidator *fake.RequestValidator
req *http.Request
Expand All @@ -48,7 +48,7 @@ var _ = Describe("App", func() {
processRepo = new(fake.CFProcessRepository)
routeRepo = new(fake.CFRouteRepository)
domainRepo = new(fake.CFDomainRepository)
spaceRepo = new(fake.SpaceRepository)
spaceRepo = new(fake.CFSpaceRepository)
packageRepo = new(fake.CFPackageRepository)
requestValidator = new(fake.RequestValidator)

Expand Down
Loading

0 comments on commit 2340c78

Please sign in to comment.