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

Follow-up of #70950: Duplicated versioned client in describer #71104

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 14 additions & 20 deletions pkg/kubectl/describe/versioned/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,6 @@ func describerMap(clientConfig *rest.Config) (map[schema.GroupKind]describe.Desc
if err != nil {
return nil, err
}
externalclient, err := clientset.NewForConfig(clientConfig)
if err != nil {
return nil, err
}

m := map[schema.GroupKind]describe.Describer{
{Group: corev1.GroupName, Kind: "Pod"}: &PodDescriber{c},
Expand All @@ -175,21 +171,21 @@ func describerMap(clientConfig *rest.Config) (map[schema.GroupKind]describe.Desc
{Group: extensionsv1beta1.GroupName, Kind: "PodSecurityPolicy"}: &PodSecurityPolicyDescriber{c},
{Group: autoscalingv2beta2.GroupName, Kind: "HorizontalPodAutoscaler"}: &HorizontalPodAutoscalerDescriber{c},
{Group: extensionsv1beta1.GroupName, Kind: "DaemonSet"}: &DaemonSetDescriber{c},
{Group: extensionsv1beta1.GroupName, Kind: "Deployment"}: &DeploymentDescriber{c, externalclient},
{Group: extensionsv1beta1.GroupName, Kind: "Deployment"}: &DeploymentDescriber{c},
{Group: extensionsv1beta1.GroupName, Kind: "Ingress"}: &IngressDescriber{c},
{Group: batchv1.GroupName, Kind: "Job"}: &JobDescriber{c},
{Group: batchv1.GroupName, Kind: "CronJob"}: &CronJobDescriber{c, externalclient},
{Group: batchv1.GroupName, Kind: "CronJob"}: &CronJobDescriber{c},
{Group: appsv1.GroupName, Kind: "StatefulSet"}: &StatefulSetDescriber{c},
{Group: appsv1.GroupName, Kind: "Deployment"}: &DeploymentDescriber{c, externalclient},
{Group: appsv1.GroupName, Kind: "Deployment"}: &DeploymentDescriber{c},
{Group: appsv1.GroupName, Kind: "DaemonSet"}: &DaemonSetDescriber{c},
{Group: appsv1.GroupName, Kind: "ReplicaSet"}: &ReplicaSetDescriber{c},
{Group: certificatesv1beta1.GroupName, Kind: "CertificateSigningRequest"}: &CertificateSigningRequestDescriber{c},
{Group: storagev1.GroupName, Kind: "StorageClass"}: &StorageClassDescriber{c},
{Group: policyv1beta1.GroupName, Kind: "PodDisruptionBudget"}: &PodDisruptionBudgetDescriber{c},
{Group: rbacv1.GroupName, Kind: "Role"}: &RoleDescriber{externalclient},
{Group: rbacv1.GroupName, Kind: "ClusterRole"}: &ClusterRoleDescriber{externalclient},
{Group: rbacv1.GroupName, Kind: "RoleBinding"}: &RoleBindingDescriber{externalclient},
{Group: rbacv1.GroupName, Kind: "ClusterRoleBinding"}: &ClusterRoleBindingDescriber{externalclient},
{Group: rbacv1.GroupName, Kind: "Role"}: &RoleDescriber{c},
{Group: rbacv1.GroupName, Kind: "ClusterRole"}: &ClusterRoleDescriber{c},
{Group: rbacv1.GroupName, Kind: "RoleBinding"}: &RoleBindingDescriber{c},
{Group: rbacv1.GroupName, Kind: "ClusterRoleBinding"}: &ClusterRoleBindingDescriber{c},
{Group: networkingv1.GroupName, Kind: "NetworkPolicy"}: &NetworkPolicyDescriber{c},
{Group: schedulingv1beta1.GroupName, Kind: "PriorityClass"}: &PriorityClassDescriber{c},
}
Expand Down Expand Up @@ -2051,19 +2047,18 @@ func describeJob(job *batchv1.Job, events *corev1.EventList) (string, error) {

// CronJobDescriber generates information about a cron job and the jobs it has created.
type CronJobDescriber struct {
clientset.Interface
external clientset.Interface
client clientset.Interface
}

func (d *CronJobDescriber) Describe(namespace, name string, describerSettings describe.DescriberSettings) (string, error) {
cronJob, err := d.external.BatchV1beta1().CronJobs(namespace).Get(name, metav1.GetOptions{})
cronJob, err := d.client.BatchV1beta1().CronJobs(namespace).Get(name, metav1.GetOptions{})
if err != nil {
return "", err
}

var events *corev1.EventList
if describerSettings.ShowEvents {
events, _ = d.Core().Events(namespace).Search(scheme.Scheme, cronJob)
events, _ = d.client.CoreV1().Events(namespace).Search(scheme.Scheme, cronJob)
}
return describeCronJob(cronJob, events)
}
Expand Down Expand Up @@ -3277,12 +3272,11 @@ func DescribeEvents(el *corev1.EventList, w PrefixWriter) {

// DeploymentDescriber generates information about a deployment.
type DeploymentDescriber struct {
clientset.Interface
external clientset.Interface
client clientset.Interface
}

func (dd *DeploymentDescriber) Describe(namespace, name string, describerSettings describe.DescriberSettings) (string, error) {
d, err := dd.external.AppsV1().Deployments(namespace).Get(name, metav1.GetOptions{})
d, err := dd.client.AppsV1().Deployments(namespace).Get(name, metav1.GetOptions{})
if err != nil {
return "", err
}
Expand All @@ -3292,7 +3286,7 @@ func (dd *DeploymentDescriber) Describe(namespace, name string, describerSetting
}
var events *corev1.EventList
if describerSettings.ShowEvents {
events, _ = dd.Core().Events(namespace).Search(scheme.Scheme, d)
events, _ = dd.client.CoreV1().Events(namespace).Search(scheme.Scheme, d)
}

return describeDeployment(d, selector, d, events, dd)
Expand Down Expand Up @@ -3322,7 +3316,7 @@ func describeDeployment(d *appsv1.Deployment, selector labels.Selector, internal
w.Write(LEVEL_1, "%v \t%v\t%v\n", c.Type, c.Status, c.Reason)
}
}
oldRSs, _, newRS, err := deploymentutil.GetAllReplicaSets(d, dd.external.AppsV1())
oldRSs, _, newRS, err := deploymentutil.GetAllReplicaSets(d, dd.client.AppsV1())
if err == nil {
w.Write(LEVEL_0, "OldReplicaSets:\t%s\n", printReplicaSetsByLabels(oldRSs))
var newRSs []*appsv1.ReplicaSet
Expand Down
11 changes: 4 additions & 7 deletions pkg/kubectl/describe/versioned/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
versionedfake "k8s.io/client-go/kubernetes/fake"
"k8s.io/kubernetes/pkg/kubectl/describe"
utilpointer "k8s.io/utils/pointer"
)
Expand Down Expand Up @@ -1482,8 +1481,7 @@ func TestPersistentVolumeClaimDescriber(t *testing.T) {
}

func TestDescribeDeployment(t *testing.T) {
fake := fake.NewSimpleClientset()
versionedFake := versionedfake.NewSimpleClientset(&appsv1.Deployment{
fakeClient := fake.NewSimpleClientset(&appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "foo",
Expand All @@ -1500,7 +1498,7 @@ func TestDescribeDeployment(t *testing.T) {
},
},
})
d := DeploymentDescriber{fake, versionedFake}
d := DeploymentDescriber{fakeClient}
out, err := d.Describe("foo", "bar", describe.DescriberSettings{ShowEvents: true})
if err != nil {
t.Errorf("unexpected error: %v", err)
Expand Down Expand Up @@ -2217,8 +2215,7 @@ func TestDescribeEvents(t *testing.T) {
}, events),
},
"DeploymentDescriber": &DeploymentDescriber{
fake.NewSimpleClientset(events),
versionedfake.NewSimpleClientset(&appsv1.Deployment{
fake.NewSimpleClientset(&appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "foo",
Expand All @@ -2227,7 +2224,7 @@ func TestDescribeEvents(t *testing.T) {
Replicas: utilpointer.Int32Ptr(1),
Selector: &metav1.LabelSelector{},
},
}),
}, events),
},
"EndpointsDescriber": &EndpointsDescriber{
fake.NewSimpleClientset(&corev1.Endpoints{
Expand Down