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

make 'oc status' compatible with bare kube #1947

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 9 additions & 15 deletions pkg/cli/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
appsv1client "github.com/openshift/client-go/apps/clientset/versioned/typed/apps/v1"
buildv1client "github.com/openshift/client-go/build/clientset/versioned/typed/build/v1"
imagev1client "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1"
projectv1client "github.com/openshift/client-go/project/clientset/versioned/typed/project/v1"
routev1client "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
"github.com/openshift/oc/pkg/helpers/describe"
dotutil "github.com/openshift/oc/pkg/helpers/dot"
Expand Down Expand Up @@ -110,10 +109,6 @@ func (o *StatusOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []
if err != nil {
return err
}
projectClient, err := projectv1client.NewForConfig(clientConfig)
if err != nil {
return err
}
buildClient, err := buildv1client.NewForConfig(clientConfig)
if err != nil {
return err
Expand Down Expand Up @@ -147,7 +142,7 @@ func (o *StatusOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []
if err != nil {
return err
}
_, err = projectClient.Projects().Get(context.TODO(), namespace, metav1.GetOptions{})
_, err = kclientset.CoreV1().Namespaces().Get(context.TODO(), namespace, metav1.GetOptions{})
switch {
case kapierrors.IsForbidden(err), kapierrors.IsNotFound(err):
return fmt.Errorf("you do not have rights to view project %q specified in your config or the project doesn't exist", namespace)
Expand All @@ -166,15 +161,14 @@ func (o *StatusOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []
canRequestProjects, _ := loginutil.CanRequestProjects(clientConfig, o.namespace)

o.describer = &describe.ProjectStatusDescriber{
KubeClient: kclientset,
RESTMapper: restMapper,
ProjectClient: projectClient,
BuildClient: buildClient,
ImageClient: imageClient,
AppsClient: appsClient,
RouteClient: routeClient,
Suggest: o.suggest,
Server: clientConfig.Host,
KubeClient: kclientset,
RESTMapper: restMapper,
BuildClient: buildClient,
ImageClient: imageClient,
AppsClient: appsClient,
RouteClient: routeClient,
Suggest: o.suggest,
Server: clientConfig.Host,

RequestedNamespace: nsFlag,
CurrentNamespace: currentNamespace,
Expand Down
34 changes: 15 additions & 19 deletions pkg/helpers/describe/projectstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ import (
appsv1 "github.com/openshift/api/apps/v1"
buildv1 "github.com/openshift/api/build/v1"
imagev1 "github.com/openshift/api/image/v1"
projectv1 "github.com/openshift/api/project/v1"
routev1 "github.com/openshift/api/route/v1"
appsv1client "github.com/openshift/client-go/apps/clientset/versioned/typed/apps/v1"
buildv1client "github.com/openshift/client-go/build/clientset/versioned/typed/build/v1"
imagev1client "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1"
projectv1client "github.com/openshift/client-go/project/clientset/versioned/typed/project/v1"
routev1client "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
"github.com/openshift/library-go/pkg/apps/appsutil"
deployutil "github.com/openshift/oc/pkg/helpers/deployment"
Expand Down Expand Up @@ -67,13 +65,12 @@ type ProjectStatusDescriber struct {
RESTMapper meta.RESTMapper

// OpenShift clients
ProjectClient projectv1client.ProjectV1Interface
BuildClient buildv1client.BuildV1Interface
ImageClient imagev1client.ImageV1Interface
AppsClient appsv1client.AppsV1Interface
RouteClient routev1client.RouteV1Interface
Server string
Suggest bool
BuildClient buildv1client.BuildV1Interface
ImageClient imagev1client.ImageV1Interface
AppsClient appsv1client.AppsV1Interface
RouteClient routev1client.RouteV1Interface
Server string
Suggest bool

RequestedNamespace string
CurrentNamespace string
Expand Down Expand Up @@ -193,9 +190,9 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
}

allNamespaces := namespace == metav1.NamespaceAll
var project *projectv1.Project
var project *corev1.Namespace
if !allNamespaces {
p, err := d.ProjectClient.Projects().Get(context.TODO(), namespace, metav1.GetOptions{})
p, err := d.KubeClient.CoreV1().Namespaces().Get(context.TODO(), namespace, metav1.GetOptions{})
if err != nil {
// a forbidden error here (without a --namespace value) means that
// the user has not created any projects, and is therefore using a
Expand All @@ -206,7 +203,7 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error
if !kapierrors.IsNotFound(err) {
return "", err
}
p = &projectv1.Project{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
p = &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
}
project = p
f = namespacedFormatter{currentNamespace: namespace}
Expand Down Expand Up @@ -726,20 +723,19 @@ func (f namespacedFormatter) ResourceName(obj interface{}) string {
}
}

func describeProjectAndServer(f formatter, project *projectv1.Project, server string) string {
projectName := project.Name
displayName := project.Annotations[annotations.OpenShiftDisplayName]
func describeProjectAndServer(f formatter, namespace *corev1.Namespace, server string) string {
projectName := namespace.Name
displayName := namespace.Annotations[annotations.OpenShiftDisplayName]
if len(displayName) == 0 {
displayName = project.Annotations["displayName"]
displayName = namespace.Annotations["displayName"]
}
if len(displayName) > 0 && displayName != project.Name {
projectName = fmt.Sprintf("%s (%s)", displayName, project.Name)
if len(displayName) > 0 && displayName != namespace.Name {
projectName = fmt.Sprintf("%s (%s)", displayName, namespace.Name)
}
if len(server) == 0 {
return fmt.Sprintf("In project %s\n", projectName)
}
return fmt.Sprintf("In project %s on server %s\n", projectName, server)

}

func describeAllProjectsOnServer(f formatter, server string) string {
Expand Down
Loading