Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch Pods to pass pod security admission #6602

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Workaround for ServerPreferredResources panicking
feloy committed Mar 20, 2023

Verified

This commit was signed with the committer’s verified signature. The key has expired.
chfast Paweł Bylica
commit b488536d0284de69736660c2a2ca813ddb23b574
19 changes: 18 additions & 1 deletion pkg/kclient/all.go
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/klog"
@@ -125,7 +126,23 @@ type resourceMap struct {

func findAPIs(client discovery.DiscoveryInterface) (*resourceMap, error) {
start := time.Now()
resList, err := client.ServerPreferredResources()

var resList []*metav1.APIResourceList

// TODO(feloy) Remove call to ServerGroups() when https://github.com/kubernetes/kubernetes/issues/116414 is fixed

// The call to ServerGroups() prevents from calling ServerPreferredResources() when ServerGroups() returns nil
// (which will make ServerPreferredResources() panic)
originalErrorHandlers := runtime.ErrorHandlers
runtime.ErrorHandlers = nil
groups, err := client.ServerGroups()
if groups == nil {
resList = nil
} else {
resList, err = client.ServerPreferredResources()
}
runtime.ErrorHandlers = originalErrorHandlers

if err != nil {
return nil, fmt.Errorf("failed to fetch api groups from kubernetes: %w", err)
}