mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #42849 from janetkuo/kubectl-describe-controllerRef
Automatic merge from submit-queue In 'kubectl describe', find controllers with ControllerRef, instead of showing the original creator @enisoc @kargakis @kubernetes/sig-apps-pr-reviews @kubernetes/sig-cli-pr-reviews ```release-note In 'kubectl describe', find controllers with ControllerRef, instead of showing the original creator. ```
This commit is contained in:
		@@ -288,7 +288,7 @@ run_pod_tests() {
 | 
				
			|||||||
  kube::test::get_object_jsonpath_assert 'pod/valid-pod' "{$id_field}" 'valid-pod'
 | 
					  kube::test::get_object_jsonpath_assert 'pod/valid-pod' "{$id_field}" 'valid-pod'
 | 
				
			||||||
  kube::test::get_object_jsonpath_assert 'pods/valid-pod' "{$id_field}" 'valid-pod'
 | 
					  kube::test::get_object_jsonpath_assert 'pods/valid-pod' "{$id_field}" 'valid-pod'
 | 
				
			||||||
  # Describe command should print detailed information
 | 
					  # Describe command should print detailed information
 | 
				
			||||||
  kube::test::describe_object_assert pods 'valid-pod' "Name:" "Image:" "Node:" "Labels:" "Status:" "Controllers"
 | 
					  kube::test::describe_object_assert pods 'valid-pod' "Name:" "Image:" "Node:" "Labels:" "Status:"
 | 
				
			||||||
  # Describe command should print events information by default
 | 
					  # Describe command should print events information by default
 | 
				
			||||||
  kube::test::describe_object_events_assert pods 'valid-pod'
 | 
					  kube::test::describe_object_events_assert pods 'valid-pod'
 | 
				
			||||||
  # Describe command should not print events information when show-events=false
 | 
					  # Describe command should not print events information when show-events=false
 | 
				
			||||||
@@ -296,7 +296,7 @@ run_pod_tests() {
 | 
				
			|||||||
  # Describe command should print events information when show-events=true
 | 
					  # Describe command should print events information when show-events=true
 | 
				
			||||||
  kube::test::describe_object_events_assert pods 'valid-pod' true
 | 
					  kube::test::describe_object_events_assert pods 'valid-pod' true
 | 
				
			||||||
  # Describe command (resource only) should print detailed information
 | 
					  # Describe command (resource only) should print detailed information
 | 
				
			||||||
  kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:" "Controllers"
 | 
					  kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # Describe command should print events information by default
 | 
					  # Describe command should print events information by default
 | 
				
			||||||
  kube::test::describe_resource_events_assert pods
 | 
					  kube::test::describe_resource_events_assert pods
 | 
				
			||||||
@@ -1084,6 +1084,8 @@ run_kubectl_run_tests() {
 | 
				
			|||||||
  kubectl run pi --generator=job/v1 "--image=$IMAGE_PERL" --restart=OnFailure -- perl -Mbignum=bpi -wle 'print bpi(20)' "${kube_flags[@]}"
 | 
					  kubectl run pi --generator=job/v1 "--image=$IMAGE_PERL" --restart=OnFailure -- perl -Mbignum=bpi -wle 'print bpi(20)' "${kube_flags[@]}"
 | 
				
			||||||
  # Post-Condition: Job "pi" is created
 | 
					  # Post-Condition: Job "pi" is created
 | 
				
			||||||
  kube::test::get_object_assert jobs "{{range.items}}{{$id_field}}:{{end}}" 'pi:'
 | 
					  kube::test::get_object_assert jobs "{{range.items}}{{$id_field}}:{{end}}" 'pi:'
 | 
				
			||||||
 | 
					  # Describe command (resource only) should print detailed information
 | 
				
			||||||
 | 
					  kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:" "Created By"
 | 
				
			||||||
  # Clean up
 | 
					  # Clean up
 | 
				
			||||||
  kubectl delete jobs pi "${kube_flags[@]}"
 | 
					  kubectl delete jobs pi "${kube_flags[@]}"
 | 
				
			||||||
  # Post-condition: no pods exist.
 | 
					  # Post-condition: no pods exist.
 | 
				
			||||||
@@ -2376,6 +2378,10 @@ run_deployment_tests() {
 | 
				
			|||||||
  kube::test::if_has_string "${output_message}" 'extensions/v1beta1'
 | 
					  kube::test::if_has_string "${output_message}" 'extensions/v1beta1'
 | 
				
			||||||
  output_message=$(kubectl get deployment.apps -o=jsonpath='{.items[0].apiVersion}' 2>&1 "${kube_flags[@]}")
 | 
					  output_message=$(kubectl get deployment.apps -o=jsonpath='{.items[0].apiVersion}' 2>&1 "${kube_flags[@]}")
 | 
				
			||||||
  kube::test::if_has_string "${output_message}" 'apps/v1beta1'
 | 
					  kube::test::if_has_string "${output_message}" 'apps/v1beta1'
 | 
				
			||||||
 | 
					  # Describe command (resource only) should print detailed information
 | 
				
			||||||
 | 
					  kube::test::describe_resource_assert rs "Name:" "Pod Template:" "Labels:" "Selector:" "Controlled By" "Replicas:" "Pods Status:" "Volumes:"
 | 
				
			||||||
 | 
					  # Describe command (resource only) should print detailed information
 | 
				
			||||||
 | 
					  kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:" "Created By" "Controlled By"
 | 
				
			||||||
  # Clean up
 | 
					  # Clean up
 | 
				
			||||||
  kubectl delete deployment test-nginx-apps "${kube_flags[@]}"
 | 
					  kubectl delete deployment test-nginx-apps "${kube_flags[@]}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -2556,6 +2562,8 @@ run_rs_tests() {
 | 
				
			|||||||
  kube::test::describe_resource_events_assert rs false
 | 
					  kube::test::describe_resource_events_assert rs false
 | 
				
			||||||
  # Describe command should print events information when show-events=true
 | 
					  # Describe command should print events information when show-events=true
 | 
				
			||||||
  kube::test::describe_resource_events_assert rs true
 | 
					  kube::test::describe_resource_events_assert rs true
 | 
				
			||||||
 | 
					  # Describe command (resource only) should print detailed information
 | 
				
			||||||
 | 
					  kube::test::describe_resource_assert pods "Name:" "Image:" "Node:" "Labels:" "Status:" "Created By" "Controlled By"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ### Scale replica set frontend with current-replicas and replicas
 | 
					  ### Scale replica set frontend with current-replicas and replicas
 | 
				
			||||||
  # Pre-condition: 3 replicas
 | 
					  # Pre-condition: 3 replicas
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -79,6 +79,7 @@ go_library(
 | 
				
			|||||||
        "//pkg/client/clientset_generated/internalclientset:go_default_library",
 | 
					        "//pkg/client/clientset_generated/internalclientset:go_default_library",
 | 
				
			||||||
        "//pkg/client/clientset_generated/internalclientset/typed/core/internalversion:go_default_library",
 | 
					        "//pkg/client/clientset_generated/internalclientset/typed/core/internalversion:go_default_library",
 | 
				
			||||||
        "//pkg/client/clientset_generated/internalclientset/typed/extensions/internalversion:go_default_library",
 | 
					        "//pkg/client/clientset_generated/internalclientset/typed/extensions/internalversion:go_default_library",
 | 
				
			||||||
 | 
					        "//pkg/controller:go_default_library",
 | 
				
			||||||
        "//pkg/controller/deployment/util:go_default_library",
 | 
					        "//pkg/controller/deployment/util:go_default_library",
 | 
				
			||||||
        "//pkg/fieldpath:go_default_library",
 | 
					        "//pkg/fieldpath:go_default_library",
 | 
				
			||||||
        "//pkg/kubelet/qos:go_default_library",
 | 
					        "//pkg/kubelet/qos:go_default_library",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -63,6 +63,7 @@ import (
 | 
				
			|||||||
	clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
 | 
						clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
 | 
				
			||||||
	coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
 | 
						coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
 | 
				
			||||||
	extensionsclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/extensions/internalversion"
 | 
						extensionsclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/extensions/internalversion"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/controller"
 | 
				
			||||||
	deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
 | 
						deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/fieldpath"
 | 
						"k8s.io/kubernetes/pkg/fieldpath"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/kubelet/qos"
 | 
						"k8s.io/kubernetes/pkg/kubelet/qos"
 | 
				
			||||||
@@ -555,7 +556,12 @@ func describePod(pod *api.Pod, events *api.EventList) (string, error) {
 | 
				
			|||||||
			w.Write(LEVEL_0, "Message:\t%s\n", pod.Status.Message)
 | 
								w.Write(LEVEL_0, "Message:\t%s\n", pod.Status.Message)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		w.Write(LEVEL_0, "IP:\t%s\n", pod.Status.PodIP)
 | 
							w.Write(LEVEL_0, "IP:\t%s\n", pod.Status.PodIP)
 | 
				
			||||||
		w.Write(LEVEL_0, "Controllers:\t%s\n", printControllers(pod.Annotations))
 | 
							if createdBy := printCreator(pod.Annotations); len(createdBy) > 0 {
 | 
				
			||||||
 | 
								w.Write(LEVEL_0, "Created By:\t%s\n", createdBy)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if controlledBy := printController(pod); len(controlledBy) > 0 {
 | 
				
			||||||
 | 
								w.Write(LEVEL_0, "Controlled By:\t%s\n", controlledBy)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if len(pod.Spec.InitContainers) > 0 {
 | 
							if len(pod.Spec.InitContainers) > 0 {
 | 
				
			||||||
			describeContainers("Init Containers", pod.Spec.InitContainers, pod.Status.InitContainerStatuses, EnvValueRetriever(pod), w, "")
 | 
								describeContainers("Init Containers", pod.Spec.InitContainers, pod.Status.InitContainerStatuses, EnvValueRetriever(pod), w, "")
 | 
				
			||||||
@@ -584,7 +590,14 @@ func describePod(pod *api.Pod, events *api.EventList) (string, error) {
 | 
				
			|||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func printControllers(annotation map[string]string) string {
 | 
					func printController(controllee metav1.Object) string {
 | 
				
			||||||
 | 
						if controllerRef := controller.GetControllerOf(controllee); controllerRef != nil {
 | 
				
			||||||
 | 
							return fmt.Sprintf("%s/%s", controllerRef.Kind, controllerRef.Name)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return ""
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func printCreator(annotation map[string]string) string {
 | 
				
			||||||
	value, ok := annotation[api.CreatedByAnnotation]
 | 
						value, ok := annotation[api.CreatedByAnnotation]
 | 
				
			||||||
	if ok {
 | 
						if ok {
 | 
				
			||||||
		var r api.SerializedReference
 | 
							var r api.SerializedReference
 | 
				
			||||||
@@ -593,7 +606,7 @@ func printControllers(annotation map[string]string) string {
 | 
				
			|||||||
			return fmt.Sprintf("%s/%s", r.Reference.Kind, r.Reference.Name)
 | 
								return fmt.Sprintf("%s/%s", r.Reference.Kind, r.Reference.Name)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return "<none>"
 | 
						return ""
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func describeVolumes(volumes []api.Volume, w PrefixWriter, space string) {
 | 
					func describeVolumes(volumes []api.Volume, w PrefixWriter, space string) {
 | 
				
			||||||
@@ -1358,6 +1371,9 @@ func describeReplicaSet(rs *extensions.ReplicaSet, events *api.EventList, runnin
 | 
				
			|||||||
		w.Write(LEVEL_0, "Selector:\t%s\n", metav1.FormatLabelSelector(rs.Spec.Selector))
 | 
							w.Write(LEVEL_0, "Selector:\t%s\n", metav1.FormatLabelSelector(rs.Spec.Selector))
 | 
				
			||||||
		printLabelsMultiline(w, "Labels", rs.Labels)
 | 
							printLabelsMultiline(w, "Labels", rs.Labels)
 | 
				
			||||||
		printAnnotationsMultiline(w, "Annotations", rs.Annotations)
 | 
							printAnnotationsMultiline(w, "Annotations", rs.Annotations)
 | 
				
			||||||
 | 
							if controlledBy := printController(rs); len(controlledBy) > 0 {
 | 
				
			||||||
 | 
								w.Write(LEVEL_0, "Controlled By:\t%s\n", controlledBy)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		w.Write(LEVEL_0, "Replicas:\t%d current / %d desired\n", rs.Status.Replicas, rs.Spec.Replicas)
 | 
							w.Write(LEVEL_0, "Replicas:\t%d current / %d desired\n", rs.Status.Replicas, rs.Spec.Replicas)
 | 
				
			||||||
		w.Write(LEVEL_0, "Pods Status:\t")
 | 
							w.Write(LEVEL_0, "Pods Status:\t")
 | 
				
			||||||
		if getPodErr != nil {
 | 
							if getPodErr != nil {
 | 
				
			||||||
@@ -1401,6 +1417,9 @@ func describeJob(job *batch.Job, events *api.EventList) (string, error) {
 | 
				
			|||||||
		w.Write(LEVEL_0, "Selector:\t%s\n", selector)
 | 
							w.Write(LEVEL_0, "Selector:\t%s\n", selector)
 | 
				
			||||||
		printLabelsMultiline(w, "Labels", job.Labels)
 | 
							printLabelsMultiline(w, "Labels", job.Labels)
 | 
				
			||||||
		printAnnotationsMultiline(w, "Annotations", job.Annotations)
 | 
							printAnnotationsMultiline(w, "Annotations", job.Annotations)
 | 
				
			||||||
 | 
							if createdBy := printCreator(job.Annotations); len(createdBy) > 0 {
 | 
				
			||||||
 | 
								w.Write(LEVEL_0, "Created By:\t%s\n", createdBy)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		w.Write(LEVEL_0, "Parallelism:\t%d\n", *job.Spec.Parallelism)
 | 
							w.Write(LEVEL_0, "Parallelism:\t%d\n", *job.Spec.Parallelism)
 | 
				
			||||||
		if job.Spec.Completions != nil {
 | 
							if job.Spec.Completions != nil {
 | 
				
			||||||
			w.Write(LEVEL_0, "Completions:\t%d\n", *job.Spec.Completions)
 | 
								w.Write(LEVEL_0, "Completions:\t%d\n", *job.Spec.Completions)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -777,7 +777,8 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
 | 
				
			|||||||
					{"Annotations:"},
 | 
										{"Annotations:"},
 | 
				
			||||||
					{"Status:", "Running"},
 | 
										{"Status:", "Running"},
 | 
				
			||||||
					{"IP:"},
 | 
										{"IP:"},
 | 
				
			||||||
					{"Controllers:", "ReplicationController/redis-master"},
 | 
										{"Created By:", "ReplicationController/redis-master"},
 | 
				
			||||||
 | 
										{"Controlled By:", "ReplicationController/redis-master"},
 | 
				
			||||||
					{"Image:", redisImage},
 | 
										{"Image:", redisImage},
 | 
				
			||||||
					{"State:", "Running"},
 | 
										{"State:", "Running"},
 | 
				
			||||||
					{"QoS Class:", "BestEffort"},
 | 
										{"QoS Class:", "BestEffort"},
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user