mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 05:21:58 +00:00
[kubectl] Enhance describe output for projected volume sources to indicate optional Secret/ConfigMap (#129457)
* kubectl: enhance output for projected volume sources to indicate optional secrets * .
This commit is contained in:
parent
b358cf3a79
commit
4114a9b4e4
@ -1082,15 +1082,17 @@ func printProjectedVolumeSource(projected *corev1.ProjectedVolumeSource, w Prefi
|
||||
w.Write(LEVEL_2, "Type:\tProjected (a volume that contains injected data from multiple sources)\n")
|
||||
for _, source := range projected.Sources {
|
||||
if source.Secret != nil {
|
||||
optional := source.Secret.Optional != nil && *source.Secret.Optional
|
||||
w.Write(LEVEL_2, "SecretName:\t%v\n"+
|
||||
" SecretOptionalName:\t%v\n",
|
||||
source.Secret.Name, source.Secret.Optional)
|
||||
" Optional:\t%v\n",
|
||||
source.Secret.Name, optional)
|
||||
} else if source.DownwardAPI != nil {
|
||||
w.Write(LEVEL_2, "DownwardAPI:\ttrue\n")
|
||||
} else if source.ConfigMap != nil {
|
||||
optional := source.ConfigMap.Optional != nil && *source.ConfigMap.Optional
|
||||
w.Write(LEVEL_2, "ConfigMapName:\t%v\n"+
|
||||
" ConfigMapOptional:\t%v\n",
|
||||
source.ConfigMap.Name, source.ConfigMap.Optional)
|
||||
" Optional:\t%v\n",
|
||||
source.ConfigMap.Name, optional)
|
||||
} else if source.ServiceAccountToken != nil {
|
||||
w.Write(LEVEL_2, "TokenExpirationSeconds:\t%d\n",
|
||||
*source.ServiceAccountToken.ExpirationSeconds)
|
||||
|
@ -6906,3 +6906,43 @@ func TestDescribeSeccompProfile(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDescribeProjectedVolumesOptionalSecret(t *testing.T) {
|
||||
fake := fake.NewSimpleClientset(&corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "bar",
|
||||
Namespace: "foo",
|
||||
},
|
||||
Spec: corev1.PodSpec{
|
||||
Volumes: []corev1.Volume{
|
||||
{
|
||||
Name: "optional-secret",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Projected: &corev1.ProjectedVolumeSource{
|
||||
Sources: []corev1.VolumeProjection{
|
||||
{
|
||||
Secret: &corev1.SecretProjection{
|
||||
LocalObjectReference: corev1.LocalObjectReference{
|
||||
Name: "optional-secret",
|
||||
},
|
||||
Optional: ptr.To(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
||||
d := PodDescriber{c}
|
||||
out, err := d.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
expectedOut := "SecretName: optional-secret\n Optional: true"
|
||||
if !strings.Contains(out, expectedOut) {
|
||||
t.Errorf("expected to find %q in output: %q", expectedOut, out)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user