support fieldSelector spec.hostNetwork
Signed-off-by: Yan Zhu <hackzhuyan@gmail.com>
This commit is contained in:
		@@ -41,6 +41,7 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
 | 
				
			|||||||
				"spec.restartPolicy",
 | 
									"spec.restartPolicy",
 | 
				
			||||||
				"spec.schedulerName",
 | 
									"spec.schedulerName",
 | 
				
			||||||
				"spec.serviceAccountName",
 | 
									"spec.serviceAccountName",
 | 
				
			||||||
 | 
									"spec.hostNetwork",
 | 
				
			||||||
				"status.phase",
 | 
									"status.phase",
 | 
				
			||||||
				"status.podIP",
 | 
									"status.podIP",
 | 
				
			||||||
				"status.podIPs",
 | 
									"status.podIPs",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -303,11 +303,17 @@ func ToSelectableFields(pod *api.Pod) fields.Set {
 | 
				
			|||||||
	// amount of allocations needed to create the fields.Set. If you add any
 | 
						// amount of allocations needed to create the fields.Set. If you add any
 | 
				
			||||||
	// field here or the number of object-meta related fields changes, this should
 | 
						// field here or the number of object-meta related fields changes, this should
 | 
				
			||||||
	// be adjusted.
 | 
						// be adjusted.
 | 
				
			||||||
	podSpecificFieldsSet := make(fields.Set, 9)
 | 
						podSpecificFieldsSet := make(fields.Set, 10)
 | 
				
			||||||
	podSpecificFieldsSet["spec.nodeName"] = pod.Spec.NodeName
 | 
						podSpecificFieldsSet["spec.nodeName"] = pod.Spec.NodeName
 | 
				
			||||||
	podSpecificFieldsSet["spec.restartPolicy"] = string(pod.Spec.RestartPolicy)
 | 
						podSpecificFieldsSet["spec.restartPolicy"] = string(pod.Spec.RestartPolicy)
 | 
				
			||||||
	podSpecificFieldsSet["spec.schedulerName"] = string(pod.Spec.SchedulerName)
 | 
						podSpecificFieldsSet["spec.schedulerName"] = string(pod.Spec.SchedulerName)
 | 
				
			||||||
	podSpecificFieldsSet["spec.serviceAccountName"] = string(pod.Spec.ServiceAccountName)
 | 
						podSpecificFieldsSet["spec.serviceAccountName"] = string(pod.Spec.ServiceAccountName)
 | 
				
			||||||
 | 
						if pod.Spec.SecurityContext != nil {
 | 
				
			||||||
 | 
							podSpecificFieldsSet["spec.hostNetwork"] = strconv.FormatBool(pod.Spec.SecurityContext.HostNetwork)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							// default to false
 | 
				
			||||||
 | 
							podSpecificFieldsSet["spec.hostNetwork"] = strconv.FormatBool(false)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	podSpecificFieldsSet["status.phase"] = string(pod.Status.Phase)
 | 
						podSpecificFieldsSet["status.phase"] = string(pod.Status.Phase)
 | 
				
			||||||
	// TODO: add podIPs as a downward API value(s) with proper format
 | 
						// TODO: add podIPs as a downward API value(s) with proper format
 | 
				
			||||||
	podIP := ""
 | 
						podIP := ""
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -182,6 +182,53 @@ func TestMatchPod(t *testing.T) {
 | 
				
			|||||||
			fieldSelector: fields.ParseSelectorOrDie("status.podIP=2001:db7::"),
 | 
								fieldSelector: fields.ParseSelectorOrDie("status.podIP=2001:db7::"),
 | 
				
			||||||
			expectMatch:   false,
 | 
								expectMatch:   false,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								in: &api.Pod{
 | 
				
			||||||
 | 
									Spec: api.PodSpec{
 | 
				
			||||||
 | 
										SecurityContext: &api.PodSecurityContext{
 | 
				
			||||||
 | 
											HostNetwork: true,
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								fieldSelector: fields.ParseSelectorOrDie("spec.hostNetwork=true"),
 | 
				
			||||||
 | 
								expectMatch:   true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								in: &api.Pod{
 | 
				
			||||||
 | 
									Spec: api.PodSpec{
 | 
				
			||||||
 | 
										SecurityContext: &api.PodSecurityContext{
 | 
				
			||||||
 | 
											HostNetwork: true,
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								fieldSelector: fields.ParseSelectorOrDie("spec.hostNetwork=false"),
 | 
				
			||||||
 | 
								expectMatch:   false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								in: &api.Pod{
 | 
				
			||||||
 | 
									Spec: api.PodSpec{
 | 
				
			||||||
 | 
										SecurityContext: &api.PodSecurityContext{
 | 
				
			||||||
 | 
											HostNetwork: false,
 | 
				
			||||||
 | 
										},
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								fieldSelector: fields.ParseSelectorOrDie("spec.hostNetwork=false"),
 | 
				
			||||||
 | 
								expectMatch:   true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								in: &api.Pod{
 | 
				
			||||||
 | 
									Spec: api.PodSpec{},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								fieldSelector: fields.ParseSelectorOrDie("spec.hostNetwork=false"),
 | 
				
			||||||
 | 
								expectMatch:   true,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								in: &api.Pod{
 | 
				
			||||||
 | 
									Spec: api.PodSpec{},
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								fieldSelector: fields.ParseSelectorOrDie("spec.hostNetwork=true"),
 | 
				
			||||||
 | 
								expectMatch:   false,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, testCase := range testCases {
 | 
						for _, testCase := range testCases {
 | 
				
			||||||
		m := MatchPod(labels.Everything(), testCase.fieldSelector)
 | 
							m := MatchPod(labels.Everything(), testCase.fieldSelector)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user