1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/cmd/internal/config.go
Vishal Choudhary b385693509
feat: add basic structure for image verify cache (#7890)
* feat: add interface for image verify cache

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add basic client for cache

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add ttl to client

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add flags and flag setup

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: added a default image verify cache

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add propogation of cache to image verifier

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add useCache to image verification types

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* bug: add ivcache to image verifier

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add logger to cache

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* typo: DisabledImageVerfiyCache

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* typo: DisabledImageVerfiyCache

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* Update cmd/internal/flag.go

Signed-off-by: shuting <shutting06@gmail.com>

* feat: add use cache to v2beta1 crd

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* bug: change public attribute TTL to private

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* fix: replace nil in test with disabled cache

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* fix: convert ttl time to time.Duration

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update opts to use time.Duration

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat:add policy version and remove delete functions

by adding policy version, old entries will automatically become outdated and we will not have to remove them manually

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: remove clear and update get and set to take interface as input

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* style: fix lint issue

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

---------

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Signed-off-by: shuting <shutting06@gmail.com>
Co-authored-by: shuting <shutting06@gmail.com>
Co-authored-by: shuting <shuting@nirmata.com>
Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
2023-08-06 21:54:52 +02:00

227 lines
4.6 KiB
Go

package internal
import (
"flag"
)
type Configuration interface {
UsesMetrics() bool
UsesTracing() bool
UsesProfiling() bool
UsesKubeconfig() bool
UsesPolicyExceptions() bool
UsesConfigMapCaching() bool
UsesDeferredLoading() bool
UsesCosign() bool
UsesRegistryClient() bool
UsesImageVerifyCache() bool
UsesLeaderElection() bool
UsesKyvernoClient() bool
UsesDynamicClient() bool
UsesApiServerClient() bool
UsesMetadataClient() bool
UsesKyvernoDynamicClient() bool
FlagSets() []*flag.FlagSet
}
func NewConfiguration(options ...ConfigurationOption) Configuration {
c := &configuration{}
for _, option := range options {
option(c)
}
return c
}
type ConfigurationOption func(c *configuration)
func WithMetrics() ConfigurationOption {
return func(c *configuration) {
c.usesMetrics = true
}
}
func WithTracing() ConfigurationOption {
return func(c *configuration) {
c.usesTracing = true
}
}
func WithProfiling() ConfigurationOption {
return func(c *configuration) {
c.usesProfiling = true
}
}
func WithKubeconfig() ConfigurationOption {
return func(c *configuration) {
c.usesKubeconfig = true
}
}
func WithPolicyExceptions() ConfigurationOption {
return func(c *configuration) {
c.usesPolicyExceptions = true
}
}
func WithConfigMapCaching() ConfigurationOption {
return func(c *configuration) {
c.usesConfigMapCaching = true
}
}
func WithDeferredLoading() ConfigurationOption {
return func(c *configuration) {
c.usesDeferredLoading = true
}
}
func WithCosign() ConfigurationOption {
return func(c *configuration) {
c.usesCosign = true
}
}
func WithRegistryClient() ConfigurationOption {
return func(c *configuration) {
c.usesRegistryClient = true
}
}
func WithImageVerifyCache() ConfigurationOption {
return func(c *configuration) {
c.usesImageVerifyCache = true
}
}
func WithLeaderElection() ConfigurationOption {
return func(c *configuration) {
c.usesLeaderElection = true
}
}
func WithKyvernoClient() ConfigurationOption {
return func(c *configuration) {
c.usesKyvernoClient = true
}
}
func WithDynamicClient() ConfigurationOption {
return func(c *configuration) {
c.usesDynamicClient = true
}
}
func WithApiServerClient() ConfigurationOption {
return func(c *configuration) {
c.usesApiServerClient = true
}
}
func WithMetadataClient() ConfigurationOption {
return func(c *configuration) {
c.usesMetadataClient = true
}
}
func WithKyvernoDynamicClient() ConfigurationOption {
return func(c *configuration) {
// requires dynamic client
c.usesDynamicClient = true
c.usesKyvernoDynamicClient = true
}
}
func WithFlagSets(flagsets ...*flag.FlagSet) ConfigurationOption {
return func(c *configuration) {
c.flagSets = append(c.flagSets, flagsets...)
}
}
type configuration struct {
usesMetrics bool
usesTracing bool
usesProfiling bool
usesKubeconfig bool
usesPolicyExceptions bool
usesConfigMapCaching bool
usesDeferredLoading bool
usesCosign bool
usesRegistryClient bool
usesImageVerifyCache bool
usesLeaderElection bool
usesKyvernoClient bool
usesDynamicClient bool
usesApiServerClient bool
usesMetadataClient bool
usesKyvernoDynamicClient bool
flagSets []*flag.FlagSet
}
func (c *configuration) UsesMetrics() bool {
return c.usesMetrics
}
func (c *configuration) UsesTracing() bool {
return c.usesTracing
}
func (c *configuration) UsesProfiling() bool {
return c.usesProfiling
}
func (c *configuration) UsesKubeconfig() bool {
return c.usesKubeconfig
}
func (c *configuration) UsesPolicyExceptions() bool {
return c.usesPolicyExceptions
}
func (c *configuration) UsesConfigMapCaching() bool {
return c.usesConfigMapCaching
}
func (c *configuration) UsesDeferredLoading() bool {
return c.usesDeferredLoading
}
func (c *configuration) UsesCosign() bool {
return c.usesCosign
}
func (c *configuration) UsesRegistryClient() bool {
return c.usesRegistryClient
}
func (c *configuration) UsesImageVerifyCache() bool {
return c.usesImageVerifyCache
}
func (c *configuration) UsesLeaderElection() bool {
return c.usesLeaderElection
}
func (c *configuration) UsesKyvernoClient() bool {
return c.usesKyvernoClient
}
func (c *configuration) UsesDynamicClient() bool {
return c.usesDynamicClient
}
func (c *configuration) UsesApiServerClient() bool {
return c.usesApiServerClient
}
func (c *configuration) UsesMetadataClient() bool {
return c.usesMetadataClient
}
func (c *configuration) UsesKyvernoDynamicClient() bool {
return c.usesKyvernoDynamicClient
}
func (c *configuration) FlagSets() []*flag.FlagSet {
return c.flagSets
}