Skip to content

Commit

Permalink
boring: simple method moves
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Jul 18, 2017
1 parent 293f4c6 commit 7580da2
Show file tree
Hide file tree
Showing 240 changed files with 714 additions and 733 deletions.
4 changes: 2 additions & 2 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ func validateObject(path string, obj runtime.Object, t *testing.T) {
}

if namespaceRequired {
objectMeta, objectMetaErr := metav1.ObjectMetaFor(obj)
objectMeta, objectMetaErr := meta.Accessor(obj)
if objectMetaErr != nil {
t.Errorf("Expected no error, Got %v", objectMetaErr)
return
}

objectMeta.Namespace = metav1.NamespaceDefault
objectMeta.SetNamespace(metav1.NamespaceDefault)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/api/graph/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gonum/graph"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
)

Expand All @@ -24,12 +24,12 @@ const (
)

func GetUniqueRuntimeObjectNodeName(nodeKind string, obj runtime.Object) UniqueName {
meta, err := metav1.ObjectMetaFor(obj)
meta, err := meta.Accessor(obj)
if err != nil {
panic(err)
}

return UniqueName(fmt.Sprintf("%s|%s/%s", nodeKind, meta.Namespace, meta.Name))
return UniqueName(fmt.Sprintf("%s|%s/%s", nodeKind, meta.GetNamespace(), meta.GetName()))
}

// GetTopLevelContainerNode traverses the reverse ContainsEdgeKind edges until it finds a node
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/kubegraph/edge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/gonum/graph"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
kapi "k8s.io/kubernetes/pkg/api"
Expand Down Expand Up @@ -80,11 +81,11 @@ func namespaceFor(node graph.Node) (string, error) {
obj := node.(objectifier).Object()
switch t := obj.(type) {
case runtime.Object:
meta, err := metav1.ObjectMetaFor(t)
meta, err := meta.Accessor(t)
if err != nil {
return "", err
}
return meta.Namespace, nil
return meta.GetNamespace(), nil
case *kapi.PodSpec:
return node.(*kubegraph.PodSpecNode).Namespace, nil
case *kapi.ReplicationControllerSpec:
Expand Down
9 changes: 5 additions & 4 deletions pkg/api/kubegraph/edges.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/gonum/graph"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -130,7 +131,7 @@ func AddMountedSecretEdges(g osgraph.Graph, podSpec *kubegraph.PodSpecNode) {
containerNode := osgraph.GetTopLevelContainerNode(g, podSpec)
containerObj := g.GraphDescriber.Object(containerNode)

meta, err := metav1.ObjectMetaFor(containerObj.(runtime.Object))
meta, err := meta.Accessor(containerObj.(runtime.Object))
if err != nil {
// this should never happen. it means that a podSpec is owned by a top level container that is not a runtime.Object
panic(err)
Expand All @@ -144,7 +145,7 @@ func AddMountedSecretEdges(g osgraph.Graph, podSpec *kubegraph.PodSpecNode) {

// pod secrets must be in the same namespace
syntheticSecret := &kapi.Secret{}
syntheticSecret.Namespace = meta.Namespace
syntheticSecret.Namespace = meta.GetNamespace()
syntheticSecret.Name = source.Secret.SecretName

secretNode := kubegraph.FindOrCreateSyntheticSecretNode(g, syntheticSecret)
Expand Down Expand Up @@ -184,7 +185,7 @@ func AddRequestedServiceAccountEdges(g osgraph.Graph, podSpecNode *kubegraph.Pod
containerNode := osgraph.GetTopLevelContainerNode(g, podSpecNode)
containerObj := g.GraphDescriber.Object(containerNode)

meta, err := metav1.ObjectMetaFor(containerObj.(runtime.Object))
meta, err := meta.Accessor(containerObj.(runtime.Object))
if err != nil {
panic(err)
}
Expand All @@ -196,7 +197,7 @@ func AddRequestedServiceAccountEdges(g osgraph.Graph, podSpecNode *kubegraph.Pod
}

syntheticSA := &kapi.ServiceAccount{}
syntheticSA.Namespace = meta.Namespace
syntheticSA.Namespace = meta.GetNamespace()
syntheticSA.Name = name

saNode := kubegraph.FindOrCreateSyntheticServiceAccountNode(g, syntheticSA)
Expand Down
8 changes: 0 additions & 8 deletions pkg/api/restmapper/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,6 @@ func (d *discoveryRESTMapper) RESTMappings(gk schema.GroupKind, versions ...stri
return delegate.RESTMappings(gk, versions...)
}

func (d *discoveryRESTMapper) AliasesForResource(resource string) ([]string, bool) {
delegate, err := d.getDelegate()
if err != nil {
return nil, false
}
return delegate.AliasesForResource(resource)
}

func (d *discoveryRESTMapper) ResourceSingularizer(resource string) (singular string, err error) {
delegate, err := d.getDelegate()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ func originFuzzer(t *testing.T, seed int64) *fuzz.Fuzzer {
}
}
if c.RandBool() {
params.MaxUnavailable = intstr.FromInt(c.Rand.Int())
params.MaxSurge = intstr.FromInt(c.Rand.Int())
params.MaxUnavailable = intstr.FromInt(int(c.Rand.Int31()))
params.MaxSurge = intstr.FromInt(int(c.Rand.Int31()))
} else {
params.MaxSurge = intstr.FromString(fmt.Sprintf("%d%%", c.RandUint64()))
params.MaxUnavailable = intstr.FromString(fmt.Sprintf("%d%%", c.RandUint64()))
Expand Down
3 changes: 1 addition & 2 deletions pkg/auth/ldaputil/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"net"

utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/client-go/util/cert"

"github.com/openshift/origin/pkg/auth/ldaputil/ldapclient"
Expand Down Expand Up @@ -67,7 +66,7 @@ func (l *ldapClientConfig) Connect() (ldap.Client, error) {
// Ensure tlsConfig specifies the server we're connecting to
if tlsConfig != nil && !tlsConfig.InsecureSkipVerify && len(tlsConfig.ServerName) == 0 {
// Add to a copy of the tlsConfig to avoid mutating the original
c := utilnet.CloneTLSConfig(tlsConfig)
c := tlsConfig.Clone()
if host, _, err := net.SplitHostPort(l.host); err == nil {
c.ServerName = host
} else {
Expand Down
12 changes: 2 additions & 10 deletions pkg/authorization/apis/authorization/v1/defaults.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package v1

import (
"k8s.io/apimachinery/pkg/runtime"
kapi "k8s.io/kubernetes/pkg/api"
kapihelper "k8s.io/kubernetes/pkg/api/helper"

internal "github.com/openshift/origin/pkg/authorization/apis/authorization"
)
Expand All @@ -23,7 +22,7 @@ func SetDefaults_PolicyRule(obj *PolicyRule) {
len(obj.NonResourceURLsSlice) == 0 &&
// semantic equalities will ignore nil vs empty for other fields as a safety
// DO NOT REMOVE THIS CHECK unless you replace it with full equality comparisons
kapi.Semantic.Equalities.DeepEqual(oldAllowAllPolicyRule, *obj)
kapihelper.Semantic.Equalities.DeepEqual(oldAllowAllPolicyRule, *obj)

if oldAllowAllRule {
obj.APIGroups = []string{internal.APIGroupAll}
Expand All @@ -34,10 +33,3 @@ func SetDefaults_PolicyRule(obj *PolicyRule) {
obj.APIGroups = []string{""}
}
}

func addDefaultingFuncs(scheme *runtime.Scheme) error {
RegisterDefaults(scheme)
return scheme.AddDefaultingFuncs(
SetDefaults_PolicyRule,
)
}
8 changes: 6 additions & 2 deletions pkg/authorization/apis/authorization/v1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ var (
SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
LegacySchemeGroupVersion = schema.GroupVersion{Group: LegacyGroupName, Version: "v1"}

LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes, addConversionFuncs, addDefaultingFuncs)
LegacySchemeBuilder = runtime.NewSchemeBuilder(addLegacyKnownTypes, addConversionFuncs, RegisterDefaults)
AddToSchemeInCoreGroup = LegacySchemeBuilder.AddToScheme

SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes, addConversionFuncs, addDefaultingFuncs)
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes, addConversionFuncs, RegisterDefaults)
AddToScheme = SchemeBuilder.AddToScheme
)

func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
kvalidation "k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
kapi "k8s.io/kubernetes/pkg/api"
kapihelper "k8s.io/kubernetes/pkg/api/helper"
"k8s.io/kubernetes/pkg/api/validation"

authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
Expand Down Expand Up @@ -304,7 +305,7 @@ func validateRoleUpdate(role *authorizationapi.Role, oldRole *authorizationapi.R

func isNewRule(rule authorizationapi.PolicyRule, oldRole *authorizationapi.Role) bool {
for _, r := range oldRole.Rules {
if r.AttributeRestrictions != nil && kapi.Semantic.DeepEqual(rule, r) { // only do expensive comparision against rules that have attribute restrictions
if r.AttributeRestrictions != nil && kapihelper.Semantic.DeepEqual(rule, r) { // only do expensive comparision against rules that have attribute restrictions
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/authorization/registry/clusterpolicy/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *storage) ListClusterPolicies(ctx apirequest.Context, options *metainter
}

func (s *storage) CreateClusterPolicy(ctx apirequest.Context, policy *authorizationapi.ClusterPolicy) error {
_, err := s.Create(ctx, policy)
_, err := s.Create(ctx, policy, false)
return err
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/authorization/registry/clusterpolicy/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func (strategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object)
}

// GetAttrs returns labels and fields of a given object for filtering purposes
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, bool, error) {
policy, ok := obj.(*authorizationapi.ClusterPolicy)
if !ok {
return nil, nil, fmt.Errorf("not a ClusterPolicy")
return nil, nil, false, fmt.Errorf("not a ClusterPolicy")
}
return labels.Set(policy.ObjectMeta.Labels), authorizationapi.ClusterPolicyToSelectableFields(policy), nil
return labels.Set(policy.ObjectMeta.Labels), authorizationapi.ClusterPolicyToSelectableFields(policy), policy.Initializers != nil, nil
}

// Matcher returns a generic matcher for a given label and field selector.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *storage) ListClusterPolicyBindings(ctx apirequest.Context, options *met
}

func (s *storage) CreateClusterPolicyBinding(ctx apirequest.Context, policyBinding *authorizationapi.ClusterPolicyBinding) error {
_, err := s.Create(ctx, policyBinding)
_, err := s.Create(ctx, policyBinding, false)
return err
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/authorization/registry/clusterpolicybinding/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ func (strategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object)
}

// GetAttrs returns labels and fields of a given object for filtering purposes
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, bool, error) {
policyBinding, ok := obj.(*authorizationapi.ClusterPolicyBinding)
if !ok {
return nil, nil, fmt.Errorf("not a ClusterPolicyBinding")
return nil, nil, false, fmt.Errorf("not a ClusterPolicyBinding")
}
return labels.Set(policyBinding.ObjectMeta.Labels), authorizationapi.ClusterPolicyBindingToSelectableFields(policyBinding), nil
return labels.Set(policyBinding.ObjectMeta.Labels), authorizationapi.ClusterPolicyBindingToSelectableFields(policyBinding), policyBinding.Initializers != nil, nil
}

// Matcher returns a generic matcher for a given label and field selector.
Expand Down
4 changes: 2 additions & 2 deletions pkg/authorization/registry/clusterrole/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ func (s *ClusterRoleStorage) Delete(ctx apirequest.Context, name string, options
return ret.(*metav1.Status), false, err
}

func (s *ClusterRoleStorage) Create(ctx apirequest.Context, obj runtime.Object) (runtime.Object, error) {
func (s *ClusterRoleStorage) Create(ctx apirequest.Context, obj runtime.Object, _ bool) (runtime.Object, error) {
clusterObj := obj.(*authorizationapi.ClusterRole)
convertedObj := authorizationapi.ToRole(clusterObj)

ret, err := s.roleStorage.Create(ctx, convertedObj)
ret, err := s.roleStorage.Create(ctx, convertedObj, false)
if ret == nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/authorization/registry/clusterrolebinding/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ func (s *ClusterRoleBindingStorage) Delete(ctx apirequest.Context, name string,
return ret.(*metav1.Status), false, err
}

func (s *ClusterRoleBindingStorage) Create(ctx apirequest.Context, obj runtime.Object) (runtime.Object, error) {
func (s *ClusterRoleBindingStorage) Create(ctx apirequest.Context, obj runtime.Object, _ bool) (runtime.Object, error) {
clusterObj := obj.(*authorizationapi.ClusterRoleBinding)
convertedObj := authorizationapi.ToRoleBinding(clusterObj)

ret, err := s.roleBindingStorage.Create(ctx, convertedObj)
ret, err := s.roleBindingStorage.Create(ctx, convertedObj, false)
if ret == nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (r *REST) New() runtime.Object {

// Create transforms a LocalRAR into an ClusterRAR that is requesting a namespace. That collapses the code paths.
// LocalResourceAccessReview exists to allow clean expression of policy.
func (r *REST) Create(ctx apirequest.Context, obj runtime.Object) (runtime.Object, error) {
func (r *REST) Create(ctx apirequest.Context, obj runtime.Object, _ bool) (runtime.Object, error) {
localRAR, ok := obj.(*authorizationapi.LocalResourceAccessReview)
if !ok {
return nil, kapierrors.NewBadRequest(fmt.Sprintf("not a localResourceAccessReview: %#v", obj))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestConflictingNamespace(t *testing.T) {

storage := NewREST(resourceaccessreview.NewRegistry(resourceaccessreview.NewREST(authorizer, authorizer)))
ctx := apirequest.WithNamespace(apirequest.NewContext(), "bar")
_, err := storage.Create(ctx, reviewRequest)
_, err := storage.Create(ctx, reviewRequest, false)
if err == nil {
t.Fatalf("unexpected non-error: %v", err)
}
Expand Down Expand Up @@ -131,7 +131,7 @@ func (r *resourceAccessTest) runTest(t *testing.T) {
expectedAttributes := authorizer.ToDefaultAuthorizationAttributes(nil, r.reviewRequest.Action.Namespace, r.reviewRequest.Action)

ctx := apirequest.WithNamespace(apirequest.WithUser(apirequest.NewContext(), &user.DefaultInfo{}), r.reviewRequest.Action.Namespace)
obj, err := storage.Create(ctx, r.reviewRequest)
obj, err := storage.Create(ctx, r.reviewRequest, false)
if err != nil && len(r.authorizer.err) == 0 {
t.Fatalf("unexpected error: %v", err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (r *REST) New() runtime.Object {

// Create transforms a LocalSAR into an ClusterSAR that is requesting a namespace. That collapses the code paths.
// LocalSubjectAccessReview exists to allow clean expression of policy.
func (r *REST) Create(ctx apirequest.Context, obj runtime.Object) (runtime.Object, error) {
func (r *REST) Create(ctx apirequest.Context, obj runtime.Object, _ bool) (runtime.Object, error) {
localSAR, ok := obj.(*authorizationapi.LocalSubjectAccessReview)
if !ok {
return nil, kapierrors.NewBadRequest(fmt.Sprintf("not a localSubjectAccessReview: %#v", obj))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestConflictingNamespace(t *testing.T) {

storage := NewREST(subjectaccessreview.NewRegistry(subjectaccessreview.NewREST(authorizer)))
ctx := apirequest.WithNamespace(apirequest.NewContext(), "bar")
_, err := storage.Create(ctx, reviewRequest)
_, err := storage.Create(ctx, reviewRequest, false)
if err == nil {
t.Fatalf("unexpected non-error: %v", err)
}
Expand Down Expand Up @@ -271,7 +271,7 @@ func (r *subjectAccessTest) runTest(t *testing.T) {
ctx = apirequest.WithUser(ctx, &user.DefaultInfo{Name: "dummy"})
}

obj, err := storage.Create(ctx, r.reviewRequest)
obj, err := storage.Create(ctx, r.reviewRequest, false)
switch {
case err == nil && len(r.expectedError) == 0:
case err == nil && len(r.expectedError) != 0:
Expand Down
2 changes: 1 addition & 1 deletion pkg/authorization/registry/policy/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *storage) ListPolicies(ctx apirequest.Context, options *metainternal.Lis
}

func (s *storage) CreatePolicy(ctx apirequest.Context, node *authorizationapi.Policy) error {
_, err := s.Create(ctx, node)
_, err := s.Create(ctx, node, false)
return err
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/authorization/registry/policy/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ func (strategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object)
}

// GetAttrs returns labels and fields of a given object for filtering purposes
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, bool, error) {
policy, ok := obj.(*authorizationapi.Policy)
if !ok {
return nil, nil, fmt.Errorf("not a Policy")
return nil, nil, false, fmt.Errorf("not a Policy")
}
return labels.Set(policy.ObjectMeta.Labels), authorizationapi.PolicyToSelectableFields(policy), nil
return labels.Set(policy.ObjectMeta.Labels), authorizationapi.PolicyToSelectableFields(policy), policy.Initializers != nil, nil
}

// Matcher returns a generic matcher for a given label and field selector.
Expand Down
2 changes: 1 addition & 1 deletion pkg/authorization/registry/policybinding/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *storage) ListPolicyBindings(ctx apirequest.Context, options *metaintern
}

func (s *storage) CreatePolicyBinding(ctx apirequest.Context, policyBinding *authorizationapi.PolicyBinding) error {
_, err := s.Create(ctx, policyBinding)
_, err := s.Create(ctx, policyBinding, false)
return err
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/authorization/registry/policybinding/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ func (strategy) ValidateUpdate(ctx apirequest.Context, obj, old runtime.Object)
}

// GetAttrs returns labels and fields of a given object for filtering purposes
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) {
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, bool, error) {
policyBinding, ok := obj.(*authorizationapi.PolicyBinding)
if !ok {
return nil, nil, fmt.Errorf("not a PolicyBinding")
return nil, nil, false, fmt.Errorf("not a PolicyBinding")
}
return labels.Set(policyBinding.ObjectMeta.Labels), authorizationapi.PolicyBindingToSelectableFields(policyBinding), nil
return labels.Set(policyBinding.ObjectMeta.Labels), authorizationapi.PolicyBindingToSelectableFields(policyBinding), policyBinding.Initializers != nil, nil
}

// Matcher returns a generic matcher for a given label and field selector.
Expand Down
Loading

0 comments on commit 7580da2

Please sign in to comment.