mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	allocate map if Labels is not initialized
This commit is contained in:
		@@ -156,6 +156,10 @@ func labelFunc(obj runtime.Object, overwrite bool, resourceVersion string, label
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if meta.Labels == nil {
 | 
				
			||||||
 | 
							meta.Labels = make(map[string]string)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for key, value := range labels {
 | 
						for key, value := range labels {
 | 
				
			||||||
		meta.Labels[key] = value
 | 
							meta.Labels[key] = value
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -230,6 +230,17 @@ func TestLabelFunc(t *testing.T) {
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								obj: &api.Pod{
 | 
				
			||||||
 | 
									ObjectMeta: api.ObjectMeta{},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								labels: map[string]string{"a": "b"},
 | 
				
			||||||
 | 
								expected: &api.Pod{
 | 
				
			||||||
 | 
									ObjectMeta: api.ObjectMeta{
 | 
				
			||||||
 | 
										Labels: map[string]string{"a": "b"},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, test := range tests {
 | 
						for _, test := range tests {
 | 
				
			||||||
		out, err := labelFunc(test.obj, test.overwrite, test.version, test.labels, test.remove)
 | 
							out, err := labelFunc(test.obj, test.overwrite, test.version, test.labels, test.remove)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user