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
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
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
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/oc/admin/groups/changemembership.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/oc/admin/groups/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/oc/admin/groups/sync/cli/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/oc/admin/groups/sync/cli/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/oc/admin/image/verify-signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/oc/admin/migrate/images/imagerefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/oc/admin/network/project_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/oc/admin/policy/cani.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/oc/admin/policy/modify_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/oc/admin/policy/modify_scc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/oc/admin/policy/reconcile_clusterrolebindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/oc/admin/policy/reconcile_clusterroles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/oc/admin/policy/reconcile_sccs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
Loading