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

Bug 2069310: UPSTREAM: <carry>: use hardcoded rest mapper from library-go #1233

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ require (
github.com/openshift/api v0.0.0-20211028023115-7224b732cc14
github.com/openshift/apiserver-library-go v0.0.0-20211105091019-06e87e7030eb
github.com/openshift/client-go v0.0.0-20210831095141-e19a065e79f7
github.com/openshift/library-go v0.0.0-20211207082558-36821c7a1fa2
github.com/openshift/library-go v0.0.0-20220405121559-e304504b7d6f

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_golang v1.11.0
Expand Down Expand Up @@ -396,7 +396,7 @@ replace (
github.com/openshift/apiserver-library-go => github.com/openshift/apiserver-library-go v0.0.0-20211105091019-06e87e7030eb
github.com/openshift/build-machinery-go => github.com/openshift/build-machinery-go v0.0.0-20210806203541-4ea9b6da3a37
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20210831095141-e19a065e79f7
github.com/openshift/library-go => github.com/openshift/library-go v0.0.0-20211207082558-36821c7a1fa2
github.com/openshift/library-go => github.com/openshift/library-go v0.0.0-20220405121559-e304504b7d6f
github.com/opentracing/opentracing-go => github.com/opentracing/opentracing-go v1.1.0
github.com/pascaldekloe/goe => github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c
github.com/pelletier/go-toml => github.com/pelletier/go-toml v1.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ github.com/openshift/ginkgo v4.7.0-origin.0+incompatible h1:2qD1n/RAnycWMPjYS6ME
github.com/openshift/ginkgo v4.7.0-origin.0+incompatible/go.mod h1:8METQ1gDhl0KW+pGH4c0DIJYEN/ksVCL6hOuHPmXGnk=
github.com/openshift/google-cadvisor v0.33.2-0.20210825140152-3e7875ab2744 h1:myWWE+QcbnUk2yKaL1zZZePAFwgiytkLMkgWQ/doA4c=
github.com/openshift/google-cadvisor v0.33.2-0.20210825140152-3e7875ab2744/go.mod h1:kN93gpdevu+bpS227TyHVZyCU5bbqCzTj5T9drl34MI=
github.com/openshift/library-go v0.0.0-20211207082558-36821c7a1fa2 h1:a4mC6hoimeAxOqdsLIWB4wxiyEIre8HbAWBvJmdeNCk=
github.com/openshift/library-go v0.0.0-20211207082558-36821c7a1fa2/go.mod h1:fKtzrsRXSWMLiBT1SM8cEVT2YyL7ihx/TEuT3gmgFgQ=
github.com/openshift/library-go v0.0.0-20220405121559-e304504b7d6f h1:Ru8L44N6lsP0bWcJaQf4urxodle9rfzNZNttOZhd9A0=
github.com/openshift/library-go v0.0.0-20220405121559-e304504b7d6f/go.mod h1:5TSPiu4ZEPW5NwUspgqYqjSD/wF86JWGy+x8jB+9oB4=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
Expand Down
101 changes: 2 additions & 99 deletions pkg/kubeapiserver/admission/patch_restmapper.go
Original file line number Diff line number Diff line change
@@ -1,108 +1,11 @@
package admission

import (
"fmt"
"github.com/openshift/library-go/pkg/client/openshiftrestmapper"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// defaultRESTMappings contains enough RESTMappings to have enough of the kube-controller-manager succeed when running
// against a kube-apiserver that cannot reach aggregated APIs to do a full mapping. This happens when the OwnerReferencesPermissionEnforcement
// admission plugin runs to confirm permissions. Don't add things just because you don't want to fail. These are here so that
// we can start enough back up to get the rest of the system working correctly.
var defaultRESTMappings = []meta.RESTMapping{
{
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ConfigMap"},
Scope: meta.RESTScopeNamespace,
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "configmaps"},
},
{
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"},
Scope: meta.RESTScopeNamespace,
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "pods"},
},
{
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ReplicationController"},
Scope: meta.RESTScopeNamespace,
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "replicationcontrollers"},
},
{
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Secret"},
Scope: meta.RESTScopeNamespace,
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "secrets"},
},
{
GroupVersionKind: schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ServiceAccount"},
Scope: meta.RESTScopeNamespace,
Resource: schema.GroupVersionResource{Group: "", Version: "v1", Resource: "serviceaccounts"},
},
{
GroupVersionKind: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ControllerRevision"},
Scope: meta.RESTScopeNamespace,
Resource: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "controllerrevisions"},
},
{
GroupVersionKind: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"},
Scope: meta.RESTScopeNamespace,
Resource: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "daemonsets"},
},
{
GroupVersionKind: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"},
Scope: meta.RESTScopeNamespace,
Resource: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"},
},
{
GroupVersionKind: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "ReplicaSet"},
Scope: meta.RESTScopeNamespace,
Resource: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "replicasets"},
},
{
GroupVersionKind: schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"},
Scope: meta.RESTScopeNamespace,
Resource: schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "statefulsets"},
},
}

func NewAdmissionRESTMapper(delegate meta.RESTMapper) meta.RESTMapper {
ret := HardCodedFirstRESTMapper{
Mapping: map[schema.GroupVersionKind]meta.RESTMapping{},
RESTMapper: delegate,
}
for i := range defaultRESTMappings {
curr := defaultRESTMappings[i]
ret.Mapping[curr.GroupVersionKind] = curr
}
return ret
}

// HardCodedFirstRESTMapper is a RESTMapper that will look for hardcoded mappings first, then delegate.
// This is done in service to `OwnerReferencesPermissionEnforcement`
type HardCodedFirstRESTMapper struct {
Mapping map[schema.GroupVersionKind]meta.RESTMapping
meta.RESTMapper
}

var _ meta.RESTMapper = HardCodedFirstRESTMapper{}

func (m HardCodedFirstRESTMapper) String() string {
return fmt.Sprintf("HardCodedRESTMapper{\n\t%v\n%v\n}", m.Mapping, m.RESTMapper)
}

// RESTMapping is the only function called today. The firsthit restmapper ought to make this work right. OwnerReferencesPermissionEnforcement
// only ever calls with one version.
func (m HardCodedFirstRESTMapper) RESTMappings(gk schema.GroupKind, versions ...string) ([]*meta.RESTMapping, error) {
// not exactly one version, delegate
if len(versions) != 1 {
return m.RESTMapper.RESTMappings(gk, versions...)
}
gvk := gk.WithVersion(versions[0])

single, ok := m.Mapping[gvk]
// not handled, delegate
if !ok {
return m.RESTMapper.RESTMappings(gk, versions...)
}

return []*meta.RESTMapping{&single}, nil
return openshiftrestmapper.NewOpenShiftHardcodedRESTMapper(delegate)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is a backport I trust that we already checked and tested the new mapper.

}
2 changes: 1 addition & 1 deletion staging/src/k8s.io/api/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions staging/src/k8s.io/apiextensions-apiserver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion staging/src/k8s.io/apiserver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/googleapis/gnostic v0.5.5
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
github.com/openshift/library-go v0.0.0-20211207082558-36821c7a1fa2
github.com/openshift/library-go v0.0.0-20220405121559-e304504b7d6f
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
go.etcd.io/etcd/api/v3 v3.5.0
Expand Down
4 changes: 2 additions & 2 deletions staging/src/k8s.io/apiserver/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion staging/src/k8s.io/cli-runtime/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions staging/src/k8s.io/cloud-provider/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion staging/src/k8s.io/controller-manager/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions staging/src/k8s.io/kube-aggregator/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion staging/src/k8s.io/kube-controller-manager/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion staging/src/k8s.io/kubectl/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion staging/src/k8s.io/legacy-cloud-providers/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions staging/src/k8s.io/pod-security-admission/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.