1616 secretData = []byte ("this is very secret" )
1717
1818 cp = & controlPlane {
19- configMaps : v1.ConfigMapList {},
19+ configMaps : v1.ConfigMapList {
20+ Items : []v1.ConfigMap {{
21+ ObjectMeta : metav1.ObjectMeta {
22+ Name : "kube-apiserver" ,
23+ Namespace : "kube-system" ,
24+ },
25+ Data : map [string ]string {"key" : "value" },
26+ }},
27+ },
2028 daemonSets : v1beta1.DaemonSetList {
2129 Items : []v1beta1.DaemonSet {{
2230 ObjectMeta : metav1.ObjectMeta {
@@ -168,6 +176,10 @@ func TestFixUpBootstrapPods(t *testing.T) {
168176 Name : "ssl-certs-host" ,
169177 MountPath : "/etc/ssl/certs" ,
170178 ReadOnly : true ,
179+ }, {
180+ Name : "configs" ,
181+ MountPath : "/etc/kubernetes/config-maps" ,
182+ ReadOnly : true ,
171183 }, {
172184 Name : "secrets" ,
173185 MountPath : "/etc/kubernetes/secrets" ,
@@ -177,6 +189,9 @@ func TestFixUpBootstrapPods(t *testing.T) {
177189 Volumes : []v1.Volume {{
178190 Name : "ssl-certs-host" ,
179191 VolumeSource : v1.VolumeSource {HostPath : & v1.HostPathVolumeSource {Path : "/usr/share/ca-certificates" }},
192+ }, {
193+ Name : "configs" ,
194+ VolumeSource : v1.VolumeSource {ConfigMap : & v1.ConfigMapVolumeSource {LocalObjectReference : v1.LocalObjectReference {Name : "kube-apiserver" }}},
180195 }, {
181196 Name : "secrets" ,
182197 VolumeSource : v1.VolumeSource {Secret : & v1.SecretVolumeSource {SecretName : "kube-apiserver" }},
@@ -217,6 +232,10 @@ func TestFixUpBootstrapPods(t *testing.T) {
217232 Name : "ssl-certs-host" ,
218233 MountPath : "/etc/ssl/certs" ,
219234 ReadOnly : true ,
235+ }, {
236+ Name : "configs" ,
237+ MountPath : "/etc/kubernetes/config-maps" ,
238+ ReadOnly : true ,
220239 }, {
221240 Name : "secrets" ,
222241 MountPath : "/etc/kubernetes/secrets" ,
@@ -226,9 +245,12 @@ func TestFixUpBootstrapPods(t *testing.T) {
226245 Volumes : []v1.Volume {{
227246 Name : "ssl-certs-host" ,
228247 VolumeSource : v1.VolumeSource {HostPath : & v1.HostPathVolumeSource {Path : "/usr/share/ca-certificates" }},
248+ }, {
249+ Name : "configs" ,
250+ VolumeSource : v1.VolumeSource {HostPath : & v1.HostPathVolumeSource {Path : "/etc/kubernetes/bootstrap-secrets/config-maps/kube-apiserver" }},
229251 }, {
230252 Name : "secrets" ,
231- VolumeSource : v1.VolumeSource {HostPath : & v1.HostPathVolumeSource {Path : "/etc/kubernetes/bootstrap-secrets/kube-apiserver" }},
253+ VolumeSource : v1.VolumeSource {HostPath : & v1.HostPathVolumeSource {Path : "/etc/kubernetes/bootstrap-secrets/secrets/ kube-apiserver" }},
232254 }, {
233255 Name : "kubeconfig" ,
234256 VolumeSource : v1.VolumeSource {HostPath : & v1.HostPathVolumeSource {Path : "/etc/kubernetes/kubeconfig" }},
@@ -260,32 +282,47 @@ func TestFixUpBootstrapPods(t *testing.T) {
260282 }},
261283 },
262284 }}
263- wantSecrets := map [string ]struct {}{"kube-apiserver" : {}}
264- gotSecrets , err := fixUpBootstrapPods (pods )
265- if err != nil || ! reflect .DeepEqual (gotSecrets , wantSecrets ) {
266- t .Errorf ("fixUpBootstrapPods(%v) = %v, %v, want: %v, %v" , pods , gotSecrets , err , wantSecrets , nil )
285+ wantConfigMaps := map [string ]string {"kube-apiserver" : "/etc/kubernetes/bootstrap-secrets/config-maps/kube-apiserver" }
286+ wantSecrets := map [string ]string {"kube-apiserver" : "/etc/kubernetes/bootstrap-secrets/secrets/kube-apiserver" }
287+ gotConfigMaps , gotSecrets := fixUpBootstrapPods (pods )
288+ if ! reflect .DeepEqual (gotSecrets , wantSecrets ) || ! reflect .DeepEqual (gotConfigMaps , wantConfigMaps ) {
289+ t .Errorf ("fixUpBootstrapPods(%v) = %v, %v, want: %v, %v" , pods , gotConfigMaps , gotSecrets , wantConfigMaps , wantSecrets )
267290 } else if ! reflect .DeepEqual (pods , wantPods ) {
268291 t .Errorf ("fixUpBootstrapPods(%v) = %v, want: %v" , pods , pods , wantPods )
269292 }
270293}
271294
295+ func TestOutputConfigMaps (t * testing.T ) {
296+ requiredSecrets := map [string ]string {"kube-apiserver" : "tls/kube-apiserver" }
297+ want := asset.Assets {{
298+ Name : "tls/kube-apiserver/apiserver.crt" ,
299+ Data : secretData ,
300+ }}
301+ if got , err := outputBootstrapSecrets (cp .secrets , requiredSecrets ); err != nil {
302+ t .Errorf ("outputBootstrapSecrets(%v, %v) = %v, want: nil" , cp .secrets .Items , requiredSecrets , err )
303+ } else if ! reflect .DeepEqual (got , want ) {
304+ t .Errorf ("outputBootstrapSecrets(%v, %v) = %v, want: %v" , cp .secrets .Items , requiredSecrets , got , want )
305+ }
306+ }
307+
272308func TestOutputBootstrapSecrets (t * testing.T ) {
273- requiredSecrets := map [string ]struct {}{ "kube-apiserver" : {} }
309+ requiredSecrets := map [string ]string { "kube-apiserver" : "tls/kube-apiserver" }
274310 want := asset.Assets {{
275311 Name : "tls/kube-apiserver/apiserver.crt" ,
276312 Data : secretData ,
277313 }}
278- if got , err := outputBootstrapSecrets (cp .secrets . Items , requiredSecrets ); err != nil {
314+ if got , err := outputBootstrapSecrets (cp .secrets , requiredSecrets ); err != nil {
279315 t .Errorf ("outputBootstrapSecrets(%v, %v) = %v, want: nil" , cp .secrets .Items , requiredSecrets , err )
280316 } else if ! reflect .DeepEqual (got , want ) {
281317 t .Errorf ("outputBootstrapSecrets(%v, %v) = %v, want: %v" , cp .secrets .Items , requiredSecrets , got , want )
282318 }
283319}
284320
285- func TestOutputBootstrapSecretsMissing (t * testing.T ) {
286- requiredSecrets := map [string ]struct {}{"missing-secret" : {}}
287- if as , err := outputBootstrapSecrets (cp .secrets .Items , requiredSecrets ); err == nil {
288- t .Errorf ("outputBootstrapSecrets(%v, %v) = %v, %v, want: nil, non-nil" , cp .secrets .Items , requiredSecrets , as , err )
321+ func TestOutputKeyValueDataKeyMissing (t * testing.T ) {
322+ objList := & v1.SecretList {}
323+ requiredObjs := map [string ]string {"missing-key" : "some-path" }
324+ if as , err := outputKeyValueData (objList , requiredObjs , func (obj runtime.Object ) map [string ][]byte { return obj .(* v1.Secret ).Data }); err == nil {
325+ t .Errorf ("outputKeyValueData(%v, %v) = %v, %v, want: nil, non-nil" , objList , requiredObjs , as , err )
289326 }
290327}
291328
0 commit comments