yangwwei commented on a change in pull request #239:
URL:
https://github.com/apache/incubator-yunikorn-k8shim/pull/239#discussion_r592184225
##########
File path: pkg/cache/placeholder.go
##########
@@ -40,14 +40,14 @@ func newPlaceholder(placeholderName string, app
*Application, taskGroup v1alpha1
ObjectMeta: metav1.ObjectMeta{
Name: placeholderName,
Namespace: app.tags[constants.AppTagNamespace],
- Labels: map[string]string{
+ Labels: mergeMaps(map[string]string{
constants.LabelApplicationID:
app.GetApplicationID(),
constants.LabelQueueName: app.GetQueue(),
- },
- Annotations: map[string]string{
+ }, taskGroup.Labels),
+ Annotations: mergeMaps(map[string]string{
constants.AnnotationPlaceholderFlag: "true",
constants.AnnotationTaskGroupName:
taskGroup.Name,
- },
+ }, taskGroup.Annotations),
Review comment:
good point, these values are needed, we should not allow overwrite.
I've switched around the argument to make sure they are always set.
##########
File path: pkg/cache/placeholder.go
##########
@@ -40,14 +40,14 @@ func newPlaceholder(placeholderName string, app
*Application, taskGroup v1alpha1
ObjectMeta: metav1.ObjectMeta{
Name: placeholderName,
Namespace: app.tags[constants.AppTagNamespace],
- Labels: map[string]string{
+ Labels: mergeMaps(map[string]string{
constants.LabelApplicationID:
app.GetApplicationID(),
constants.LabelQueueName: app.GetQueue(),
- },
- Annotations: map[string]string{
+ }, taskGroup.Labels),
Review comment:
Fixed
##########
File path: pkg/cache/placeholder_test.go
##########
@@ -68,6 +68,82 @@ func TestNewPlaceholder(t *testing.T) {
assert.Equal(t, holder.String(), "appID: app01, taskGroup:
test-group-1, podName: test/ph-name")
}
+func TestNewPlaceholderWithLabelsAndAnnotations(t *testing.T) {
+ const (
+ appID = "app01"
+ queue = "root.default"
+ namespace = "test"
+ )
+ mockedSchedulerAPI := newMockSchedulerAPI()
+ app := NewApplication(appID, queue,
+ "bob", map[string]string{constants.AppTagNamespace: namespace},
mockedSchedulerAPI)
+ app.setTaskGroups([]v1alpha1.TaskGroup{
+ {
+ Name: "test-group-1",
+ MinMember: 10,
+ MinResource: map[string]resource.Quantity{
+ "cpu": resource.MustParse("500m"),
+ "memory": resource.MustParse("1024M"),
+ },
+ Labels: map[string]string{
+ "labelKey0" : "labelKeyValue0",
+ "labelKey1" : "labelKeyValue1",
+ },
+ Annotations: map[string]string{
+ "annotationKey0" : "annotationValue0",
+ "annotationKey1" : "annotationValue1",
+ "annotationKey2" : "annotationValue2",
+ },
+ },
+ })
+
+ holder := newPlaceholder("ph-name", app, app.taskGroups[0])
+ assert.Equal(t, len(holder.pod.Labels), 4)
+ assert.Equal(t, len(holder.pod.Annotations), 5)
+ assert.Equal(t, holder.pod.Labels["labelKey0"], "labelKeyValue0")
+ assert.Equal(t, holder.pod.Labels["labelKey1"], "labelKeyValue1")
+ assert.Equal(t, holder.pod.Annotations["annotationKey0"],
"annotationValue0")
+ assert.Equal(t, holder.pod.Annotations["annotationKey1"],
"annotationValue1")
+ assert.Equal(t, holder.pod.Annotations["annotationKey2"],
"annotationValue2")
+}
+
+func TestMergeMaps(t *testing.T) {
+ result := mergeMaps(nil, nil)
+ assert.Assert(t, result != nil)
+ assert.Equal(t, len(result), 0)
Review comment:
Fixed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]