-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* introduce accesses caching Signed-off-by: Francesco Ilario <[email protected]> * add serviceaccount support Signed-off-by: Francesco Ilario <[email protected]> * rename files, add tests Signed-off-by: Francesco Ilario <[email protected]> * disable performance cluster deletion Signed-off-by: Francesco Ilario <[email protected]> * making ginkgo tests parallel Signed-off-by: Francesco Ilario <[email protected]> --------- Signed-off-by: Francesco Ilario <[email protected]>
- Loading branch information
Showing
28 changed files
with
993 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- op: add | ||
path: /spec/template/spec/containers/0/env/- | ||
value: | ||
name: CACHE_RESYNC_PERIOD | ||
value: '20s' |
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
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,72 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"time" | ||
|
||
authcache "github.com/konflux-ci/namespace-lister/pkg/auth/cache" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
rbacv1 "k8s.io/api/rbac/v1" | ||
toolscache "k8s.io/client-go/tools/cache" | ||
"k8s.io/kubernetes/plugin/pkg/auth/authorizer/rbac" | ||
crcache "sigs.k8s.io/controller-runtime/pkg/cache" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
func buildAndStartAccessCache(ctx context.Context, resourceCache crcache.Cache) (*authcache.SynchronizedAccessCache, error) { | ||
aur := &CRAuthRetriever{resourceCache, ctx, getLoggerFromContext(ctx)} | ||
sae := rbac.NewSubjectAccessEvaluator(aur, aur, aur, aur, "") | ||
synchCache := authcache.NewSynchronizedAccessCache( | ||
sae, | ||
resourceCache, authcache.CacheSynchronizerOptions{ | ||
Logger: getLoggerFromContext(ctx), | ||
ResyncPeriod: getResyncPeriodFromEnvOrZero(ctx), | ||
}, | ||
) | ||
|
||
// register event handlers on resource cache | ||
oo := []client.Object{ | ||
&corev1.Namespace{}, | ||
&rbacv1.RoleBinding{}, | ||
&rbacv1.ClusterRole{}, | ||
&rbacv1.ClusterRoleBinding{}, | ||
&rbacv1.Role{}, | ||
} | ||
for _, o := range oo { | ||
i, err := resourceCache.GetInformer(ctx, o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if _, err := i.AddEventHandler( | ||
toolscache.ResourceEventHandlerFuncs{ | ||
AddFunc: func(obj interface{}) { synchCache.Request() }, | ||
UpdateFunc: func(oldObj, newObj interface{}) { synchCache.Request() }, | ||
DeleteFunc: func(obj interface{}) { synchCache.Request() }, | ||
}); err != nil { | ||
return nil, err | ||
} | ||
} | ||
synchCache.Start(ctx) | ||
|
||
if err := synchCache.Synch(ctx); err != nil { | ||
return nil, err | ||
} | ||
return synchCache, nil | ||
} | ||
|
||
func getResyncPeriodFromEnvOrZero(ctx context.Context) time.Duration { | ||
var zero time.Duration | ||
rps, ok := os.LookupEnv(EnvCacheResyncPeriod) | ||
if !ok { | ||
return zero | ||
} | ||
rp, err := time.ParseDuration(rps) | ||
if err != nil { | ||
getLoggerFromContext(ctx).Warn("can not parse duration from environment variable", "error", err) | ||
return zero | ||
} | ||
return rp | ||
} |
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,5 @@ | ||
- op: add | ||
path: /spec/template/spec/containers/0/env/- | ||
value: | ||
name: CACHE_RESYNC_PERIOD | ||
value: '10m' |
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,5 @@ | ||
- op: replace | ||
path: /spec/template/spec/containers/0/env/0 | ||
value: | ||
name: LOG_LEVEL | ||
value: "-4" |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.