From 7e2667189a61c5bc47607f365960d6a73b5c38ac Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Tue, 18 Apr 2023 20:52:24 +0000 Subject: [PATCH] Create CRDs with schema Fixes an issue where CRDs were being created without schema, allowing resources with invalid content to be created, later stalling the controller ListWatch event channel when the invalid resources could not be deserialized. Signed-off-by: Brad Davidson --- pkg/crd/crds.go | 15 +++++++++++++++ pkg/server/context.go | 8 ++++---- 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 pkg/crd/crds.go diff --git a/pkg/crd/crds.go b/pkg/crd/crds.go new file mode 100644 index 000000000000..5028f57a8572 --- /dev/null +++ b/pkg/crd/crds.go @@ -0,0 +1,15 @@ +package crd + +import ( + v1 "github.com/k3s-io/k3s/pkg/apis/k3s.cattle.io/v1" + "github.com/rancher/wrangler/pkg/crd" +) + +func List() []crd.CRD { + addon := crd.NamespacedType("Addon.k3s.cattle.io/v1"). + WithSchemaFromStruct(v1.Addon{}). + WithColumn("Source", ".status.source"). + WithColumn("Checksum", ".status.checksum") + + return []crd.CRD{addon} +} diff --git a/pkg/server/context.go b/pkg/server/context.go index 22408cac783f..0ad06230dc54 100644 --- a/pkg/server/context.go +++ b/pkg/server/context.go @@ -6,7 +6,9 @@ import ( "os" "runtime" + helmcrd "github.com/k3s-io/helm-controller/pkg/crd" "github.com/k3s-io/helm-controller/pkg/generated/controllers/helm.cattle.io" + addoncrd "github.com/k3s-io/k3s/pkg/crd" "github.com/k3s-io/k3s/pkg/deploy" "github.com/k3s-io/k3s/pkg/generated/controllers/k3s.cattle.io" "github.com/k3s-io/k3s/pkg/version" @@ -82,10 +84,8 @@ func crds(ctx context.Context, config *rest.Config) error { return err } - factory.BatchCreateCRDs(ctx, crd.NamespacedTypes( - "Addon.k3s.cattle.io/v1", - "HelmChart.helm.cattle.io/v1", - "HelmChartConfig.helm.cattle.io/v1")...) + types := append(helmcrd.List(), addoncrd.List()...) + factory.BatchCreateCRDs(ctx, types...) return factory.BatchWait() }