From 0b259bae9084d6eb02613c10775aa3bfc121a717 Mon Sep 17 00:00:00 2001 From: Zeng Xu Date: Thu, 20 Jul 2023 14:20:25 +0000 Subject: [PATCH 1/5] add subresource config --- api/generated/openapi/zz_generated.openapi.go | 72 +++ api/hello.zeng.dev/v2/generated.pb.go | 506 ++++++++++++++++-- api/hello.zeng.dev/v2/generated.proto | 16 + api/hello.zeng.dev/v2/register.go | 1 + api/hello.zeng.dev/v2/types.go | 18 + .../v2/zz_generated.deepcopy.go | 43 ++ 6 files changed, 610 insertions(+), 46 deletions(-) diff --git a/api/generated/openapi/zz_generated.openapi.go b/api/generated/openapi/zz_generated.openapi.go index f3cff31..fd9794a 100644 --- a/api/generated/openapi/zz_generated.openapi.go +++ b/api/generated/openapi/zz_generated.openapi.go @@ -22,6 +22,8 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1.Foo": schema_x_kubernetes_api_hellozengdev_v1_Foo(ref), "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1.FooList": schema_x_kubernetes_api_hellozengdev_v1_FooList(ref), "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1.FooSpec": schema_x_kubernetes_api_hellozengdev_v1_FooSpec(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.Config": schema_x_kubernetes_api_hellozengdev_v2_Config(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.ConfigSpec": schema_x_kubernetes_api_hellozengdev_v2_ConfigSpec(ref), "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.Foo": schema_x_kubernetes_api_hellozengdev_v2_Foo(ref), "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooCondition": schema_x_kubernetes_api_hellozengdev_v2_FooCondition(ref), "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooConfig": schema_x_kubernetes_api_hellozengdev_v2_FooConfig(ref), @@ -201,6 +203,76 @@ func schema_x_kubernetes_api_hellozengdev_v1_FooSpec(ref common.ReferenceCallbac } } +func schema_x_kubernetes_api_hellozengdev_v2_Config(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Config is the config subresource of Foo", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.ConfigSpec"), + }, + }, + }, + Required: []string{"spec"}, + }, + }, + Dependencies: []string{ + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.ConfigSpec", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_x_kubernetes_api_hellozengdev_v2_ConfigSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "msg": { + SchemaProps: spec.SchemaProps{ + Description: "Msg says hello world!", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "msg1": { + SchemaProps: spec.SchemaProps{ + Description: "Msg1 provides some verbose information", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"msg"}, + }, + }, + } +} + func schema_x_kubernetes_api_hellozengdev_v2_Foo(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/api/hello.zeng.dev/v2/generated.pb.go b/api/hello.zeng.dev/v2/generated.pb.go index a700e96..c669318 100644 --- a/api/hello.zeng.dev/v2/generated.pb.go +++ b/api/hello.zeng.dev/v2/generated.pb.go @@ -32,10 +32,66 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +func (m *Config) Reset() { *m = Config{} } +func (*Config) ProtoMessage() {} +func (*Config) Descriptor() ([]byte, []int) { + return fileDescriptor_18c52dbbfb632f7c, []int{0} +} +func (m *Config) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Config) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *Config) XXX_Merge(src proto.Message) { + xxx_messageInfo_Config.Merge(m, src) +} +func (m *Config) XXX_Size() int { + return m.Size() +} +func (m *Config) XXX_DiscardUnknown() { + xxx_messageInfo_Config.DiscardUnknown(m) +} + +var xxx_messageInfo_Config proto.InternalMessageInfo + +func (m *ConfigSpec) Reset() { *m = ConfigSpec{} } +func (*ConfigSpec) ProtoMessage() {} +func (*ConfigSpec) Descriptor() ([]byte, []int) { + return fileDescriptor_18c52dbbfb632f7c, []int{1} +} +func (m *ConfigSpec) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ConfigSpec) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *ConfigSpec) XXX_Merge(src proto.Message) { + xxx_messageInfo_ConfigSpec.Merge(m, src) +} +func (m *ConfigSpec) XXX_Size() int { + return m.Size() +} +func (m *ConfigSpec) XXX_DiscardUnknown() { + xxx_messageInfo_ConfigSpec.DiscardUnknown(m) +} + +var xxx_messageInfo_ConfigSpec proto.InternalMessageInfo + func (m *Foo) Reset() { *m = Foo{} } func (*Foo) ProtoMessage() {} func (*Foo) Descriptor() ([]byte, []int) { - return fileDescriptor_18c52dbbfb632f7c, []int{0} + return fileDescriptor_18c52dbbfb632f7c, []int{2} } func (m *Foo) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -63,7 +119,7 @@ var xxx_messageInfo_Foo proto.InternalMessageInfo func (m *FooCondition) Reset() { *m = FooCondition{} } func (*FooCondition) ProtoMessage() {} func (*FooCondition) Descriptor() ([]byte, []int) { - return fileDescriptor_18c52dbbfb632f7c, []int{1} + return fileDescriptor_18c52dbbfb632f7c, []int{3} } func (m *FooCondition) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -91,7 +147,7 @@ var xxx_messageInfo_FooCondition proto.InternalMessageInfo func (m *FooConfig) Reset() { *m = FooConfig{} } func (*FooConfig) ProtoMessage() {} func (*FooConfig) Descriptor() ([]byte, []int) { - return fileDescriptor_18c52dbbfb632f7c, []int{2} + return fileDescriptor_18c52dbbfb632f7c, []int{4} } func (m *FooConfig) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -119,7 +175,7 @@ var xxx_messageInfo_FooConfig proto.InternalMessageInfo func (m *FooList) Reset() { *m = FooList{} } func (*FooList) ProtoMessage() {} func (*FooList) Descriptor() ([]byte, []int) { - return fileDescriptor_18c52dbbfb632f7c, []int{3} + return fileDescriptor_18c52dbbfb632f7c, []int{5} } func (m *FooList) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -147,7 +203,7 @@ var xxx_messageInfo_FooList proto.InternalMessageInfo func (m *FooSpec) Reset() { *m = FooSpec{} } func (*FooSpec) ProtoMessage() {} func (*FooSpec) Descriptor() ([]byte, []int) { - return fileDescriptor_18c52dbbfb632f7c, []int{4} + return fileDescriptor_18c52dbbfb632f7c, []int{6} } func (m *FooSpec) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -175,7 +231,7 @@ var xxx_messageInfo_FooSpec proto.InternalMessageInfo func (m *FooStatus) Reset() { *m = FooStatus{} } func (*FooStatus) ProtoMessage() {} func (*FooStatus) Descriptor() ([]byte, []int) { - return fileDescriptor_18c52dbbfb632f7c, []int{5} + return fileDescriptor_18c52dbbfb632f7c, []int{7} } func (m *FooStatus) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -201,6 +257,8 @@ func (m *FooStatus) XXX_DiscardUnknown() { var xxx_messageInfo_FooStatus proto.InternalMessageInfo func init() { + proto.RegisterType((*Config)(nil), "github.com.phosae.x_kubernetes.api.hello.zeng.dev.v2.Config") + proto.RegisterType((*ConfigSpec)(nil), "github.com.phosae.x_kubernetes.api.hello.zeng.dev.v2.ConfigSpec") proto.RegisterType((*Foo)(nil), "github.com.phosae.x_kubernetes.api.hello.zeng.dev.v2.Foo") proto.RegisterType((*FooCondition)(nil), "github.com.phosae.x_kubernetes.api.hello.zeng.dev.v2.FooCondition") proto.RegisterType((*FooConfig)(nil), "github.com.phosae.x_kubernetes.api.hello.zeng.dev.v2.FooConfig") @@ -214,46 +272,124 @@ func init() { } var fileDescriptor_18c52dbbfb632f7c = []byte{ - // 623 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0x41, 0x6e, 0xd3, 0x40, - 0x14, 0x8d, 0x9b, 0xa4, 0xb4, 0xd3, 0x82, 0xaa, 0x59, 0x95, 0x4a, 0x38, 0x55, 0xd8, 0x74, 0xd3, - 0x19, 0x12, 0x45, 0x08, 0x16, 0x08, 0xc9, 0x20, 0x4b, 0x48, 0xad, 0x40, 0x86, 0x55, 0x85, 0x5a, - 0x26, 0xce, 0x74, 0x3c, 0xa4, 0xf6, 0x58, 0x99, 0x89, 0xd5, 0xb2, 0xe2, 0x08, 0xec, 0xb8, 0x00, - 0x17, 0x40, 0xe2, 0x0e, 0x74, 0xd9, 0x65, 0x57, 0x11, 0x35, 0xb7, 0xe8, 0x0a, 0xcd, 0x8c, 0x1d, - 0xa7, 0xad, 0x10, 0x55, 0xd8, 0xf9, 0x3f, 0xff, 0xff, 0xde, 0xcb, 0xff, 0x2f, 0x06, 0x2f, 0x19, - 0x57, 0xd1, 0xb8, 0x8f, 0x42, 0x11, 0xe3, 0x34, 0x12, 0x92, 0x50, 0x7c, 0xbc, 0x3d, 0x1c, 0xf7, - 0xe9, 0x28, 0xa1, 0x8a, 0x4a, 0x4c, 0x52, 0x8e, 0x23, 0x7a, 0x74, 0x24, 0xd0, 0x27, 0x9a, 0x30, - 0x34, 0xa0, 0x19, 0xce, 0xba, 0x98, 0xd1, 0x84, 0x8e, 0x88, 0xa2, 0x03, 0x94, 0x8e, 0x84, 0x12, - 0xb0, 0x57, 0xb1, 0x20, 0xcb, 0x82, 0x8e, 0x0f, 0x2a, 0x16, 0x44, 0x52, 0x8e, 0xae, 0xb2, 0xa0, - 0xac, 0xbb, 0xb1, 0x3d, 0xa3, 0xcd, 0x04, 0x13, 0xd8, 0x90, 0xf5, 0xc7, 0x87, 0xa6, 0x32, 0x85, - 0x79, 0xb2, 0x22, 0x1b, 0xbd, 0xe1, 0x13, 0x89, 0xb8, 0xd0, 0x96, 0x62, 0x12, 0x46, 0x3c, 0xa1, - 0xa3, 0x13, 0x9c, 0x0e, 0x99, 0x06, 0x24, 0x8e, 0xa9, 0x22, 0x38, 0xeb, 0x5c, 0xb7, 0xb6, 0x81, - 0xff, 0x36, 0x35, 0x1a, 0x27, 0x8a, 0xc7, 0xf4, 0xc6, 0xc0, 0xe3, 0x7f, 0x0d, 0xc8, 0x30, 0xa2, - 0x31, 0xb9, 0x3e, 0xd7, 0xfe, 0xbe, 0x00, 0xea, 0xbe, 0x10, 0xf0, 0x03, 0x58, 0xd2, 0x5e, 0x06, - 0x44, 0x91, 0x75, 0x67, 0xd3, 0xd9, 0x5a, 0xe9, 0x3e, 0x42, 0x96, 0x12, 0xcd, 0x52, 0xa2, 0x74, - 0xc8, 0x34, 0x20, 0x91, 0xee, 0x46, 0x59, 0x07, 0xbd, 0xee, 0x7f, 0xa4, 0xa1, 0xda, 0xa5, 0x8a, - 0x78, 0xf0, 0x74, 0xd2, 0xaa, 0xe5, 0x93, 0x16, 0xa8, 0xb0, 0x60, 0xca, 0x0a, 0x0f, 0x40, 0x43, - 0xa6, 0x34, 0x5c, 0x5f, 0x30, 0xec, 0xcf, 0xd0, 0x3c, 0xcb, 0x47, 0xbe, 0x10, 0x6f, 0x53, 0x1a, - 0x7a, 0xab, 0x85, 0x54, 0x43, 0x57, 0x81, 0x21, 0x86, 0x0c, 0x2c, 0x4a, 0x45, 0xd4, 0x58, 0xae, - 0xd7, 0x8d, 0xc4, 0xf3, 0xf9, 0x25, 0x0c, 0x8d, 0x77, 0xaf, 0x10, 0x59, 0xb4, 0x75, 0x50, 0xd0, - 0xb7, 0xbf, 0x39, 0x60, 0xd5, 0x17, 0xe2, 0x85, 0x48, 0x06, 0x5c, 0x71, 0x91, 0xc0, 0x1e, 0x68, - 0xa8, 0x93, 0x94, 0x9a, 0xc5, 0x2d, 0x7b, 0x9b, 0xa5, 0xb7, 0x77, 0x27, 0x29, 0xbd, 0x9c, 0xb4, - 0xd6, 0x66, 0x7b, 0x35, 0x16, 0x98, 0x6e, 0xb8, 0x3f, 0xf5, 0xbb, 0x60, 0xe6, 0xfc, 0xab, 0x72, - 0x97, 0x93, 0xd6, 0xad, 0xb2, 0x83, 0xa6, 0xdc, 0xd7, 0x6c, 0xee, 0x80, 0x65, 0xab, 0x7c, 0xc8, - 0x19, 0x7c, 0x00, 0xea, 0xb1, 0x64, 0x85, 0xc3, 0x95, 0x42, 0xa9, 0xbe, 0x2b, 0x59, 0xa0, 0x71, - 0xb8, 0x09, 0x1a, 0xb1, 0x64, 0x9d, 0xc2, 0xc9, 0x74, 0xbb, 0xbb, 0x92, 0x75, 0x02, 0xf3, 0xa6, - 0xfd, 0xd3, 0x01, 0x77, 0x7c, 0x21, 0x76, 0xb8, 0x54, 0xf0, 0xfd, 0x8d, 0xb0, 0xa0, 0xdb, 0x85, - 0x45, 0x4f, 0x9b, 0xa8, 0xac, 0x15, 0x0a, 0x4b, 0x25, 0x32, 0x13, 0x94, 0x7d, 0xd0, 0xe4, 0x8a, - 0xc6, 0x7a, 0x2d, 0xf5, 0xad, 0x95, 0xee, 0xd3, 0xb9, 0xcf, 0xe8, 0xdd, 0x2d, 0x54, 0x9a, 0xaf, - 0x34, 0x5f, 0x60, 0x69, 0xdb, 0x5f, 0xed, 0x2f, 0xd1, 0xc9, 0x81, 0x0f, 0x41, 0x93, 0xc7, 0x84, - 0x95, 0xa7, 0xab, 0x06, 0x34, 0x18, 0xd8, 0x77, 0x3a, 0x58, 0xa1, 0xd9, 0x62, 0x91, 0xdd, 0xf9, - 0x83, 0x65, 0x8f, 0x51, 0x05, 0xcb, 0xd6, 0x41, 0x41, 0xdf, 0xfe, 0xe1, 0x98, 0x93, 0xd9, 0x3b, - 0x42, 0x0c, 0x9a, 0x69, 0x44, 0x64, 0xe9, 0xed, 0x7e, 0xe9, 0xed, 0x8d, 0x06, 0x2f, 0x27, 0xad, - 0x25, 0x5f, 0x08, 0xf3, 0x1c, 0xd8, 0x3e, 0x98, 0x01, 0x10, 0x96, 0x59, 0x28, 0xb7, 0xe7, 0xfd, - 0x8f, 0x57, 0x4b, 0x55, 0xfd, 0xaf, 0xa7, 0x90, 0x0c, 0x66, 0x94, 0xbc, 0xbd, 0xd3, 0x0b, 0xb7, - 0x76, 0x76, 0xe1, 0xd6, 0xce, 0x2f, 0xdc, 0xda, 0xe7, 0xdc, 0x75, 0x4e, 0x73, 0xd7, 0x39, 0xcb, - 0x5d, 0xe7, 0x3c, 0x77, 0x9d, 0x5f, 0xb9, 0xeb, 0x7c, 0xf9, 0xed, 0xd6, 0xf6, 0x7a, 0xf3, 0x7c, - 0xb3, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, 0x39, 0x70, 0x7c, 0x92, 0xea, 0x05, 0x00, 0x00, + // 656 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x55, 0xc1, 0x6e, 0xd3, 0x30, + 0x18, 0x6e, 0xd6, 0x76, 0x6c, 0xde, 0x40, 0x93, 0x4f, 0x63, 0x12, 0xe9, 0x54, 0x2e, 0xbb, 0xcc, + 0xa6, 0x55, 0x85, 0xe0, 0x80, 0x40, 0x19, 0xaa, 0x84, 0xb4, 0x0a, 0x14, 0x38, 0x4d, 0x68, 0xc3, + 0x4d, 0x3d, 0xd7, 0x74, 0x89, 0xa3, 0xda, 0xad, 0x36, 0x4e, 0x3c, 0x02, 0x37, 0x5e, 0x80, 0x17, + 0x40, 0xe2, 0x1d, 0xd8, 0x09, 0xed, 0xb8, 0x53, 0xc5, 0xc2, 0x5b, 0xec, 0x84, 0x6c, 0x27, 0x4d, + 0xb7, 0x69, 0x62, 0xca, 0x24, 0x6e, 0xf1, 0x97, 0xff, 0xff, 0xbe, 0x2f, 0xff, 0xff, 0x59, 0x01, + 0x2f, 0x19, 0x57, 0xfd, 0x51, 0x17, 0x05, 0x22, 0xc4, 0x71, 0x5f, 0x48, 0x42, 0xf1, 0xe1, 0xe6, + 0x60, 0xd4, 0xa5, 0xc3, 0x88, 0x2a, 0x2a, 0x31, 0x89, 0x39, 0xee, 0xd3, 0x83, 0x03, 0x81, 0x3e, + 0xd1, 0x88, 0xa1, 0x1e, 0x1d, 0xe3, 0x71, 0x13, 0x33, 0x1a, 0xd1, 0x21, 0x51, 0xb4, 0x87, 0xe2, + 0xa1, 0x50, 0x02, 0xb6, 0x72, 0x16, 0x64, 0x59, 0xd0, 0xe1, 0x5e, 0xce, 0x82, 0x48, 0xcc, 0xd1, + 0x45, 0x16, 0x34, 0x6e, 0xae, 0x6d, 0xce, 0x68, 0x33, 0xc1, 0x04, 0x36, 0x64, 0xdd, 0xd1, 0xbe, + 0x39, 0x99, 0x83, 0x79, 0xb2, 0x22, 0x6b, 0xad, 0xc1, 0x13, 0x89, 0xb8, 0xd0, 0x96, 0x42, 0x12, + 0xf4, 0x79, 0x44, 0x87, 0x47, 0x38, 0x1e, 0x30, 0x0d, 0x48, 0x1c, 0x52, 0x45, 0xf0, 0xb8, 0x71, + 0xd9, 0xda, 0x1a, 0xbe, 0xae, 0x6b, 0x38, 0x8a, 0x14, 0x0f, 0xe9, 0x95, 0x86, 0xc7, 0xff, 0x6a, + 0x90, 0x41, 0x9f, 0x86, 0xe4, 0x72, 0x5f, 0xfd, 0x97, 0x03, 0xe6, 0xb7, 0x44, 0xb4, 0xcf, 0x19, + 0xfc, 0x00, 0x16, 0xb4, 0x9d, 0x1e, 0x51, 0x64, 0xd5, 0x59, 0x77, 0x36, 0x96, 0x9a, 0x8f, 0x90, + 0x65, 0x45, 0xb3, 0xac, 0x28, 0x1e, 0x30, 0x0d, 0x48, 0xa4, 0xab, 0xd1, 0xb8, 0x81, 0x5e, 0x77, + 0x3f, 0xd2, 0x40, 0x75, 0xa8, 0x22, 0x1e, 0x3c, 0x9e, 0xd4, 0x4a, 0xc9, 0xa4, 0x06, 0x72, 0xcc, + 0x9f, 0xb2, 0xc2, 0x2e, 0xa8, 0xc8, 0x98, 0x06, 0xab, 0x73, 0x86, 0xfd, 0x05, 0x2a, 0x32, 0x7f, + 0x64, 0xdd, 0xbe, 0x8d, 0x69, 0xe0, 0x2d, 0xa7, 0x6a, 0x15, 0x7d, 0xf2, 0x0d, 0x77, 0xbd, 0x03, + 0x40, 0x5e, 0x01, 0x1f, 0x80, 0x72, 0x28, 0x99, 0xf9, 0x9c, 0x45, 0x6f, 0x29, 0x2d, 0x2f, 0x77, + 0x24, 0xf3, 0x35, 0x0e, 0xd7, 0x41, 0x25, 0x94, 0xac, 0x61, 0x0c, 0x2d, 0xe6, 0x74, 0x1d, 0xc9, + 0x1a, 0xbe, 0x79, 0x53, 0xff, 0x3e, 0x07, 0xca, 0x6d, 0x21, 0xfe, 0xc3, 0x70, 0xf6, 0x2e, 0x0c, + 0xe7, 0x59, 0xb1, 0xe1, 0xb4, 0x85, 0xb8, 0x6e, 0x32, 0x90, 0x81, 0x79, 0xa9, 0x88, 0x1a, 0xc9, + 0xd5, 0xb2, 0x91, 0x78, 0x5e, 0x5c, 0xc2, 0xd0, 0x78, 0xf7, 0x52, 0x91, 0x79, 0x7b, 0xf6, 0x53, + 0xfa, 0xfa, 0x37, 0x07, 0x2c, 0xb7, 0x85, 0xd8, 0x12, 0x51, 0x8f, 0x2b, 0x2e, 0x22, 0xd8, 0x02, + 0x15, 0x75, 0x14, 0xd3, 0x74, 0x0d, 0xeb, 0x99, 0xb7, 0x77, 0x47, 0x31, 0x3d, 0x9f, 0xd4, 0x56, + 0x66, 0x6b, 0x35, 0xe6, 0x9b, 0x6a, 0xb8, 0x3b, 0xf5, 0x6b, 0xd7, 0xd3, 0xbe, 0x28, 0x77, 0x3e, + 0xa9, 0xdd, 0xe8, 0x6e, 0xa1, 0x29, 0xf7, 0x25, 0x9b, 0xdb, 0x60, 0xd1, 0x2a, 0xeb, 0xf0, 0xdf, + 0x3a, 0x28, 0x3f, 0x1d, 0x70, 0xa7, 0x2d, 0xc4, 0x36, 0x97, 0x0a, 0xbe, 0xbf, 0x12, 0x16, 0x74, + 0xb3, 0xb0, 0xe8, 0x6e, 0x13, 0x95, 0x95, 0x54, 0x61, 0x21, 0x43, 0x66, 0x82, 0xb2, 0x0b, 0xaa, + 0x5c, 0xd1, 0x50, 0x8f, 0xa5, 0xbc, 0xb1, 0xd4, 0x7c, 0x5a, 0x78, 0x8d, 0xde, 0xdd, 0x54, 0xa5, + 0xfa, 0x4a, 0xf3, 0xf9, 0x96, 0xb6, 0xfe, 0xd5, 0x7e, 0x89, 0xb9, 0x3f, 0x0f, 0x41, 0x95, 0x87, + 0x84, 0x65, 0xab, 0xcb, 0x1b, 0x34, 0xe8, 0xdb, 0x77, 0x3a, 0x58, 0x81, 0x99, 0x62, 0x9a, 0xdd, + 0xe2, 0xc1, 0xb2, 0xcb, 0xc8, 0x83, 0x65, 0xcf, 0x7e, 0x4a, 0x5f, 0xff, 0xe1, 0x98, 0x95, 0xd9, + 0x3d, 0x42, 0x0c, 0xaa, 0x71, 0x9f, 0xc8, 0xcc, 0xdb, 0xfd, 0xcc, 0xdb, 0x1b, 0x0d, 0x9e, 0x4f, + 0x6a, 0x0b, 0x6d, 0x21, 0xcc, 0xb3, 0x6f, 0xeb, 0xe0, 0x18, 0x80, 0x20, 0xcb, 0x42, 0x36, 0x3d, + 0xef, 0x36, 0x5e, 0x2d, 0x55, 0x7e, 0xaf, 0xa7, 0x90, 0xf4, 0x67, 0x94, 0xbc, 0x9d, 0xe3, 0x33, + 0xb7, 0x74, 0x72, 0xe6, 0x96, 0x4e, 0xcf, 0xdc, 0xd2, 0xe7, 0xc4, 0x75, 0x8e, 0x13, 0xd7, 0x39, + 0x49, 0x5c, 0xe7, 0x34, 0x71, 0x9d, 0xdf, 0x89, 0xeb, 0x7c, 0xf9, 0xe3, 0x96, 0x76, 0x5a, 0x45, + 0xfe, 0x69, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xec, 0x4b, 0x1c, 0x81, 0x0a, 0x07, 0x00, 0x00, +} + +func (m *Config) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Config) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Config) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Spec.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.ObjectMeta.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *ConfigSpec) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ConfigSpec) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ConfigSpec) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + i -= len(m.Msg1) + copy(dAtA[i:], m.Msg1) + i = encodeVarintGenerated(dAtA, i, uint64(len(m.Msg1))) + i-- + dAtA[i] = 0x12 + i -= len(m.Msg) + copy(dAtA[i:], m.Msg) + i = encodeVarintGenerated(dAtA, i, uint64(len(m.Msg))) + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil } func (m *Foo) Marshal() (dAtA []byte, err error) { @@ -513,6 +649,32 @@ func encodeVarintGenerated(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *Config) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ObjectMeta.Size() + n += 1 + l + sovGenerated(uint64(l)) + l = m.Spec.Size() + n += 1 + l + sovGenerated(uint64(l)) + return n +} + +func (m *ConfigSpec) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Msg) + n += 1 + l + sovGenerated(uint64(l)) + l = len(m.Msg1) + n += 1 + l + sovGenerated(uint64(l)) + return n +} + func (m *Foo) Size() (n int) { if m == nil { return 0 @@ -607,6 +769,28 @@ func sovGenerated(x uint64) (n int) { func sozGenerated(x uint64) (n int) { return sovGenerated(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (this *Config) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Config{`, + `ObjectMeta:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.ObjectMeta), "ObjectMeta", "v1.ObjectMeta", 1), `&`, ``, 1) + `,`, + `Spec:` + strings.Replace(strings.Replace(this.Spec.String(), "ConfigSpec", "ConfigSpec", 1), `&`, ``, 1) + `,`, + `}`, + }, "") + return s +} +func (this *ConfigSpec) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ConfigSpec{`, + `Msg:` + fmt.Sprintf("%v", this.Msg) + `,`, + `Msg1:` + fmt.Sprintf("%v", this.Msg1) + `,`, + `}`, + }, "") + return s +} func (this *Foo) String() string { if this == nil { return "nil" @@ -692,6 +876,236 @@ func valueToStringGenerated(v interface{}) string { pv := reflect.Indirect(rv).Interface() return fmt.Sprintf("*%v", pv) } +func (m *Config) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Config: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Config: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ObjectMeta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ObjectMeta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Spec", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Spec.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *ConfigSpec) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ConfigSpec: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ConfigSpec: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msg = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Msg1", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Msg1 = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *Foo) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/api/hello.zeng.dev/v2/generated.proto b/api/hello.zeng.dev/v2/generated.proto index 2cef7da..652b1af 100644 --- a/api/hello.zeng.dev/v2/generated.proto +++ b/api/hello.zeng.dev/v2/generated.proto @@ -16,6 +16,22 @@ import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto"; // Package-wide variables from generator "generated". option go_package = "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2"; +// Config is the config subresource of Foo +message Config { + optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + + optional ConfigSpec spec = 2; +} + +message ConfigSpec { + // Msg says hello world! + optional string msg = 1; + + // Msg1 provides some verbose information + // +optional + optional string msg1 = 2; +} + message Foo { optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; diff --git a/api/hello.zeng.dev/v2/register.go b/api/hello.zeng.dev/v2/register.go index b5e01c8..79bbd11 100644 --- a/api/hello.zeng.dev/v2/register.go +++ b/api/hello.zeng.dev/v2/register.go @@ -28,6 +28,7 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &Foo{}, &FooList{}, + &Config{}, ) // add common meta types (i.e WatchEvent, ListOptions, ...) to the SchemeGroupVersion metav1.AddToGroupVersion(scheme, SchemeGroupVersion) diff --git a/api/hello.zeng.dev/v2/types.go b/api/hello.zeng.dev/v2/types.go index cd46faa..3cfa4b2 100644 --- a/api/hello.zeng.dev/v2/types.go +++ b/api/hello.zeng.dev/v2/types.go @@ -72,3 +72,21 @@ type FooList struct { Items []Foo `json:"items" protobuf:"bytes,2,rep,name=items"` } + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Config is the config subresource of Foo +type Config struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + Spec ConfigSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"` +} + +type ConfigSpec struct { + // Msg says hello world! + Msg string `json:"msg" protobuf:"bytes,1,opt,name=msg"` + // Msg1 provides some verbose information + // +optional + Msg1 string `json:"msg1,omitempty" protobuf:"bytes,2,opt,name=msg1"` +} diff --git a/api/hello.zeng.dev/v2/zz_generated.deepcopy.go b/api/hello.zeng.dev/v2/zz_generated.deepcopy.go index 81529ff..fbc0ec7 100644 --- a/api/hello.zeng.dev/v2/zz_generated.deepcopy.go +++ b/api/hello.zeng.dev/v2/zz_generated.deepcopy.go @@ -13,6 +13,49 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Config) DeepCopyInto(out *Config) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Config. +func (in *Config) DeepCopy() *Config { + if in == nil { + return nil + } + out := new(Config) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Config) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConfigSpec) DeepCopyInto(out *ConfigSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConfigSpec. +func (in *ConfigSpec) DeepCopy() *ConfigSpec { + if in == nil { + return nil + } + out := new(ConfigSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Foo) DeepCopyInto(out *Foo) { *out = *in From c8aaefdba992b7999372259492b2396b52110b71 Mon Sep 17 00:00:00 2001 From: Zeng Xu Date: Fri, 21 Jul 2023 15:41:33 +0000 Subject: [PATCH 2/5] implement subresource foos/config --- .../pkg/api/hello.zeng.dev/register.go | 1 + .../pkg/api/hello.zeng.dev/types.go | 18 ++ .../v2/zz_generated.conversion.go | 68 +++++++ .../hello.zeng.dev/zz_generated.deepcopy.go | 43 +++++ .../pkg/apiserver/apiserver.go | 28 +-- .../pkg/registry/hello.zeng.dev/foo/etcd.go | 171 +++++++++++++++++- 6 files changed, 313 insertions(+), 16 deletions(-) diff --git a/api-aggregation-lib/pkg/api/hello.zeng.dev/register.go b/api-aggregation-lib/pkg/api/hello.zeng.dev/register.go index 1c78ca7..e2b8fda 100644 --- a/api-aggregation-lib/pkg/api/hello.zeng.dev/register.go +++ b/api-aggregation-lib/pkg/api/hello.zeng.dev/register.go @@ -33,6 +33,7 @@ func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, &Foo{}, &FooList{}, + &Config{}, ) return nil } diff --git a/api-aggregation-lib/pkg/api/hello.zeng.dev/types.go b/api-aggregation-lib/pkg/api/hello.zeng.dev/types.go index 57585cc..e8d7eb0 100644 --- a/api-aggregation-lib/pkg/api/hello.zeng.dev/types.go +++ b/api-aggregation-lib/pkg/api/hello.zeng.dev/types.go @@ -71,3 +71,21 @@ type FooList struct { Items []Foo } + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Config is the config subresource of Foo +type Config struct { + metav1.TypeMeta + metav1.ObjectMeta + + Spec ConfigSpec +} + +type ConfigSpec struct { + // Msg says hello world! + Msg string + // Msg1 provides some verbose information + // +optional + Msg1 string +} diff --git a/api-aggregation-lib/pkg/api/hello.zeng.dev/v2/zz_generated.conversion.go b/api-aggregation-lib/pkg/api/hello.zeng.dev/v2/zz_generated.conversion.go index e13ec68..65620b6 100644 --- a/api-aggregation-lib/pkg/api/hello.zeng.dev/v2/zz_generated.conversion.go +++ b/api-aggregation-lib/pkg/api/hello.zeng.dev/v2/zz_generated.conversion.go @@ -26,6 +26,26 @@ func init() { // RegisterConversions adds conversion functions to the given scheme. // Public to allow building arbitrary schemes. func RegisterConversions(s *runtime.Scheme) error { + if err := s.AddGeneratedConversionFunc((*v2.Config)(nil), (*hellozengdev.Config)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v2_Config_To_hellozengdev_Config(a.(*v2.Config), b.(*hellozengdev.Config), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*hellozengdev.Config)(nil), (*v2.Config)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_hellozengdev_Config_To_v2_Config(a.(*hellozengdev.Config), b.(*v2.Config), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v2.ConfigSpec)(nil), (*hellozengdev.ConfigSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v2_ConfigSpec_To_hellozengdev_ConfigSpec(a.(*v2.ConfigSpec), b.(*hellozengdev.ConfigSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*hellozengdev.ConfigSpec)(nil), (*v2.ConfigSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_hellozengdev_ConfigSpec_To_v2_ConfigSpec(a.(*hellozengdev.ConfigSpec), b.(*v2.ConfigSpec), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*v2.Foo)(nil), (*hellozengdev.Foo)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v2_Foo_To_hellozengdev_Foo(a.(*v2.Foo), b.(*hellozengdev.Foo), scope) }); err != nil { @@ -89,6 +109,54 @@ func RegisterConversions(s *runtime.Scheme) error { return nil } +func autoConvert_v2_Config_To_hellozengdev_Config(in *v2.Config, out *hellozengdev.Config, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v2_ConfigSpec_To_hellozengdev_ConfigSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + return nil +} + +// Convert_v2_Config_To_hellozengdev_Config is an autogenerated conversion function. +func Convert_v2_Config_To_hellozengdev_Config(in *v2.Config, out *hellozengdev.Config, s conversion.Scope) error { + return autoConvert_v2_Config_To_hellozengdev_Config(in, out, s) +} + +func autoConvert_hellozengdev_Config_To_v2_Config(in *hellozengdev.Config, out *v2.Config, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_hellozengdev_ConfigSpec_To_v2_ConfigSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + return nil +} + +// Convert_hellozengdev_Config_To_v2_Config is an autogenerated conversion function. +func Convert_hellozengdev_Config_To_v2_Config(in *hellozengdev.Config, out *v2.Config, s conversion.Scope) error { + return autoConvert_hellozengdev_Config_To_v2_Config(in, out, s) +} + +func autoConvert_v2_ConfigSpec_To_hellozengdev_ConfigSpec(in *v2.ConfigSpec, out *hellozengdev.ConfigSpec, s conversion.Scope) error { + out.Msg = in.Msg + out.Msg1 = in.Msg1 + return nil +} + +// Convert_v2_ConfigSpec_To_hellozengdev_ConfigSpec is an autogenerated conversion function. +func Convert_v2_ConfigSpec_To_hellozengdev_ConfigSpec(in *v2.ConfigSpec, out *hellozengdev.ConfigSpec, s conversion.Scope) error { + return autoConvert_v2_ConfigSpec_To_hellozengdev_ConfigSpec(in, out, s) +} + +func autoConvert_hellozengdev_ConfigSpec_To_v2_ConfigSpec(in *hellozengdev.ConfigSpec, out *v2.ConfigSpec, s conversion.Scope) error { + out.Msg = in.Msg + out.Msg1 = in.Msg1 + return nil +} + +// Convert_hellozengdev_ConfigSpec_To_v2_ConfigSpec is an autogenerated conversion function. +func Convert_hellozengdev_ConfigSpec_To_v2_ConfigSpec(in *hellozengdev.ConfigSpec, out *v2.ConfigSpec, s conversion.Scope) error { + return autoConvert_hellozengdev_ConfigSpec_To_v2_ConfigSpec(in, out, s) +} + func autoConvert_v2_Foo_To_hellozengdev_Foo(in *v2.Foo, out *hellozengdev.Foo, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta if err := Convert_v2_FooSpec_To_hellozengdev_FooSpec(&in.Spec, &out.Spec, s); err != nil { diff --git a/api-aggregation-lib/pkg/api/hello.zeng.dev/zz_generated.deepcopy.go b/api-aggregation-lib/pkg/api/hello.zeng.dev/zz_generated.deepcopy.go index 03145a2..361a632 100644 --- a/api-aggregation-lib/pkg/api/hello.zeng.dev/zz_generated.deepcopy.go +++ b/api-aggregation-lib/pkg/api/hello.zeng.dev/zz_generated.deepcopy.go @@ -13,6 +13,49 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Config) DeepCopyInto(out *Config) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Config. +func (in *Config) DeepCopy() *Config { + if in == nil { + return nil + } + out := new(Config) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Config) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConfigSpec) DeepCopyInto(out *ConfigSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConfigSpec. +func (in *ConfigSpec) DeepCopy() *ConfigSpec { + if in == nil { + return nil + } + out := new(ConfigSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Foo) DeepCopyInto(out *Foo) { *out = *in diff --git a/api-aggregation-lib/pkg/apiserver/apiserver.go b/api-aggregation-lib/pkg/apiserver/apiserver.go index c4f24d4..fbbe847 100644 --- a/api-aggregation-lib/pkg/apiserver/apiserver.go +++ b/api-aggregation-lib/pkg/apiserver/apiserver.go @@ -110,20 +110,24 @@ func (c completedConfig) New() (*HelloApiServer, error) { } apiGroupInfo := genericapiserver.NewDefaultAPIGroupInfo(hello.GroupName, Scheme, metav1.ParameterCodec, Codecs) - restStorage, err := func() (rest.Storage, error) { - if c.ExtraConfig.EnableEtcdStorage { - return fooregistry.NewREST(Scheme, c.GenericConfig.RESTOptionsGetter) - } else { - return fooregistry.NewMemStore(), nil + + if !c.ExtraConfig.EnableEtcdStorage { + restStorage := fooregistry.NewMemStore() + v1storage := map[string]rest.Storage{"foos": restStorage} + v2storage := map[string]rest.Storage{"foos": restStorage} + apiGroupInfo.VersionedResourcesStorageMap["v1"] = v1storage + apiGroupInfo.VersionedResourcesStorageMap["v2"] = v2storage + } else { + restStorage, err := fooregistry.NewREST(Scheme, c.GenericConfig.RESTOptionsGetter) + if err != nil { + return nil, err } - }() - if err != nil { - return nil, err + + v1storage := map[string]rest.Storage{"foos": restStorage.Foo} + v2storage := map[string]rest.Storage{"foos": restStorage.Foo, "foos/config": restStorage.Config} + apiGroupInfo.VersionedResourcesStorageMap["v1"] = v1storage + apiGroupInfo.VersionedResourcesStorageMap["v2"] = v2storage } - v1storage := map[string]rest.Storage{"foos": restStorage} - v2storage := map[string]rest.Storage{"foos": restStorage} - apiGroupInfo.VersionedResourcesStorageMap["v1"] = v1storage - apiGroupInfo.VersionedResourcesStorageMap["v2"] = v2storage if err := s.GenericAPIServer.InstallAPIGroup(&apiGroupInfo); err != nil { return nil, err diff --git a/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go index eb3f826..0234e23 100644 --- a/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go +++ b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go @@ -1,21 +1,32 @@ package foo import ( + "context" + "fmt" + + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apiserver/pkg/registry/generic" genericregistry "k8s.io/apiserver/pkg/registry/generic/registry" "k8s.io/apiserver/pkg/registry/rest" + "sigs.k8s.io/structured-merge-diff/v4/fieldpath" hello "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/hello.zeng.dev" ) -type fooStorage struct { +type REST struct { *genericregistry.Store } -var _ rest.ShortNamesProvider = &fooStorage{} +type fooStorage struct { + Foo *REST + Config *ConfigREST +} + +var _ rest.ShortNamesProvider = &REST{} -func (*fooStorage) ShortNames() []string { +func (*REST) ShortNames() []string { return []string{"fo"} } @@ -39,5 +50,157 @@ func NewREST(scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) (*foo if err := store.CompleteWithOptions(options); err != nil { return nil, err } - return &fooStorage{store}, nil + + configStore := *store + + return &fooStorage{&REST{store}, &ConfigREST{Store: &configStore}}, nil +} + +// ConfigREST implements the config subresource for a Foo +type ConfigREST struct { + Store *genericregistry.Store +} + +var _ = rest.Patcher(&ConfigREST{}) + +// New creates a new Config resource +func (r *ConfigREST) New() runtime.Object { + return &hello.Config{} +} + +func (*ConfigREST) Destroy() { + // Given that underlying store is shared with REST, + // we don't destroy it here explicitly. +} + +// Get retrieves the object from the storage. It is required to support Patch. +func (r *ConfigREST) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) { + fooObj, err := r.Store.Get(ctx, name, options) + if err != nil { + if errors.IsNotFound(err) { + return nil, errors.NewNotFound(hello.Resource("foos/config"), name) + } + return nil, err + } + + foo := fooObj.(*hello.Foo) + + return configFromFoo(foo), nil +} + +// Update alters the spec.config subset of an object. +func (r *ConfigREST) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) { + obj, _, err := r.Store.Update( + ctx, + name, + &configUpdatedObjectInfo{name, objInfo}, + toConfigCreateValidation(createValidation), + toConfigUpdateValidation(updateValidation), + false, + options, + ) + if err != nil { + return nil, false, err + } + foo := obj.(*hello.Foo) + newConfig := configFromFoo(foo) + if err != nil { + return nil, false, errors.NewBadRequest(fmt.Sprintf("%v", err)) + } + return newConfig, false, nil +} + +// GetResetFields implements rest.ResetFieldsStrategy +func (r *ConfigREST) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set { + return r.Store.GetResetFields() +} + +// configFromFoo returns a config subresource for a foo. +func configFromFoo(foo *hello.Foo) *hello.Config { + return &hello.Config{ + ObjectMeta: metav1.ObjectMeta{ + Name: foo.Name, + Namespace: foo.Namespace, + UID: foo.UID, + ResourceVersion: foo.ResourceVersion, + CreationTimestamp: foo.CreationTimestamp, + }, + Spec: hello.ConfigSpec{ + Msg: foo.Spec.Config.Msg, + Msg1: foo.Spec.Config.Msg1, + }, + } +} + +func (r *ConfigREST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) { + return r.Store.ConvertToTable(ctx, object, tableOptions) +} + +func toConfigCreateValidation(f rest.ValidateObjectFunc) rest.ValidateObjectFunc { + return func(ctx context.Context, obj runtime.Object) error { + config := configFromFoo(obj.(*hello.Foo)) + return f(ctx, config) + } +} + +func toConfigUpdateValidation(f rest.ValidateObjectUpdateFunc) rest.ValidateObjectUpdateFunc { + return func(ctx context.Context, obj, old runtime.Object) error { + config := configFromFoo(obj.(*hello.Foo)) + oldConfig := configFromFoo(old.(*hello.Foo)) + return f(ctx, config, oldConfig) + } +} + +// configUpdatedObjectInfo transforms existing foo -> existing config -> new config -> new foo +type configUpdatedObjectInfo struct { + name string + reqObjInfo rest.UpdatedObjectInfo +} + +func (c *configUpdatedObjectInfo) Preconditions() *metav1.Preconditions { + return c.reqObjInfo.Preconditions() +} + +func (c *configUpdatedObjectInfo) UpdatedObject(ctx context.Context, oldObj runtime.Object) (runtime.Object, error) { + foo, ok := oldObj.DeepCopyObject().(*hello.Foo) + if !ok { + return nil, errors.NewBadRequest(fmt.Sprintf("expected existing object type to be Foo, got %T", foo)) + } + + // if zero-value, the existing object does not exist + if len(foo.ResourceVersion) == 0 { + return nil, errors.NewNotFound(hello.Resource("foos/config"), c.name) + } + + oldConfig := configFromFoo(foo) + + // old config -> new config + newConfigObj, err := c.reqObjInfo.UpdatedObject(ctx, oldConfig) + if err != nil { + return nil, err + } + if newConfigObj == nil { + return nil, errors.NewBadRequest("nil update passed to Config") + } + + config, ok := newConfigObj.(*hello.Config) + if !ok { + return nil, errors.NewBadRequest(fmt.Sprintf("expected input object type to be Config, but %T", newConfigObj)) + } + + // validate precondition if specified (resourceVersion matching is handled by storage) + if len(config.UID) > 0 && config.UID != foo.UID { + return nil, errors.NewConflict( + hello.Resource("foos/config"), + foo.Name, + fmt.Errorf("precondition failed: UID in precondition: %v, UID in object meta: %v", config.UID, foo.UID), + ) + } + + // move fields to object and return + foo.Spec.Config.Msg = config.Spec.Msg + foo.Spec.Config.Msg1 = config.Spec.Msg1 + foo.ResourceVersion = config.ResourceVersion + + return foo, nil } From dd45a967451104846ff497da6831deac9a0d3cb6 Mon Sep 17 00:00:00 2001 From: Zeng Xu Date: Mon, 24 Jul 2023 12:55:39 +0000 Subject: [PATCH 3/5] subresource status --- api-aggregation-lib/go.mod | 2 +- .../pkg/apiserver/apiserver.go | 2 +- .../pkg/registry/hello.zeng.dev/foo/etcd.go | 48 ++++++++++++++++- .../registry/hello.zeng.dev/foo/strategy.go | 52 +++++++++++++++++++ 4 files changed, 101 insertions(+), 3 deletions(-) diff --git a/api-aggregation-lib/go.mod b/api-aggregation-lib/go.mod index fe35d9b..dfb7afd 100644 --- a/api-aggregation-lib/go.mod +++ b/api-aggregation-lib/go.mod @@ -10,6 +10,7 @@ require ( k8s.io/client-go v0.27.3 k8s.io/component-base v0.27.3 k8s.io/klog/v2 v2.100.1 + sigs.k8s.io/structured-merge-diff/v4 v4.2.3 ) require ( @@ -99,7 +100,6 @@ require ( k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.1.2 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect ) diff --git a/api-aggregation-lib/pkg/apiserver/apiserver.go b/api-aggregation-lib/pkg/apiserver/apiserver.go index fbbe847..ad85b52 100644 --- a/api-aggregation-lib/pkg/apiserver/apiserver.go +++ b/api-aggregation-lib/pkg/apiserver/apiserver.go @@ -124,7 +124,7 @@ func (c completedConfig) New() (*HelloApiServer, error) { } v1storage := map[string]rest.Storage{"foos": restStorage.Foo} - v2storage := map[string]rest.Storage{"foos": restStorage.Foo, "foos/config": restStorage.Config} + v2storage := map[string]rest.Storage{"foos": restStorage.Foo, "foos/config": restStorage.Config, "foos/status": restStorage.Status} apiGroupInfo.VersionedResourcesStorageMap["v1"] = v1storage apiGroupInfo.VersionedResourcesStorageMap["v2"] = v2storage } diff --git a/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go index 0234e23..e4d6fac 100644 --- a/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go +++ b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go @@ -22,6 +22,7 @@ type REST struct { type fooStorage struct { Foo *REST Config *ConfigREST + Status *StatusREST } var _ rest.ShortNamesProvider = &REST{} @@ -33,6 +34,7 @@ func (*REST) ShortNames() []string { // NewREST returns a RESTStorage object that will work against API services. func NewREST(scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) (*fooStorage, error) { strategy := NewStrategy(scheme) + statusStrategy := NewStatusStrategy(strategy) store := &genericregistry.Store{ NewFunc: func() runtime.Object { return &hello.Foo{} }, @@ -52,8 +54,11 @@ func NewREST(scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) (*foo } configStore := *store + statusStore := *store + statusStore.UpdateStrategy = statusStrategy + statusStore.ResetFieldsStrategy = statusStrategy - return &fooStorage{&REST{store}, &ConfigREST{Store: &configStore}}, nil + return &fooStorage{&REST{store}, &ConfigREST{Store: &configStore}, &StatusREST{&statusStore}}, nil } // ConfigREST implements the config subresource for a Foo @@ -89,6 +94,10 @@ func (r *ConfigREST) Get(ctx context.Context, name string, options *metav1.GetOp } // Update alters the spec.config subset of an object. +// Normally option createValidation and option updateValidation are validating admission control funcs +// +// see https://github.com/kubernetes/kubernetes/blob/d25c0a1bdb81b7a9b52abf10687d701c82704602/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/patch.go#L270 +// see https://github.com/kubernetes/kubernetes/blob/d25c0a1bdb81b7a9b52abf10687d701c82704602/staging/src/k8s.io/apiserver/pkg/endpoints/handlers/update.go#L210-L216 func (r *ConfigREST) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) { obj, _, err := r.Store.Update( ctx, @@ -204,3 +213,40 @@ func (c *configUpdatedObjectInfo) UpdatedObject(ctx context.Context, oldObj runt return foo, nil } + +// StatusREST implements the REST endpoint for changing the status of a foo. +type StatusREST struct { + store *genericregistry.Store +} + +// New creates a new foo resource +func (r *StatusREST) New() runtime.Object { + return &hello.Foo{} +} + +// Destroy cleans up resources on shutdown. +func (r *StatusREST) Destroy() { + // Given that underlying store is shared with REST, + // we don't destroy it here explicitly. +} + +// Get retrieves the object from the storage. It is required to support Patch. +func (r *StatusREST) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) { + return r.store.Get(ctx, name, options) +} + +// Update alters the status subset of an object. +func (r *StatusREST) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) { + // We are explicitly setting forceAllowCreate to false in the call to the underlying storage because + // subresources should never allow create on update. + return r.store.Update(ctx, name, objInfo, createValidation, updateValidation, false, options) +} + +// GetResetFields implements rest.ResetFieldsStrategy +func (r *StatusREST) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set { + return r.store.GetResetFields() +} + +func (r *StatusREST) ConvertToTable(ctx context.Context, object runtime.Object, tableOptions runtime.Object) (*metav1.Table, error) { + return r.store.ConvertToTable(ctx, object, tableOptions) +} diff --git a/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/strategy.go b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/strategy.go index 693d7a3..2de6cfd 100644 --- a/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/strategy.go +++ b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/strategy.go @@ -12,6 +12,7 @@ import ( "k8s.io/apiserver/pkg/registry/generic" "k8s.io/apiserver/pkg/storage" "k8s.io/apiserver/pkg/storage/names" + "sigs.k8s.io/structured-merge-diff/v4/fieldpath" hello "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/hello.zeng.dev" "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/hello.zeng.dev/validation" @@ -55,6 +56,18 @@ func (fooStrategy) NamespaceScoped() bool { return true } +// GetResetFields returns the set of fields that get reset by the strategy +// and should not be modified by the user. +func (fooStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set { + fields := map[fieldpath.APIVersion]*fieldpath.Set{ + "v1": fieldpath.NewSet( + fieldpath.MakePathOrDie("status"), + ), + } + + return fields +} + func (fooStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) { } @@ -113,3 +126,42 @@ func (fooStrategy) ConvertToTable(ctx context.Context, object runtime.Object, ta return &table, nil } + +// NewStrategy creates and returns a fooStrategy instance +func NewStatusStrategy(s fooStrategy) fooStatusStrategy { + return fooStatusStrategy{fooStrategy: s} +} + +type fooStatusStrategy struct { + fooStrategy +} + +// GetResetFields returns the set of fields that get reset by the strategy +// and should not be modified by the user. +func (fooStatusStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set { + return map[fieldpath.APIVersion]*fieldpath.Set{ + "v1": fieldpath.NewSet( + fieldpath.MakePathOrDie("spec"), + fieldpath.MakePathOrDie("metadata", "deletionTimestamp"), + fieldpath.MakePathOrDie("metadata", "ownerReferences"), + ), + } +} + +func (fooStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) { + newFoo := obj.(*hello.Foo) + oldFoo := old.(*hello.Foo) + newFoo.Spec = oldFoo.Spec + newFoo.DeletionTimestamp = nil + + newFoo.OwnerReferences = oldFoo.OwnerReferences +} + +func (fooStatusStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList { + return field.ErrorList{} +} + +// WarningsOnUpdate returns warnings for the given update. +func (fooStatusStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string { + return nil +} From be8df3e9d420be8f792254e090033c4e5e6559f1 Mon Sep 17 00:00:00 2001 From: Zeng Xu Date: Tue, 25 Jul 2023 02:29:45 +0000 Subject: [PATCH 4/5] subresource base64 --- .../pkg/api/transformation/doc.go | 6 + .../pkg/api/transformation/install/install.go | 16 + .../pkg/api/transformation/register.go | 36 + .../pkg/api/transformation/types.go | 28 + .../api/transformation/v1beta1/defaults.go | 5 + .../pkg/api/transformation/v1beta1/doc.go | 9 + .../api/transformation/v1beta1/register.go | 22 + .../v1beta1/zz_generated.conversion.go | 129 +++ .../v1beta1/zz_generated.defaults.go | 21 + .../transformation/zz_generated.deepcopy.go | 74 ++ .../pkg/apiserver/apiserver.go | 10 +- .../pkg/registry/hello.zeng.dev/foo/base64.go | 118 +++ .../pkg/registry/hello.zeng.dev/foo/etcd.go | 3 +- api/generated/openapi/zz_generated.openapi.go | 217 +++-- api/hack/update-codegen-docker.sh | 2 +- api/transformation/v1beta1/doc.go | 8 + api/transformation/v1beta1/generated.pb.go | 758 ++++++++++++++++++ api/transformation/v1beta1/generated.proto | 42 + api/transformation/v1beta1/register.go | 39 + api/transformation/v1beta1/types.go | 31 + .../v1beta1/zz_generated.deepcopy.go | 74 ++ 21 files changed, 1579 insertions(+), 69 deletions(-) create mode 100644 api-aggregation-lib/pkg/api/transformation/doc.go create mode 100644 api-aggregation-lib/pkg/api/transformation/install/install.go create mode 100644 api-aggregation-lib/pkg/api/transformation/register.go create mode 100644 api-aggregation-lib/pkg/api/transformation/types.go create mode 100644 api-aggregation-lib/pkg/api/transformation/v1beta1/defaults.go create mode 100644 api-aggregation-lib/pkg/api/transformation/v1beta1/doc.go create mode 100644 api-aggregation-lib/pkg/api/transformation/v1beta1/register.go create mode 100644 api-aggregation-lib/pkg/api/transformation/v1beta1/zz_generated.conversion.go create mode 100644 api-aggregation-lib/pkg/api/transformation/v1beta1/zz_generated.defaults.go create mode 100644 api-aggregation-lib/pkg/api/transformation/zz_generated.deepcopy.go create mode 100644 api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/base64.go create mode 100644 api/transformation/v1beta1/doc.go create mode 100644 api/transformation/v1beta1/generated.pb.go create mode 100644 api/transformation/v1beta1/generated.proto create mode 100644 api/transformation/v1beta1/register.go create mode 100644 api/transformation/v1beta1/types.go create mode 100644 api/transformation/v1beta1/zz_generated.deepcopy.go diff --git a/api-aggregation-lib/pkg/api/transformation/doc.go b/api-aggregation-lib/pkg/api/transformation/doc.go new file mode 100644 index 0000000..b84d3ac --- /dev/null +++ b/api-aggregation-lib/pkg/api/transformation/doc.go @@ -0,0 +1,6 @@ +/**/ + +// +k8s:deepcopy-gen=package +// +groupName=transformation.zeng.dev + +package transformation diff --git a/api-aggregation-lib/pkg/api/transformation/install/install.go b/api-aggregation-lib/pkg/api/transformation/install/install.go new file mode 100644 index 0000000..8758f8b --- /dev/null +++ b/api-aggregation-lib/pkg/api/transformation/install/install.go @@ -0,0 +1,16 @@ +package install + +import ( + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + + transformation "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/transformation" + transformationv1beta1 "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/transformation/v1beta1" +) + +// Install registers the API group and adds types to a scheme +func Install(scheme *runtime.Scheme) { + utilruntime.Must(transformationv1beta1.AddToScheme(scheme)) + utilruntime.Must(transformation.AddToScheme(scheme)) + utilruntime.Must(scheme.SetVersionPriority(transformationv1beta1.SchemeGroupVersion)) +} diff --git a/api-aggregation-lib/pkg/api/transformation/register.go b/api-aggregation-lib/pkg/api/transformation/register.go new file mode 100644 index 0000000..27b56b1 --- /dev/null +++ b/api-aggregation-lib/pkg/api/transformation/register.go @@ -0,0 +1,36 @@ +package transformation + +import ( + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name use in this package +const GroupName = "transformation.zeng.dev" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} + +// Kind takes an unqualified kind and returns a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + // SchemeBuilder points to a list of functions added to Scheme. + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + // AddToScheme applies all the stored functions to the scheme. + AddToScheme = SchemeBuilder.AddToScheme +) + +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &Base64{}, + ) + return nil +} diff --git a/api-aggregation-lib/pkg/api/transformation/types.go b/api-aggregation-lib/pkg/api/transformation/types.go new file mode 100644 index 0000000..6b4b7f3 --- /dev/null +++ b/api-aggregation-lib/pkg/api/transformation/types.go @@ -0,0 +1,28 @@ +package transformation + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Base64 generates a base64 encoding for a specified Kubernetes object. +type Base64 struct { + metav1.TypeMeta + metav1.ObjectMeta + + Spec Base64Spec + Status Base64Status +} + +type Base64Spec struct { + // Path of the field to select in the specified object. + // defaults to . for the entire object + FieldPath string +} + +type Base64Status struct { + // Output is the base64-encoded representation of + // the specified Kubernetes object or its subfield, as defined by the fieldPath. + Output string +} diff --git a/api-aggregation-lib/pkg/api/transformation/v1beta1/defaults.go b/api-aggregation-lib/pkg/api/transformation/v1beta1/defaults.go new file mode 100644 index 0000000..8e4823b --- /dev/null +++ b/api-aggregation-lib/pkg/api/transformation/v1beta1/defaults.go @@ -0,0 +1,5 @@ +package v1beta1 + +func init() { + localSchemeBuilder.Register(RegisterDefaults) +} diff --git a/api-aggregation-lib/pkg/api/transformation/v1beta1/doc.go b/api-aggregation-lib/pkg/api/transformation/v1beta1/doc.go new file mode 100644 index 0000000..07d64c7 --- /dev/null +++ b/api-aggregation-lib/pkg/api/transformation/v1beta1/doc.go @@ -0,0 +1,9 @@ +/**/ + +// +k8s:conversion-gen=github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/transformation +// +k8s:conversion-gen-external-types=github.com/phosae/x-kubernetes/api/transformation/v1beta1 +// +groupName=transformation.zeng.dev +// +k8s:defaulter-gen=TypeMeta +// +k8s:defaulter-gen-input=github.com/phosae/x-kubernetes/api/transformation/v1beta1 + +package v1beta1 diff --git a/api-aggregation-lib/pkg/api/transformation/v1beta1/register.go b/api-aggregation-lib/pkg/api/transformation/v1beta1/register.go new file mode 100644 index 0000000..77bd075 --- /dev/null +++ b/api-aggregation-lib/pkg/api/transformation/v1beta1/register.go @@ -0,0 +1,22 @@ +package v1beta1 + +import ( + transformationv1beta1 "github.com/phosae/x-kubernetes/api/transformation/v1beta1" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name use in this package +const GroupName = "transformation.zeng.dev" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + localSchemeBuilder = &transformationv1beta1.SchemeBuilder + AddToScheme = localSchemeBuilder.AddToScheme +) diff --git a/api-aggregation-lib/pkg/api/transformation/v1beta1/zz_generated.conversion.go b/api-aggregation-lib/pkg/api/transformation/v1beta1/zz_generated.conversion.go new file mode 100644 index 0000000..76c68d3 --- /dev/null +++ b/api-aggregation-lib/pkg/api/transformation/v1beta1/zz_generated.conversion.go @@ -0,0 +1,129 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +boilerplate text in generated file header +*/ + +// Code generated by conversion-gen. DO NOT EDIT. + +package v1beta1 + +import ( + transformation "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/transformation" + v1beta1 "github.com/phosae/x-kubernetes/api/transformation/v1beta1" + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +func init() { + localSchemeBuilder.Register(RegisterConversions) +} + +// RegisterConversions adds conversion functions to the given scheme. +// Public to allow building arbitrary schemes. +func RegisterConversions(s *runtime.Scheme) error { + if err := s.AddGeneratedConversionFunc((*v1beta1.Base64)(nil), (*transformation.Base64)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_Base64_To_transformation_Base64(a.(*v1beta1.Base64), b.(*transformation.Base64), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*transformation.Base64)(nil), (*v1beta1.Base64)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_transformation_Base64_To_v1beta1_Base64(a.(*transformation.Base64), b.(*v1beta1.Base64), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.Base64Spec)(nil), (*transformation.Base64Spec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_Base64Spec_To_transformation_Base64Spec(a.(*v1beta1.Base64Spec), b.(*transformation.Base64Spec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*transformation.Base64Spec)(nil), (*v1beta1.Base64Spec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_transformation_Base64Spec_To_v1beta1_Base64Spec(a.(*transformation.Base64Spec), b.(*v1beta1.Base64Spec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1beta1.Base64Status)(nil), (*transformation.Base64Status)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_Base64Status_To_transformation_Base64Status(a.(*v1beta1.Base64Status), b.(*transformation.Base64Status), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*transformation.Base64Status)(nil), (*v1beta1.Base64Status)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_transformation_Base64Status_To_v1beta1_Base64Status(a.(*transformation.Base64Status), b.(*v1beta1.Base64Status), scope) + }); err != nil { + return err + } + return nil +} + +func autoConvert_v1beta1_Base64_To_transformation_Base64(in *v1beta1.Base64, out *transformation.Base64, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1beta1_Base64Spec_To_transformation_Base64Spec(&in.Spec, &out.Spec, s); err != nil { + return err + } + if err := Convert_v1beta1_Base64Status_To_transformation_Base64Status(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +// Convert_v1beta1_Base64_To_transformation_Base64 is an autogenerated conversion function. +func Convert_v1beta1_Base64_To_transformation_Base64(in *v1beta1.Base64, out *transformation.Base64, s conversion.Scope) error { + return autoConvert_v1beta1_Base64_To_transformation_Base64(in, out, s) +} + +func autoConvert_transformation_Base64_To_v1beta1_Base64(in *transformation.Base64, out *v1beta1.Base64, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_transformation_Base64Spec_To_v1beta1_Base64Spec(&in.Spec, &out.Spec, s); err != nil { + return err + } + if err := Convert_transformation_Base64Status_To_v1beta1_Base64Status(&in.Status, &out.Status, s); err != nil { + return err + } + return nil +} + +// Convert_transformation_Base64_To_v1beta1_Base64 is an autogenerated conversion function. +func Convert_transformation_Base64_To_v1beta1_Base64(in *transformation.Base64, out *v1beta1.Base64, s conversion.Scope) error { + return autoConvert_transformation_Base64_To_v1beta1_Base64(in, out, s) +} + +func autoConvert_v1beta1_Base64Spec_To_transformation_Base64Spec(in *v1beta1.Base64Spec, out *transformation.Base64Spec, s conversion.Scope) error { + out.FieldPath = in.FieldPath + return nil +} + +// Convert_v1beta1_Base64Spec_To_transformation_Base64Spec is an autogenerated conversion function. +func Convert_v1beta1_Base64Spec_To_transformation_Base64Spec(in *v1beta1.Base64Spec, out *transformation.Base64Spec, s conversion.Scope) error { + return autoConvert_v1beta1_Base64Spec_To_transformation_Base64Spec(in, out, s) +} + +func autoConvert_transformation_Base64Spec_To_v1beta1_Base64Spec(in *transformation.Base64Spec, out *v1beta1.Base64Spec, s conversion.Scope) error { + out.FieldPath = in.FieldPath + return nil +} + +// Convert_transformation_Base64Spec_To_v1beta1_Base64Spec is an autogenerated conversion function. +func Convert_transformation_Base64Spec_To_v1beta1_Base64Spec(in *transformation.Base64Spec, out *v1beta1.Base64Spec, s conversion.Scope) error { + return autoConvert_transformation_Base64Spec_To_v1beta1_Base64Spec(in, out, s) +} + +func autoConvert_v1beta1_Base64Status_To_transformation_Base64Status(in *v1beta1.Base64Status, out *transformation.Base64Status, s conversion.Scope) error { + out.Output = in.Output + return nil +} + +// Convert_v1beta1_Base64Status_To_transformation_Base64Status is an autogenerated conversion function. +func Convert_v1beta1_Base64Status_To_transformation_Base64Status(in *v1beta1.Base64Status, out *transformation.Base64Status, s conversion.Scope) error { + return autoConvert_v1beta1_Base64Status_To_transformation_Base64Status(in, out, s) +} + +func autoConvert_transformation_Base64Status_To_v1beta1_Base64Status(in *transformation.Base64Status, out *v1beta1.Base64Status, s conversion.Scope) error { + out.Output = in.Output + return nil +} + +// Convert_transformation_Base64Status_To_v1beta1_Base64Status is an autogenerated conversion function. +func Convert_transformation_Base64Status_To_v1beta1_Base64Status(in *transformation.Base64Status, out *v1beta1.Base64Status, s conversion.Scope) error { + return autoConvert_transformation_Base64Status_To_v1beta1_Base64Status(in, out, s) +} diff --git a/api-aggregation-lib/pkg/api/transformation/v1beta1/zz_generated.defaults.go b/api-aggregation-lib/pkg/api/transformation/v1beta1/zz_generated.defaults.go new file mode 100644 index 0000000..82baa57 --- /dev/null +++ b/api-aggregation-lib/pkg/api/transformation/v1beta1/zz_generated.defaults.go @@ -0,0 +1,21 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +boilerplate text in generated file header +*/ + +// Code generated by defaulter-gen. DO NOT EDIT. + +package v1beta1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// RegisterDefaults adds defaulters functions to the given scheme. +// Public to allow building arbitrary schemes. +// All generated defaulters are covering - they call all nested defaulters. +func RegisterDefaults(scheme *runtime.Scheme) error { + return nil +} diff --git a/api-aggregation-lib/pkg/api/transformation/zz_generated.deepcopy.go b/api-aggregation-lib/pkg/api/transformation/zz_generated.deepcopy.go new file mode 100644 index 0000000..6c86fc4 --- /dev/null +++ b/api-aggregation-lib/pkg/api/transformation/zz_generated.deepcopy.go @@ -0,0 +1,74 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +boilerplate text in generated file header +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package transformation + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Base64) DeepCopyInto(out *Base64) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Base64. +func (in *Base64) DeepCopy() *Base64 { + if in == nil { + return nil + } + out := new(Base64) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Base64) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Base64Spec) DeepCopyInto(out *Base64Spec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Base64Spec. +func (in *Base64Spec) DeepCopy() *Base64Spec { + if in == nil { + return nil + } + out := new(Base64Spec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Base64Status) DeepCopyInto(out *Base64Status) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Base64Status. +func (in *Base64Status) DeepCopy() *Base64Status { + if in == nil { + return nil + } + out := new(Base64Status) + in.DeepCopyInto(out) + return out +} diff --git a/api-aggregation-lib/pkg/apiserver/apiserver.go b/api-aggregation-lib/pkg/apiserver/apiserver.go index ad85b52..a9515b1 100644 --- a/api-aggregation-lib/pkg/apiserver/apiserver.go +++ b/api-aggregation-lib/pkg/apiserver/apiserver.go @@ -27,7 +27,8 @@ import ( clientrest "k8s.io/client-go/rest" hello "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/hello.zeng.dev" - "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/hello.zeng.dev/install" + intallhello "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/hello.zeng.dev/install" + intalltransformation "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/transformation/install" fooregistry "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo" ) @@ -40,7 +41,8 @@ var ( ) func init() { - install.Install(Scheme) + intallhello.Install(Scheme) + intalltransformation.Install(Scheme) // we need to add the options to empty v1 metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Group: "", Version: "v1"}) @@ -123,8 +125,8 @@ func (c completedConfig) New() (*HelloApiServer, error) { return nil, err } - v1storage := map[string]rest.Storage{"foos": restStorage.Foo} - v2storage := map[string]rest.Storage{"foos": restStorage.Foo, "foos/config": restStorage.Config, "foos/status": restStorage.Status} + v1storage := map[string]rest.Storage{"foos": restStorage.Foo, "foos/base64": restStorage.Base64} + v2storage := map[string]rest.Storage{"foos": restStorage.Foo, "foos/config": restStorage.Config, "foos/status": restStorage.Status, "foos/base64": restStorage.Base64} apiGroupInfo.VersionedResourcesStorageMap["v1"] = v1storage apiGroupInfo.VersionedResourcesStorageMap["v2"] = v2storage } diff --git a/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/base64.go b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/base64.go new file mode 100644 index 0000000..7c16a1b --- /dev/null +++ b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/base64.go @@ -0,0 +1,118 @@ +package foo + +import ( + "context" + "encoding/base64" + "encoding/json" + "fmt" + "strings" + + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/validation/field" + genericapirequest "k8s.io/apiserver/pkg/endpoints/request" + "k8s.io/apiserver/pkg/registry/rest" + + hello "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/hello.zeng.dev" + transformationapi "github.com/phosae/x-kubernetes/api-aggregation-lib/pkg/api/transformation" + transformationv1beta1 "github.com/phosae/x-kubernetes/api/transformation/v1beta1" +) + +type getter interface { + Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) +} + +var _ = rest.NamedCreater(&Base64REST{}) +var _ = rest.GroupVersionKindProvider(&Base64REST{}) + +type Base64REST struct { + foos getter + scheme runtime.Scheme +} + +func NewBase64REST(fooGetter getter, s *runtime.Scheme) *Base64REST { + return &Base64REST{foos: fooGetter, scheme: *s} +} + +func (r *Base64REST) New() runtime.Object { + return &transformationapi.Base64{} +} + +// Destroy cleans up resources on shutdown. +func (r *Base64REST) Destroy() { + // Given no underlying store, we don't destroy anything + // here explicitly. +} + +var gvk = schema.GroupVersionKind{ + Group: transformationv1beta1.SchemeGroupVersion.Group, + Version: transformationv1beta1.SchemeGroupVersion.Version, + Kind: "Base64", +} + +func (r *Base64REST) Create(ctx context.Context, name string, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) { + req := obj.(*transformationapi.Base64) + + // Get the namespace from the context (populated from the URL). + namespace, ok := genericapirequest.NamespaceFrom(ctx) + if !ok { + return nil, errors.NewBadRequest("namespace is required") + } + + info, ok := genericapirequest.RequestInfoFrom(ctx) + if !ok { + return nil, errors.NewBadRequest("request info is required") + } + + // require name/namespace in the body to match URL if specified + if len(req.Name) > 0 && req.Name != name { + errs := field.ErrorList{field.Invalid(field.NewPath("metadata").Child("name"), req.Name, "must match the foo name if specified")} + return nil, errors.NewInvalid(gvk.GroupKind(), name, errs) + } + if len(req.Namespace) > 0 && req.Namespace != namespace { + errs := field.ErrorList{field.Invalid(field.NewPath("metadata").Child("namespace"), req.Namespace, "must match the foo namespace if specified")} + return nil, errors.NewInvalid(gvk.GroupKind(), name, errs) + } + + // Lookup foo + fooObj, err := r.foos.Get(ctx, name, &metav1.GetOptions{}) + if err != nil { + return nil, err + } + foo := fooObj.(*hello.Foo) + groupVersioner := schema.GroupVersions([]schema.GroupVersion{{Group: info.APIGroup, Version: info.APIVersion}}) + target := unstructured.Unstructured{} + if err != r.scheme.Convert(foo, &target, groupVersioner) { + return nil, errors.NewBadRequest(fmt.Sprintf("unknown request version %s, %s", groupVersioner, err)) + } + + targetBytes, err := target.MarshalJSON() + if err != nil { + return nil, errors.NewInternalError(err) + } + + if len(req.Spec.FieldPath) > 0 { + fields := strings.Split(req.Spec.FieldPath, ".") + v, ok, err := unstructured.NestedFieldNoCopy(target.Object, fields...) + if !ok || err != nil { + return nil, errors.NewBadRequest(fmt.Sprintf("undefined field path %s", req.Spec.FieldPath)) + } + targetBytes, err = json.Marshal(v) + if err != nil { + return nil, errors.NewBadRequest(fmt.Sprintf("unexpected nested object %s", err)) + } + } + + out := req.DeepCopy() + out.Status = transformationapi.Base64Status{ + Output: base64.StdEncoding.EncodeToString(targetBytes), + } + return out, nil +} + +func (r *Base64REST) GroupVersionKind(schema.GroupVersion) schema.GroupVersionKind { + return gvk +} diff --git a/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go index e4d6fac..c5e17b7 100644 --- a/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go +++ b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go @@ -23,6 +23,7 @@ type fooStorage struct { Foo *REST Config *ConfigREST Status *StatusREST + Base64 *Base64REST } var _ rest.ShortNamesProvider = &REST{} @@ -58,7 +59,7 @@ func NewREST(scheme *runtime.Scheme, optsGetter generic.RESTOptionsGetter) (*foo statusStore.UpdateStrategy = statusStrategy statusStore.ResetFieldsStrategy = statusStrategy - return &fooStorage{&REST{store}, &ConfigREST{Store: &configStore}, &StatusREST{&statusStore}}, nil + return &fooStorage{&REST{store}, &ConfigREST{Store: &configStore}, &StatusREST{&statusStore}, NewBase64REST(store, scheme)}, nil } // ConfigREST implements the config subresource for a Foo diff --git a/api/generated/openapi/zz_generated.openapi.go b/api/generated/openapi/zz_generated.openapi.go index fd9794a..ee0178a 100644 --- a/api/generated/openapi/zz_generated.openapi.go +++ b/api/generated/openapi/zz_generated.openapi.go @@ -19,69 +19,72 @@ import ( func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { return map[string]common.OpenAPIDefinition{ - "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1.Foo": schema_x_kubernetes_api_hellozengdev_v1_Foo(ref), - "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1.FooList": schema_x_kubernetes_api_hellozengdev_v1_FooList(ref), - "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1.FooSpec": schema_x_kubernetes_api_hellozengdev_v1_FooSpec(ref), - "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.Config": schema_x_kubernetes_api_hellozengdev_v2_Config(ref), - "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.ConfigSpec": schema_x_kubernetes_api_hellozengdev_v2_ConfigSpec(ref), - "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.Foo": schema_x_kubernetes_api_hellozengdev_v2_Foo(ref), - "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooCondition": schema_x_kubernetes_api_hellozengdev_v2_FooCondition(ref), - "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooConfig": schema_x_kubernetes_api_hellozengdev_v2_FooConfig(ref), - "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooList": schema_x_kubernetes_api_hellozengdev_v2_FooList(ref), - "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooSpec": schema_x_kubernetes_api_hellozengdev_v2_FooSpec(ref), - "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooStatus": schema_x_kubernetes_api_hellozengdev_v2_FooStatus(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.APIGroup": schema_pkg_apis_meta_v1_APIGroup(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.APIGroupList": schema_pkg_apis_meta_v1_APIGroupList(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.APIResource": schema_pkg_apis_meta_v1_APIResource(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.APIResourceList": schema_pkg_apis_meta_v1_APIResourceList(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.APIVersions": schema_pkg_apis_meta_v1_APIVersions(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.ApplyOptions": schema_pkg_apis_meta_v1_ApplyOptions(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.Condition": schema_pkg_apis_meta_v1_Condition(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.CreateOptions": schema_pkg_apis_meta_v1_CreateOptions(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.DeleteOptions": schema_pkg_apis_meta_v1_DeleteOptions(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.Duration": schema_pkg_apis_meta_v1_Duration(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.FieldsV1": schema_pkg_apis_meta_v1_FieldsV1(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.GetOptions": schema_pkg_apis_meta_v1_GetOptions(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.GroupKind": schema_pkg_apis_meta_v1_GroupKind(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.GroupResource": schema_pkg_apis_meta_v1_GroupResource(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.GroupVersion": schema_pkg_apis_meta_v1_GroupVersion(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.GroupVersionForDiscovery": schema_pkg_apis_meta_v1_GroupVersionForDiscovery(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.GroupVersionKind": schema_pkg_apis_meta_v1_GroupVersionKind(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.GroupVersionResource": schema_pkg_apis_meta_v1_GroupVersionResource(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.InternalEvent": schema_pkg_apis_meta_v1_InternalEvent(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelector": schema_pkg_apis_meta_v1_LabelSelector(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelectorRequirement": schema_pkg_apis_meta_v1_LabelSelectorRequirement(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.List": schema_pkg_apis_meta_v1_List(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta": schema_pkg_apis_meta_v1_ListMeta(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.ListOptions": schema_pkg_apis_meta_v1_ListOptions(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.ManagedFieldsEntry": schema_pkg_apis_meta_v1_ManagedFieldsEntry(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.MicroTime": schema_pkg_apis_meta_v1_MicroTime(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta": schema_pkg_apis_meta_v1_ObjectMeta(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.OwnerReference": schema_pkg_apis_meta_v1_OwnerReference(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.PartialObjectMetadata": schema_pkg_apis_meta_v1_PartialObjectMetadata(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.PartialObjectMetadataList": schema_pkg_apis_meta_v1_PartialObjectMetadataList(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.Patch": schema_pkg_apis_meta_v1_Patch(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.PatchOptions": schema_pkg_apis_meta_v1_PatchOptions(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.Preconditions": schema_pkg_apis_meta_v1_Preconditions(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.RootPaths": schema_pkg_apis_meta_v1_RootPaths(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.ServerAddressByClientCIDR": schema_pkg_apis_meta_v1_ServerAddressByClientCIDR(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.Status": schema_pkg_apis_meta_v1_Status(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.StatusCause": schema_pkg_apis_meta_v1_StatusCause(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.StatusDetails": schema_pkg_apis_meta_v1_StatusDetails(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.Table": schema_pkg_apis_meta_v1_Table(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.TableColumnDefinition": schema_pkg_apis_meta_v1_TableColumnDefinition(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.TableOptions": schema_pkg_apis_meta_v1_TableOptions(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.TableRow": schema_pkg_apis_meta_v1_TableRow(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.TableRowCondition": schema_pkg_apis_meta_v1_TableRowCondition(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.Time": schema_pkg_apis_meta_v1_Time(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.Timestamp": schema_pkg_apis_meta_v1_Timestamp(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta": schema_pkg_apis_meta_v1_TypeMeta(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.UpdateOptions": schema_pkg_apis_meta_v1_UpdateOptions(ref), - "k8s.io/apimachinery/pkg/apis/meta/v1.WatchEvent": schema_pkg_apis_meta_v1_WatchEvent(ref), - "k8s.io/apimachinery/pkg/runtime.RawExtension": schema_k8sio_apimachinery_pkg_runtime_RawExtension(ref), - "k8s.io/apimachinery/pkg/runtime.TypeMeta": schema_k8sio_apimachinery_pkg_runtime_TypeMeta(ref), - "k8s.io/apimachinery/pkg/runtime.Unknown": schema_k8sio_apimachinery_pkg_runtime_Unknown(ref), - "k8s.io/apimachinery/pkg/version.Info": schema_k8sio_apimachinery_pkg_version_Info(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1.Foo": schema_x_kubernetes_api_hellozengdev_v1_Foo(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1.FooList": schema_x_kubernetes_api_hellozengdev_v1_FooList(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1.FooSpec": schema_x_kubernetes_api_hellozengdev_v1_FooSpec(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.Config": schema_x_kubernetes_api_hellozengdev_v2_Config(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.ConfigSpec": schema_x_kubernetes_api_hellozengdev_v2_ConfigSpec(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.Foo": schema_x_kubernetes_api_hellozengdev_v2_Foo(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooCondition": schema_x_kubernetes_api_hellozengdev_v2_FooCondition(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooConfig": schema_x_kubernetes_api_hellozengdev_v2_FooConfig(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooList": schema_x_kubernetes_api_hellozengdev_v2_FooList(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooSpec": schema_x_kubernetes_api_hellozengdev_v2_FooSpec(ref), + "github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2.FooStatus": schema_x_kubernetes_api_hellozengdev_v2_FooStatus(ref), + "github.com/phosae/x-kubernetes/api/transformation/v1beta1.Base64": schema_x_kubernetes_api_transformation_v1beta1_Base64(ref), + "github.com/phosae/x-kubernetes/api/transformation/v1beta1.Base64Spec": schema_x_kubernetes_api_transformation_v1beta1_Base64Spec(ref), + "github.com/phosae/x-kubernetes/api/transformation/v1beta1.Base64Status": schema_x_kubernetes_api_transformation_v1beta1_Base64Status(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.APIGroup": schema_pkg_apis_meta_v1_APIGroup(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.APIGroupList": schema_pkg_apis_meta_v1_APIGroupList(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.APIResource": schema_pkg_apis_meta_v1_APIResource(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.APIResourceList": schema_pkg_apis_meta_v1_APIResourceList(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.APIVersions": schema_pkg_apis_meta_v1_APIVersions(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.ApplyOptions": schema_pkg_apis_meta_v1_ApplyOptions(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.Condition": schema_pkg_apis_meta_v1_Condition(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.CreateOptions": schema_pkg_apis_meta_v1_CreateOptions(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.DeleteOptions": schema_pkg_apis_meta_v1_DeleteOptions(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.Duration": schema_pkg_apis_meta_v1_Duration(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.FieldsV1": schema_pkg_apis_meta_v1_FieldsV1(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.GetOptions": schema_pkg_apis_meta_v1_GetOptions(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.GroupKind": schema_pkg_apis_meta_v1_GroupKind(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.GroupResource": schema_pkg_apis_meta_v1_GroupResource(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.GroupVersion": schema_pkg_apis_meta_v1_GroupVersion(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.GroupVersionForDiscovery": schema_pkg_apis_meta_v1_GroupVersionForDiscovery(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.GroupVersionKind": schema_pkg_apis_meta_v1_GroupVersionKind(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.GroupVersionResource": schema_pkg_apis_meta_v1_GroupVersionResource(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.InternalEvent": schema_pkg_apis_meta_v1_InternalEvent(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelector": schema_pkg_apis_meta_v1_LabelSelector(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelectorRequirement": schema_pkg_apis_meta_v1_LabelSelectorRequirement(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.List": schema_pkg_apis_meta_v1_List(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta": schema_pkg_apis_meta_v1_ListMeta(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.ListOptions": schema_pkg_apis_meta_v1_ListOptions(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.ManagedFieldsEntry": schema_pkg_apis_meta_v1_ManagedFieldsEntry(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.MicroTime": schema_pkg_apis_meta_v1_MicroTime(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta": schema_pkg_apis_meta_v1_ObjectMeta(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.OwnerReference": schema_pkg_apis_meta_v1_OwnerReference(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.PartialObjectMetadata": schema_pkg_apis_meta_v1_PartialObjectMetadata(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.PartialObjectMetadataList": schema_pkg_apis_meta_v1_PartialObjectMetadataList(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.Patch": schema_pkg_apis_meta_v1_Patch(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.PatchOptions": schema_pkg_apis_meta_v1_PatchOptions(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.Preconditions": schema_pkg_apis_meta_v1_Preconditions(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.RootPaths": schema_pkg_apis_meta_v1_RootPaths(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.ServerAddressByClientCIDR": schema_pkg_apis_meta_v1_ServerAddressByClientCIDR(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.Status": schema_pkg_apis_meta_v1_Status(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.StatusCause": schema_pkg_apis_meta_v1_StatusCause(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.StatusDetails": schema_pkg_apis_meta_v1_StatusDetails(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.Table": schema_pkg_apis_meta_v1_Table(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.TableColumnDefinition": schema_pkg_apis_meta_v1_TableColumnDefinition(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.TableOptions": schema_pkg_apis_meta_v1_TableOptions(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.TableRow": schema_pkg_apis_meta_v1_TableRow(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.TableRowCondition": schema_pkg_apis_meta_v1_TableRowCondition(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.Time": schema_pkg_apis_meta_v1_Time(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.Timestamp": schema_pkg_apis_meta_v1_Timestamp(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta": schema_pkg_apis_meta_v1_TypeMeta(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.UpdateOptions": schema_pkg_apis_meta_v1_UpdateOptions(ref), + "k8s.io/apimachinery/pkg/apis/meta/v1.WatchEvent": schema_pkg_apis_meta_v1_WatchEvent(ref), + "k8s.io/apimachinery/pkg/runtime.RawExtension": schema_k8sio_apimachinery_pkg_runtime_RawExtension(ref), + "k8s.io/apimachinery/pkg/runtime.TypeMeta": schema_k8sio_apimachinery_pkg_runtime_TypeMeta(ref), + "k8s.io/apimachinery/pkg/runtime.Unknown": schema_k8sio_apimachinery_pkg_runtime_Unknown(ref), + "k8s.io/apimachinery/pkg/version.Info": schema_k8sio_apimachinery_pkg_version_Info(ref), } } @@ -494,6 +497,94 @@ func schema_x_kubernetes_api_hellozengdev_v2_FooStatus(ref common.ReferenceCallb } } +func schema_x_kubernetes_api_transformation_v1beta1_Base64(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "Base64 generates a base64 encoding for a specified Kubernetes object. Base64 is commonly implemented as a subresource for specific Kubernetes kind. For instance, you can find it used in the `/apis/hello.zeng.dev/v2/namespaces/default/foos/myfoo/base64` endpoint.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/phosae/x-kubernetes/api/transformation/v1beta1.Base64Spec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/phosae/x-kubernetes/api/transformation/v1beta1.Base64Status"), + }, + }, + }, + Required: []string{"spec"}, + }, + }, + Dependencies: []string{ + "github.com/phosae/x-kubernetes/api/transformation/v1beta1.Base64Spec", "github.com/phosae/x-kubernetes/api/transformation/v1beta1.Base64Status", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_x_kubernetes_api_transformation_v1beta1_Base64Spec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "fieldPath": { + SchemaProps: spec.SchemaProps{ + Description: "Path of the field to select in the specified object. defaults to . for the entire object", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + } +} + +func schema_x_kubernetes_api_transformation_v1beta1_Base64Status(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "output": { + SchemaProps: spec.SchemaProps{ + Description: "Output is the base64-encoded representation of the specified Kubernetes object or its subfield, as defined by the fieldPath.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"output"}, + }, + }, + } +} + func schema_pkg_apis_meta_v1_APIGroup(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/api/hack/update-codegen-docker.sh b/api/hack/update-codegen-docker.sh index 556d76d..bc99a65 100755 --- a/api/hack/update-codegen-docker.sh +++ b/api/hack/update-codegen-docker.sh @@ -23,4 +23,4 @@ docker run -it --rm -u root \ -v ${PWD}:/go/src/${PROJECT_PACKAGE}\ -w /go/src/${PROJECT_PACKAGE}\ zengxu/kube-code-generator:v1.28.0-alpha.1\ - update-generated-protobuf.sh github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1,github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2 \ No newline at end of file + update-generated-protobuf.sh github.com/phosae/x-kubernetes/api/hello.zeng.dev/v1,github.com/phosae/x-kubernetes/api/hello.zeng.dev/v2,github.com/phosae/x-kubernetes/api/transformation/v1beta1 \ No newline at end of file diff --git a/api/transformation/v1beta1/doc.go b/api/transformation/v1beta1/doc.go new file mode 100644 index 0000000..6a43fb2 --- /dev/null +++ b/api/transformation/v1beta1/doc.go @@ -0,0 +1,8 @@ +/**/ + +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package +// +k8s:protobuf-gen=package +// +groupName=transformation + +package v1beta1 diff --git a/api/transformation/v1beta1/generated.pb.go b/api/transformation/v1beta1/generated.pb.go new file mode 100644 index 0000000..2443ec5 --- /dev/null +++ b/api/transformation/v1beta1/generated.pb.go @@ -0,0 +1,758 @@ +/* +boilerplate text in generated file header +*/ + +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: github.com/phosae/x-kubernetes/api/transformation/v1beta1/generated.proto + +package v1beta1 + +import ( + fmt "fmt" + + io "io" + + proto "github.com/gogo/protobuf/proto" + + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +func (m *Base64) Reset() { *m = Base64{} } +func (*Base64) ProtoMessage() {} +func (*Base64) Descriptor() ([]byte, []int) { + return fileDescriptor_74422ff5091607f4, []int{0} +} +func (m *Base64) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Base64) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *Base64) XXX_Merge(src proto.Message) { + xxx_messageInfo_Base64.Merge(m, src) +} +func (m *Base64) XXX_Size() int { + return m.Size() +} +func (m *Base64) XXX_DiscardUnknown() { + xxx_messageInfo_Base64.DiscardUnknown(m) +} + +var xxx_messageInfo_Base64 proto.InternalMessageInfo + +func (m *Base64Spec) Reset() { *m = Base64Spec{} } +func (*Base64Spec) ProtoMessage() {} +func (*Base64Spec) Descriptor() ([]byte, []int) { + return fileDescriptor_74422ff5091607f4, []int{1} +} +func (m *Base64Spec) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Base64Spec) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *Base64Spec) XXX_Merge(src proto.Message) { + xxx_messageInfo_Base64Spec.Merge(m, src) +} +func (m *Base64Spec) XXX_Size() int { + return m.Size() +} +func (m *Base64Spec) XXX_DiscardUnknown() { + xxx_messageInfo_Base64Spec.DiscardUnknown(m) +} + +var xxx_messageInfo_Base64Spec proto.InternalMessageInfo + +func (m *Base64Status) Reset() { *m = Base64Status{} } +func (*Base64Status) ProtoMessage() {} +func (*Base64Status) Descriptor() ([]byte, []int) { + return fileDescriptor_74422ff5091607f4, []int{2} +} +func (m *Base64Status) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Base64Status) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *Base64Status) XXX_Merge(src proto.Message) { + xxx_messageInfo_Base64Status.Merge(m, src) +} +func (m *Base64Status) XXX_Size() int { + return m.Size() +} +func (m *Base64Status) XXX_DiscardUnknown() { + xxx_messageInfo_Base64Status.DiscardUnknown(m) +} + +var xxx_messageInfo_Base64Status proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Base64)(nil), "github.com.phosae.x_kubernetes.api.transformation.v1beta1.Base64") + proto.RegisterType((*Base64Spec)(nil), "github.com.phosae.x_kubernetes.api.transformation.v1beta1.Base64Spec") + proto.RegisterType((*Base64Status)(nil), "github.com.phosae.x_kubernetes.api.transformation.v1beta1.Base64Status") +} + +func init() { + proto.RegisterFile("github.com/phosae/x-kubernetes/api/transformation/v1beta1/generated.proto", fileDescriptor_74422ff5091607f4) +} + +var fileDescriptor_74422ff5091607f4 = []byte{ + // 424 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x93, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0xc7, 0xed, 0x52, 0x45, 0xe4, 0xa8, 0x90, 0xf0, 0x14, 0x65, 0xb8, 0xa2, 0x0c, 0x88, 0xa5, + 0x77, 0x04, 0x55, 0x11, 0x1d, 0x58, 0x2c, 0x01, 0x62, 0x40, 0x45, 0x66, 0x63, 0x29, 0xcf, 0xce, + 0x8b, 0x7d, 0x18, 0xfb, 0x4e, 0xbe, 0xe7, 0xa8, 0x6c, 0x7c, 0x04, 0x3e, 0x14, 0x43, 0xc6, 0x8e, + 0x9d, 0x2a, 0x62, 0xbe, 0x08, 0xf2, 0xd9, 0xd4, 0x81, 0x0a, 0x21, 0x95, 0xcd, 0xef, 0xdd, 0xfd, + 0x7f, 0xbf, 0xbf, 0x6c, 0x99, 0xbd, 0x4e, 0x15, 0x65, 0x75, 0x2c, 0x12, 0x5d, 0x48, 0x93, 0x69, + 0x0b, 0x28, 0xcf, 0x8f, 0xf2, 0x3a, 0xc6, 0xaa, 0x44, 0x42, 0x2b, 0xc1, 0x28, 0x49, 0x15, 0x94, + 0x76, 0xa5, 0xab, 0x02, 0x48, 0xe9, 0x52, 0xae, 0xe7, 0x31, 0x12, 0xcc, 0x65, 0x8a, 0x25, 0x56, + 0x40, 0xb8, 0x14, 0xa6, 0xd2, 0xa4, 0x83, 0x93, 0x01, 0x25, 0x3a, 0x94, 0x38, 0x3f, 0x1b, 0x50, + 0x02, 0x8c, 0x12, 0xbf, 0xa3, 0x44, 0x8f, 0x9a, 0x1e, 0xed, 0xb4, 0x48, 0x75, 0xaa, 0xa5, 0x23, + 0xc6, 0xf5, 0xca, 0x4d, 0x6e, 0x70, 0x4f, 0x9d, 0x69, 0x7a, 0x9c, 0x3f, 0xb3, 0x42, 0xe9, 0xb6, + 0x5c, 0x01, 0x49, 0xa6, 0x4a, 0xac, 0x3e, 0x4b, 0x93, 0xa7, 0xed, 0xc2, 0xca, 0x02, 0x09, 0xe4, + 0xfa, 0x46, 0xbf, 0xa9, 0xfc, 0x5b, 0xaa, 0xaa, 0x4b, 0x52, 0x05, 0xde, 0x08, 0x2c, 0xfe, 0x15, + 0xb0, 0x49, 0x86, 0x05, 0xfc, 0x99, 0x9b, 0x7d, 0xdb, 0x63, 0xa3, 0x10, 0x2c, 0x2e, 0x8e, 0x83, + 0x0f, 0xec, 0x6e, 0x5b, 0x67, 0x09, 0x04, 0x13, 0xff, 0xa1, 0xff, 0xf8, 0xde, 0xd3, 0x27, 0xa2, + 0xa3, 0x8a, 0x5d, 0xaa, 0x30, 0x79, 0xda, 0x2e, 0xac, 0x68, 0x6f, 0x8b, 0xf5, 0x5c, 0x9c, 0xc6, + 0x1f, 0x31, 0xa1, 0x37, 0x48, 0x10, 0x06, 0x9b, 0xab, 0x43, 0xaf, 0xb9, 0x3a, 0x64, 0xc3, 0x2e, + 0xba, 0xa6, 0x06, 0x29, 0xdb, 0xb7, 0x06, 0x93, 0xc9, 0x9e, 0xa3, 0xbf, 0x10, 0xb7, 0xfe, 0x08, + 0xa2, 0xab, 0xfc, 0xce, 0x60, 0x12, 0x1e, 0xf4, 0xca, 0xfd, 0x76, 0x8a, 0x9c, 0x20, 0xd0, 0x6c, + 0x64, 0x09, 0xa8, 0xb6, 0x93, 0x3b, 0x4e, 0xf5, 0xea, 0xff, 0x55, 0x0e, 0x17, 0xde, 0xef, 0x65, + 0xa3, 0x6e, 0x8e, 0x7a, 0xcd, 0xec, 0x39, 0x63, 0x43, 0xa5, 0x40, 0xb2, 0xf1, 0x4a, 0xe1, 0xa7, + 0xe5, 0x5b, 0xa0, 0xcc, 0xbd, 0xca, 0x71, 0xf8, 0xa0, 0x0f, 0x8e, 0x5f, 0xfe, 0x3a, 0x88, 0x86, + 0x3b, 0xb3, 0x05, 0x3b, 0xd8, 0xd5, 0x04, 0x8f, 0xd8, 0x48, 0xd7, 0x64, 0x6a, 0xea, 0xd3, 0xd7, + 0xda, 0x53, 0xb7, 0x8d, 0xfa, 0xd3, 0xf0, 0x6c, 0xb3, 0xe5, 0xde, 0xc5, 0x96, 0x7b, 0x97, 0x5b, + 0xee, 0x7d, 0x69, 0xb8, 0xbf, 0x69, 0xb8, 0x7f, 0xd1, 0x70, 0xff, 0xb2, 0xe1, 0xfe, 0xf7, 0x86, + 0xfb, 0x5f, 0x7f, 0x70, 0xef, 0xfd, 0xc9, 0xad, 0xff, 0x9b, 0x9f, 0x01, 0x00, 0x00, 0xff, 0xff, + 0x2a, 0xe0, 0x1b, 0xcd, 0x73, 0x03, 0x00, 0x00, +} + +func (m *Base64) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Base64) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Base64) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Status.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size, err := m.Spec.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.ObjectMeta.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *Base64Spec) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Base64Spec) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Base64Spec) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + i -= len(m.FieldPath) + copy(dAtA[i:], m.FieldPath) + i = encodeVarintGenerated(dAtA, i, uint64(len(m.FieldPath))) + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *Base64Status) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Base64Status) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Base64Status) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + i -= len(m.Output) + copy(dAtA[i:], m.Output) + i = encodeVarintGenerated(dAtA, i, uint64(len(m.Output))) + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenerated(dAtA []byte, offset int, v uint64) int { + offset -= sovGenerated(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Base64) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ObjectMeta.Size() + n += 1 + l + sovGenerated(uint64(l)) + l = m.Spec.Size() + n += 1 + l + sovGenerated(uint64(l)) + l = m.Status.Size() + n += 1 + l + sovGenerated(uint64(l)) + return n +} + +func (m *Base64Spec) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.FieldPath) + n += 1 + l + sovGenerated(uint64(l)) + return n +} + +func (m *Base64Status) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Output) + n += 1 + l + sovGenerated(uint64(l)) + return n +} + +func sovGenerated(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenerated(x uint64) (n int) { + return sovGenerated(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *Base64) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Base64{`, + `ObjectMeta:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.ObjectMeta), "ObjectMeta", "v1.ObjectMeta", 1), `&`, ``, 1) + `,`, + `Spec:` + strings.Replace(strings.Replace(this.Spec.String(), "Base64Spec", "Base64Spec", 1), `&`, ``, 1) + `,`, + `Status:` + strings.Replace(strings.Replace(this.Status.String(), "Base64Status", "Base64Status", 1), `&`, ``, 1) + `,`, + `}`, + }, "") + return s +} +func (this *Base64Spec) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Base64Spec{`, + `FieldPath:` + fmt.Sprintf("%v", this.FieldPath) + `,`, + `}`, + }, "") + return s +} +func (this *Base64Status) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&Base64Status{`, + `Output:` + fmt.Sprintf("%v", this.Output) + `,`, + `}`, + }, "") + return s +} +func valueToStringGenerated(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *Base64) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Base64: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Base64: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ObjectMeta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ObjectMeta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Spec", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Spec.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Status", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Status.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Base64Spec) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Base64Spec: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Base64Spec: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FieldPath", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FieldPath = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Base64Status) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Base64Status: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Base64Status: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Output", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Output = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenerated(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenerated + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenerated + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenerated + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenerated + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenerated + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenerated + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenerated = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenerated = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenerated = fmt.Errorf("proto: unexpected end of group") +) diff --git a/api/transformation/v1beta1/generated.proto b/api/transformation/v1beta1/generated.proto new file mode 100644 index 0000000..aad594f --- /dev/null +++ b/api/transformation/v1beta1/generated.proto @@ -0,0 +1,42 @@ +/* +boilerplate text in generated file header +*/ + + +// This file was autogenerated by go-to-protobuf. Do not edit it manually! + +syntax = "proto2"; + +package github.com.phosae.x_kubernetes.api.transformation.v1beta1; + +import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto"; +import "k8s.io/apimachinery/pkg/runtime/generated.proto"; +import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto"; + +// Package-wide variables from generator "generated". +option go_package = "github.com/phosae/x-kubernetes/api/transformation/v1beta1"; + +// Base64 generates a base64 encoding for a specified Kubernetes object. +// Base64 is commonly implemented as a subresource for specific Kubernetes kind. +// For instance, you can find it used in the +// `/apis/hello.zeng.dev/v2/namespaces/default/foos/myfoo/base64` endpoint. +message Base64 { + optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + + optional Base64Spec spec = 2; + + optional Base64Status status = 3; +} + +message Base64Spec { + // Path of the field to select in the specified object. + // defaults to . for the entire object + optional string fieldPath = 1; +} + +message Base64Status { + // Output is the base64-encoded representation of + // the specified Kubernetes object or its subfield, as defined by the fieldPath. + optional string output = 1; +} + diff --git a/api/transformation/v1beta1/register.go b/api/transformation/v1beta1/register.go new file mode 100644 index 0000000..ff39d1e --- /dev/null +++ b/api/transformation/v1beta1/register.go @@ -0,0 +1,39 @@ +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +const GroupName = "transformation.zeng.dev" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta1"} + +var ( + SchemeBuilder runtime.SchemeBuilder + localSchemeBuilder = &SchemeBuilder + + // AddToScheme adds this group to a scheme. + AddToScheme = localSchemeBuilder.AddToScheme +) + +func init() { + localSchemeBuilder.Register(addKnownTypes) +} + +// Adds the list of known types to the given scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &Base64{}, + ) + // add common meta types (i.e WatchEvent, ListOptions, ...) to the SchemeGroupVersion + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} diff --git a/api/transformation/v1beta1/types.go b/api/transformation/v1beta1/types.go new file mode 100644 index 0000000..5160ec8 --- /dev/null +++ b/api/transformation/v1beta1/types.go @@ -0,0 +1,31 @@ +package v1beta1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// Base64 generates a base64 encoding for a specified Kubernetes object. +// Base64 is commonly implemented as a subresource for specific Kubernetes kind. +// For instance, you can find it used in the +// `/apis/hello.zeng.dev/v2/namespaces/default/foos/myfoo/base64` endpoint. +type Base64 struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + Spec Base64Spec `json:"spec" protobuf:"bytes,2,opt,name=spec"` + Status Base64Status `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` +} + +type Base64Spec struct { + // Path of the field to select in the specified object. + // defaults to . for the entire object + FieldPath string `json:"fieldPath,omitempty" protobuf:"bytes,1,opt,name=fieldPath"` +} + +type Base64Status struct { + // Output is the base64-encoded representation of + // the specified Kubernetes object or its subfield, as defined by the fieldPath. + Output string `json:"output" protobuf:"bytes,1,opt,name=output"` +} diff --git a/api/transformation/v1beta1/zz_generated.deepcopy.go b/api/transformation/v1beta1/zz_generated.deepcopy.go new file mode 100644 index 0000000..109b852 --- /dev/null +++ b/api/transformation/v1beta1/zz_generated.deepcopy.go @@ -0,0 +1,74 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +boilerplate text in generated file header +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1beta1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Base64) DeepCopyInto(out *Base64) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Base64. +func (in *Base64) DeepCopy() *Base64 { + if in == nil { + return nil + } + out := new(Base64) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Base64) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Base64Spec) DeepCopyInto(out *Base64Spec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Base64Spec. +func (in *Base64Spec) DeepCopy() *Base64Spec { + if in == nil { + return nil + } + out := new(Base64Spec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Base64Status) DeepCopyInto(out *Base64Status) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Base64Status. +func (in *Base64Status) DeepCopy() *Base64Status { + if in == nil { + return nil + } + out := new(Base64Status) + in.DeepCopyInto(out) + return out +} From fb635e2c92dee9eb82436e041c6ca1b339d60d10 Mon Sep 17 00:00:00 2001 From: Zeng Xu Date: Tue, 25 Jul 2023 03:17:45 +0000 Subject: [PATCH 5/5] comment managedfields for config subresource --- api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go index c5e17b7..7404adf 100644 --- a/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go +++ b/api-aggregation-lib/pkg/registry/hello.zeng.dev/foo/etcd.go @@ -162,6 +162,8 @@ func toConfigUpdateValidation(f rest.ValidateObjectUpdateFunc) rest.ValidateObje } // configUpdatedObjectInfo transforms existing foo -> existing config -> new config -> new foo +// maybe or not: impelements custom managedfields for config, +// like https://github.com/kubernetes/kubernetes/blob/7e0a9a7f4e70e4cc6f5dd49917d18101a8e1a25c/pkg/registry/apps/replicaset/storage/storage.go#L320 type configUpdatedObjectInfo struct { name string reqObjInfo rest.UpdatedObjectInfo