Skip to content

Commit 4114a9b

Browse files
authored
[kubectl] Enhance describe output for projected volume sources to indicate optional Secret/ConfigMap (kubernetes#129457)
* kubectl: enhance output for projected volume sources to indicate optional secrets * .
1 parent b358cf3 commit 4114a9b

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

staging/src/k8s.io/kubectl/pkg/describe/describe.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,15 +1082,17 @@ func printProjectedVolumeSource(projected *corev1.ProjectedVolumeSource, w Prefi
10821082
w.Write(LEVEL_2, "Type:\tProjected (a volume that contains injected data from multiple sources)\n")
10831083
for _, source := range projected.Sources {
10841084
if source.Secret != nil {
1085+
optional := source.Secret.Optional != nil && *source.Secret.Optional
10851086
w.Write(LEVEL_2, "SecretName:\t%v\n"+
1086-
" SecretOptionalName:\t%v\n",
1087-
source.Secret.Name, source.Secret.Optional)
1087+
" Optional:\t%v\n",
1088+
source.Secret.Name, optional)
10881089
} else if source.DownwardAPI != nil {
10891090
w.Write(LEVEL_2, "DownwardAPI:\ttrue\n")
10901091
} else if source.ConfigMap != nil {
1092+
optional := source.ConfigMap.Optional != nil && *source.ConfigMap.Optional
10911093
w.Write(LEVEL_2, "ConfigMapName:\t%v\n"+
1092-
" ConfigMapOptional:\t%v\n",
1093-
source.ConfigMap.Name, source.ConfigMap.Optional)
1094+
" Optional:\t%v\n",
1095+
source.ConfigMap.Name, optional)
10941096
} else if source.ServiceAccountToken != nil {
10951097
w.Write(LEVEL_2, "TokenExpirationSeconds:\t%d\n",
10961098
*source.ServiceAccountToken.ExpirationSeconds)

staging/src/k8s.io/kubectl/pkg/describe/describe_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6906,3 +6906,43 @@ func TestDescribeSeccompProfile(t *testing.T) {
69066906
})
69076907
}
69086908
}
6909+
6910+
func TestDescribeProjectedVolumesOptionalSecret(t *testing.T) {
6911+
fake := fake.NewSimpleClientset(&corev1.Pod{
6912+
ObjectMeta: metav1.ObjectMeta{
6913+
Name: "bar",
6914+
Namespace: "foo",
6915+
},
6916+
Spec: corev1.PodSpec{
6917+
Volumes: []corev1.Volume{
6918+
{
6919+
Name: "optional-secret",
6920+
VolumeSource: corev1.VolumeSource{
6921+
Projected: &corev1.ProjectedVolumeSource{
6922+
Sources: []corev1.VolumeProjection{
6923+
{
6924+
Secret: &corev1.SecretProjection{
6925+
LocalObjectReference: corev1.LocalObjectReference{
6926+
Name: "optional-secret",
6927+
},
6928+
Optional: ptr.To(true),
6929+
},
6930+
},
6931+
},
6932+
},
6933+
},
6934+
},
6935+
},
6936+
},
6937+
})
6938+
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
6939+
d := PodDescriber{c}
6940+
out, err := d.Describe("foo", "bar", DescriberSettings{ShowEvents: true})
6941+
if err != nil {
6942+
t.Errorf("unexpected error: %v", err)
6943+
}
6944+
expectedOut := "SecretName: optional-secret\n Optional: true"
6945+
if !strings.Contains(out, expectedOut) {
6946+
t.Errorf("expected to find %q in output: %q", expectedOut, out)
6947+
}
6948+
}

0 commit comments

Comments
 (0)