Merge pull request #18818 from mqliang/parseordie

Auto commit by PR queue bot
This commit is contained in:
k8s-merge-robot 2015-12-20 15:08:38 -08:00
commit b97cfd8d8f
4 changed files with 14 additions and 24 deletions

View File

@ -61,7 +61,7 @@ func New(kubeClient client.Interface, resyncPeriod controller.ResyncPeriodFunc,
}, },
} }
terminatedSelector := compileTerminatedPodSelector() terminatedSelector := fields.ParseSelectorOrDie("status.phase!=" + string(api.PodPending) + ",status.phase!=" + string(api.PodRunning) + ",status.phase!=" + string(api.PodUnknown))
gcc.podStore.Store, gcc.podStoreSyncer = framework.NewInformer( gcc.podStore.Store, gcc.podStoreSyncer = framework.NewInformer(
&cache.ListWatch{ &cache.ListWatch{
@ -115,14 +115,6 @@ func (gcc *GCController) gc() {
wait.Wait() wait.Wait()
} }
func compileTerminatedPodSelector() fields.Selector {
selector, err := fields.ParseSelector("status.phase!=" + string(api.PodPending) + ",status.phase!=" + string(api.PodRunning) + ",status.phase!=" + string(api.PodUnknown))
if err != nil {
panic("terminatedSelector must compile: " + err.Error())
}
return selector
}
// byCreationTimestamp sorts a list by creation timestamp, using their names as a tie breaker. // byCreationTimestamp sorts a list by creation timestamp, using their names as a tie breaker.
type byCreationTimestamp []*api.Pod type byCreationTimestamp []*api.Pod

View File

@ -102,7 +102,3 @@ func TestGC(t *testing.T) {
} }
} }
} }
func TestTerminatedPodSelectorCompiles(t *testing.T) {
compileTerminatedPodSelector()
}

View File

@ -181,6 +181,16 @@ func SelectorFromSet(ls Set) Selector {
return andTerm(items) return andTerm(items)
} }
// ParseSelectorOrDie takes a string representing a selector and returns an
// object suitable for matching, or panic when an error occur.
func ParseSelectorOrDie(s string) Selector {
selector, err := ParseSelector(s)
if err != nil {
panic(err)
}
return selector
}
// ParseSelector takes a string representing a selector and returns an // ParseSelector takes a string representing a selector and returns an
// object suitable for matching, or an error. // object suitable for matching, or an error.
func ParseSelector(selector string) (Selector, error) { func ParseSelector(selector string) (Selector, error) {

View File

@ -261,20 +261,12 @@ func (factory *ConfigFactory) createUnassignedPodLW() *cache.ListWatch {
return cache.NewListWatchFromClient(factory.Client, "pods", api.NamespaceAll, fields.Set{client.PodHost: ""}.AsSelector()) return cache.NewListWatchFromClient(factory.Client, "pods", api.NamespaceAll, fields.Set{client.PodHost: ""}.AsSelector())
} }
func parseSelectorOrDie(s string) fields.Selector {
selector, err := fields.ParseSelector(s)
if err != nil {
panic(err)
}
return selector
}
// Returns a cache.ListWatch that finds all pods that are // Returns a cache.ListWatch that finds all pods that are
// already scheduled. // already scheduled.
// TODO: return a ListerWatcher interface instead? // TODO: return a ListerWatcher interface instead?
func (factory *ConfigFactory) createAssignedPodLW() *cache.ListWatch { func (factory *ConfigFactory) createAssignedPodLW() *cache.ListWatch {
return cache.NewListWatchFromClient(factory.Client, "pods", api.NamespaceAll, return cache.NewListWatchFromClient(factory.Client, "pods", api.NamespaceAll,
parseSelectorOrDie(client.PodHost+"!=")) fields.ParseSelectorOrDie(client.PodHost+"!="))
} }
// createNodeLW returns a cache.ListWatch that gets all changes to nodes. // createNodeLW returns a cache.ListWatch that gets all changes to nodes.
@ -286,12 +278,12 @@ func (factory *ConfigFactory) createNodeLW() *cache.ListWatch {
// Returns a cache.ListWatch that gets all changes to services. // Returns a cache.ListWatch that gets all changes to services.
func (factory *ConfigFactory) createServiceLW() *cache.ListWatch { func (factory *ConfigFactory) createServiceLW() *cache.ListWatch {
return cache.NewListWatchFromClient(factory.Client, "services", api.NamespaceAll, parseSelectorOrDie("")) return cache.NewListWatchFromClient(factory.Client, "services", api.NamespaceAll, fields.ParseSelectorOrDie(""))
} }
// Returns a cache.ListWatch that gets all changes to controllers. // Returns a cache.ListWatch that gets all changes to controllers.
func (factory *ConfigFactory) createControllerLW() *cache.ListWatch { func (factory *ConfigFactory) createControllerLW() *cache.ListWatch {
return cache.NewListWatchFromClient(factory.Client, "replicationControllers", api.NamespaceAll, parseSelectorOrDie("")) return cache.NewListWatchFromClient(factory.Client, "replicationControllers", api.NamespaceAll, fields.ParseSelectorOrDie(""))
} }
func (factory *ConfigFactory) makeDefaultErrorFunc(backoff *podBackoff, podQueue *cache.FIFO) func(pod *api.Pod, err error) { func (factory *ConfigFactory) makeDefaultErrorFunc(backoff *podBackoff, podQueue *cache.FIFO) func(pod *api.Pod, err error) {