fix can not export service bug

pull/6/head
AdoHe 2016-03-05 11:23:50 -05:00
parent b198c820cd
commit 5fdfc4bde3
8 changed files with 70 additions and 2 deletions

View File

@ -13288,6 +13288,22 @@
"required": 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",
"paramType": "path",

View File

@ -15104,6 +15104,22 @@ span.icon > [class^="icon-"], span.icon > [class*=" icon-"] { cursor: default; }
<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">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">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>
@ -29901,7 +29917,7 @@ span.icon > [class^="icon-"], span.icon > [class*=" icon-"] { cursor: default; }
</div>
<div id="footer">
<div id="footer-text">
Last updated 2016-03-02 21:40:42 UTC
Last updated 2016-03-05 16:17:11 UTC
</div>
</div>
</body>

View File

@ -20,6 +20,7 @@ import (
"sync"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/watch"
)
@ -112,3 +113,10 @@ func (r *ServiceRegistry) WatchServices(ctx api.Context, options *api.ListOption
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
}

View File

@ -59,6 +59,7 @@ func NewREST(opts generic.RESTOptions) (*REST, *StatusREST) {
CreateStrategy: service.Strategy,
UpdateStrategy: service.Strategy,
ExportStrategy: service.Strategy,
Storage: storageInterface,
}

View File

@ -17,8 +17,11 @@ limitations under the License.
package service
import (
"fmt"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/watch"
)
@ -30,6 +33,7 @@ type Registry interface {
DeleteService(ctx api.Context, name string) error
UpdateService(ctx api.Context, svc *api.Service) (*api.Service, 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
@ -84,6 +88,20 @@ func (s *storage) WatchServices(ctx api.Context, options *api.ListOptions) (watc
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)
// RangeRegistry is a registry that can retrieve or persist a RangeAllocation object.
type RangeRegistry interface {

View File

@ -198,6 +198,12 @@ func (rs *REST) Watch(ctx api.Context, options *api.ListOptions) (watch.Interfac
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 {
return &api.Service{}
}

View File

@ -90,7 +90,7 @@ func (svcStrategy) Export(obj runtime.Object, exact bool) error {
return nil
}
if t.Spec.ClusterIP != api.ClusterIPNone {
t.Spec.ClusterIP = ""
t.Spec.ClusterIP = "<unknown>"
}
if t.Spec.Type == api.ServiceTypeNodePort {
for i := range t.Spec.Ports {

View File

@ -81,6 +81,9 @@ func TestExportService(t *testing.T) {
Name: "foo",
Namespace: "bar",
},
Spec: api.ServiceSpec{
ClusterIP: "<unknown>",
},
},
},
{