mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #22285 from AdoHe/fix_service_export
Auto commit by PR queue bot
This commit is contained in:
		@@ -13288,6 +13288,22 @@
 | 
				
			|||||||
        "required": false,
 | 
					        "required": false,
 | 
				
			||||||
        "allowMultiple": false
 | 
					        "allowMultiple": false
 | 
				
			||||||
       },
 | 
					       },
 | 
				
			||||||
 | 
					       {
 | 
				
			||||||
 | 
					        "type": "boolean",
 | 
				
			||||||
 | 
					        "paramType": "query",
 | 
				
			||||||
 | 
					        "name": "export",
 | 
				
			||||||
 | 
					        "description": "Should this value be exported.  Export strips fields that a user can not specify.",
 | 
				
			||||||
 | 
					        "required": false,
 | 
				
			||||||
 | 
					        "allowMultiple": false
 | 
				
			||||||
 | 
					       },
 | 
				
			||||||
 | 
					       {
 | 
				
			||||||
 | 
					        "type": "boolean",
 | 
				
			||||||
 | 
					        "paramType": "query",
 | 
				
			||||||
 | 
					        "name": "exact",
 | 
				
			||||||
 | 
					        "description": "Should the export be exact.  Exact export maintains cluster-specific fields like 'Namespace'",
 | 
				
			||||||
 | 
					        "required": false,
 | 
				
			||||||
 | 
					        "allowMultiple": false
 | 
				
			||||||
 | 
					       },
 | 
				
			||||||
       {
 | 
					       {
 | 
				
			||||||
        "type": "string",
 | 
					        "type": "string",
 | 
				
			||||||
        "paramType": "path",
 | 
					        "paramType": "path",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15104,6 +15104,22 @@ span.icon > [class^="icon-"], span.icon > [class*=" icon-"] { cursor: default; }
 | 
				
			|||||||
<td class="tableblock halign-left valign-top"></td>
 | 
					<td class="tableblock halign-left valign-top"></td>
 | 
				
			||||||
</tr>
 | 
					</tr>
 | 
				
			||||||
<tr>
 | 
					<tr>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">QueryParameter</p></td>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">export</p></td>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">Should this value be exported.  Export strips fields that a user can not specify.</p></td>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"></td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">QueryParameter</p></td>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">exact</p></td>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">Should the export be exact.  Exact export maintains cluster-specific fields like <em>Namespace</em></p></td>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
 | 
				
			||||||
 | 
					<td class="tableblock halign-left valign-top"></td>
 | 
				
			||||||
 | 
					</tr>
 | 
				
			||||||
 | 
					<tr>
 | 
				
			||||||
<td class="tableblock halign-left valign-top"><p class="tableblock">PathParameter</p></td>
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">PathParameter</p></td>
 | 
				
			||||||
<td class="tableblock halign-left valign-top"><p class="tableblock">namespace</p></td>
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">namespace</p></td>
 | 
				
			||||||
<td class="tableblock halign-left valign-top"><p class="tableblock">object name and auth scope, such as for teams and projects</p></td>
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">object name and auth scope, such as for teams and projects</p></td>
 | 
				
			||||||
@@ -29901,7 +29917,7 @@ span.icon > [class^="icon-"], span.icon > [class*=" icon-"] { cursor: default; }
 | 
				
			|||||||
</div>
 | 
					</div>
 | 
				
			||||||
<div id="footer">
 | 
					<div id="footer">
 | 
				
			||||||
<div id="footer-text">
 | 
					<div id="footer-text">
 | 
				
			||||||
Last updated 2016-03-02 21:40:42 UTC
 | 
					Last updated 2016-03-05 16:17:11 UTC
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
</body>
 | 
					</body>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,6 +20,7 @@ import (
 | 
				
			|||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api"
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api/unversioned"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/watch"
 | 
						"k8s.io/kubernetes/pkg/watch"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -112,3 +113,10 @@ func (r *ServiceRegistry) WatchServices(ctx api.Context, options *api.ListOption
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	return nil, r.Err
 | 
						return nil, r.Err
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (r *ServiceRegistry) ExportService(ctx api.Context, name string, options unversioned.ExportOptions) (*api.Service, error) {
 | 
				
			||||||
 | 
						r.mu.Lock()
 | 
				
			||||||
 | 
						defer r.mu.Lock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return r.Service, r.Err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,6 +59,7 @@ func NewREST(opts generic.RESTOptions) (*REST, *StatusREST) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		CreateStrategy: service.Strategy,
 | 
							CreateStrategy: service.Strategy,
 | 
				
			||||||
		UpdateStrategy: service.Strategy,
 | 
							UpdateStrategy: service.Strategy,
 | 
				
			||||||
 | 
							ExportStrategy: service.Strategy,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Storage: storageInterface,
 | 
							Storage: storageInterface,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,8 +17,11 @@ limitations under the License.
 | 
				
			|||||||
package service
 | 
					package service
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api"
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/api/rest"
 | 
						"k8s.io/kubernetes/pkg/api/rest"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api/unversioned"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/watch"
 | 
						"k8s.io/kubernetes/pkg/watch"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -30,6 +33,7 @@ type Registry interface {
 | 
				
			|||||||
	DeleteService(ctx api.Context, name string) error
 | 
						DeleteService(ctx api.Context, name string) error
 | 
				
			||||||
	UpdateService(ctx api.Context, svc *api.Service) (*api.Service, error)
 | 
						UpdateService(ctx api.Context, svc *api.Service) (*api.Service, error)
 | 
				
			||||||
	WatchServices(ctx api.Context, options *api.ListOptions) (watch.Interface, error)
 | 
						WatchServices(ctx api.Context, options *api.ListOptions) (watch.Interface, error)
 | 
				
			||||||
 | 
						ExportService(ctx api.Context, name string, options unversioned.ExportOptions) (*api.Service, error)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// storage puts strong typing around storage calls
 | 
					// storage puts strong typing around storage calls
 | 
				
			||||||
@@ -84,6 +88,20 @@ func (s *storage) WatchServices(ctx api.Context, options *api.ListOptions) (watc
 | 
				
			|||||||
	return s.Watch(ctx, options)
 | 
						return s.Watch(ctx, options)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// If StandardStorage implements rest.Exporter, returns exported service.
 | 
				
			||||||
 | 
					// Otherwise export is not supported.
 | 
				
			||||||
 | 
					func (s *storage) ExportService(ctx api.Context, name string, options unversioned.ExportOptions) (*api.Service, error) {
 | 
				
			||||||
 | 
						exporter, isExporter := s.StandardStorage.(rest.Exporter)
 | 
				
			||||||
 | 
						if !isExporter {
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("export is not supported")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						obj, err := exporter.Export(ctx, name, options)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return obj.(*api.Service), nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// TODO: Move to a general location (as other components may need allocation in future; it's not service specific)
 | 
					// TODO: Move to a general location (as other components may need allocation in future; it's not service specific)
 | 
				
			||||||
// RangeRegistry is a registry that can retrieve or persist a RangeAllocation object.
 | 
					// RangeRegistry is a registry that can retrieve or persist a RangeAllocation object.
 | 
				
			||||||
type RangeRegistry interface {
 | 
					type RangeRegistry interface {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -198,6 +198,12 @@ func (rs *REST) Watch(ctx api.Context, options *api.ListOptions) (watch.Interfac
 | 
				
			|||||||
	return rs.registry.WatchServices(ctx, options)
 | 
						return rs.registry.WatchServices(ctx, options)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Export returns Service stripped of cluster-specific information.
 | 
				
			||||||
 | 
					// It implements rest.Exporter.
 | 
				
			||||||
 | 
					func (rs *REST) Export(ctx api.Context, name string, opts unversioned.ExportOptions) (runtime.Object, error) {
 | 
				
			||||||
 | 
						return rs.registry.ExportService(ctx, name, opts)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (*REST) New() runtime.Object {
 | 
					func (*REST) New() runtime.Object {
 | 
				
			||||||
	return &api.Service{}
 | 
						return &api.Service{}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -90,7 +90,7 @@ func (svcStrategy) Export(obj runtime.Object, exact bool) error {
 | 
				
			|||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if t.Spec.ClusterIP != api.ClusterIPNone {
 | 
						if t.Spec.ClusterIP != api.ClusterIPNone {
 | 
				
			||||||
		t.Spec.ClusterIP = ""
 | 
							t.Spec.ClusterIP = "<unknown>"
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if t.Spec.Type == api.ServiceTypeNodePort {
 | 
						if t.Spec.Type == api.ServiceTypeNodePort {
 | 
				
			||||||
		for i := range t.Spec.Ports {
 | 
							for i := range t.Spec.Ports {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -81,6 +81,9 @@ func TestExportService(t *testing.T) {
 | 
				
			|||||||
					Name:      "foo",
 | 
										Name:      "foo",
 | 
				
			||||||
					Namespace: "bar",
 | 
										Namespace: "bar",
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
 | 
									Spec: api.ServiceSpec{
 | 
				
			||||||
 | 
										ClusterIP: "<unknown>",
 | 
				
			||||||
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user