mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
Moving Status object to a common package
This commit is contained in:
@@ -37,6 +37,7 @@ import (
|
||||
apierrs "k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
"k8s.io/kubernetes/pkg/api/rest"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
@@ -94,26 +95,26 @@ func newMapper() *meta.DefaultRESTMapper {
|
||||
func addTestTypes() {
|
||||
type ListOptions struct {
|
||||
runtime.Object
|
||||
api.TypeMeta `json:",inline"`
|
||||
LabelSelector string `json:"labels,omitempty"`
|
||||
FieldSelector string `json:"fields,omitempty"`
|
||||
Watch bool `json:"watch,omitempty"`
|
||||
ResourceVersion string `json:"resourceVersion,omitempty"`
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
LabelSelector string `json:"labels,omitempty"`
|
||||
FieldSelector string `json:"fields,omitempty"`
|
||||
Watch bool `json:"watch,omitempty"`
|
||||
ResourceVersion string `json:"resourceVersion,omitempty"`
|
||||
}
|
||||
api.Scheme.AddKnownTypes(testVersion, &Simple{}, &SimpleList{}, &api.Status{}, &ListOptions{}, &api.DeleteOptions{}, &SimpleGetOptions{}, &SimpleRoot{})
|
||||
api.Scheme.AddKnownTypes(testVersion, &Simple{}, &SimpleList{}, &unversioned.Status{}, &ListOptions{}, &api.DeleteOptions{}, &SimpleGetOptions{}, &SimpleRoot{})
|
||||
api.Scheme.AddKnownTypes(testVersion, &api.Pod{})
|
||||
}
|
||||
|
||||
func addNewTestTypes() {
|
||||
type ListOptions struct {
|
||||
runtime.Object
|
||||
api.TypeMeta `json:",inline"`
|
||||
LabelSelector string `json:"labelSelector,omitempty"`
|
||||
FieldSelector string `json:"fieldSelector,omitempty"`
|
||||
Watch bool `json:"watch,omitempty"`
|
||||
ResourceVersion string `json:"resourceVersion,omitempty"`
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
LabelSelector string `json:"labelSelector,omitempty"`
|
||||
FieldSelector string `json:"fieldSelector,omitempty"`
|
||||
Watch bool `json:"watch,omitempty"`
|
||||
ResourceVersion string `json:"resourceVersion,omitempty"`
|
||||
}
|
||||
api.Scheme.AddKnownTypes(newVersion, &Simple{}, &SimpleList{}, &api.Status{}, &ListOptions{}, &api.DeleteOptions{}, &SimpleGetOptions{}, &SimpleRoot{})
|
||||
api.Scheme.AddKnownTypes(newVersion, &Simple{}, &SimpleList{}, &unversioned.Status{}, &ListOptions{}, &api.DeleteOptions{}, &SimpleGetOptions{}, &SimpleRoot{})
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -121,7 +122,7 @@ func init() {
|
||||
// api.Status is returned in errors
|
||||
|
||||
// "internal" version
|
||||
api.Scheme.AddKnownTypes("", &Simple{}, &SimpleList{}, &api.Status{}, &api.ListOptions{}, &SimpleGetOptions{}, &SimpleRoot{})
|
||||
api.Scheme.AddKnownTypes("", &Simple{}, &SimpleList{}, &unversioned.Status{}, &api.ListOptions{}, &SimpleGetOptions{}, &SimpleRoot{})
|
||||
addTestTypes()
|
||||
addNewTestTypes()
|
||||
|
||||
@@ -228,28 +229,28 @@ func handleInternal(legacy bool, storage map[string]rest.Storage, admissionContr
|
||||
}
|
||||
|
||||
type Simple struct {
|
||||
api.TypeMeta `json:",inline"`
|
||||
api.ObjectMeta `json:"metadata"`
|
||||
Other string `json:"other,omitempty"`
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
api.ObjectMeta `json:"metadata"`
|
||||
Other string `json:"other,omitempty"`
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
}
|
||||
|
||||
func (*Simple) IsAnAPIObject() {}
|
||||
|
||||
type SimpleRoot struct {
|
||||
api.TypeMeta `json:",inline"`
|
||||
api.ObjectMeta `json:"metadata"`
|
||||
Other string `json:"other,omitempty"`
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
api.ObjectMeta `json:"metadata"`
|
||||
Other string `json:"other,omitempty"`
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
}
|
||||
|
||||
func (*SimpleRoot) IsAnAPIObject() {}
|
||||
|
||||
type SimpleGetOptions struct {
|
||||
api.TypeMeta `json:",inline"`
|
||||
Param1 string `json:"param1"`
|
||||
Param2 string `json:"param2"`
|
||||
Path string `json:"atAPath"`
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
Param1 string `json:"param1"`
|
||||
Param2 string `json:"param2"`
|
||||
Path string `json:"atAPath"`
|
||||
}
|
||||
|
||||
func (SimpleGetOptions) SwaggerDoc() map[string]string {
|
||||
@@ -262,9 +263,9 @@ func (SimpleGetOptions) SwaggerDoc() map[string]string {
|
||||
func (*SimpleGetOptions) IsAnAPIObject() {}
|
||||
|
||||
type SimpleList struct {
|
||||
api.TypeMeta `json:",inline"`
|
||||
api.ListMeta `json:"metadata,inline"`
|
||||
Items []Simple `json:"items,omitempty"`
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
unversioned.ListMeta `json:"metadata,inline"`
|
||||
Items []Simple `json:"items,omitempty"`
|
||||
}
|
||||
|
||||
func (*SimpleList) IsAnAPIObject() {}
|
||||
@@ -397,7 +398,7 @@ func (storage *SimpleRESTStorage) Delete(ctx api.Context, id string, options *ap
|
||||
if err := storage.errors["delete"]; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var obj runtime.Object = &api.Status{Status: api.StatusSuccess}
|
||||
var obj runtime.Object = &unversioned.Status{Status: unversioned.StatusSuccess}
|
||||
var err error
|
||||
if storage.injectedFunction != nil {
|
||||
obj, err = storage.injectedFunction(&Simple{ObjectMeta: api.ObjectMeta{Name: id}})
|
||||
@@ -2418,7 +2419,7 @@ func TestCreateInvokesAdmissionControl(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func expectApiStatus(t *testing.T, method, url string, data []byte, code int) *api.Status {
|
||||
func expectApiStatus(t *testing.T, method, url string, data []byte, code int) *unversioned.Status {
|
||||
client := http.Client{}
|
||||
request, err := http.NewRequest(method, url, bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
@@ -2430,7 +2431,7 @@ func expectApiStatus(t *testing.T, method, url string, data []byte, code int) *a
|
||||
t.Fatalf("unexpected error on %s %s: %v", method, url, err)
|
||||
return nil
|
||||
}
|
||||
var status api.Status
|
||||
var status unversioned.Status
|
||||
_, err = extractBody(response, &status)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error on %s %s: %v", method, url, err)
|
||||
@@ -2453,7 +2454,7 @@ func TestDelayReturnsError(t *testing.T) {
|
||||
defer server.Close()
|
||||
|
||||
status := expectApiStatus(t, "DELETE", fmt.Sprintf("%s/api/version/namespaces/default/foo/bar", server.URL), nil, http.StatusConflict)
|
||||
if status.Status != api.StatusFailure || status.Message == "" || status.Details == nil || status.Reason != api.StatusReasonAlreadyExists {
|
||||
if status.Status != unversioned.StatusFailure || status.Message == "" || status.Details == nil || status.Reason != unversioned.StatusReasonAlreadyExists {
|
||||
t.Errorf("Unexpected status %#v", status)
|
||||
}
|
||||
}
|
||||
@@ -2470,7 +2471,7 @@ func TestWriteJSONDecodeError(t *testing.T) {
|
||||
}))
|
||||
defer server.Close()
|
||||
status := expectApiStatus(t, "GET", server.URL, nil, http.StatusInternalServerError)
|
||||
if status.Reason != api.StatusReasonUnknown {
|
||||
if status.Reason != unversioned.StatusReasonUnknown {
|
||||
t.Errorf("unexpected reason %#v", status)
|
||||
}
|
||||
if !strings.Contains(status.Message, "type apiserver.UnregisteredAPIObject is not registered") {
|
||||
@@ -2524,7 +2525,7 @@ func TestCreateTimeout(t *testing.T) {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
itemOut := expectApiStatus(t, "POST", server.URL+"/api/version/namespaces/default/foo?timeout=4ms", data, apierrs.StatusServerTimeout)
|
||||
if itemOut.Status != api.StatusFailure || itemOut.Reason != api.StatusReasonTimeout {
|
||||
if itemOut.Status != unversioned.StatusFailure || itemOut.Reason != unversioned.StatusReasonTimeout {
|
||||
t.Errorf("Unexpected status %#v", itemOut)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user