mirror of https://github.com/k3s-io/k3s
make Registry use Encode
parent
fb991fb84e
commit
2bcb44b6bd
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
package registry
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
|
@ -53,7 +51,6 @@ func (storage *ControllerRegistryStorage) Get(id string) (interface{}, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
controller.Kind = "cluster#replicationController"
|
||||
return controller, err
|
||||
}
|
||||
|
||||
|
@ -63,8 +60,7 @@ func (storage *ControllerRegistryStorage) Delete(id string) (<-chan interface{},
|
|||
|
||||
func (storage *ControllerRegistryStorage) Extract(body []byte) (interface{}, error) {
|
||||
result := api.ReplicationController{}
|
||||
err := json.Unmarshal(body, &result)
|
||||
result.Kind = "cluster#replicationController"
|
||||
err := api.DecodeInto(body, &result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
|
|
|
@ -121,12 +121,10 @@ func TestExtractControllerJson(t *testing.T) {
|
|||
ID: "foo",
|
||||
},
|
||||
}
|
||||
body, err := json.Marshal(controller)
|
||||
body, err := api.Encode(&controller)
|
||||
expectNoError(t, err)
|
||||
controllerOut, err := storage.Extract(body)
|
||||
expectNoError(t, err)
|
||||
// Extract adds a Kind
|
||||
controller.Kind = "cluster#replicationController"
|
||||
if !reflect.DeepEqual(controller, controllerOut) {
|
||||
t.Errorf("Expected %#v, found %#v", controller, controllerOut)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ limitations under the License.
|
|||
package registry
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
@ -73,7 +72,6 @@ func (storage *PodRegistryStorage) List(selector labels.Selector) (interface{},
|
|||
}
|
||||
}
|
||||
|
||||
result.Kind = "cluster#podList"
|
||||
return result, err
|
||||
}
|
||||
|
||||
|
@ -128,7 +126,6 @@ func (storage *PodRegistryStorage) Get(id string) (interface{}, error) {
|
|||
}
|
||||
pod.CurrentState.HostIP = getInstanceIP(storage.cloud, pod.CurrentState.Host)
|
||||
|
||||
pod.Kind = "cluster#pod"
|
||||
return pod, err
|
||||
}
|
||||
|
||||
|
@ -138,8 +135,7 @@ func (storage *PodRegistryStorage) Delete(id string) (<-chan interface{}, error)
|
|||
|
||||
func (storage *PodRegistryStorage) Extract(body []byte) (interface{}, error) {
|
||||
pod := api.Pod{}
|
||||
err := json.Unmarshal(body, &pod)
|
||||
pod.Kind = "cluster#pod"
|
||||
err := api.DecodeInto(body, &pod)
|
||||
return pod, err
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ limitations under the License.
|
|||
package registry
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
@ -102,12 +101,10 @@ func TestExtractJson(t *testing.T) {
|
|||
ID: "foo",
|
||||
},
|
||||
}
|
||||
body, err := json.Marshal(pod)
|
||||
body, err := api.Encode(&pod)
|
||||
expectNoError(t, err)
|
||||
podOut, err := storage.Extract(body)
|
||||
expectNoError(t, err)
|
||||
// Extract adds in a kind
|
||||
pod.Kind = "cluster#pod"
|
||||
if !reflect.DeepEqual(pod, podOut) {
|
||||
t.Errorf("Expected %#v, found %#v", pod, podOut)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||
package registry
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -64,7 +63,6 @@ func (sr *ServiceRegistryStorage) List(selector labels.Selector) (interface{}, e
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list.Kind = "cluster#serviceList"
|
||||
var filtered []api.Service
|
||||
for _, service := range list.Items {
|
||||
if selector.Matches(labels.Set(service.Labels)) {
|
||||
|
@ -80,7 +78,6 @@ func (sr *ServiceRegistryStorage) Get(id string) (interface{}, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
service.Kind = "cluster#service"
|
||||
return service, err
|
||||
}
|
||||
|
||||
|
@ -107,8 +104,7 @@ func (sr *ServiceRegistryStorage) Delete(id string) (<-chan interface{}, error)
|
|||
|
||||
func (sr *ServiceRegistryStorage) Extract(body []byte) (interface{}, error) {
|
||||
var svc api.Service
|
||||
err := json.Unmarshal([]byte(body), &svc)
|
||||
svc.Kind = "cluster#service"
|
||||
err := api.DecodeInto(body, &svc)
|
||||
return svc, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue