Skip to content

Commit

Permalink
Merge branch 'main' into 8313
Browse files Browse the repository at this point in the history
  • Loading branch information
realshuting authored Jan 31, 2024
2 parents 65bc0d4 + 1305226 commit 977c669
Show file tree
Hide file tree
Showing 24 changed files with 265 additions and 576 deletions.
4 changes: 2 additions & 2 deletions .nancy-ignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# golang/k8s.io/apiserver@v0.29.0
CVE-2020-8561 until=2024-01-31
CVE-2020-8561 until=2024-02-28
# golang/github.com/notaryproject/notation-go@v1.1.0
CVE-2024-23332 until=2024-01-31
CVE-2024-23332 until=2024-02-28
2 changes: 2 additions & 0 deletions charts/kyverno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,7 @@ The chart values are organised per component.
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| cleanupJobs.admissionReports.enabled | bool | `true` | Enable cleanup cronjob |
| cleanupJobs.admissionReports.backoffLimit | int | `3` | Maximum number of retries before considering a Job as failed. Defaults to 3. |
| cleanupJobs.admissionReports.image.registry | string | `nil` | Image registry |
| cleanupJobs.admissionReports.image.repository | string | `"bitnami/kubectl"` | Image repository |
| cleanupJobs.admissionReports.image.tag | string | `"1.28.5"` | Image tag Defaults to `latest` if omitted |
Expand All @@ -743,6 +744,7 @@ The chart values are organised per component.
| cleanupJobs.admissionReports.podAffinity | object | `{}` | Pod affinity constraints. |
| cleanupJobs.admissionReports.nodeAffinity | object | `{}` | Node affinity constraints. |
| cleanupJobs.clusterAdmissionReports.enabled | bool | `true` | Enable cleanup cronjob |
| cleanupJobs.clusterAdmissionReports.backoffLimit | int | `3` | Maximum number of retries before considering a Job as failed. Defaults to 3. |
| cleanupJobs.clusterAdmissionReports.image.registry | string | `nil` | Image registry |
| cleanupJobs.clusterAdmissionReports.image.repository | string | `"bitnami/kubectl"` | Image repository |
| cleanupJobs.clusterAdmissionReports.image.tag | string | `"1.28.5"` | Image tag Defaults to `latest` if omitted |
Expand Down
2 changes: 1 addition & 1 deletion charts/kyverno/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
{{- end -}}
{{- with .omitEvents -}}
{{- with .eventTypes -}}
{{- $flags = append $flags (print "--omit-events=" (join "," .)) -}}
{{- $flags = append $flags (print "--omitEvents=" (join "," .)) -}}
{{- end -}}
{{- end -}}
{{- with .policyExceptions -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
failedJobsHistoryLimit: {{ .Values.cleanupJobs.admissionReports.history.failure }}
jobTemplate:
spec:
backoffLimit: 3
backoffLimit: {{ .Values.cleanupJobs.admissionReports.backoffLimit }}
template:
metadata:
{{- with .Values.cleanupJobs.admissionReports.podAnnotations }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
failedJobsHistoryLimit: {{ .Values.cleanupJobs.clusterAdmissionReports.history.failure }}
jobTemplate:
spec:
backoffLimit: 3
backoffLimit: {{ .Values.cleanupJobs.clusterAdmissionReports.backoffLimit }}
template:
metadata:
{{- with .Values.cleanupJobs.clusterAdmissionReports.podAnnotations }}
Expand Down
6 changes: 6 additions & 0 deletions charts/kyverno/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ cleanupJobs:
# -- Enable cleanup cronjob
enabled: true

# -- Maximum number of retries before considering a Job as failed. Defaults to 3.
backoffLimit: 3

image:
# -- (string) Image registry
registry: ~
Expand Down Expand Up @@ -739,6 +742,9 @@ cleanupJobs:
# -- Enable cleanup cronjob
enabled: true

# -- Maximum number of retries before considering a Job as failed. Defaults to 3.
backoffLimit: 3

image:
# -- (string) Image registry
registry: ~
Expand Down
23 changes: 11 additions & 12 deletions cmd/background-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ func main() {
flagset := flag.NewFlagSet("updaterequest-controller", flag.ExitOnError)
flagset.IntVar(&genWorkers, "genWorkers", 10, "Workers for the background controller.")
flagset.IntVar(&maxQueuedEvents, "maxQueuedEvents", 1000, "Maximum events to be queued.")
flagset.StringVar(&omitEvents, "omit-events", "", "Set this flag to a comma sperated list of PolicyViolation, PolicyApplied, PolicyError, PolicySkipped to disable events, e.g. --omit-events=PolicyApplied,PolicyViolation")
flagset.StringVar(&omitEvents, "omitEvents", "", "Set this flag to a comma sperated list of PolicyViolation, PolicyApplied, PolicyError, PolicySkipped to disable events, e.g. --omitEvents=PolicyApplied,PolicyViolation")
flagset.Int64Var(&maxAPICallResponseLength, "maxAPICallResponseLength", 2*1000*1000, "Maximum allowed response size from API Calls. A value of 0 bypasses checks (not recommended).")

// config
appConfig := internal.NewConfiguration(
internal.WithProfiling(),
Expand All @@ -116,7 +115,6 @@ func main() {
// setup
signalCtx, setup, sdown := internal.Setup(appConfig, "kyverno-background-controller", false)
defer sdown()

var err error
bgscanInterval := time.Hour
val := os.Getenv("BACKGROUND_SCAN_INTERVAL")
Expand All @@ -127,23 +125,23 @@ func main() {
}
}
setup.Logger.V(2).Info("setting the background scan interval", "value", bgscanInterval.String())

// THIS IS AN UGLY FIX
// ELSE KYAML IS NOT THREAD SAFE
kyamlopenapi.Schema()
// informer factories
kyvernoInformer := kyvernoinformer.NewSharedInformerFactory(setup.KyvernoClient, resyncPeriod)
emitEventsValues := strings.Split(omitEvents, ",")
if omitEvents == "" {
emitEventsValues = []string{}
}
var wg sync.WaitGroup
eventGenerator := event.NewEventGenerator(
setup.EventsClient,
logging.WithName("EventGenerator"),
emitEventsValues...,
strings.Split(omitEvents, ",")...,
)
eventController := internal.NewController(
event.ControllerName,
eventGenerator,
event.Workers,
)
// this controller only subscribe to events, nothing is returned...
var wg sync.WaitGroup
policymetricscontroller.NewController(
setup.MetricsManager,
kyvernoInformer.Kyverno().V1().ClusterPolicies(),
Expand All @@ -169,8 +167,6 @@ func main() {
setup.Logger.Error(errors.New("failed to wait for cache sync"), "failed to wait for cache sync")
os.Exit(1)
}
// start event generator
go eventGenerator.Run(signalCtx, event.Workers, &wg)
// setup leader election
le, err := leaderelection.New(
setup.Logger.WithName("leader-election"),
Expand Down Expand Up @@ -221,7 +217,10 @@ func main() {
setup.Logger.Error(err, "failed to initialize leader election")
os.Exit(1)
}
// start non leader controllers
eventController.Run(signalCtx, setup.Logger, &wg)
// start leader election
le.Run(signalCtx)
// wait for everything to shut down and exit
wg.Wait()
}
16 changes: 12 additions & 4 deletions cmd/cleanup-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func main() {
// informer factories
kubeInformer := kubeinformers.NewSharedInformerFactoryWithOptions(setup.KubeClient, resyncPeriod)
kyvernoInformer := kyvernoinformer.NewSharedInformerFactory(setup.KyvernoClient, resyncPeriod)
var wg sync.WaitGroup
// listers
nsLister := kubeInformer.Core().V1().Namespaces().Lister()
// log policy changes
Expand All @@ -139,13 +140,15 @@ func main() {
setup.EventsClient,
logging.WithName("EventGenerator"),
)
eventController := internal.NewController(
event.ControllerName,
eventGenerator,
event.Workers,
)
// start informers and wait for cache sync
if !internal.StartInformersAndWaitForCacheSync(ctx, setup.Logger, kubeInformer, kyvernoInformer) {
os.Exit(1)
}
// start event generator
var wg sync.WaitGroup
go eventGenerator.Run(ctx, event.CleanupWorkers, &wg)
// setup leader election
le, err := leaderelection.New(
setup.Logger.WithName("leader-election"),
Expand Down Expand Up @@ -331,7 +334,12 @@ func main() {
setup.Configuration,
)
// start server
server.Run(ctx.Done())
server.Run()
defer server.Stop()
// start non leader controllers
eventController.Run(ctx, setup.Logger, &wg)
// start leader election
le.Run(ctx)
// wait for everything to shut down and exit
wg.Wait()
}
10 changes: 6 additions & 4 deletions cmd/cleanup-controller/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (

type Server interface {
// Run TLS server in separate thread and returns control immediately
Run(<-chan struct{})
Run()
// Stop TLS server and returns control after the server is shut down
Stop(context.Context)
Stop()
}

type server struct {
Expand Down Expand Up @@ -110,15 +110,17 @@ func NewServer(
}
}

func (s *server) Run(stopCh <-chan struct{}) {
func (s *server) Run() {
go func() {
if err := s.server.ListenAndServeTLS("", ""); err != nil {
logging.Error(err, "failed to start server")
}
}()
}

func (s *server) Stop(ctx context.Context) {
func (s *server) Stop() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
err := s.server.Shutdown(ctx)
if err != nil {
err = s.server.Close()
Expand Down
14 changes: 4 additions & 10 deletions cmd/cli/kubectl-kyverno/commands/test/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,11 @@ func testCommandExecute(
}
fmt.Fprintln(out, " Checking results ...")
var resultsTable table.Table
{
err := printTestResult(out, filteredResults, responses, rc, &resultsTable, test.Fs, resourcePath)
if err != nil {
return fmt.Errorf("failed to print test result (%w)", err)
}
if err := printTestResult(out, filteredResults, responses, rc, &resultsTable, test.Fs, resourcePath); err != nil {
return fmt.Errorf("failed to print test result (%w)", err)
}
{
err := printCheckResult(out, test.Test.Checks, responses, rc, &resultsTable)
if err != nil {
return fmt.Errorf("failed to print test result (%w)", err)
}
if err := printCheckResult(out, test.Test.Checks, responses, rc, &resultsTable); err != nil {
return fmt.Errorf("failed to print test result (%w)", err)
}
fullTable.AddFailed(resultsTable.RawRows...)
printer := table.NewTablePrinter(out)
Expand Down
1 change: 1 addition & 0 deletions cmd/cli/kubectl-kyverno/commands/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func runTest(out io.Writer, testCase test.TestCase, registryAccess bool, auditWa
if res.IsValidatingAdmissionPolicy {
continue
}
// TODO: what if two policies have a rule with the same name ?
if rule.Name == res.Rule {
if rule.HasGenerate() {
if len(rule.Generation.CloneList.Kinds) != 0 { // cloneList
Expand Down
41 changes: 17 additions & 24 deletions cmd/kyverno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func main() {
flagset.BoolVar(&dumpPayload, "dumpPayload", false, "Set this flag to activate/deactivate debug mode.")
flagset.IntVar(&webhookTimeout, "webhookTimeout", webhookcontroller.DefaultWebhookTimeout, "Timeout for webhook configurations (number of seconds, integer).")
flagset.IntVar(&maxQueuedEvents, "maxQueuedEvents", 1000, "Maximum events to be queued.")
flagset.StringVar(&omitEvents, "omit-events", "", "Set this flag to a comma sperated list of PolicyViolation, PolicyApplied, PolicyError, PolicySkipped to disable events, e.g. --omit-events=PolicyApplied,PolicyViolation")
flagset.StringVar(&omitEvents, "omitEvents", "", "Set this flag to a comma sperated list of PolicyViolation, PolicyApplied, PolicyError, PolicySkipped to disable events, e.g. --omitEvents=PolicyApplied,PolicyViolation")
flagset.StringVar(&serverIP, "serverIP", "", "IP address where Kyverno controller runs. Only required if out-of-cluster.")
flagset.BoolVar(&autoUpdateWebhooks, "autoUpdateWebhooks", true, "Set this flag to 'false' to disable auto-configuration of the webhook.")
flagset.DurationVar(&webhookRegistrationTimeout, "webhookRegistrationTimeout", 120*time.Second, "Timeout for webhook registration, e.g., 30s, 1m, 5m.")
Expand Down Expand Up @@ -317,14 +317,15 @@ func main() {
tlsSecretName,
)
policyCache := policycache.NewCache()
omitEventsValues := strings.Split(omitEvents, ",")
if omitEvents == "" {
omitEventsValues = []string{}
}
eventGenerator := event.NewEventGenerator(
setup.EventsClient,
logging.WithName("EventGenerator"),
omitEventsValues...,
strings.Split(omitEvents, ",")...,
)
eventController := internal.NewController(
event.ControllerName,
eventGenerator,
event.Workers,
)
// this controller only subscribe to events, nothing is returned...
policymetricscontroller.NewController(
Expand Down Expand Up @@ -390,8 +391,6 @@ func main() {
os.Exit(1)
}
}
// start event generator
go eventGenerator.Run(signalCtx, event.Workers, &wg)
// setup leader election
le, err := leaderelection.New(
setup.Logger.WithName("leader-election"),
Expand Down Expand Up @@ -456,19 +455,6 @@ func main() {
setup.Logger.Error(err, "failed to initialize leader election")
os.Exit(1)
}
// start non leader controllers
for _, controller := range nonLeaderControllers {
controller.Run(signalCtx, setup.Logger.WithName("controllers"), &wg)
}
// start leader election
go func() {
select {
case <-signalCtx.Done():
return
default:
le.Run(signalCtx)
}
}()
// create webhooks server
urgen := webhookgenerate.NewGenerator(
setup.KyvernoClient,
Expand Down Expand Up @@ -532,8 +518,15 @@ func main() {
os.Exit(1)
}
// start webhooks server
server.Run(signalCtx.Done())
server.Run()
defer server.Stop()
// start non leader controllers
eventController.Run(signalCtx, setup.Logger, &wg)
for _, controller := range nonLeaderControllers {
controller.Run(signalCtx, setup.Logger.WithName("controllers"), &wg)
}
// start leader election
le.Run(signalCtx)
// wait for everything to shut down and exit
wg.Wait()
// say goodbye...
setup.Logger.V(2).Info("Kyverno shutdown successful")
}
24 changes: 13 additions & 11 deletions cmd/reports-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/kyverno/kyverno/pkg/clients/dclient"
"github.com/kyverno/kyverno/pkg/config"
admissionreportcontroller "github.com/kyverno/kyverno/pkg/controllers/report/admission"
aggregatereportcontroller "github.com/kyverno/kyverno/pkg/controllers/report/aggregate/resource"
aggregatereportcontroller "github.com/kyverno/kyverno/pkg/controllers/report/aggregate"
backgroundscancontroller "github.com/kyverno/kyverno/pkg/controllers/report/background"
resourcereportcontroller "github.com/kyverno/kyverno/pkg/controllers/report/resource"
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
Expand Down Expand Up @@ -209,7 +209,7 @@ func main() {
flagset.IntVar(&backgroundScanWorkers, "backgroundScanWorkers", backgroundscancontroller.Workers, "Configure the number of background scan workers.")
flagset.DurationVar(&backgroundScanInterval, "backgroundScanInterval", time.Hour, "Configure background scan interval.")
flagset.IntVar(&maxQueuedEvents, "maxQueuedEvents", 1000, "Maximum events to be queued.")
flagset.StringVar(&omitEvents, "omit-events", "", "Set this flag to a comma separated list of PolicyViolation, PolicyApplied, PolicyError, PolicySkipped to disable events, e.g. --omit-events=PolicyApplied,PolicyViolation")
flagset.StringVar(&omitEvents, "omitEvents", "", "Set this flag to a comma separated list of PolicyViolation, PolicyApplied, PolicyError, PolicySkipped to disable events, e.g. --omitEvents=PolicyApplied,PolicyViolation")
flagset.BoolVar(&skipResourceFilters, "skipResourceFilters", true, "If true, resource filters wont be considered.")
flagset.Int64Var(&maxAPICallResponseLength, "maxAPICallResponseLength", 2*1000*1000, "Maximum allowed response size from API Calls. A value of 0 bypasses checks (not recommended).")
// config
Expand Down Expand Up @@ -255,14 +255,16 @@ func main() {
}
// informer factories
kyvernoInformer := kyvernoinformer.NewSharedInformerFactory(setup.KyvernoClient, resyncPeriod)
omitEventsValues := strings.Split(omitEvents, ",")
if omitEvents == "" {
omitEventsValues = []string{}
}
var wg sync.WaitGroup
eventGenerator := event.NewEventGenerator(
setup.EventsClient,
logging.WithName("EventGenerator"),
omitEventsValues...,
strings.Split(omitEvents, ",")...,
)
eventController := internal.NewController(
event.ControllerName,
eventGenerator,
event.Workers,
)
// engine
engine := internal.NewEngine(
Expand All @@ -284,9 +286,6 @@ func main() {
setup.Logger.Error(errors.New("failed to wait for cache sync"), "failed to wait for cache sync")
os.Exit(1)
}
// start event generator
var wg sync.WaitGroup
go eventGenerator.Run(ctx, event.Workers, &wg)
// setup leader election
le, err := leaderelection.New(
setup.Logger.WithName("leader-election"),
Expand Down Expand Up @@ -354,7 +353,10 @@ func main() {
setup.Logger.Error(err, "failed to initialize leader election")
os.Exit(1)
}
// start non leader controllers
eventController.Run(ctx, setup.Logger, &wg)
// start leader election
le.Run(ctx)
sdown()
// wait for everything to shut down and exit
wg.Wait()
}
Loading

0 comments on commit 977c669

Please sign in to comment.