mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Add namespace error checking if a resource is not found.
This commit is contained in:
		@@ -283,6 +283,8 @@ func TestApplyNonExistObject(t *testing.T) {
 | 
			
		||||
		NegotiatedSerializer: ns,
 | 
			
		||||
		Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
 | 
			
		||||
			switch p, m := req.URL.Path, req.Method; {
 | 
			
		||||
			case p == "/api/v1/namespaces/test" && m == "GET":
 | 
			
		||||
				return &http.Response{StatusCode: 404, Header: defaultHeader(), Body: ioutil.NopCloser(bytes.NewReader(nil))}, nil
 | 
			
		||||
			case p == pathNameRC && m == "GET":
 | 
			
		||||
				return &http.Response{StatusCode: 404, Header: defaultHeader(), Body: ioutil.NopCloser(bytes.NewReader(nil))}, nil
 | 
			
		||||
			case p == pathRC && m == "POST":
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,7 @@ import (
 | 
			
		||||
	"strings"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/client/typed/dynamic"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/client/unversioned/fake"
 | 
			
		||||
)
 | 
			
		||||
@@ -37,6 +38,8 @@ func TestReplaceObject(t *testing.T) {
 | 
			
		||||
		NegotiatedSerializer: ns,
 | 
			
		||||
		Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
 | 
			
		||||
			switch p, m := req.URL.Path, req.Method; {
 | 
			
		||||
			case p == "/api/v1/namespaces/test" && m == http.MethodGet:
 | 
			
		||||
				return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &api.Namespace{})}, nil
 | 
			
		||||
			case p == "/namespaces/test/replicationcontrollers/redis-master" && m == http.MethodDelete:
 | 
			
		||||
				deleted = true
 | 
			
		||||
				fallthrough
 | 
			
		||||
@@ -92,6 +95,8 @@ func TestReplaceMultipleObject(t *testing.T) {
 | 
			
		||||
		NegotiatedSerializer: ns,
 | 
			
		||||
		Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
 | 
			
		||||
			switch p, m := req.URL.Path, req.Method; {
 | 
			
		||||
			case p == "/api/v1/namespaces/test" && m == http.MethodGet:
 | 
			
		||||
				return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &api.Namespace{})}, nil
 | 
			
		||||
			case p == "/namespaces/test/replicationcontrollers/redis-master" && m == http.MethodDelete:
 | 
			
		||||
				redisMasterDeleted = true
 | 
			
		||||
				fallthrough
 | 
			
		||||
@@ -159,6 +164,8 @@ func TestReplaceDirectory(t *testing.T) {
 | 
			
		||||
		NegotiatedSerializer: ns,
 | 
			
		||||
		Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
 | 
			
		||||
			switch p, m := req.URL.Path, req.Method; {
 | 
			
		||||
			case p == "/api/v1/namespaces/test" && m == http.MethodGet:
 | 
			
		||||
				return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &api.Namespace{})}, nil
 | 
			
		||||
			case strings.HasPrefix(p, "/namespaces/test/replicationcontrollers/") && m == http.MethodPut:
 | 
			
		||||
				created[p] = true
 | 
			
		||||
				return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &rc.Items[0])}, nil
 | 
			
		||||
@@ -213,6 +220,8 @@ func TestForceReplaceObjectNotFound(t *testing.T) {
 | 
			
		||||
		NegotiatedSerializer: ns,
 | 
			
		||||
		Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) {
 | 
			
		||||
			switch p, m := req.URL.Path, req.Method; {
 | 
			
		||||
			case p == "/api/v1/namespaces/test" && m == http.MethodGet:
 | 
			
		||||
				return &http.Response{StatusCode: http.StatusOK, Header: defaultHeader(), Body: objBody(codec, &api.Namespace{})}, nil
 | 
			
		||||
			case p == "/namespaces/test/replicationcontrollers/redis-master" && (m == http.MethodGet || m == http.MethodDelete):
 | 
			
		||||
				return &http.Response{StatusCode: http.StatusNotFound, Header: defaultHeader(), Body: stringBody("")}, nil
 | 
			
		||||
			case p == "/namespaces/test/replicationcontrollers" && m == http.MethodPost:
 | 
			
		||||
 
 | 
			
		||||
@@ -26,6 +26,8 @@ import (
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api/errors"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api/meta"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api/unversioned"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/api/validation"
 | 
			
		||||
@@ -110,6 +112,12 @@ func (i *Info) Visit(fn VisitorFunc) error {
 | 
			
		||||
func (i *Info) Get() (err error) {
 | 
			
		||||
	obj, err := NewHelper(i.Client, i.Mapping).Get(i.Namespace, i.Name, i.Export)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if errors.IsNotFound(err) && len(i.Namespace) > 0 && i.Namespace != api.NamespaceDefault && i.Namespace != api.NamespaceAll {
 | 
			
		||||
			err2 := i.Client.Get().AbsPath("api", "v1", "namespaces", i.Namespace).Do().Error()
 | 
			
		||||
			if err2 != nil && errors.IsNotFound(err2) {
 | 
			
		||||
				return err2
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	i.Object = obj
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user