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

ensure we never print a non-groupified object #20384

Closed
wants to merge 2 commits into from
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
23 changes: 23 additions & 0 deletions pkg/api/legacygroupification/groupification.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ import (
"github.com/openshift/origin/pkg/user/apis/user"
)

func IsOAPI(gvk schema.GroupVersionKind) bool {
if len(gvk.Group) > 0 {
return false
}

_, ok := oapiKindsToGroup[gvk.Kind]
return ok
}

func OAPIToGroupifiedGVK(gvk *schema.GroupVersionKind) {
if len(gvk.Group) > 0 {
return
Expand All @@ -53,27 +62,32 @@ func OAPIToGroupified(uncast runtime.Object, gvk *schema.GroupVersionKind) {
newGroup := fixOAPIGroupKindInTopLevelUnstructured(obj.Object)
if len(newGroup) > 0 {
gvk.Group = newGroup
uncast.GetObjectKind().SetGroupVersionKind(*gvk)
}
case *unstructured.UnstructuredList:
newGroup := fixOAPIGroupKindInTopLevelUnstructured(obj.Object)
if len(newGroup) > 0 {
gvk.Group = newGroup
uncast.GetObjectKind().SetGroupVersionKind(*gvk)
}

case *apps.DeploymentConfig, *appsv1.DeploymentConfig, *apps.DeploymentConfigList, *appsv1.DeploymentConfigList,
*apps.DeploymentConfigRollback, *appsv1.DeploymentConfigRollback:
gvk.Group = apps.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

case *authorization.ClusterRoleBinding, *authorizationv1.ClusterRoleBinding, *authorization.ClusterRoleBindingList, *authorizationv1.ClusterRoleBindingList,
*authorization.ClusterRole, *authorizationv1.ClusterRole, *authorization.ClusterRoleList, *authorizationv1.ClusterRoleList,
*authorization.Role, *authorizationv1.Role, *authorization.RoleList, *authorizationv1.RoleList,
*authorization.RoleBinding, *authorizationv1.RoleBinding, *authorization.RoleBindingList, *authorizationv1.RoleBindingList,
*authorization.RoleBindingRestriction, *authorizationv1.RoleBindingRestriction, *authorization.RoleBindingRestrictionList, *authorizationv1.RoleBindingRestrictionList:
gvk.Group = authorization.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

case *build.BuildConfig, *buildv1.BuildConfig, *build.BuildConfigList, *buildv1.BuildConfigList,
*build.Build, *buildv1.Build, *build.BuildList, *buildv1.BuildList:
gvk.Group = build.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

case *image.Image, *imagev1.Image, *image.ImageList, *imagev1.ImageList,
*image.ImageSignature, *imagev1.ImageSignature,
Expand All @@ -83,43 +97,52 @@ func OAPIToGroupified(uncast runtime.Object, gvk *schema.GroupVersionKind) {
*image.ImageStream, *imagev1.ImageStream, *image.ImageStreamList, *imagev1.ImageStreamList,
*image.ImageStreamTag, *imagev1.ImageStreamTag:
gvk.Group = image.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

case *network.ClusterNetwork, *networkv1.ClusterNetwork, *network.ClusterNetworkList, *networkv1.ClusterNetworkList,
*network.NetNamespace, *networkv1.NetNamespace, *network.NetNamespaceList, *networkv1.NetNamespaceList,
*network.HostSubnet, *networkv1.HostSubnet, *network.HostSubnetList, *networkv1.HostSubnetList,
*network.EgressNetworkPolicy, *networkv1.EgressNetworkPolicy, *network.EgressNetworkPolicyList, *networkv1.EgressNetworkPolicyList:
gvk.Group = network.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

case *project.Project, *projectv1.Project, *project.ProjectList, *projectv1.ProjectList,
*project.ProjectRequest, *projectv1.ProjectRequest:
gvk.Group = project.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

case *quota.ClusterResourceQuota, *quotav1.ClusterResourceQuota, *quota.ClusterResourceQuotaList, *quotav1.ClusterResourceQuotaList:
gvk.Group = quota.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

case *oauth.OAuthAuthorizeToken, *oauthv1.OAuthAuthorizeToken, *oauth.OAuthAuthorizeTokenList, *oauthv1.OAuthAuthorizeTokenList,
*oauth.OAuthClientAuthorization, *oauthv1.OAuthClientAuthorization, *oauth.OAuthClientAuthorizationList, *oauthv1.OAuthClientAuthorizationList,
*oauth.OAuthClient, *oauthv1.OAuthClient, *oauth.OAuthClientList, *oauthv1.OAuthClientList,
*oauth.OAuthAccessToken, *oauthv1.OAuthAccessToken, *oauth.OAuthAccessTokenList, *oauthv1.OAuthAccessTokenList:
gvk.Group = oauth.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

case *route.Route, *routev1.Route, *route.RouteList, *routev1.RouteList:
gvk.Group = route.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

case *security.SecurityContextConstraints, *securityv1.SecurityContextConstraints, *security.SecurityContextConstraintsList, *securityv1.SecurityContextConstraintsList,
*security.PodSecurityPolicySubjectReview, *securityv1.PodSecurityPolicySubjectReview,
*security.PodSecurityPolicySelfSubjectReview, *securityv1.PodSecurityPolicySelfSubjectReview,
*security.PodSecurityPolicyReview, *securityv1.PodSecurityPolicyReview:
gvk.Group = security.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

case *template.Template, *templatev1.Template, *template.TemplateList, *templatev1.TemplateList:
gvk.Group = template.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

case *user.Group, *userv1.Group, *user.GroupList, *userv1.GroupList,
*user.Identity, *userv1.Identity, *user.IdentityList, *userv1.IdentityList,
*user.UserIdentityMapping, *userv1.UserIdentityMapping,
*user.User, *userv1.User, *user.UserList, *userv1.UserList:
gvk.Group = user.GroupName
uncast.GetObjectKind().SetGroupVersionKind(*gvk)

}
}
Expand Down
13 changes: 5 additions & 8 deletions pkg/oc/cli/shim_kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package cli

import (
kclientcmd "k8s.io/client-go/tools/clientcmd"
kcmd "k8s.io/kubernetes/pkg/kubectl/cmd"
kcmdset "k8s.io/kubernetes/pkg/kubectl/cmd/set"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/cmd/util/editor"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/resource"
"k8s.io/kubernetes/pkg/kubectl/genericclioptions/openshiftpatch"
"k8s.io/kubernetes/pkg/kubectl/polymorphichelpers"

"github.com/openshift/origin/pkg/api/legacygroupification"
Expand All @@ -18,13 +16,12 @@ import (
func shimKubectlForOc() {
// we only need this change for `oc`. `kubectl` should behave as close to `kubectl` as we can
// if we call this factory construction method, we want the openshift style config loading
genericclioptions.UseOpenShiftKubeConfigValues = true
kclientcmd.ErrEmptyConfig = genericclioptions.NewErrConfigurationMissing()
kcmdset.ParseDockerImageReferenceToStringFunc = clientcmd.ParseDockerImageReferenceToStringFunc
editor.UseOpenShiftEditorEnvVars = true
resource.OAPIToGroupified = legacygroupification.OAPIToGroupified
kcmd.OAPIToGroupifiedGVK = legacygroupification.OAPIToGroupifiedGVK
kcmd.UseOpenShiftGenerator = true
openshiftpatch.OAPIToGroupified = legacygroupification.OAPIToGroupified
openshiftpatch.OAPIToGroupifiedGVK = legacygroupification.OAPIToGroupifiedGVK
openshiftpatch.IsOAPIFn = legacygroupification.IsOAPI
openshiftpatch.IsOC = true

// update polymorphic helpers
polymorphichelpers.AttachablePodForObjectFn = originpolymorphichelpers.NewAttachablePodForObjectFn(polymorphichelpers.AttachablePodForObjectFn)
Expand Down
15 changes: 0 additions & 15 deletions vendor/k8s.io/kubernetes/pkg/kubectl/cmd/patch_run.go

This file was deleted.

5 changes: 3 additions & 2 deletions vendor/k8s.io/kubernetes/pkg/kubectl/cmd/run.go

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

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

This file was deleted.

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

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

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

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

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

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

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

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

Loading