Merge pull request #99649 from howardjohn/kubectl/better-default-logs
Improve warnings for default-container Kubernetes-commit: cd8d3c4e792bee7d48cd144df042839758df8197
This commit is contained in:
		
						commit
						b3f4363d68
					
				|  | @ -920,7 +920,7 @@ | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"ImportPath": "k8s.io/api", | 			"ImportPath": "k8s.io/api", | ||||||
| 			"Rev": "c4b19412b7d9" | 			"Rev": "c218b228ac09" | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			"ImportPath": "k8s.io/apimachinery", | 			"ImportPath": "k8s.io/apimachinery", | ||||||
|  |  | ||||||
							
								
								
									
										4
									
								
								go.mod
								
								
								
								
							
							
						
						
									
										4
									
								
								go.mod
								
								
								
								
							|  | @ -33,7 +33,7 @@ require ( | ||||||
| 	github.com/stretchr/testify v1.6.1 | 	github.com/stretchr/testify v1.6.1 | ||||||
| 	golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073 | 	golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073 | ||||||
| 	gopkg.in/yaml.v2 v2.2.8 | 	gopkg.in/yaml.v2 v2.2.8 | ||||||
| 	k8s.io/api v0.0.0-20210303224014-c4b19412b7d9 | 	k8s.io/api v0.0.0-20210304012009-c218b228ac09 | ||||||
| 	k8s.io/apimachinery v0.0.0-20210303224021-086982076e5b | 	k8s.io/apimachinery v0.0.0-20210303224021-086982076e5b | ||||||
| 	k8s.io/cli-runtime v0.0.0-20210304013618-f536d1e57e2c | 	k8s.io/cli-runtime v0.0.0-20210304013618-f536d1e57e2c | ||||||
| 	k8s.io/client-go v0.0.0-20210303092632-a33729487127 | 	k8s.io/client-go v0.0.0-20210303092632-a33729487127 | ||||||
|  | @ -48,7 +48,7 @@ require ( | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| replace ( | replace ( | ||||||
| 	k8s.io/api => k8s.io/api v0.0.0-20210303224014-c4b19412b7d9 | 	k8s.io/api => k8s.io/api v0.0.0-20210304012009-c218b228ac09 | ||||||
| 	k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210303224021-086982076e5b | 	k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210303224021-086982076e5b | ||||||
| 	k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20210304013618-f536d1e57e2c | 	k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20210304013618-f536d1e57e2c | ||||||
| 	k8s.io/client-go => k8s.io/client-go v0.0.0-20210303092632-a33729487127 | 	k8s.io/client-go => k8s.io/client-go v0.0.0-20210303092632-a33729487127 | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								go.sum
								
								
								
								
							
							
						
						
									
										2
									
								
								go.sum
								
								
								
								
							|  | @ -629,7 +629,7 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh | ||||||
| honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= | ||||||
| honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= | honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= | ||||||
| honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= | honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= | ||||||
| k8s.io/api v0.0.0-20210303224014-c4b19412b7d9/go.mod h1:qxh9oDzIeshHqWh3cuMICYK1FYe9LYCg1mIgGu4TFGQ= | k8s.io/api v0.0.0-20210304012009-c218b228ac09/go.mod h1:YspOqQmF4OXdACGAs03nGPxRrWe/nIKAS3Cwch9YyFk= | ||||||
| k8s.io/apimachinery v0.0.0-20210303224021-086982076e5b/go.mod h1:+s3G/nGQJY9oe1CFOXRrb9QkXTIEgTnFtF8GeKZIgOg= | k8s.io/apimachinery v0.0.0-20210303224021-086982076e5b/go.mod h1:+s3G/nGQJY9oe1CFOXRrb9QkXTIEgTnFtF8GeKZIgOg= | ||||||
| k8s.io/cli-runtime v0.0.0-20210304013618-f536d1e57e2c/go.mod h1:TtZMuW66gOQw/UkzFrUR9nnEBaVTQ9Zk7luH6yayEQ8= | k8s.io/cli-runtime v0.0.0-20210304013618-f536d1e57e2c/go.mod h1:TtZMuW66gOQw/UkzFrUR9nnEBaVTQ9Zk7luH6yayEQ8= | ||||||
| k8s.io/client-go v0.0.0-20210303092632-a33729487127/go.mod h1:6J5z3g0yr1utdrepdA0iHThBu/efpfp4kVR65Z3KB4U= | k8s.io/client-go v0.0.0-20210303092632-a33729487127/go.mod h1:6J5z3g0yr1utdrepdA0iHThBu/efpfp4kVR65Z3KB4U= | ||||||
|  |  | ||||||
|  | @ -79,11 +79,15 @@ func logsForObjectWithClient(clientset corev1client.CoreV1Interface, object, opt | ||||||
| 			// container. This gives users ability to preselect the most interesting container in pod.
 | 			// container. This gives users ability to preselect the most interesting container in pod.
 | ||||||
| 			if annotations := t.GetAnnotations(); annotations != nil && len(opts.Container) == 0 { | 			if annotations := t.GetAnnotations(); annotations != nil && len(opts.Container) == 0 { | ||||||
| 				var containerName string | 				var containerName string | ||||||
| 				if len(annotations[defaultLogsContainerAnnotationName]) > 0 { | 				if len(annotations[podutils.DefaultContainerAnnotationName]) > 0 { | ||||||
|  | 					containerName = annotations[podutils.DefaultContainerAnnotationName] | ||||||
|  | 				} else if len(annotations[defaultLogsContainerAnnotationName]) > 0 { | ||||||
|  | 					// Only log deprecation if we have only the old annotation. This allows users to
 | ||||||
|  | 					// set both to support multiple versions of kubectl; if they are setting both
 | ||||||
|  | 					// they must already know it is deprecated, so we don't need to add noisy
 | ||||||
|  | 					// warnings.
 | ||||||
| 					containerName = annotations[defaultLogsContainerAnnotationName] | 					containerName = annotations[defaultLogsContainerAnnotationName] | ||||||
| 					fmt.Fprintf(os.Stderr, "Using deprecated annotation `kubectl.kubernetes.io/default-logs-container` in pod/%v. Please use `kubectl.kubernetes.io/default-container` instead\n", t.Name) | 					fmt.Fprintf(os.Stderr, "Using deprecated annotation `kubectl.kubernetes.io/default-logs-container` in pod/%v. Please use `kubectl.kubernetes.io/default-container` instead\n", t.Name) | ||||||
| 				} else if len(annotations[podutils.DefaultContainerAnnotationName]) > 0 { |  | ||||||
| 					containerName = annotations[podutils.DefaultContainerAnnotationName] |  | ||||||
| 				} | 				} | ||||||
| 				if len(containerName) > 0 { | 				if len(containerName) > 0 { | ||||||
| 					if exists, _ := podutils.FindContainerByName(t, containerName); exists != nil { | 					if exists, _ := podutils.FindContainerByName(t, containerName); exists != nil { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue