Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/crd-puller/pull-crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/kcp-dev/sdk/cmd/help"

"github.com/kcp-dev/kcp/pkg/crdpuller"
"github.com/kcp-dev/kcp/pkg/crdpuller/scheme"
)

func main() {
Expand Down Expand Up @@ -73,7 +74,7 @@ func main() {
return err
}

puller, err := crdpuller.NewSchemaPuller(discoveryClient, crdClient)
puller, err := crdpuller.NewSchemaPuller(discoveryClient, crdClient, scheme.DefaultIgnores())
if err != nil {
return err
}
Expand Down
14 changes: 11 additions & 3 deletions pkg/crdpuller/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import (

"k8s.io/apiextensions-apiserver/pkg/apihelpers"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
extensionsapiserver "k8s.io/apiextensions-apiserver/pkg/apiserver"
apiextensionsv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
Expand All @@ -53,6 +53,7 @@ type schemaPuller struct {
resourceFor func(groupResource schema.GroupResource) (schema.GroupResource, error)
getCRD func(ctx context.Context, name string) (*apiextensionsv1.CustomResourceDefinition, error)
models openapi.ModelsByGKV
ignoredScheme *runtime.Scheme
}

// NewSchemaPuller allows creating a SchemaPuller from the `Config` of
Expand All @@ -61,7 +62,12 @@ type schemaPuller struct {
func NewSchemaPuller(
discoveryClient discovery.DiscoveryInterface,
crdClient apiextensionsv1client.ApiextensionsV1Interface,
ignoredScheme *runtime.Scheme,
) (*schemaPuller, error) {
if ignoredScheme == nil {
ignoredScheme = runtime.NewScheme()
}

openapiSchema, err := discoveryClient.OpenAPISchema()
if err != nil {
return nil, err
Expand Down Expand Up @@ -91,7 +97,8 @@ func NewSchemaPuller(
getCRD: func(ctx context.Context, name string) (*apiextensionsv1.CustomResourceDefinition, error) {
return crdClient.CustomResourceDefinitions().Get(ctx, name, metav1.GetOptions{})
},
models: modelsByGKV,
models: modelsByGKV,
ignoredScheme: ignoredScheme,
}, nil
}

Expand Down Expand Up @@ -162,7 +169,8 @@ func (sp *schemaPuller) PullCRDs(ctx context.Context, resourceNames ...string) (

gvk := gv.WithKind(apiResource.Kind)
logger = logger.WithValues("kind", apiResource.Kind)
if (kcpscheme.Scheme.Recognizes(gvk) || extensionsapiserver.Scheme.Recognizes(gvk)) && !resourcesToPull.Has(groupResource.String()) {
// ignore the resource unles we're asked to explicitly pull it
if sp.ignoredScheme.Recognizes(gvk) && !resourcesToPull.Has(groupResource.String()) {
logger.Info("ignoring a resource since it is part of the core kcp resources")
continue
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/crdpuller/scheme/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright 2026 The kcp Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package scheme exists to prevent a dependency on apiextensions-apiserver
// in the main crdpuller package, which would make it unnecessarily
// hard to import the crdpuller from other projects.
package scheme
29 changes: 29 additions & 0 deletions pkg/crdpuller/scheme/ignore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2026 The kcp Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package scheme

import (
extensionsapiserver "k8s.io/apiextensions-apiserver/pkg/apiserver"
"k8s.io/apimachinery/pkg/runtime"

"github.com/kcp-dev/kcp/pkg/crdpuller"
kcpscheme "github.com/kcp-dev/kcp/pkg/server/scheme"
)

func DefaultIgnores() *runtime.Scheme {
return crdpuller.MergeSchemes(runtime.NewScheme(), kcpscheme.Scheme, extensionsapiserver.Scheme)
}
35 changes: 35 additions & 0 deletions pkg/crdpuller/schemes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2026 The kcp Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package crdpuller

import (
"k8s.io/apimachinery/pkg/runtime"
)

// MergeSchemes merges multiple source schemes into a target scheme by copying
// all registered group versions and known types.
func MergeSchemes(target *runtime.Scheme, sources ...*runtime.Scheme) *runtime.Scheme {
for _, source := range sources {
for gvk := range source.AllKnownTypes() {
if obj, err := source.New(gvk); err == nil {
target.AddKnownTypeWithName(gvk, obj)
}
}
}

return target
}