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

stop injecting special discovery behavior into oc/kubectl #19327

Merged
merged 4 commits into from
Apr 17, 2018
Merged
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
39 changes: 22 additions & 17 deletions pkg/oc/admin/diagnostics/diagnostics/client/config_contexts.go
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import (

"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
osclientcmd "github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
projectclientinternal "github.com/openshift/origin/pkg/project/generated/internalclientset"
)

// ConfigContext diagnostics (one per context) validate that the client config context is complete and has connectivity to the master.
@@ -235,26 +236,30 @@ func (d ConfigContext) Check() types.DiagnosticResult {

// Actually send a request to see if context has connectivity.
// Note: we cannot reuse factories as they cache the clients, so build new factory for each context.
projectClient, err := osclientcmd.NewFactory(kclientcmd.NewDefaultClientConfig(*d.RawConfig, &kclientcmd.ConfigOverrides{Context: *context})).OpenshiftInternalProjectClient()
// client create now *fails* if cannot connect to server; so, address connectivity errors below
temporaryFactory := osclientcmd.NewFactory(kclientcmd.NewDefaultClientConfig(*d.RawConfig, &kclientcmd.ConfigOverrides{Context: *context}))
clientConfig, err := temporaryFactory.ClientConfig()
if err == nil {
if projects, projerr := projectClient.Project().Projects().List(metav1.ListOptions{}); projerr != nil {
err = projerr
} else { // success!
list := []string{}
for i, project := range projects.Items {
if i > 9 {
list = append(list, "...")
break
projectClient, err := projectclientinternal.NewForConfig(clientConfig)
// client create now *fails* if cannot connect to server; so, address connectivity errors below
if err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens when err != nil ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what happens when err != nil ?

Review with whitespace ignored. This increased nesting. The error is handled below as it was before.

if projects, projerr := projectClient.Project().Projects().List(metav1.ListOptions{}); projerr != nil {
err = projerr
} else { // success!
list := []string{}
for i, project := range projects.Items {
if i > 9 {
list = append(list, "...")
break
}
list = append(list, project.Name)
}
list = append(list, project.Name)
}
if len(list) == 0 {
r.Info("DCli0003", msgText+"Successfully requested project list, but it is empty, so user has no access to anything.")
} else {
r.Info("DCli0004", msgText+fmt.Sprintf("Successfully requested project list; has access to project(s):\n %v", list))
if len(list) == 0 {
r.Info("DCli0003", msgText+"Successfully requested project list, but it is empty, so user has no access to anything.")
} else {
r.Info("DCli0004", msgText+fmt.Sprintf("Successfully requested project list; has access to project(s):\n %v", list))
}
return r
}
return r
}
}

Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"

networkclientinternal "github.com/openshift/origin/pkg/network/generated/internalclientset"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/log"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
"github.com/openshift/origin/pkg/oc/admin/diagnostics/options"
@@ -123,7 +124,11 @@ func (o NetworkPodDiagnosticsOptions) buildNetworkPodDiagnostics() ([]types.Diag
if clientErr != nil {
return nil, clientErr
}
networkClient, err := factory.OpenshiftInternalNetworkClient()
clientConfig, err := factory.ClientConfig()
if err != nil {
return nil, err
}
networkClient, err := networkclientinternal.NewForConfig(clientConfig)
if err != nil {
return nil, err
}
7 changes: 6 additions & 1 deletion pkg/oc/admin/groups/changemembership.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import (
"github.com/spf13/cobra"

"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
userclientinternal "github.com/openshift/origin/pkg/user/generated/internalclientset"
usertypedclient "github.com/openshift/origin/pkg/user/generated/internalclientset/typed/user/internalversion"
)

@@ -102,7 +103,11 @@ func (o *GroupModificationOptions) Complete(f *clientcmd.Factory, args []string)
o.Group = args[0]
o.Users = append(o.Users, args[1:]...)

userClient, err := f.OpenshiftInternalUserClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
userClient, err := userclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
7 changes: 6 additions & 1 deletion pkg/oc/admin/groups/new.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import (

"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
userapi "github.com/openshift/origin/pkg/user/apis/user"
userclientinternal "github.com/openshift/origin/pkg/user/generated/internalclientset"
usertypedclient "github.com/openshift/origin/pkg/user/generated/internalclientset/typed/user/internalversion"
)

@@ -79,7 +80,11 @@ func (o *NewGroupOptions) Complete(f *clientcmd.Factory, cmd *cobra.Command, arg
o.Users = append(o.Users, args[1:]...)
}

userClient, err := f.OpenshiftInternalUserClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
userClient, err := userclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
7 changes: 6 additions & 1 deletion pkg/oc/admin/groups/sync/cli/prune.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import (
"github.com/openshift/origin/pkg/oauthserver/ldaputil/ldapclient"
"github.com/openshift/origin/pkg/oc/admin/groups/sync"
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
userclientinternal "github.com/openshift/origin/pkg/user/generated/internalclientset"
usertypedclient "github.com/openshift/origin/pkg/user/generated/internalclientset/typed/user/internalversion"
)

@@ -148,7 +149,11 @@ func (o *PruneOptions) Complete(whitelistFile, blacklistFile, configFile string,
return err
}

userClient, err := f.OpenshiftInternalUserClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
userClient, err := userclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
7 changes: 6 additions & 1 deletion pkg/oc/admin/groups/sync/cli/sync.go
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ import (
"github.com/openshift/origin/pkg/oc/admin/groups/sync/interfaces"
"github.com/openshift/origin/pkg/oc/admin/groups/sync/syncerror"
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
userclientinternal "github.com/openshift/origin/pkg/user/generated/internalclientset"
usertypedclient "github.com/openshift/origin/pkg/user/generated/internalclientset/typed/user/internalversion"
)

@@ -221,7 +222,11 @@ func (o *SyncOptions) Complete(typeArg, whitelistFile, blacklistFile, configFile
}
}

userClient, err := f.OpenshiftInternalUserClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
userClient, err := userclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
10 changes: 8 additions & 2 deletions pkg/oc/admin/image/verify-signature.go
Original file line number Diff line number Diff line change
@@ -23,8 +23,10 @@ import (
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"

imageapi "github.com/openshift/origin/pkg/image/apis/image"
imageclientinternal "github.com/openshift/origin/pkg/image/generated/internalclientset"
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset/typed/image/internalversion"
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
userclientinternal "github.com/openshift/origin/pkg/user/generated/internalclientset"
)

var (
@@ -147,13 +149,17 @@ func (o *VerifyImageSignatureOptions) Complete(f *clientcmd.Factory, cmd *cobra.
return fmt.Errorf("unable to read --public-key: %v", err)
}
}
imageClient, err := f.OpenshiftInternalImageClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
imageClient, err := imageclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
o.ImageClient = imageClient.Image()

userClient, err := f.OpenshiftInternalUserClient()
userClient, err := userclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
7 changes: 6 additions & 1 deletion pkg/oc/admin/migrate/images/imagerefs.go
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import (
"github.com/openshift/origin/pkg/oc/admin/migrate"

imageapi "github.com/openshift/origin/pkg/image/apis/image"
imageclientinternal "github.com/openshift/origin/pkg/image/generated/internalclientset"
imagetypedclient "github.com/openshift/origin/pkg/image/generated/internalclientset/typed/image/internalversion"
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
)
@@ -131,7 +132,11 @@ func (o *MigrateImageReferenceOptions) Complete(f *clientcmd.Factory, c *cobra.C
return err
}

imageClient, err := f.OpenshiftInternalImageClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
imageClient, err := imageclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
10 changes: 7 additions & 3 deletions pkg/oc/admin/network/project_options.go
Original file line number Diff line number Diff line change
@@ -22,14 +22,14 @@ import (

"github.com/openshift/origin/pkg/network"
networkapi "github.com/openshift/origin/pkg/network/apis/network"
networkclient "github.com/openshift/origin/pkg/network/generated/internalclientset"
networkclientinternal "github.com/openshift/origin/pkg/network/generated/internalclientset"
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
projectapi "github.com/openshift/origin/pkg/project/apis/project"
)

type ProjectOptions struct {
DefaultNamespace string
Oclient networkclient.Interface
Oclient networkclientinternal.Interface
Kclient kclientset.Interface
Out io.Writer

@@ -53,7 +53,11 @@ func (p *ProjectOptions) Complete(f *clientcmd.Factory, c *cobra.Command, args [
if err != nil {
return err
}
networkClient, err := f.OpenshiftInternalNetworkClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
networkClient, err := networkclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
8 changes: 6 additions & 2 deletions pkg/oc/admin/policy/cani.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import (
"k8s.io/kubernetes/pkg/printers"

authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
authorizationclientinternal "github.com/openshift/origin/pkg/authorization/generated/internalclientset"
oauthorizationtypedclient "github.com/openshift/origin/pkg/authorization/generated/internalclientset/typed/authorization/internalversion"
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
)
@@ -120,8 +121,11 @@ func (o *canIOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, args []
}
}

var err error
authorizationClient, err := f.OpenshiftInternalAuthorizationClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
authorizationClient, err := authorizationclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
13 changes: 11 additions & 2 deletions pkg/oc/admin/policy/modify_roles.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ import (
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"

authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
authorizationclientinternal "github.com/openshift/origin/pkg/authorization/generated/internalclientset"
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
)

@@ -340,7 +341,11 @@ func (o *RoleModificationOptions) CompleteUserWithSA(f *clientcmd.Factory, cmd *
}
}

authorizationClient, err := f.OpenshiftInternalAuthorizationClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
authorizationClient, err := authorizationclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
@@ -380,7 +385,11 @@ func (o *RoleModificationOptions) Complete(f *clientcmd.Factory, cmd *cobra.Comm

o.Targets = *target

authorizationClient, err := f.OpenshiftInternalAuthorizationClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
authorizationClient, err := authorizationclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
13 changes: 11 additions & 2 deletions pkg/oc/admin/policy/modify_scc.go
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ import (

authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
securityclientinternal "github.com/openshift/origin/pkg/security/generated/internalclientset"
securitytypedclient "github.com/openshift/origin/pkg/security/generated/internalclientset/typed/security/internalversion"
)

@@ -168,7 +169,11 @@ func (o *SCCModificationOptions) CompleteUsers(f *clientcmd.Factory, cmd *cobra.
return kcmdutil.PrintObject(cmd, obj, out)
}

securityClient, err := f.OpenshiftInternalSecurityClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
securityClient, err := securityclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
@@ -204,7 +209,11 @@ func (o *SCCModificationOptions) CompleteGroups(f *clientcmd.Factory, cmd *cobra

o.DryRun = kcmdutil.GetFlagBool(cmd, "dry-run")

securityClient, err := f.OpenshiftInternalSecurityClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
securityClient, err := securityclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
7 changes: 6 additions & 1 deletion pkg/oc/admin/policy/reconcile_clusterrolebindings.go
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import (
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"

authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
authorizationclientinternal "github.com/openshift/origin/pkg/authorization/generated/internalclientset"
authorizationtypedclient "github.com/openshift/origin/pkg/authorization/generated/internalclientset/typed/authorization/internalversion"
"github.com/openshift/origin/pkg/authorization/registry/util"
authorizationutil "github.com/openshift/origin/pkg/authorization/util"
@@ -119,7 +120,11 @@ func NewCmdReconcileClusterRoleBindings(name, fullName string, f *clientcmd.Fact
}

func (o *ReconcileClusterRoleBindingsOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, args []string, excludeUsers, excludeGroups []string) error {
authorizationClient, err := f.OpenshiftInternalAuthorizationClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
authorizationClient, err := authorizationclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
7 changes: 6 additions & 1 deletion pkg/oc/admin/policy/reconcile_clusterroles.go
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ import (
rbacregistryvalidation "k8s.io/kubernetes/pkg/registry/rbac/validation"

authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
authorizationclientinternal "github.com/openshift/origin/pkg/authorization/generated/internalclientset"
authorizationtypedclient "github.com/openshift/origin/pkg/authorization/generated/internalclientset/typed/authorization/internalversion"
"github.com/openshift/origin/pkg/authorization/registry/util"
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
@@ -113,7 +114,11 @@ func NewCmdReconcileClusterRoles(name, fullName string, f *clientcmd.Factory, ou
}

func (o *ReconcileClusterRolesOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, args []string) error {
authorizationClient, err := f.OpenshiftInternalAuthorizationClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
authorizationClient, err := authorizationclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
7 changes: 6 additions & 1 deletion pkg/oc/admin/policy/reconcile_sccs.go
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ import (
cmdutil "github.com/openshift/origin/pkg/cmd/util"
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
securityapi "github.com/openshift/origin/pkg/security/apis/security"
securityclientinternal "github.com/openshift/origin/pkg/security/generated/internalclientset"
securitytypedclient "github.com/openshift/origin/pkg/security/generated/internalclientset/typed/security/internalversion"
)

@@ -120,7 +121,11 @@ func (o *ReconcileSCCOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory,
if err != nil {
return err
}
securityClient, err := f.OpenshiftInternalSecurityClient()
clientConfig, err := f.ClientConfig()
if err != nil {
return err
}
securityClient, err := securityclientinternal.NewForConfig(clientConfig)
if err != nil {
return err
}
Loading