mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #282 from jjhuff/allow_empty_manifest_list
Allow empty lists when polling manifests via http
This commit is contained in:
commit
39065d3b7b
@ -490,10 +490,7 @@ func (kl *Kubelet) extractFromHTTP(url string, updateChannel chan<- manifestUpda
|
||||
// We're not sure if the person reading the logs is going to care about the single or
|
||||
// multiple manifest unmarshalling attempt, so we need to put both in the logs, as is
|
||||
// done at the end. Hence not returning early here.
|
||||
if multiErr == nil && len(manifests) == 0 {
|
||||
multiErr = fmt.Errorf("no elements in ContainerManifest array")
|
||||
}
|
||||
if multiErr == nil && manifests[0].Version == "" {
|
||||
if multiErr == nil && len(manifests) > 0 && manifests[0].Version == "" {
|
||||
multiErr = fmt.Errorf("got blank version field")
|
||||
}
|
||||
if multiErr == nil {
|
||||
|
@ -784,6 +784,42 @@ func TestExtractFromHttpMultiple(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractFromHttpEmptyArray(t *testing.T) {
|
||||
kubelet := Kubelet{}
|
||||
updateChannel := make(chan manifestUpdate)
|
||||
reader := startReading(updateChannel)
|
||||
|
||||
manifests := []api.ContainerManifest{}
|
||||
data, err := json.Marshal(manifests)
|
||||
if err != nil {
|
||||
t.Fatalf("Some weird json problem: %v", err)
|
||||
}
|
||||
|
||||
t.Logf("Serving: %v", string(data))
|
||||
|
||||
fakeHandler := util.FakeHandler{
|
||||
StatusCode: 200,
|
||||
ResponseBody: string(data),
|
||||
}
|
||||
testServer := httptest.NewServer(&fakeHandler)
|
||||
|
||||
err = kubelet.extractFromHTTP(testServer.URL, updateChannel)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %#v", err)
|
||||
}
|
||||
close(updateChannel)
|
||||
|
||||
read := reader.GetList()
|
||||
|
||||
if len(read) != 1 {
|
||||
t.Errorf("Unexpected list: %#v", read)
|
||||
return
|
||||
}
|
||||
if len(read[0]) != 0 {
|
||||
t.Errorf("Unexpected manifests: %#v", read[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestWatchEtcd(t *testing.T) {
|
||||
watchChannel := make(chan *etcd.Response)
|
||||
updateChannel := make(chan manifestUpdate)
|
||||
|
Loading…
Reference in New Issue
Block a user