Move watch/versioned to pkg/apis/meta/v1/watch.go

Move the encoder and decoder to restclient since it is generic to that package.
parent de59ede6
......@@ -64,7 +64,6 @@ func New() *Generator {
`+k8s.io/kubernetes/pkg/api/resource`,
`+k8s.io/kubernetes/pkg/runtime/schema`,
`+k8s.io/kubernetes/pkg/runtime`,
`+k8s.io/kubernetes/pkg/watch/versioned`,
`k8s.io/kubernetes/pkg/apis/meta/v1`,
`k8s.io/kubernetes/pkg/api/v1`,
`k8s.io/kubernetes/pkg/apis/policy/v1beta1`,
......
......@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package versioned
package v1
import (
"k8s.io/kubernetes/pkg/conversion"
......@@ -23,23 +23,19 @@ import (
"k8s.io/kubernetes/pkg/watch"
)
// WatchEventKind is name reserved for serializing watch events.
const WatchEventKind = "WatchEvent"
// Event represents a single event to a watched resource.
//
// +protobuf=true
// +k8s:openapi-gen=true
type Event struct {
Type string `json:"type" protobuf:"bytes,1,opt,name=type"`
// AddToGroupVersion registers the watch external and internal kinds with the scheme, and ensures the proper
// conversions are in place.
func AddToGroupVersion(scheme *runtime.Scheme, groupVersion schema.GroupVersion) {
scheme.AddKnownTypeWithName(groupVersion.WithKind(WatchEventKind), &Event{})
scheme.AddKnownTypeWithName(
schema.GroupVersion{Group: groupVersion.Group, Version: runtime.APIVersionInternal}.WithKind(WatchEventKind),
&InternalEvent{},
)
scheme.AddConversionFuncs(
Convert_versioned_Event_to_watch_Event,
Convert_versioned_InternalEvent_to_versioned_Event,
Convert_watch_Event_to_versioned_Event,
Convert_versioned_Event_to_versioned_InternalEvent,
)
// Object is:
// * If Type is Added or Modified: the new state of the object.
// * If Type is Deleted: the state of the object immediately before deletion.
// * If Type is Error: *Status is recommended; other types may make sense
// depending on context.
Object runtime.RawExtension `json:"object" protobuf:"bytes,2,opt,name=object"`
}
func Convert_watch_Event_to_versioned_Event(in *watch.Event, out *Event, s conversion.Scope) error {
......
......@@ -19,6 +19,7 @@ package versioned
import (
"encoding/json"
"k8s.io/kubernetes/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime/serializer/streaming"
"k8s.io/kubernetes/pkg/watch"
......@@ -27,6 +28,7 @@ import (
// Encoder serializes watch.Events into io.Writer. The internal objects
// are encoded using embedded encoder, and the outer Event is serialized
// using encoder.
// TODO: this type is only used by tests
type Encoder struct {
encoder streaming.Encoder
embeddedEncoder runtime.Encoder
......@@ -47,5 +49,5 @@ func (e *Encoder) Encode(event *watch.Event) error {
return err
}
// FIXME: get rid of json.RawMessage.
return e.encoder.Encode(&Event{string(event.Type), runtime.RawExtension{Raw: json.RawMessage(data)}})
return e.encoder.Encode(&v1.Event{string(event.Type), runtime.RawExtension{Raw: json.RawMessage(data)}})
}
package(default_visibility = ["//visibility:public"])
licenses(["notice"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"decoder.go",
"encoder.go",
"generated.pb.go",
"register.go",
"types.go",
],
tags = ["automanaged"],
deps = [
"//pkg/conversion:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/runtime/schema:go_default_library",
"//pkg/runtime/serializer/streaming:go_default_library",
"//pkg/watch:go_default_library",
"//vendor:github.com/gogo/protobuf/proto",
],
)
go_test(
name = "go_default_xtest",
srcs = [
"decoder_test.go",
"encoder_test.go",
],
tags = ["automanaged"],
deps = [
"//pkg/api:go_default_library",
"//pkg/api/testapi:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/runtime/serializer/streaming:go_default_library",
"//pkg/util/wait:go_default_library",
"//pkg/watch:go_default_library",
"//pkg/watch/versioned:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// This file was autogenerated by go-to-protobuf. Do not edit it manually!
syntax = 'proto2';
package k8s.io.kubernetes.pkg.watch.versioned;
import "k8s.io/kubernetes/pkg/runtime/generated.proto";
import "k8s.io/kubernetes/pkg/util/intstr/generated.proto";
// Package-wide variables from generator "generated".
option go_package = "versioned";
// Event represents a single event to a watched resource.
//
// +protobuf=true
// +k8s:openapi-gen=true
message Event {
optional string type = 1;
// Object is:
// * If Type is Added or Modified: the new state of the object.
// * If Type is Deleted: the state of the object immediately before deletion.
// * If Type is Error: *api.Status is recommended; other types may make sense
// depending on context.
optional k8s.io.kubernetes.pkg.runtime.RawExtension object = 2;
}
/*
Copyright 2015 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package versioned contains the versioned types for watch. This is the first
// serialization version unless otherwise noted.
package versioned
import (
"k8s.io/kubernetes/pkg/runtime"
)
// Event represents a single event to a watched resource.
//
// +protobuf=true
// +k8s:openapi-gen=true
type Event struct {
Type string `json:"type" protobuf:"bytes,1,opt,name=type"`
// Object is:
// * If Type is Added or Modified: the new state of the object.
// * If Type is Deleted: the state of the object immediately before deletion.
// * If Type is Error: *api.Status is recommended; other types may make sense
// depending on context.
Object runtime.RawExtension `json:"object" protobuf:"bytes,2,opt,name=object"`
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment