Skip to content

Commit d5cb67d

Browse files
Merge pull request #19327 from deads2k/cli-23-removeoapi-2
stop injecting special discovery behavior into oc/kubectl
2 parents 87440f4 + e974738 commit d5cb67d

File tree

80 files changed

+824
-560
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+824
-560
lines changed

pkg/oc/admin/diagnostics/diagnostics/client/config_contexts.go

+22-17
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
1414
osclientcmd "github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
15+
projectclientinternal "github.com/openshift/origin/pkg/project/generated/internalclientset"
1516
)
1617

1718
// 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 {
235236

236237
// Actually send a request to see if context has connectivity.
237238
// Note: we cannot reuse factories as they cache the clients, so build new factory for each context.
238-
projectClient, err := osclientcmd.NewFactory(kclientcmd.NewDefaultClientConfig(*d.RawConfig, &kclientcmd.ConfigOverrides{Context: *context})).OpenshiftInternalProjectClient()
239-
// client create now *fails* if cannot connect to server; so, address connectivity errors below
239+
temporaryFactory := osclientcmd.NewFactory(kclientcmd.NewDefaultClientConfig(*d.RawConfig, &kclientcmd.ConfigOverrides{Context: *context}))
240+
clientConfig, err := temporaryFactory.ClientConfig()
240241
if err == nil {
241-
if projects, projerr := projectClient.Project().Projects().List(metav1.ListOptions{}); projerr != nil {
242-
err = projerr
243-
} else { // success!
244-
list := []string{}
245-
for i, project := range projects.Items {
246-
if i > 9 {
247-
list = append(list, "...")
248-
break
242+
projectClient, err := projectclientinternal.NewForConfig(clientConfig)
243+
// client create now *fails* if cannot connect to server; so, address connectivity errors below
244+
if err == nil {
245+
if projects, projerr := projectClient.Project().Projects().List(metav1.ListOptions{}); projerr != nil {
246+
err = projerr
247+
} else { // success!
248+
list := []string{}
249+
for i, project := range projects.Items {
250+
if i > 9 {
251+
list = append(list, "...")
252+
break
253+
}
254+
list = append(list, project.Name)
249255
}
250-
list = append(list, project.Name)
251-
}
252-
if len(list) == 0 {
253-
r.Info("DCli0003", msgText+"Successfully requested project list, but it is empty, so user has no access to anything.")
254-
} else {
255-
r.Info("DCli0004", msgText+fmt.Sprintf("Successfully requested project list; has access to project(s):\n %v", list))
256+
if len(list) == 0 {
257+
r.Info("DCli0003", msgText+"Successfully requested project list, but it is empty, so user has no access to anything.")
258+
} else {
259+
r.Info("DCli0004", msgText+fmt.Sprintf("Successfully requested project list; has access to project(s):\n %v", list))
260+
}
261+
return r
256262
}
257-
return r
258263
}
259264
}
260265

pkg/oc/admin/diagnostics/diagnostics/cluster/network/in_pod/cmd.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"k8s.io/apimachinery/pkg/util/sets"
1212
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
1313

14+
networkclientinternal "github.com/openshift/origin/pkg/network/generated/internalclientset"
1415
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/log"
1516
"github.com/openshift/origin/pkg/oc/admin/diagnostics/diagnostics/types"
1617
"github.com/openshift/origin/pkg/oc/admin/diagnostics/options"
@@ -123,7 +124,11 @@ func (o NetworkPodDiagnosticsOptions) buildNetworkPodDiagnostics() ([]types.Diag
123124
if clientErr != nil {
124125
return nil, clientErr
125126
}
126-
networkClient, err := factory.OpenshiftInternalNetworkClient()
127+
clientConfig, err := factory.ClientConfig()
128+
if err != nil {
129+
return nil, err
130+
}
131+
networkClient, err := networkclientinternal.NewForConfig(clientConfig)
127132
if err != nil {
128133
return nil, err
129134
}

pkg/oc/admin/groups/changemembership.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/spf13/cobra"
1414

1515
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
16+
userclientinternal "github.com/openshift/origin/pkg/user/generated/internalclientset"
1617
usertypedclient "github.com/openshift/origin/pkg/user/generated/internalclientset/typed/user/internalversion"
1718
)
1819

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

105-
userClient, err := f.OpenshiftInternalUserClient()
106+
clientConfig, err := f.ClientConfig()
107+
if err != nil {
108+
return err
109+
}
110+
userClient, err := userclientinternal.NewForConfig(clientConfig)
106111
if err != nil {
107112
return err
108113
}

pkg/oc/admin/groups/new.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
1717
userapi "github.com/openshift/origin/pkg/user/apis/user"
18+
userclientinternal "github.com/openshift/origin/pkg/user/generated/internalclientset"
1819
usertypedclient "github.com/openshift/origin/pkg/user/generated/internalclientset/typed/user/internalversion"
1920
)
2021

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

82-
userClient, err := f.OpenshiftInternalUserClient()
83+
clientConfig, err := f.ClientConfig()
84+
if err != nil {
85+
return err
86+
}
87+
userClient, err := userclientinternal.NewForConfig(clientConfig)
8388
if err != nil {
8489
return err
8590
}

pkg/oc/admin/groups/sync/cli/prune.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/openshift/origin/pkg/oauthserver/ldaputil/ldapclient"
2020
"github.com/openshift/origin/pkg/oc/admin/groups/sync"
2121
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
22+
userclientinternal "github.com/openshift/origin/pkg/user/generated/internalclientset"
2223
usertypedclient "github.com/openshift/origin/pkg/user/generated/internalclientset/typed/user/internalversion"
2324
)
2425

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

151-
userClient, err := f.OpenshiftInternalUserClient()
152+
clientConfig, err := f.ClientConfig()
153+
if err != nil {
154+
return err
155+
}
156+
userClient, err := userclientinternal.NewForConfig(clientConfig)
152157
if err != nil {
153158
return err
154159
}

pkg/oc/admin/groups/sync/cli/sync.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/openshift/origin/pkg/oc/admin/groups/sync/interfaces"
3030
"github.com/openshift/origin/pkg/oc/admin/groups/sync/syncerror"
3131
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
32+
userclientinternal "github.com/openshift/origin/pkg/user/generated/internalclientset"
3233
usertypedclient "github.com/openshift/origin/pkg/user/generated/internalclientset/typed/user/internalversion"
3334
)
3435

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

224-
userClient, err := f.OpenshiftInternalUserClient()
225+
clientConfig, err := f.ClientConfig()
226+
if err != nil {
227+
return err
228+
}
229+
userClient, err := userclientinternal.NewForConfig(clientConfig)
225230
if err != nil {
226231
return err
227232
}

pkg/oc/admin/image/verify-signature.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import (
2323
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
2424

2525
imageapi "github.com/openshift/origin/pkg/image/apis/image"
26+
imageclientinternal "github.com/openshift/origin/pkg/image/generated/internalclientset"
2627
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset/typed/image/internalversion"
2728
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
29+
userclientinternal "github.com/openshift/origin/pkg/user/generated/internalclientset"
2830
)
2931

3032
var (
@@ -147,13 +149,17 @@ func (o *VerifyImageSignatureOptions) Complete(f *clientcmd.Factory, cmd *cobra.
147149
return fmt.Errorf("unable to read --public-key: %v", err)
148150
}
149151
}
150-
imageClient, err := f.OpenshiftInternalImageClient()
152+
clientConfig, err := f.ClientConfig()
153+
if err != nil {
154+
return err
155+
}
156+
imageClient, err := imageclientinternal.NewForConfig(clientConfig)
151157
if err != nil {
152158
return err
153159
}
154160
o.ImageClient = imageClient.Image()
155161

156-
userClient, err := f.OpenshiftInternalUserClient()
162+
userClient, err := userclientinternal.NewForConfig(clientConfig)
157163
if err != nil {
158164
return err
159165
}

pkg/oc/admin/migrate/images/imagerefs.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/openshift/origin/pkg/oc/admin/migrate"
2222

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

134-
imageClient, err := f.OpenshiftInternalImageClient()
135+
clientConfig, err := f.ClientConfig()
136+
if err != nil {
137+
return err
138+
}
139+
imageClient, err := imageclientinternal.NewForConfig(clientConfig)
135140
if err != nil {
136141
return err
137142
}

pkg/oc/admin/network/project_options.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import (
2222

2323
"github.com/openshift/origin/pkg/network"
2424
networkapi "github.com/openshift/origin/pkg/network/apis/network"
25-
networkclient "github.com/openshift/origin/pkg/network/generated/internalclientset"
25+
networkclientinternal "github.com/openshift/origin/pkg/network/generated/internalclientset"
2626
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
2727
projectapi "github.com/openshift/origin/pkg/project/apis/project"
2828
)
2929

3030
type ProjectOptions struct {
3131
DefaultNamespace string
32-
Oclient networkclient.Interface
32+
Oclient networkclientinternal.Interface
3333
Kclient kclientset.Interface
3434
Out io.Writer
3535

@@ -53,7 +53,11 @@ func (p *ProjectOptions) Complete(f *clientcmd.Factory, c *cobra.Command, args [
5353
if err != nil {
5454
return err
5555
}
56-
networkClient, err := f.OpenshiftInternalNetworkClient()
56+
clientConfig, err := f.ClientConfig()
57+
if err != nil {
58+
return err
59+
}
60+
networkClient, err := networkclientinternal.NewForConfig(clientConfig)
5761
if err != nil {
5862
return err
5963
}

pkg/oc/admin/policy/cani.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"k8s.io/kubernetes/pkg/printers"
1919

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

123-
var err error
124-
authorizationClient, err := f.OpenshiftInternalAuthorizationClient()
124+
clientConfig, err := f.ClientConfig()
125+
if err != nil {
126+
return err
127+
}
128+
authorizationClient, err := authorizationclientinternal.NewForConfig(clientConfig)
125129
if err != nil {
126130
return err
127131
}

pkg/oc/admin/policy/modify_roles.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
1818

1919
authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
20+
authorizationclientinternal "github.com/openshift/origin/pkg/authorization/generated/internalclientset"
2021
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
2122
)
2223

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

343-
authorizationClient, err := f.OpenshiftInternalAuthorizationClient()
344+
clientConfig, err := f.ClientConfig()
345+
if err != nil {
346+
return err
347+
}
348+
authorizationClient, err := authorizationclientinternal.NewForConfig(clientConfig)
344349
if err != nil {
345350
return err
346351
}
@@ -380,7 +385,11 @@ func (o *RoleModificationOptions) Complete(f *clientcmd.Factory, cmd *cobra.Comm
380385

381386
o.Targets = *target
382387

383-
authorizationClient, err := f.OpenshiftInternalAuthorizationClient()
388+
clientConfig, err := f.ClientConfig()
389+
if err != nil {
390+
return err
391+
}
392+
authorizationClient, err := authorizationclientinternal.NewForConfig(clientConfig)
384393
if err != nil {
385394
return err
386395
}

pkg/oc/admin/policy/modify_scc.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
1717
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
18+
securityclientinternal "github.com/openshift/origin/pkg/security/generated/internalclientset"
1819
securitytypedclient "github.com/openshift/origin/pkg/security/generated/internalclientset/typed/security/internalversion"
1920
)
2021

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

171-
securityClient, err := f.OpenshiftInternalSecurityClient()
172+
clientConfig, err := f.ClientConfig()
173+
if err != nil {
174+
return err
175+
}
176+
securityClient, err := securityclientinternal.NewForConfig(clientConfig)
172177
if err != nil {
173178
return err
174179
}
@@ -204,7 +209,11 @@ func (o *SCCModificationOptions) CompleteGroups(f *clientcmd.Factory, cmd *cobra
204209

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

207-
securityClient, err := f.OpenshiftInternalSecurityClient()
212+
clientConfig, err := f.ClientConfig()
213+
if err != nil {
214+
return err
215+
}
216+
securityClient, err := securityclientinternal.NewForConfig(clientConfig)
208217
if err != nil {
209218
return err
210219
}

pkg/oc/admin/policy/reconcile_clusterrolebindings.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
2020

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

121122
func (o *ReconcileClusterRoleBindingsOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, args []string, excludeUsers, excludeGroups []string) error {
122-
authorizationClient, err := f.OpenshiftInternalAuthorizationClient()
123+
clientConfig, err := f.ClientConfig()
124+
if err != nil {
125+
return err
126+
}
127+
authorizationClient, err := authorizationclientinternal.NewForConfig(clientConfig)
123128
if err != nil {
124129
return err
125130
}

pkg/oc/admin/policy/reconcile_clusterroles.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
rbacregistryvalidation "k8s.io/kubernetes/pkg/registry/rbac/validation"
1919

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

115116
func (o *ReconcileClusterRolesOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, args []string) error {
116-
authorizationClient, err := f.OpenshiftInternalAuthorizationClient()
117+
clientConfig, err := f.ClientConfig()
118+
if err != nil {
119+
return err
120+
}
121+
authorizationClient, err := authorizationclientinternal.NewForConfig(clientConfig)
117122
if err != nil {
118123
return err
119124
}

pkg/oc/admin/policy/reconcile_sccs.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
cmdutil "github.com/openshift/origin/pkg/cmd/util"
2323
"github.com/openshift/origin/pkg/oc/cli/util/clientcmd"
2424
securityapi "github.com/openshift/origin/pkg/security/apis/security"
25+
securityclientinternal "github.com/openshift/origin/pkg/security/generated/internalclientset"
2526
securitytypedclient "github.com/openshift/origin/pkg/security/generated/internalclientset/typed/security/internalversion"
2627
)
2728

@@ -120,7 +121,11 @@ func (o *ReconcileSCCOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory,
120121
if err != nil {
121122
return err
122123
}
123-
securityClient, err := f.OpenshiftInternalSecurityClient()
124+
clientConfig, err := f.ClientConfig()
125+
if err != nil {
126+
return err
127+
}
128+
securityClient, err := securityclientinternal.NewForConfig(clientConfig)
124129
if err != nil {
125130
return err
126131
}

0 commit comments

Comments
 (0)