You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by zh...@apache.org on 2026/01/19 16:22:24 UTC
(dubbo-kubernetes) branch master updated: Update tools and crds gen manifests (#849)
This is an automated email from the ASF dual-hosted git repository.
zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git
The following commit(s) were added to refs/heads/master by this push:
new ba5fc8ad Update tools and crds gen manifests (#849)
ba5fc8ad is described below
commit ba5fc8adaee7e4a97d38d25edd2854e505d48d76
Author: mfordjody <11...@qq.com>
AuthorDate: Tue Jan 20 00:22:18 2026 +0800
Update tools and crds gen manifests (#849)
* Update tools and crds gen manifests
* fix ci v1
* fix ci v2
---
.licenserc.yaml | 1 +
Makefile | 4 -
api/kubernetes/customresourcedefinitions.gen.yaml | 378 ++++++++
api/networking/v1alpha3/destination_rule.proto | 45 +-
api/networking/v1alpha3/virtual_service.proto | 40 +-
api/security/v1alpha3/peer_authentication.proto | 20 +-
dubbod/planet/pkg/bootstrap/config_controller.go | 3 -
dubbod/planet/pkg/bootstrap/options.go | 1 -
dubbod/planet/pkg/model/service.go | 2 +-
.../kube/controller/endpointslice.go | 24 +-
.../planet/pkg/serviceregistry/kube/conversion.go | 2 +-
dubbod/planet/pkg/xds/ads.go | 13 -
dubbod/planet/pkg/xds/delta.go | 25 +-
dubbod/planet/pkg/xds/statusgen.go | 6 -
dubbod/planet/pkg/xds/v3/model.go | 15 +-
dubbod/planet/pkg/xds/xdsgen.go | 34 +-
go.mod | 6 +
go.sum | 13 +
manifests/charts/base/files/crd-all.gen.yaml | 378 ++++++++
manifests/charts/base/files/crd-all.yaml | 305 ------
pkg/adsc/adsc.go | 163 ++--
pkg/adsc/util.go | 6 +-
pkg/backoff/exponential.go | 14 +-
pkg/config/constants/constants.go | 25 +-
pkg/config/kube/conversion.go | 14 +-
pkg/config/protocol/instance.go | 102 --
pkg/dubbo-agent/xds_proxy.go | 19 -
pkg/dubbo-agent/xds_proxy_delta.go | 17 -
pkg/model/xds.go | 23 +-
pkg/xds/server.go | 11 +-
tools/build-tools/docker/Dockerfile | 25 +-
tools/cmd/protoc-gen-crd/main.go | 101 ++
tools/cmd/protoc-gen-crd/openapiGenerator.go | 1025 ++++++++++++++++++++
tools/cmd/protoc-gen-crd/pkg/protocgen/generate.go | 62 ++
.../cmd/protoc-gen-crd/pkg/protomodel/baseDesc.go | 125 +++
.../pkg/protomodel/enumDescriptor.go | 63 ++
.../pkg/protomodel/fileDescriptor.go | 97 ++
.../protoc-gen-crd/pkg/protomodel/frontMatter.go | 116 +++
.../pkg/protomodel/locationDescriptor.go | 28 +-
.../pkg/protomodel/messageDescriptor.go | 80 ++
tools/cmd/protoc-gen-crd/pkg/protomodel/model.go | 180 ++++
.../pkg/protomodel/packageDescriptor.go | 73 ++
.../protoc-gen-crd/pkg/protomodel/pathVector.go | 64 ++
.../pkg/protomodel/serviceDescriptor.go | 57 ++
tools/scripts/update_crds.sh | 6 +
45 files changed, 3068 insertions(+), 743 deletions(-)
diff --git a/.licenserc.yaml b/.licenserc.yaml
index acc79317..2364d900 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -21,6 +21,7 @@ header:
# Build and dependency files
- '**/go.sum'
- '**/*.pb.go'
+ - '**/*.gen.go'
- '**/*.cache'
# Configuration and template files
diff --git a/Makefile b/Makefile
index c41923aa..07d41d4e 100644
--- a/Makefile
+++ b/Makefile
@@ -24,10 +24,6 @@ clone-sample:
mkdir -p bin
cp -r samples bin/samples
-#########
-
-#########
-
# allow optional per-repo overrides
-include client-go/Makefile.overrides.mk
diff --git a/api/kubernetes/customresourcedefinitions.gen.yaml b/api/kubernetes/customresourcedefinitions.gen.yaml
new file mode 100644
index 00000000..0c6c1dea
--- /dev/null
+++ b/api/kubernetes/customresourcedefinitions.gen.yaml
@@ -0,0 +1,378 @@
+# DO NOT EDIT - Generated by Cue OpenAPI generator based on Dubbo APIs.
+apiVersion: apiextensions.k8s.io/v1
+kind: CustomResourceDefinition
+metadata:
+ annotations:
+ "helm.sh/resource-policy": keep
+ labels:
+ app: dubbo-planet
+ chart: dubbo
+ heritage: Tiller
+ release: dubbo
+ name: destinationrules.networking.dubbo.apache.org
+spec:
+ group: networking.dubbo.apache.org
+ names:
+ categories:
+ - dubbo
+ - networking
+ kind: DestinationRule
+ listKind: DestinationRuleList
+ plural: destinationrules
+ shortNames:
+ - dr
+ singular: destinationrule
+ scope: Namespaced
+ versions:
+ - additionalPrinterColumns:
+ - description: The name of a service from the service registry
+ jsonPath: .spec.host
+ name: Host
+ type: string
+ - description: CreationTimestamp is a timestamp representing the server time when
+ this object was created. It is not guaranteed to be set in happens-before
+ order across separate operations. Clients may not set this value. It is represented
+ in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for
+ lists. For more information, see [Kubernetes API Conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata)
+ jsonPath: .metadata.creationTimestamp
+ name: Age
+ type: date
+ name: v1alpha3
+ schema:
+ openAPIV3Schema:
+ properties:
+ spec:
+ description: 'Configuration affecting load balancing, outlier detection,
+ etc. See more details at: '
+ properties:
+ exportTo:
+ description: A list of namespaces to which this destination rule is
+ exported.
+ items:
+ type: string
+ type: array
+ host:
+ type: string
+ subsets:
+ description: One or more named sets that represent individual versions
+ of a service.
+ items:
+ properties:
+ labels:
+ additionalProperties:
+ type: string
+ description: Labels apply a filter over the endpoints of a service
+ in the service registry.
+ type: object
+ name:
+ description: Name of the subset.
+ type: string
+ trafficPolicy:
+ description: Traffic policies that apply to this subset.
+ properties:
+ tls:
+ description: TLS related settings for connections to the
+ upstream service.
+ properties:
+ mode:
+ description: |-
+ Indicates whether connections to this port should be secured using TLS.
+
+ Valid Options: DISABLE, MUTUAL, DUBBO_MUTUAL
+ type: string
+ x-kubernetes-int-or-string: true
+ type: object
+ type: object
+ required:
+ - name
+ type: object
+ type: array
+ trafficPolicy:
+ description: Traffic policies to apply (load balancing policy, connection
+ pool sizes, outlier detection).
+ properties:
+ tls:
+ description: TLS related settings for connections to the upstream
+ service.
+ properties:
+ mode:
+ description: |-
+ Indicates whether connections to this port should be secured using TLS.
+
+ Valid Options: DISABLE, MUTUAL, DUBBO_MUTUAL
+ type: string
+ x-kubernetes-int-or-string: true
+ type: object
+ type: object
+ required:
+ - host
+ type: object
+ status:
+ properties:
+ conditions:
+ items:
+ properties:
+ observedGeneration:
+ anyOf:
+ - type: integer
+ - type: string
+ x-kubernetes-int-or-string: true
+ reason:
+ type: string
+ status:
+ type: string
+ type:
+ type: string
+ type: object
+ type: array
+ type: object
+ x-kubernetes-preserve-unknown-fields: true
+ type: object
+ served: true
+ storage: true
+ subresources:
+ status: {}
+---
+apiVersion: apiextensions.k8s.io/v1
+kind: CustomResourceDefinition
+metadata:
+ annotations:
+ "helm.sh/resource-policy": keep
+ labels:
+ app: dubbo-planet
+ chart: dubbo
+ heritage: Tiller
+ release: dubbo
+ name: virtualservices.networking.dubbo.apache.org
+spec:
+ group: networking.dubbo.apache.org
+ names:
+ categories:
+ - dubbo
+ - networking
+ kind: VirtualService
+ listKind: VirtualServiceList
+ plural: virtualservices
+ shortNames:
+ - vs
+ singular: virtualservice
+ scope: Namespaced
+ versions:
+ - additionalPrinterColumns:
+ - description: The destination hosts to which traffic is being sent
+ jsonPath: .spec.hosts
+ name: Hosts
+ type: string
+ - description: 'CreationTimestamp is a timestamp representing the server time
+ when this object was created. It is not guaranteed to be set in happens-before
+ order across separate operations. Clients may not set this value. It is represented
+ in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for
+ lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata'
+ jsonPath: .metadata.creationTimestamp
+ name: Age
+ type: date
+ name: v1alpha3
+ schema:
+ openAPIV3Schema:
+ properties:
+ spec:
+ description: 'Configuration affecting label/content routing, sni routing,
+ etc. See more details at: '
+ properties:
+ exportTo:
+ description: A list of namespaces to which this virtual service is
+ exported.
+ items:
+ type: string
+ type: array
+ hosts:
+ description: The hosts field applies to both HTTP and TCP services.
+ items:
+ type: string
+ type: array
+ http:
+ description: An ordered list of route rules for HTTP traffic.
+ items:
+ properties:
+ route:
+ description: A HTTP rule can either return a direct_response,
+ redirect or forward (default) traffic.
+ items:
+ properties:
+ destination:
+ description: Destination uniquely identifies the instances
+ of a service to which the request/connection should
+ be forwarded to.
+ properties:
+ host:
+ description: The name of a service from the service
+ registry.
+ type: string
+ subset:
+ description: The name of a subset within the service.
+ type: string
+ required:
+ - host
+ type: object
+ weight:
+ description: Weight specifies the relative proportion
+ of traffic to be forwarded to the destination.
+ format: int32
+ type: integer
+ required:
+ - destination
+ type: object
+ type: array
+ type: object
+ type: array
+ type: object
+ status:
+ properties:
+ conditions:
+ items:
+ properties:
+ observedGeneration:
+ anyOf:
+ - type: integer
+ - type: string
+ x-kubernetes-int-or-string: true
+ reason:
+ type: string
+ status:
+ type: string
+ type:
+ type: string
+ type: object
+ type: array
+ type: object
+ x-kubernetes-preserve-unknown-fields: true
+ type: object
+ served: true
+ storage: true
+ subresources:
+ status: {}
+---
+apiVersion: apiextensions.k8s.io/v1
+kind: CustomResourceDefinition
+metadata:
+ annotations:
+ "helm.sh/resource-policy": keep
+ labels:
+ app: dubbo-planet
+ chart: dubbo
+ dubbo: security
+ heritage: Tiller
+ release: dubbo
+ name: peerauthentications.security.dubbo.apache.org
+spec:
+ group: security.dubbo.apache.org
+ names:
+ categories:
+ - dubbo
+ - security
+ kind: PeerAuthentication
+ listKind: PeerAuthenticationList
+ plural: peerauthentications
+ shortNames:
+ - pa
+ singular: peerauthentication
+ scope: Namespaced
+ versions:
+ - additionalPrinterColumns:
+ - description: Defines the mTLS mode used for peer authentication.
+ jsonPath: .spec.mtls.mode
+ name: Mode
+ type: string
+ - description: 'CreationTimestamp is a timestamp representing the server time
+ when this object was created. It is not guaranteed to be set in happens-before
+ order across separate operations. Clients may not set this value. It is represented
+ in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for
+ lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata'
+ jsonPath: .metadata.creationTimestamp
+ name: Age
+ type: date
+ name: v1alpha3
+ schema:
+ openAPIV3Schema:
+ properties:
+ spec:
+ description: 'Peer authentication configuration for workloads. See more
+ details at: '
+ properties:
+ mtls:
+ description: Mutual TLS settings for workload.
+ properties:
+ mode:
+ description: |-
+ Defines the mTLS mode used for peer authentication.
+
+ Valid Options: DISABLE, PERMISSIVE, STRICT
+ type: string
+ x-kubernetes-int-or-string: true
+ type: object
+ portLevelMtls:
+ additionalProperties:
+ properties:
+ mode:
+ description: |-
+ Defines the mTLS mode used for peer authentication.
+
+ Valid Options: DISABLE, PERMISSIVE, STRICT
+ type: string
+ x-kubernetes-int-or-string: true
+ type: object
+ description: Port specific mutual TLS settings.
+ minProperties: 1
+ type: object
+ x-kubernetes-validations:
+ - message: port must be between 1-65535
+ rule: self.all(key, 0 < int(key) && int(key) <= 65535)
+ selector:
+ description: The selector determines the workloads to apply the PeerAuthentication
+ on.
+ properties:
+ matchLabels:
+ additionalProperties:
+ maxLength: 63
+ type: string
+ x-kubernetes-validations:
+ - message: wildcard not allowed in label value match
+ rule: '!self.contains("*")'
+ maxProperties: 4096
+ type: object
+ x-kubernetes-validations:
+ - message: wildcard not allowed in label key match
+ rule: self.all(key, !key.contains("*"))
+ - message: key must not be empty
+ rule: self.all(key, key.size() != 0)
+ type: object
+ type: object
+ x-kubernetes-validations:
+ - message: portLevelMtls requires selector
+ rule: 'has(self.portLevelMtls) ? (((has(self.selector) && has(self.selector.matchLabels))
+ ? self.selector.matchLabels : {}).size() > 0) : true'
+ status:
+ properties:
+ conditions:
+ items:
+ properties:
+ observedGeneration:
+ anyOf:
+ - type: integer
+ - type: string
+ x-kubernetes-int-or-string: true
+ reason:
+ type: string
+ status:
+ type: string
+ type:
+ type: string
+ type: object
+ type: array
+ type: object
+ x-kubernetes-preserve-unknown-fields: true
+ type: object
+ served: true
+ storage: true
+ subresources:
+ status: {}
diff --git a/api/networking/v1alpha3/destination_rule.proto b/api/networking/v1alpha3/destination_rule.proto
index f21bec3c..64b62207 100644
--- a/api/networking/v1alpha3/destination_rule.proto
+++ b/api/networking/v1alpha3/destination_rule.proto
@@ -18,6 +18,7 @@ syntax = "proto3";
// $schema: dubbo.networking.v1alpha3.DestinationRule
// $title: Destination Rule
+// $description: Configuration affecting load balancing, outlier detection, etc.
package dubbo.networking.v1alpha3;
@@ -54,29 +55,69 @@ option go_package = "/api/networking/v1alpha3";
// +k8s:deepcopy-gen=true
// -->
message DestinationRule {
+ // Note that the host field applies to both HTTP and TCP services
string host = 1 [(google.api.field_behavior) = REQUIRED];
+ // Traffic policies to apply (load balancing policy, connection pool
+ // sizes, outlier detection).
TrafficPolicy traffic_policy = 2;
+ // One or more named sets that represent individual versions of a
+ // service. Traffic policies can be overridden at subset level.
repeated Subset subsets = 3;
+ // A list of namespaces to which this destination rule is exported.
+ // The resolution of a destination rule to apply to a service occurs in the
+ // context of a hierarchy of namespaces. Exporting a destination rule allows
+ // it to be included in the resolution hierarchy for services in
+ // other namespaces. This feature provides a mechanism for service owners
+ // and mesh administrators to control the visibility of destination rules
+ // across namespace boundaries.
+ //
+ // If no namespaces are specified then the destination rule is exported to all
+ // namespaces by default.
+ //
+ // The value "." is reserved and defines an export to the same namespace that
+ // the destination rule is declared in. Similarly, the value "*" is reserved and
+ // defines an export to all namespaces.
repeated string export_to = 4;
}
+// Traffic policies to apply for a specific destination, across all
+// destination ports. See DestinationRule for examples.
message TrafficPolicy {
- ClientTLSSettings tls = 4;
+ // TLS related settings for connections to the upstream service.
+ ClientTLSSettings tls = 1;
}
message Subset {
+ // Name of the subset. The service name and the subset name can
+ // be used for traffic splitting in a route rule.
string name = 1 [(google.api.field_behavior) = REQUIRED];
+ // Labels apply a filter over the endpoints of a service in the
+ // service registry. See route rules for examples of usage.
map<string, string> labels = 2;
+ // Traffic policies that apply to this subset. Subsets inherit the
+ // traffic policies specified at the DestinationRule level. Settings
+ // specified at the subset level will override the corresponding settings
+ // specified at the DestinationRule level.
TrafficPolicy traffic_policy = 3;
}
+
message ClientTLSSettings {
+ // TLS connection mode
enum TLSmode {
+ // Do not setup a TLS connection to the upstream endpoint.
DISABLE = 0;
- // TODO Not yet implemented
+ // Originate a TLS connection to the upstream endpoint.
MUTUAL = 1;
+ // Secure connections to the upstream using mutual TLS by presenting
+ // client certificates for authentication.
+ // Compared to Mutual mode, this mode uses certificates generated
+ // automatically by Dubbo for mTLS authentication. When this mode is
+ // used, all other fields in `ClientTLSSettings` should be empty.
DUBBO_MUTUAL = 2;
}
+ // Indicates whether connections to this port should be secured
+ // using TLS. The value of this field determines how TLS is enforced.
TLSmode mode = 1;
}
diff --git a/api/networking/v1alpha3/virtual_service.proto b/api/networking/v1alpha3/virtual_service.proto
index 7b1e0b7f..ef56c119 100644
--- a/api/networking/v1alpha3/virtual_service.proto
+++ b/api/networking/v1alpha3/virtual_service.proto
@@ -16,6 +16,10 @@
syntax = "proto3";
+// $schema: dubbo.networking.v1alpha3.VirtualService
+// $title: Virtual Service
+// $description: Configuration affecting label/content routing, sni routing, etc.
+
package dubbo.networking.v1alpha3;
import "google/api/field_behavior.proto";
@@ -24,10 +28,7 @@ import "google/protobuf/wrappers.proto";
option go_package = "/api/networking/v1alpha3";
-// VirtualService defines a set of traffic routing rules to apply when a host is
-// addressed. Each routing rule defines matching criteria for traffic of a specific
-// protocol. If the traffic is matched, then it is sent to a named destination service
-// (or subset/version of it) defined in the registry.
+// Configuration affecting traffic routing.
//
// <!-- crd generation tags
// +cue-gen:VirtualService:groupName:networking.dubbo.apache.org
@@ -52,22 +53,53 @@ option go_package = "/api/networking/v1alpha3";
// +k8s:deepcopy-gen=true
// -->
message VirtualService {
+ // The hosts field applies to both HTTP and TCP services. Service inside
+ // the mesh, i.e., those found in the service registry, must always be
+ // referred to using their alphanumeric names.
repeated string hosts = 1;
+ // An ordered list of route rules for HTTP traffic.
repeated HTTPRoute http = 2;
+ // A list of namespaces to which this virtual service is exported. Exporting a
+ // virtual service allows it to be used by sidecars and gateways defined in
+ // other namespaces. This feature provides a mechanism for service owners
+ // and mesh administrators to control the visibility of virtual services
+ // across namespace boundaries.
+ //
+ // If no namespaces are specified then the virtual service is exported to all
+ // namespaces by default.
+ //
+ // The value "." is reserved and defines an export to the same namespace that
+ // the virtual service is declared in. Similarly the value "*" is reserved and
+ // defines an export to all namespaces.
repeated string export_to = 3;
}
message Destination {
+ // The name of a service from the service registry.
string host = 1 [(google.api.field_behavior) = REQUIRED];
+ // The name of a subset within the service. Applicable only to services
+ // within the mesh. The subset must be defined in a corresponding
+ // DestinationRule.
string subset = 2;
}
+// Describes match conditions and actions for routing HTTP/1.1, HTTP2, and
+// gRPC traffic. See VirtualService for usage examples.
message HTTPRoute {
+ // A HTTP rule can either return a direct_response, redirect or forward (default) traffic.
+ // The forwarding target can be one of several versions of a service (see
+ // glossary in beginning of document). Weights associated with the
+ // service version determine the proportion of traffic it receives.
repeated HTTPRouteDestination route = 1;
}
message HTTPRouteDestination {
+ // Destination uniquely identifies the instances of a service
+ // to which the request/connection should be forwarded to.
Destination destination = 1 [(google.api.field_behavior) = REQUIRED];
+ // Weight specifies the relative proportion of traffic to be forwarded to the destination. A destination will receive `weight/(sum of all weights)` requests.
+ // If there is only one destination in a rule, it will receive all traffic.
+ // Otherwise, if weight is `0`, the destination will not receive any traffic.
int32 weight = 2;
}
diff --git a/api/security/v1alpha3/peer_authentication.proto b/api/security/v1alpha3/peer_authentication.proto
index a2f50c04..adf33baa 100644
--- a/api/security/v1alpha3/peer_authentication.proto
+++ b/api/security/v1alpha3/peer_authentication.proto
@@ -16,12 +16,18 @@
syntax = "proto3";
+// $schema: dubbo.security.v1alpha3.PeerAuthentication
+// $title: PeerAuthentication
+// $description: Peer authentication configuration for workloads.
+
package dubbo.security.v1alpha3;
import "type/v1alpha3/selector.proto";
option go_package = "/api/security/v1alpha3";
+// PeerAuthentication defines mutual TLS (mTLS) requirements for incoming connections.
+//
// <!-- crd generation tags
// +cue-gen:PeerAuthentication:groupName:security.dubbo.apache.org
// +cue-gen:PeerAuthentication:versions:v1alpha3
@@ -47,30 +53,32 @@ option go_package = "/api/security/v1alpha3";
// -->
// +kubebuilder:validation:XValidation:message="portLevelMtls requires selector",rule="has(self.portLevelMtls) ? self.index({}, selector, matchLabels).size() > 0 : true"
message PeerAuthentication {
+ // The selector determines the workloads to apply the PeerAuthentication on. The selector will match with workloads in the
+ // same namespace as the policy. If the policy is in the root namespace, the selector will additionally match with workloads in all namespace.
+ //
+ // If not set, the policy will be applied to all workloads in the same namespace as the policy. If it is in the root namespace, it would be applied
+ // to all workloads in the mesh.
dubbo.type.v1alpha3.WorkloadSelector selector = 1;
// Mutual TLS settings.
message MutualTLS {
enum Mode {
// Inherit from parent, if has one. Otherwise treated as `PERMISSIVE`.
UNSET = 0;
-
// Connection is not tunneled.
DISABLE = 1;
-
// Connection can be either plaintext or mTLS tunnel.
PERMISSIVE = 2;
-
// Connection is an mTLS tunnel (TLS with client cert must be presented).
STRICT = 3;
}
-
// Defines the mTLS mode used for peer authentication.
Mode mode = 1;
}
-
// Mutual TLS settings for workload. If not defined, inherit from parent.
MutualTLS mtls = 2;
-
+ // Port specific mutual TLS settings. These only apply when a workload selector
+ // is specified. The port refers to the port of the workload, not the port of the
+ // Kubernetes service.
// +kubebuilder:validation:XValidation:message="port must be between 1-65535",rule="self.all(key, 0 < int(key) && int(key) <= 65535)"
// +kubebuilder:validation:MinProperties=1
map<uint32, MutualTLS> port_level_mtls = 3;
diff --git a/dubbod/planet/pkg/bootstrap/config_controller.go b/dubbod/planet/pkg/bootstrap/config_controller.go
index 1e13ff6d..6d230a5a 100644
--- a/dubbod/planet/pkg/bootstrap/config_controller.go
+++ b/dubbod/planet/pkg/bootstrap/config_controller.go
@@ -180,9 +180,7 @@ func (s *Server) initConfigSources(args *PlanetArgs) (err error) {
InitialDiscoveryRequests: adsc.ConfigInitialRequests(),
Config: adsc.Config{
Namespace: args.Namespace,
- Workload: args.PodName,
Revision: args.Revision,
- Meta: nil,
GrpcOpts: []grpc.DialOption{
args.KeepaliveOptions.ConvertToClientOption(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
@@ -193,7 +191,6 @@ func (s *Server) initConfigSources(args *PlanetArgs) (err error) {
return fmt.Errorf("failed to dial XDS %s %v", configSource.Address, err)
}
store := memory.Make(collections.Planet)
- // TODO: enable namespace filter for memory controller
configController := memory.NewController(store)
configController.RegisterHasSyncedHandler(xdsClient.HasSynced)
xdsClient.Store = configController
diff --git a/dubbod/planet/pkg/bootstrap/options.go b/dubbod/planet/pkg/bootstrap/options.go
index b7a71498..25fb2927 100644
--- a/dubbod/planet/pkg/bootstrap/options.go
+++ b/dubbod/planet/pkg/bootstrap/options.go
@@ -53,7 +53,6 @@ type PlanetArgs struct {
CtrlZOptions *ctrlz.Options
KeepaliveOptions *keepalive.Options
KrtDebugger *krt.DebugHandler `json:"-"`
- JwtRule string
Revision string
}
diff --git a/dubbod/planet/pkg/model/service.go b/dubbod/planet/pkg/model/service.go
index c020311b..f4f9fdc8 100644
--- a/dubbod/planet/pkg/model/service.go
+++ b/dubbod/planet/pkg/model/service.go
@@ -483,7 +483,7 @@ func (ports PortList) Equals(other PortList) bool {
func (ports PortList) GetByPort(num int) (*Port, bool) {
for _, port := range ports {
- if port.Port == num && port.Protocol != protocol.UDP {
+ if port.Port == num {
return port, true
}
}
diff --git a/dubbod/planet/pkg/serviceregistry/kube/controller/endpointslice.go b/dubbod/planet/pkg/serviceregistry/kube/controller/endpointslice.go
index 1a58d3b3..b3c8b77f 100644
--- a/dubbod/planet/pkg/serviceregistry/kube/controller/endpointslice.go
+++ b/dubbod/planet/pkg/serviceregistry/kube/controller/endpointslice.go
@@ -106,18 +106,18 @@ func (esc *endpointSliceController) onEventInternal(_, ep *v1.EndpointSlice, eve
}
configsUpdated := sets.New[model.ConfigKey]()
- supportsOnlyHTTP := true
- for _, modelSvc := range esc.c.servicesForNamespacedName(config.NamespacedName(svc)) {
- for _, p := range modelSvc.Ports {
- if !p.Protocol.IsHTTP() {
- supportsOnlyHTTP = false
- break
- }
- }
- if supportsOnlyHTTP {
- configsUpdated.Insert(model.ConfigKey{Kind: kind.ServiceEntry, Name: modelSvc.Hostname.String(), Namespace: svc.Namespace})
- }
- }
+ // supportsOnlyHTTP := true
+ // for _, modelSvc := range esc.c.servicesForNamespacedName(config.NamespacedName(svc)) {
+ // for _, p := range modelSvc.Ports {
+ // if !p.Protocol.IsHTTP() {
+ // supportsOnlyHTTP = false
+ // break
+ // }
+ // }
+ // if supportsOnlyHTTP {
+ // configsUpdated.Insert(model.ConfigKey{Kind: kind.ServiceEntry, Name: modelSvc.Hostname.String(), Namespace: svc.Namespace})
+ // }
+ // }
if len(configsUpdated) > 0 {
esc.c.opts.XDSUpdater.ConfigUpdate(&model.PushRequest{
diff --git a/dubbod/planet/pkg/serviceregistry/kube/conversion.go b/dubbod/planet/pkg/serviceregistry/kube/conversion.go
index 1ab025fd..146d3b2c 100644
--- a/dubbod/planet/pkg/serviceregistry/kube/conversion.go
+++ b/dubbod/planet/pkg/serviceregistry/kube/conversion.go
@@ -86,7 +86,7 @@ func convertPort(port corev1.ServicePort) *model.Port {
return &model.Port{
Name: port.Name,
Port: int(port.Port),
- Protocol: kube.ConvertProtocol(port.Port, port.Name, port.Protocol, port.AppProtocol),
+ Protocol: kube.ConvertProtocol(port.Port, port.Name, port.AppProtocol),
}
}
diff --git a/dubbod/planet/pkg/xds/ads.go b/dubbod/planet/pkg/xds/ads.go
index fb6b5851..6914d834 100644
--- a/dubbod/planet/pkg/xds/ads.go
+++ b/dubbod/planet/pkg/xds/ads.go
@@ -307,12 +307,6 @@ func (s *DiscoveryServer) processRequest(req *discovery.DiscoveryRequest, con *C
return nil
}
- if strings.HasPrefix(req.TypeUrl, v3.DebugType) {
- return s.pushXds(con,
- &model.WatchedResource{TypeUrl: req.TypeUrl, ResourceNames: sets.New(req.ResourceNames...)},
- &model.PushRequest{Full: true, Push: con.proxy.LastPushContext, Forced: true})
- }
-
shouldRespond, delta := xds.ShouldRespond(con.proxy, con.ID(), req)
// Log NEW requests (will respond) at INFO level so every grpcurl request is visible
@@ -331,7 +325,6 @@ func (s *DiscoveryServer) processRequest(req *discovery.DiscoveryRequest, con *C
resourceNamesStr = " [wildcard]"
}
- // Always log at INFO so手工调用 grpcurl 也能看到完整请求轨迹
if shouldRespond {
log.Infof("%s: REQ %s resources:%d nonce:%s%s (will respond)", stype,
con.ID(), len(req.ResourceNames), req.ResponseNonce, resourceNamesStr)
@@ -407,11 +400,6 @@ func (s *DiscoveryServer) processDeltaRequest(req *discovery.DeltaDiscoveryReque
if req.TypeUrl == v3.HealthInfoType {
return nil
}
- if strings.HasPrefix(req.TypeUrl, v3.DebugType) {
- return s.pushDeltaXds(con,
- &model.WatchedResource{TypeUrl: req.TypeUrl, ResourceNames: sets.New(req.ResourceNamesSubscribe...)},
- &model.PushRequest{Full: true, Push: con.proxy.LastPushContext, Forced: true})
- }
shouldRespond := shouldRespondDelta(con, req)
if !shouldRespond {
@@ -460,7 +448,6 @@ var PushOrder = []string{
v3.EndpointType,
v3.ListenerType,
v3.RouteType,
- v3.AddressType,
}
var KnownOrderedTypeUrls = sets.New(PushOrder...)
diff --git a/dubbod/planet/pkg/xds/delta.go b/dubbod/planet/pkg/xds/delta.go
index 9110511f..c2e501fd 100644
--- a/dubbod/planet/pkg/xds/delta.go
+++ b/dubbod/planet/pkg/xds/delta.go
@@ -18,10 +18,8 @@ package xds
import (
"errors"
- "strings"
- "time"
-
dubbolog "github.com/apache/dubbo-kubernetes/pkg/log"
+ "strings"
dubbogrpc "github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/grpc"
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/model"
@@ -284,10 +282,6 @@ func shouldRespondDelta(con *Connection, request *discovery.DeltaDiscoveryReques
}
res, wildcard, _ := deltaWatchedResources(nil, request)
- skip := request.TypeUrl == v3.AddressType && wildcard
- if skip {
- res = nil
- }
con.proxy.WatchedResources[request.TypeUrl] = &model.WatchedResource{
TypeUrl: request.TypeUrl,
ResourceNames: res,
@@ -342,22 +336,7 @@ func (conn *Connection) sendDelta(res *discovery.DeltaDiscoveryResponse, newReso
return conn.deltaStream.Send(res)
}
err := sendResonse()
- if err == nil {
- if !strings.HasPrefix(res.TypeUrl, v3.DebugType) {
- conn.proxy.UpdateWatchedResource(res.TypeUrl, func(wr *model.WatchedResource) *model.WatchedResource {
- if wr == nil {
- wr = &model.WatchedResource{TypeUrl: res.TypeUrl}
- }
- // some resources dynamically update ResourceNames. Most don't though
- if newResourceNames != nil {
- wr.ResourceNames = newResourceNames
- }
- wr.NonceSent = res.Nonce
- wr.LastSendTime = time.Now()
- return wr
- })
- }
- } else if status.Convert(err).Code() == codes.DeadlineExceeded {
+ if status.Convert(err).Code() == codes.DeadlineExceeded {
deltaLog.Infof("Timeout writing %s: %v", conn.ID(), v3.GetShortType(res.TypeUrl))
}
return err
diff --git a/dubbod/planet/pkg/xds/statusgen.go b/dubbod/planet/pkg/xds/statusgen.go
index ed16e549..d6216191 100644
--- a/dubbod/planet/pkg/xds/statusgen.go
+++ b/dubbod/planet/pkg/xds/statusgen.go
@@ -18,12 +18,6 @@ package xds
import (
"github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/model"
- v3 "github.com/apache/dubbo-kubernetes/dubbod/planet/pkg/xds/v3"
-)
-
-const (
- TypeDebugPrefix = v3.DebugType + "/"
- TypeDebugSyncronization = v3.DebugType + "/syncz"
)
type StatusGen struct {
diff --git a/dubbod/planet/pkg/xds/v3/model.go b/dubbod/planet/pkg/xds/v3/model.go
index bb1b39be..78664a91 100644
--- a/dubbod/planet/pkg/xds/v3/model.go
+++ b/dubbod/planet/pkg/xds/v3/model.go
@@ -19,15 +19,12 @@ package v3
import "github.com/apache/dubbo-kubernetes/pkg/model"
const (
- ClusterType = model.ClusterType
- ListenerType = model.ListenerType
- EndpointType = model.EndpointType
- RouteType = model.RouteType
- SecretType = model.SecretType
- ExtensionConfigurationType = model.ExtensionConfigurationType
- DebugType = model.DebugType
- HealthInfoType = model.HealthInfoType
- AddressType = model.AddressType
+ ClusterType = model.ClusterType
+ ListenerType = model.ListenerType
+ EndpointType = model.EndpointType
+ RouteType = model.RouteType
+ SecretType = model.SecretType
+ HealthInfoType = model.HealthInfoType
)
func GetShortType(typeURL string) string {
diff --git a/dubbod/planet/pkg/xds/xdsgen.go b/dubbod/planet/pkg/xds/xdsgen.go
index 3cf57d24..af40f01b 100644
--- a/dubbod/planet/pkg/xds/xdsgen.go
+++ b/dubbod/planet/pkg/xds/xdsgen.go
@@ -284,7 +284,7 @@ func (s *DiscoveryServer) pushXds(con *Connection, w *model.WatchedResource, req
nonceValue := nonce(req.Push.PushVersion)
resp := &discovery.DiscoveryResponse{
- ControlPlane: ControlPlane(w.TypeUrl),
+ ControlPlane: ControlPlane(),
TypeUrl: w.TypeUrl,
VersionInfo: req.Push.PushVersion,
Nonce: nonceValue,
@@ -556,7 +556,7 @@ func (s *DiscoveryServer) pushDeltaXds(con *Connection, w *model.WatchedResource
}
defer func() {}()
resp := &discovery.DeltaDiscoveryResponse{
- ControlPlane: ControlPlane(w.TypeUrl),
+ ControlPlane: ControlPlane(),
TypeUrl: w.TypeUrl,
// TODO: send different version for incremental eds
SystemVersionInfo: req.Push.PushVersion,
@@ -591,9 +591,6 @@ func (s *DiscoveryServer) pushDeltaXds(con *Connection, w *model.WatchedResource
newResourceNames = resourceNamesSet(res)
}
}
- if neverRemoveDelta(w.TypeUrl) {
- resp.RemovedResources = nil
- }
if len(resp.RemovedResources) > 0 {
deltaLog.Infof("%v REMOVE for node:%s %v", v3.GetShortType(w.TypeUrl), con.ID(), resp.RemovedResources)
}
@@ -636,12 +633,8 @@ func (s *DiscoveryServer) findGenerator(typeURL string, con *Connection) model.X
// some types to use custom generators - for example EDS.
g := con.proxy.XdsResourceGenerator
if g == nil {
- if strings.HasPrefix(typeURL, TypeDebugPrefix) {
- g = s.Generators["event"]
- } else {
- // TODO move this to just directly using the resource TypeUrl
- g = s.Generators["api"] // default to "MCP" generators - any type supported by store
- }
+ // TODO move this to just directly using the resource TypeUrl
+ g = s.Generators["api"] // default to "MCP" generators - any type supported by store
}
return g
}
@@ -660,22 +653,9 @@ func shouldSetWatchedResources(w *model.WatchedResource) bool {
if w == nil {
return false
}
- if requiresResourceNamesModification(w.TypeUrl) {
- return false
- }
return xds.IsWildcardTypeURL(w.TypeUrl)
}
-func requiresResourceNamesModification(typeURL string) bool {
- return typeURL == v3.AddressType
-}
-
-func neverRemoveDelta(typeURL string) bool {
- // Align with Envoy bug https://github.com/envoyproxy/envoy/issues/32823
- // Skip removals for ExtensionConfiguration to avoid flapping.
- return typeURL == v3.ExtensionConfigurationType
-}
-
// extractRouteNamesFromLDS extracts route names referenced in LDS listener resources
// For outbound listeners with ApiListener, the route name is the RouteConfigName from Rds config
// Route name format is the same as cluster name: "outbound|port||hostname"
@@ -807,11 +787,7 @@ func extractEDSClusterNamesFromCDS(clusters model.Resources) []string {
return clusterNames.UnsortedList()
}
-func ControlPlane(typ string) *core.ControlPlane {
- if typ != TypeDebugSyncronization {
- // Currently only TypeDebugSyncronization utilizes this so don't both sending otherwise
- return nil
- }
+func ControlPlane() *core.ControlPlane {
cp, _ := controlPlane.Get()
return cp
}
diff --git a/go.mod b/go.mod
index c20da82a..d77fed3e 100644
--- a/go.mod
+++ b/go.mod
@@ -57,6 +57,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/golang-lru/v2 v2.0.5
github.com/heroku/color v0.0.6
+ github.com/howardjohn/celpp v0.1.0
github.com/miekg/dns v1.1.68
github.com/moby/term v0.5.2
github.com/ory/viper v1.7.5
@@ -85,6 +86,7 @@ require (
k8s.io/klog/v2 v2.130.1
k8s.io/kubectl v0.33.3
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d
+ sigs.k8s.io/controller-tools v0.19.0
sigs.k8s.io/gateway-api v1.4.1
sigs.k8s.io/mcs-api v0.2.0
sigs.k8s.io/structured-merge-diff/v4 v4.6.0
@@ -112,6 +114,7 @@ require (
github.com/ProtonMail/go-crypto v1.1.3 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
+ github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/apex/log v1.9.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.12 // indirect
@@ -160,10 +163,12 @@ require (
github.com/go-openapi/jsonpointer v0.21.2 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.1 // indirect
+ github.com/gobuffalo/flect v1.0.3 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/btree v1.1.3 // indirect
+ github.com/google/cel-go v0.26.0 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/pprof v0.0.0-20250607225305-033d6d78b36a // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
@@ -236,6 +241,7 @@ require (
github.com/spf13/afero v1.14.0 // indirect
github.com/spf13/cast v1.8.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
+ github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/vbatts/tar-split v0.12.1 // indirect
diff --git a/go.sum b/go.sum
index ef273857..f44e229c 100644
--- a/go.sum
+++ b/go.sum
@@ -89,6 +89,8 @@ github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsVi
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
+github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
+github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/apex/log v1.9.0 h1:FHtw/xuaM8AgmvDDTI9fiwoAL25Sq2cxojnZICUU8l0=
github.com/apex/log v1.9.0/go.mod h1:m82fZlWIuiWzWP04XCTXmnX0xRkYYbCdYn8jbJeLBEA=
github.com/apex/logs v1.0.0/go.mod h1:XzxuLZ5myVHDy9SAmYpamKKRNApGj54PfYLcFrXqDwo=
@@ -314,6 +316,8 @@ github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
+github.com/gobuffalo/flect v1.0.3 h1:xeWBM2nui+qnVvNM4S3foBhCAL2XgPU+a7FdpelbTq4=
+github.com/gobuffalo/flect v1.0.3/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnDvkbYKHs=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
@@ -348,6 +352,8 @@ github.com/gomarkdown/markdown v0.0.0-20250810172220-2e2c11897d1a h1:l7A0loSszR5
github.com/gomarkdown/markdown v0.0.0-20250810172220-2e2c11897d1a/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
+github.com/google/cel-go v0.26.0 h1:DPGjXackMpJWH680oGY4lZhYjIameYmR+/6RBdDGmaI=
+github.com/google/cel-go v0.26.0/go.mod h1:A9O8OU9rdvrK5MQyrqfIxo1a0u4g3sF8KB6PUIaryMM=
github.com/google/generative-ai-go v0.15.1 h1:n8aQUpvhPOlGVuM2DRkJ2jvx04zpp42B778AROJa+pQ=
github.com/google/generative-ai-go v0.15.1/go.mod h1:AAucpWZjXsDKhQYWvCYuP6d0yB1kX998pJlOW1rAesw=
github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo=
@@ -409,6 +415,8 @@ github.com/heroku/color v0.0.6 h1:UTFFMrmMLFcL3OweqP1lAdp8i1y/9oHqkeHjQ/b/Ny0=
github.com/heroku/color v0.0.6/go.mod h1:ZBvOcx7cTF2QKOv4LbmoBtNl5uB17qWxGuzZrsi1wLU=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
+github.com/howardjohn/celpp v0.1.0 h1:FrN60AmjI3X90HyhiG2P1OcR5QrfCW5MDqVaSxXifKg=
+github.com/howardjohn/celpp v0.1.0/go.mod h1:3J/4o9zlxiyptUUb692ev/+WLhk26tT0TtBxx64KKYY=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI=
github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
@@ -621,6 +629,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M=
github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
+github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
+github.com/stoewer/go-strcase v1.3.0/go.mod h1:fAH5hQ5pehh+j3nZfvwdk2RgEgQjAoM8wodgtPmh1xo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
@@ -634,6 +644,7 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
+github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
@@ -917,6 +928,8 @@ k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d h1:wAhiDyZ4Tdtt7e46e9M5ZSAJ/MnPG
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
nhooyr.io/websocket v1.8.7 h1:usjR2uOr/zjjkVMy0lW+PPohFok7PCow5sDjLgX4P4g=
nhooyr.io/websocket v1.8.7/go.mod h1:B70DZP8IakI65RVQ51MsWP/8jndNma26DVA/nFSCgW0=
+sigs.k8s.io/controller-tools v0.19.0 h1:OU7jrPPiZusryu6YK0jYSjPqg8Vhf8cAzluP9XGI5uk=
+sigs.k8s.io/controller-tools v0.19.0/go.mod h1:y5HY/iNDFkmFla2CfQoVb2AQXMsBk4ad84iR1PLANB0=
sigs.k8s.io/gateway-api v1.4.1 h1:NPxFutNkKNa8UfLd2CMlEuhIPMQgDQ6DXNKG9sHbJU8=
sigs.k8s.io/gateway-api v1.4.1/go.mod h1:AR5RSqciWP98OPckEjOjh2XJhAe2Na4LHyXD2FUY7Qk=
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 h1:IpInykpT6ceI+QxKBbEflcR5EXP7sU1kvOlxwZh5txg=
diff --git a/manifests/charts/base/files/crd-all.gen.yaml b/manifests/charts/base/files/crd-all.gen.yaml
new file mode 100644
index 00000000..0c6c1dea
--- /dev/null
+++ b/manifests/charts/base/files/crd-all.gen.yaml
@@ -0,0 +1,378 @@
+# DO NOT EDIT - Generated by Cue OpenAPI generator based on Dubbo APIs.
+apiVersion: apiextensions.k8s.io/v1
+kind: CustomResourceDefinition
+metadata:
+ annotations:
+ "helm.sh/resource-policy": keep
+ labels:
+ app: dubbo-planet
+ chart: dubbo
+ heritage: Tiller
+ release: dubbo
+ name: destinationrules.networking.dubbo.apache.org
+spec:
+ group: networking.dubbo.apache.org
+ names:
+ categories:
+ - dubbo
+ - networking
+ kind: DestinationRule
+ listKind: DestinationRuleList
+ plural: destinationrules
+ shortNames:
+ - dr
+ singular: destinationrule
+ scope: Namespaced
+ versions:
+ - additionalPrinterColumns:
+ - description: The name of a service from the service registry
+ jsonPath: .spec.host
+ name: Host
+ type: string
+ - description: CreationTimestamp is a timestamp representing the server time when
+ this object was created. It is not guaranteed to be set in happens-before
+ order across separate operations. Clients may not set this value. It is represented
+ in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for
+ lists. For more information, see [Kubernetes API Conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata)
+ jsonPath: .metadata.creationTimestamp
+ name: Age
+ type: date
+ name: v1alpha3
+ schema:
+ openAPIV3Schema:
+ properties:
+ spec:
+ description: 'Configuration affecting load balancing, outlier detection,
+ etc. See more details at: '
+ properties:
+ exportTo:
+ description: A list of namespaces to which this destination rule is
+ exported.
+ items:
+ type: string
+ type: array
+ host:
+ type: string
+ subsets:
+ description: One or more named sets that represent individual versions
+ of a service.
+ items:
+ properties:
+ labels:
+ additionalProperties:
+ type: string
+ description: Labels apply a filter over the endpoints of a service
+ in the service registry.
+ type: object
+ name:
+ description: Name of the subset.
+ type: string
+ trafficPolicy:
+ description: Traffic policies that apply to this subset.
+ properties:
+ tls:
+ description: TLS related settings for connections to the
+ upstream service.
+ properties:
+ mode:
+ description: |-
+ Indicates whether connections to this port should be secured using TLS.
+
+ Valid Options: DISABLE, MUTUAL, DUBBO_MUTUAL
+ type: string
+ x-kubernetes-int-or-string: true
+ type: object
+ type: object
+ required:
+ - name
+ type: object
+ type: array
+ trafficPolicy:
+ description: Traffic policies to apply (load balancing policy, connection
+ pool sizes, outlier detection).
+ properties:
+ tls:
+ description: TLS related settings for connections to the upstream
+ service.
+ properties:
+ mode:
+ description: |-
+ Indicates whether connections to this port should be secured using TLS.
+
+ Valid Options: DISABLE, MUTUAL, DUBBO_MUTUAL
+ type: string
+ x-kubernetes-int-or-string: true
+ type: object
+ type: object
+ required:
+ - host
+ type: object
+ status:
+ properties:
+ conditions:
+ items:
+ properties:
+ observedGeneration:
+ anyOf:
+ - type: integer
+ - type: string
+ x-kubernetes-int-or-string: true
+ reason:
+ type: string
+ status:
+ type: string
+ type:
+ type: string
+ type: object
+ type: array
+ type: object
+ x-kubernetes-preserve-unknown-fields: true
+ type: object
+ served: true
+ storage: true
+ subresources:
+ status: {}
+---
+apiVersion: apiextensions.k8s.io/v1
+kind: CustomResourceDefinition
+metadata:
+ annotations:
+ "helm.sh/resource-policy": keep
+ labels:
+ app: dubbo-planet
+ chart: dubbo
+ heritage: Tiller
+ release: dubbo
+ name: virtualservices.networking.dubbo.apache.org
+spec:
+ group: networking.dubbo.apache.org
+ names:
+ categories:
+ - dubbo
+ - networking
+ kind: VirtualService
+ listKind: VirtualServiceList
+ plural: virtualservices
+ shortNames:
+ - vs
+ singular: virtualservice
+ scope: Namespaced
+ versions:
+ - additionalPrinterColumns:
+ - description: The destination hosts to which traffic is being sent
+ jsonPath: .spec.hosts
+ name: Hosts
+ type: string
+ - description: 'CreationTimestamp is a timestamp representing the server time
+ when this object was created. It is not guaranteed to be set in happens-before
+ order across separate operations. Clients may not set this value. It is represented
+ in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for
+ lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata'
+ jsonPath: .metadata.creationTimestamp
+ name: Age
+ type: date
+ name: v1alpha3
+ schema:
+ openAPIV3Schema:
+ properties:
+ spec:
+ description: 'Configuration affecting label/content routing, sni routing,
+ etc. See more details at: '
+ properties:
+ exportTo:
+ description: A list of namespaces to which this virtual service is
+ exported.
+ items:
+ type: string
+ type: array
+ hosts:
+ description: The hosts field applies to both HTTP and TCP services.
+ items:
+ type: string
+ type: array
+ http:
+ description: An ordered list of route rules for HTTP traffic.
+ items:
+ properties:
+ route:
+ description: A HTTP rule can either return a direct_response,
+ redirect or forward (default) traffic.
+ items:
+ properties:
+ destination:
+ description: Destination uniquely identifies the instances
+ of a service to which the request/connection should
+ be forwarded to.
+ properties:
+ host:
+ description: The name of a service from the service
+ registry.
+ type: string
+ subset:
+ description: The name of a subset within the service.
+ type: string
+ required:
+ - host
+ type: object
+ weight:
+ description: Weight specifies the relative proportion
+ of traffic to be forwarded to the destination.
+ format: int32
+ type: integer
+ required:
+ - destination
+ type: object
+ type: array
+ type: object
+ type: array
+ type: object
+ status:
+ properties:
+ conditions:
+ items:
+ properties:
+ observedGeneration:
+ anyOf:
+ - type: integer
+ - type: string
+ x-kubernetes-int-or-string: true
+ reason:
+ type: string
+ status:
+ type: string
+ type:
+ type: string
+ type: object
+ type: array
+ type: object
+ x-kubernetes-preserve-unknown-fields: true
+ type: object
+ served: true
+ storage: true
+ subresources:
+ status: {}
+---
+apiVersion: apiextensions.k8s.io/v1
+kind: CustomResourceDefinition
+metadata:
+ annotations:
+ "helm.sh/resource-policy": keep
+ labels:
+ app: dubbo-planet
+ chart: dubbo
+ dubbo: security
+ heritage: Tiller
+ release: dubbo
+ name: peerauthentications.security.dubbo.apache.org
+spec:
+ group: security.dubbo.apache.org
+ names:
+ categories:
+ - dubbo
+ - security
+ kind: PeerAuthentication
+ listKind: PeerAuthenticationList
+ plural: peerauthentications
+ shortNames:
+ - pa
+ singular: peerauthentication
+ scope: Namespaced
+ versions:
+ - additionalPrinterColumns:
+ - description: Defines the mTLS mode used for peer authentication.
+ jsonPath: .spec.mtls.mode
+ name: Mode
+ type: string
+ - description: 'CreationTimestamp is a timestamp representing the server time
+ when this object was created. It is not guaranteed to be set in happens-before
+ order across separate operations. Clients may not set this value. It is represented
+ in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for
+ lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata'
+ jsonPath: .metadata.creationTimestamp
+ name: Age
+ type: date
+ name: v1alpha3
+ schema:
+ openAPIV3Schema:
+ properties:
+ spec:
+ description: 'Peer authentication configuration for workloads. See more
+ details at: '
+ properties:
+ mtls:
+ description: Mutual TLS settings for workload.
+ properties:
+ mode:
+ description: |-
+ Defines the mTLS mode used for peer authentication.
+
+ Valid Options: DISABLE, PERMISSIVE, STRICT
+ type: string
+ x-kubernetes-int-or-string: true
+ type: object
+ portLevelMtls:
+ additionalProperties:
+ properties:
+ mode:
+ description: |-
+ Defines the mTLS mode used for peer authentication.
+
+ Valid Options: DISABLE, PERMISSIVE, STRICT
+ type: string
+ x-kubernetes-int-or-string: true
+ type: object
+ description: Port specific mutual TLS settings.
+ minProperties: 1
+ type: object
+ x-kubernetes-validations:
+ - message: port must be between 1-65535
+ rule: self.all(key, 0 < int(key) && int(key) <= 65535)
+ selector:
+ description: The selector determines the workloads to apply the PeerAuthentication
+ on.
+ properties:
+ matchLabels:
+ additionalProperties:
+ maxLength: 63
+ type: string
+ x-kubernetes-validations:
+ - message: wildcard not allowed in label value match
+ rule: '!self.contains("*")'
+ maxProperties: 4096
+ type: object
+ x-kubernetes-validations:
+ - message: wildcard not allowed in label key match
+ rule: self.all(key, !key.contains("*"))
+ - message: key must not be empty
+ rule: self.all(key, key.size() != 0)
+ type: object
+ type: object
+ x-kubernetes-validations:
+ - message: portLevelMtls requires selector
+ rule: 'has(self.portLevelMtls) ? (((has(self.selector) && has(self.selector.matchLabels))
+ ? self.selector.matchLabels : {}).size() > 0) : true'
+ status:
+ properties:
+ conditions:
+ items:
+ properties:
+ observedGeneration:
+ anyOf:
+ - type: integer
+ - type: string
+ x-kubernetes-int-or-string: true
+ reason:
+ type: string
+ status:
+ type: string
+ type:
+ type: string
+ type: object
+ type: array
+ type: object
+ x-kubernetes-preserve-unknown-fields: true
+ type: object
+ served: true
+ storage: true
+ subresources:
+ status: {}
diff --git a/manifests/charts/base/files/crd-all.yaml b/manifests/charts/base/files/crd-all.yaml
deleted file mode 100644
index 3ec71baf..00000000
--- a/manifests/charts/base/files/crd-all.yaml
+++ /dev/null
@@ -1,305 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
----
-apiVersion: apiextensions.k8s.io/v1
-kind: CustomResourceDefinition
-metadata:
- annotations:
- "helm.sh/resource-policy": keep
- labels:
- app: dubbo-planet
- chart: dubbo
- heritage: Tiller
- release: dubbo
- name: destinationrules.networking.dubbo.apache.org
-spec:
- group: networking.dubbo.apache.org
- names:
- categories:
- - dubbo
- - networking
- kind: DestinationRule
- listKind: DestinationRuleList
- plural: destinationrules
- shortNames:
- - dr
- singular: destinationrule
- scope: Namespaced
- versions:
- - additionalPrinterColumns:
- - description: The name of a service from the service registry
- jsonPath: .spec.host
- name: Host
- type: string
- - description: CreationTimestamp is a timestamp representing the server time when
- this object was created. It is not guaranteed to be set in happens-before
- order across separate operations. Clients may not set this value. It is represented
- in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for
- lists. For more information, see [Kubernetes API Conventions](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#metadata)
- jsonPath: .metadata.creationTimestamp
- name: Age
- type: date
- name: v1
- schema:
- openAPIV3Schema:
- properties:
- spec:
- description: 'Configuration related to load balancing and traffic policies.'
- properties:
- exportTo:
- description: A list of namespaces to which this subset rule is exported.
- items:
- type: string
- type: array
- host:
- description: The name of a service from the service registry.
- type: string
- subsets:
- description: One or more named sets that represent individual versions of a service.
- items:
- properties:
- labels:
- additionalProperties:
- type: string
- description: Labels apply a filter over the endpoints of a service in the service registry.
- type: object
- name:
- description: Name of the subset.
- type: string
- trafficPolicy:
- description: Traffic policies that apply to this subset.
- properties:
- tls:
- description: TLS related settings for connections to the
- upstream service.
- properties:
- mode:
- description: |-
- Indicates whether connections to this port should be secured using TLS.
-
- Valid Options: DISABLE, SIMPLE, MUTUAL, DUBBO_MUTUAL
- enum:
- - DISABLE
- - SIMPLE
- - MUTUAL
- - DUBBO_MUTUAL
- type: string
- type: object
- type: object
- required:
- - name
- type: object
- type: array
- trafficPolicy:
- description: Traffic policies to apply (load balancing policy, connection
- pool sizes, outlier detection).
- properties:
- tls:
- description: TLS related settings for connections to the upstream service.
- properties:
- mode:
- description: |-
- Indicates whether connections to this port should be secured using TLS.
-
- Valid Options: DISABLE, SIMPLE, MUTUAL, DUBBO_MUTUAL
- enum:
- - DISABLE
- - SIMPLE
- - MUTUAL
- - DUBBO_MUTUAL
- type: string
- type: object
- type: object
- required:
- - host
- type: object
- type: object
- served: true
- storage: true
- subresources:
- status: {}
----
-apiVersion: apiextensions.k8s.io/v1
-kind: CustomResourceDefinition
-metadata:
- annotations:
- "helm.sh/resource-policy": keep
- labels:
- app: dubbo-planet
- chart: dubbo
- heritage: Tiller
- release: dubbo
- name: virtualservices.networking.dubbo.apache.org
-spec:
- group: networking.dubbo.apache.org
- names:
- categories:
- - dubbo
- - networking
- kind: VirtualService
- listKind: VirtualServiceList
- plural: virtualservices
- shortNames:
- - vs
- singular: virtualservice
- scope: Namespaced
- versions:
- - additionalPrinterColumns:
- - description: The subset hosts to which traffic is being sent
- jsonPath: .spec.hosts
- name: Hosts
- type: string
- - description: 'CreationTimestamp is a timestamp representing the server time
- when this object was created. It is not guaranteed to be set in happens-before
- order across separate operations. Clients may not set this value. It is represented
- in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for
- lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata'
- jsonPath: .metadata.creationTimestamp
- name: Age
- type: date
- name: v1
- schema:
- openAPIV3Schema:
- properties:
- spec:
- description: 'Configuration related to label-based routing.'
- properties:
- exportTo:
- description: A list of namespaces to which this service route is
- exported.
- items:
- type: string
- type: array
- hosts:
- description: The subset hosts to which traffic is being sent.
- items:
- type: string
- type: array
- http:
- description: An ordered list of route rules for HTTP traffic.
- items:
- properties:
- route:
- description: A HTTP rule can either return a direct_response,
- redirect or forward (default) traffic.
- items:
- properties:
- destination:
- description: Subset uniquely identifies the instances
- of a service to which the request/connection should
- be forwarded to.
- properties:
- host:
- description: The name of a service from the service registry.
- type: string
- port:
- description: Specifies the port on the host that is being addressed.
- properties:
- number:
- maximum: 4294967295
- minimum: 0
- type: integer
- type: object
- subset:
- description: The name of a subset within the service.
- type: string
- required:
- - host
- type: object
- weight:
- description: Weight specifies the relative proportion
- of traffic to be forwarded to the subset.
- format: int32
- type: integer
- required:
- - destination
- type: object
- type: array
- type: object
- type: array
- type: object
- type: object
- served: true
- storage: true
- subresources:
- status: {}
----
-apiVersion: apiextensions.k8s.io/v1
-kind: CustomResourceDefinition
-metadata:
- annotations:
- "helm.sh/resource-policy": keep
- labels:
- app: dubbo-planet
- chart: dubbo
- heritage: Tiller
- release: dubbo
- name: peerauthentications.security.dubbo.apache.org
-spec:
- group: security.dubbo.apache.org
- names:
- categories:
- - dubbo
- - security
- kind: PeerAuthentication
- listKind: PeerAuthenticationList
- plural: peerauthentications
- shortNames:
- - pa
- singular: peerauthentication
- scope: Namespaced
- versions:
- - additionalPrinterColumns:
- - description: Defines the mTLS mode used for peer authentication.
- jsonPath: .spec.mtls.mode
- name: Mode
- type: string
- - description: 'CreationTimestamp is a timestamp representing the server time
- when this object was created. It is not guaranteed to be set in happens-before
- order across separate operations. Clients may not set this value. It is represented
- in RFC3339 form and is in UTC. Populated by the system. Read-only. Null for
- lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata'
- jsonPath: .metadata.creationTimestamp
- name: Age
- type: date
- name: v1
- schema:
- openAPIV3Schema:
- properties:
- spec:
- description: 'Peer authentication configuration for workloads.'
- properties:
- mtls:
- description: Mutual TLS settings for workload.
- properties:
- mode:
- description: |-
- Defines the mTLS mode used for peer authentication.
-
- Valid Options: DISABLE, PERMISSIVE, STRICT
- enum:
- - UNSET
- - DISABLE
- - PERMISSIVE
- - STRICT
- type: string
- type: object
- type: object
- type: object
- served: true
- storage: true
- subresources:
- status: {}
diff --git a/pkg/adsc/adsc.go b/pkg/adsc/adsc.go
index f60a2e17..b9be6ef6 100644
--- a/pkg/adsc/adsc.go
+++ b/pkg/adsc/adsc.go
@@ -24,7 +24,6 @@ import (
"math"
"net"
"os"
- "strings"
"sync"
"time"
@@ -35,11 +34,11 @@ import (
"github.com/apache/dubbo-kubernetes/pkg/backoff"
"github.com/apache/dubbo-kubernetes/pkg/config/schema/collections"
"github.com/apache/dubbo-kubernetes/pkg/config/schema/gvk"
+ dubbolog "github.com/apache/dubbo-kubernetes/pkg/log"
"github.com/apache/dubbo-kubernetes/pkg/security"
"github.com/apache/dubbo-kubernetes/pkg/util/protomarshal"
"github.com/apache/dubbo-kubernetes/pkg/wellknown"
cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
- core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
endpoint "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
listener "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
route "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
@@ -48,21 +47,26 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/proto"
- pstruct "google.golang.org/protobuf/types/known/structpb"
-
- dubbolog "github.com/apache/dubbo-kubernetes/pkg/log"
)
var log = dubbolog.RegisterScope("adsc", "adsc debugging")
+type ResponseHandler interface {
+ HandleResponse(con *ADSC, response *discovery.DiscoveryResponse)
+}
+
const (
defaultClientMaxReceiveMessageSize = math.MaxInt32
defaultInitialConnWindowSize = 1024 * 1024 // default gRPC InitialWindowSize
defaultInitialWindowSize = 1024 * 1024 // default gRPC ConnWindowSize
)
-type ResponseHandler interface {
- HandleResponse(con *ADSC, response *discovery.DiscoveryResponse)
+func defaultGrpcDialOptions() []grpc.DialOption {
+ return []grpc.DialOption{
+ grpc.WithInitialWindowSize(int32(defaultInitialWindowSize)),
+ grpc.WithInitialConnWindowSize(int32(defaultInitialConnWindowSize)),
+ grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaultClientMaxReceiveMessageSize)),
+ }
}
type Config struct {
@@ -82,12 +86,8 @@ type Config struct {
XDSRootCAFile string
// XDSSAN is the expected SAN of the XDS server. If not set, the ProxyConfig.DiscoveryAddress is used.
XDSSAN string
- // Workload defaults to 'test'
- Workload string
// Revision for this control plane instance. We will only read configs that match this revision.
Revision string
- // Meta includes additional metadata for the node
- Meta *pstruct.Struct
// BackoffPolicy determines the reconnect policy.
BackoffPolicy backoff.BackOff
}
@@ -107,18 +107,12 @@ type ADSC struct {
errChan chan error
XDSUpdates chan *discovery.DiscoveryResponse
VersionInfo map[string]string
-
// Last received message, by type
Received map[string]*discovery.DiscoveryResponse
-
- mutex sync.RWMutex
-
- Mesh *v1alpha1.MeshGlobalConfig
-
- Store model.ConfigStore
- cfg *ADSConfig
- // sendNodeMeta is set to true if the connection is new - and we need to send node meta.,
- sendNodeMeta bool
+ mutex sync.RWMutex
+ Mesh *v1alpha1.MeshGlobalConfig
+ Store model.ConfigStore
+ cfg *ADSConfig
// initialLoad tracks the time to receive the initial configuration.
initialLoad time.Duration
// indicates if the initial LDS request is sent
@@ -141,11 +135,9 @@ type ADSC struct {
// ADSConfig for the ADS connection.
type ADSConfig struct {
Config
-
// InitialDiscoveryRequests is a list of resources to watch at first, represented as URLs (for new XDS resource naming)
// or type URLs.
InitialDiscoveryRequests []*discovery.DiscoveryRequest
-
// ResponseHandler will be called on each DiscoveryResponse.
// TODO: mirror Generator, allow adding handler per type
ResponseHandler ResponseHandler
@@ -180,6 +172,16 @@ func New(discoveryAddr string, opts *ADSConfig) (*ADSC, error) {
return adsc, nil
}
+func setDefaultConfig(config *Config) Config {
+ if config == nil {
+ config = &Config{}
+ }
+ if config.Namespace == "" {
+ config.Namespace = "default"
+ }
+ return *config
+}
+
func ConfigInitialRequests() []*discovery.DiscoveryRequest {
out := make([]*discovery.DiscoveryRequest, 0, len(collections.Planet.All())+1)
out = append(out, &discovery.DiscoveryRequest{
@@ -194,16 +196,6 @@ func ConfigInitialRequests() []*discovery.DiscoveryRequest {
return out
}
-func setDefaultConfig(config *Config) Config {
- if config == nil {
- config = &Config{}
- }
- if config.Namespace == "" {
- config.Namespace = "default"
- }
- return *config
-}
-
func dialWithConfig(ctx context.Context, config *Config) (*grpc.ClientConn, error) {
defaultGrpcDialOptions := defaultGrpcDialOptions()
var grpcDialOptions []grpc.DialOption
@@ -278,40 +270,6 @@ func tlsConfig(config *Config) (*tls.Config, error) {
}, nil
}
-func defaultGrpcDialOptions() []grpc.DialOption {
- return []grpc.DialOption{
- // TODO(SpecialYang) maybe need to make it configurable.
- grpc.WithInitialWindowSize(int32(defaultInitialWindowSize)),
- grpc.WithInitialConnWindowSize(int32(defaultInitialConnWindowSize)),
- grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(defaultClientMaxReceiveMessageSize)),
- }
-}
-
-// Run will create a new stream using the existing grpc client connection and send the initial xds requests.
-// And then it will run a go routine receiving and handling xds response.
-// Note: it is non blocking
-func (a *ADSC) Run() error {
- var err error
- a.client = discovery.NewAggregatedDiscoveryServiceClient(a.conn)
- a.stream, err = a.client.StreamAggregatedResources(context.Background())
- if err != nil {
- return err
- }
- a.sendNodeMeta = true
- a.initialLoad = 0
- a.initialLds = false
- // Send the initial requests
- for _, r := range a.cfg.InitialDiscoveryRequests {
- if r.TypeUrl == v3.ClusterType {
- a.watchTime = time.Now()
- }
- _ = a.Send(r)
- }
-
- go a.handleRecv()
- return nil
-}
-
// Dial connects to a ADS server, with optional MTLS authentication if a cert dir is specified.
func (a *ADSC) Dial() error {
conn, err := dialWithConfig(context.Background(), &a.cfg.Config)
@@ -324,10 +282,6 @@ func (a *ADSC) Dial() error {
// Raw send of a request.
func (a *ADSC) Send(req *discovery.DiscoveryRequest) error {
- if a.sendNodeMeta {
- req.Node = a.node()
- a.sendNodeMeta = false
- }
req.ResponseNonce = time.Now().String()
return a.stream.Send(req)
}
@@ -345,12 +299,36 @@ func (a *ADSC) WaitClear() {
}
// HasSynced returns true if configs have synced
-// MCP support removed - it's a legacy protocol replaced by APIGenerator
func (a *ADSC) HasSynced() bool {
- // MCP was replaced by APIGenerator, not needed for proxyless mesh
return true
}
+// Run will create a new stream using the existing grpc client connection and send the initial xds requests.
+// And then it will run a go routine receiving and handling xds response.
+// Note: it is non blocking
+func (a *ADSC) Run() error {
+ var err error
+ a.client = discovery.NewAggregatedDiscoveryServiceClient(a.conn)
+ a.stream, err = a.client.StreamAggregatedResources(context.Background())
+ if err != nil {
+ return err
+ }
+
+ a.initialLoad = 0
+ a.initialLds = false
+
+ // Send the initial requests
+ for _, r := range a.cfg.InitialDiscoveryRequests {
+ if r.TypeUrl == v3.ClusterType {
+ a.watchTime = time.Now()
+ }
+ _ = a.Send(r)
+ }
+
+ go a.handleReceive()
+ return nil
+}
+
// Close the stream.
func (a *ADSC) Close() {
a.mutex.Lock()
@@ -377,10 +355,6 @@ func (a *ADSC) reconnect() {
func (a *ADSC) ack(msg *discovery.DiscoveryResponse) {
var resources []string
- if strings.HasPrefix(msg.TypeUrl, v3.DebugType) {
- return
- }
-
if msg.TypeUrl == v3.EndpointType {
for c := range a.edsClusters {
resources = append(resources, c)
@@ -395,13 +369,12 @@ func (a *ADSC) ack(msg *discovery.DiscoveryResponse) {
_ = a.stream.Send(&discovery.DiscoveryRequest{
ResponseNonce: msg.Nonce,
TypeUrl: msg.TypeUrl,
- Node: a.node(),
VersionInfo: msg.VersionInfo,
ResourceNames: resources,
})
}
-func (a *ADSC) handleRecv() {
+func (a *ADSC) handleReceive() {
// We connected, so reset the backoff
if a.cfg.BackoffPolicy != nil {
a.cfg.BackoffPolicy.Reset()
@@ -508,7 +481,6 @@ func (a *ADSC) handleRecv() {
}
}
-// nolint: staticcheck
func (a *ADSC) handleLDS(ll []*listener.Listener) {
lh := map[string]*listener.Listener{}
lt := map[string]*listener.Listener{}
@@ -561,7 +533,7 @@ func (a *ADSC) handleLDS(ll []*listener.Listener) {
a.mutex.Lock()
defer a.mutex.Unlock()
if len(routes) > 0 {
- a.sendRsc(v3.RouteType, routes)
+ a.sendResources(v3.RouteType, routes)
}
a.httpListeners = lh
a.tcpListeners = lt
@@ -629,7 +601,7 @@ func (a *ADSC) handleCDS(ll []*cluster.Cluster) {
log.Infof("CDS: %d size=%d", len(cn), cdsSize)
if len(cn) > 0 {
- a.sendRsc(v3.EndpointType, cn)
+ a.sendResources(v3.EndpointType, cn)
}
a.mutex.Lock()
@@ -657,7 +629,6 @@ func (a *ADSC) handleEDS(eds []*endpoint.ClusterLoadAssignment) {
if a.initialLoad == 0 && !a.initialLds {
// first load - Envoy loads listeners after endpoints
_ = a.stream.Send(&discovery.DiscoveryRequest{
- Node: a.node(),
TypeUrl: v3.ListenerType,
})
a.initialLds = true
@@ -673,28 +644,7 @@ func (a *ADSC) handleEDS(eds []*endpoint.ClusterLoadAssignment) {
}
}
-func buildNode(config *Config) *core.Node {
- n := &core.Node{}
- if config.Meta == nil {
- n.Metadata = &pstruct.Struct{
- Fields: map[string]*pstruct.Value{
- "DUBBO_VERSION": {Kind: &pstruct.Value_StringValue{StringValue: "65536.65536.65536"}},
- },
- }
- } else {
- n.Metadata = config.Meta
- if config.Meta.Fields["DUBBO_VERSION"] == nil {
- config.Meta.Fields["DUBBO_VERSION"] = &pstruct.Value{Kind: &pstruct.Value_StringValue{StringValue: "65536.65536.65536"}}
- }
- }
- return n
-}
-
-func (a *ADSC) node() *core.Node {
- return buildNode(&a.cfg.Config)
-}
-
-func (a *ADSC) sendRsc(typeurl string, rsc []string) {
+func (a *ADSC) sendResources(typeurl string, resource []string) {
ex := a.Received[typeurl]
version := ""
nonce := ""
@@ -705,8 +655,7 @@ func (a *ADSC) sendRsc(typeurl string, rsc []string) {
_ = a.stream.Send(&discovery.DiscoveryRequest{
ResponseNonce: nonce,
VersionInfo: version,
- Node: a.node(),
TypeUrl: typeurl,
- ResourceNames: rsc,
+ ResourceNames: resource,
})
}
diff --git a/pkg/adsc/util.go b/pkg/adsc/util.go
index 0e991593..9337d167 100644
--- a/pkg/adsc/util.go
+++ b/pkg/adsc/util.go
@@ -23,6 +23,8 @@ import (
)
func getClientCertFn(config *Config) func(requestInfo *tls.CertificateRequestInfo) (*tls.Certificate, error) {
+ // Request a certificate chain and private key from SecretManager,
+ // combine them into a tls.Certificate object, and return it for use by TLS.
if config.SecretManager != nil {
return func(requestInfo *tls.CertificateRequestInfo) (*tls.Certificate, error) {
key, err := config.SecretManager.GenerateSecret(security.WorkloadKeyCertResourceName)
@@ -36,6 +38,7 @@ func getClientCertFn(config *Config) func(requestInfo *tls.CertificateRequestInf
return &clientCert, nil
}
}
+ // local file
if config.CertDir != "" {
return func(requestInfo *tls.CertificateRequestInfo) (*tls.Certificate, error) {
certName := config.CertDir + "/cert-chain.pem"
@@ -47,6 +50,7 @@ func getClientCertFn(config *Config) func(requestInfo *tls.CertificateRequestInf
}
}
+ // If neither option is selected,
+ // mTLS client certificates will not be enabled.
return nil
}
-
diff --git a/pkg/backoff/exponential.go b/pkg/backoff/exponential.go
index 3f52a4aa..2b227b8a 100644
--- a/pkg/backoff/exponential.go
+++ b/pkg/backoff/exponential.go
@@ -41,6 +41,13 @@ type Option struct {
MaxInterval time.Duration
}
+func DefaultOption() Option {
+ return Option{
+ InitialInterval: defaultInitialInterval,
+ MaxInterval: defaultMaxInterval,
+ }
+}
+
type ExponentialBackOff struct {
exponentialBackOff *backoff.ExponentialBackOff
}
@@ -81,10 +88,3 @@ func (b ExponentialBackOff) RetryWithContext(ctx context.Context, operation func
}
}
}
-
-func DefaultOption() Option {
- return Option{
- InitialInterval: defaultInitialInterval,
- MaxInterval: defaultMaxInterval,
- }
-}
diff --git a/pkg/config/constants/constants.go b/pkg/config/constants/constants.go
index 55e86fd4..2df004ef 100644
--- a/pkg/config/constants/constants.go
+++ b/pkg/config/constants/constants.go
@@ -19,21 +19,22 @@ package constants
const (
UnspecifiedIP = "0.0.0.0"
- DubboSystemNamespace = "dubbo-system"
- DefaultClusterLocalDomain = "cluster.local"
- DefaultClusterName = "Kubernetes"
- ServiceClusterName = "dubbo-proxy"
- ConfigPathDir = "./etc/dubbo/proxy"
- BinaryPathFilename = "/usr/local/bin/planet-agent"
- KeyFilename = "key.pem"
- CertChainFilename = "cert-chain.pem"
+ DubboSystemNamespace = "dubbo-system"
+ KubeSystemNamespace = "kube-system"
+
+ DefaultClusterLocalDomain = "cluster.local"
+ DefaultClusterName = "Kubernetes"
+
+ CertChainFilename = "cert-chain.pem"
+
CertProviderDubbod = "dubbod"
CertProviderKubernetes = "kubernetes"
CertProviderKubernetesSignerPrefix = "k8s.io/"
CertProviderNone = "none"
CertProviderCustom = "custom"
- CACertNamespaceConfigMapDataName = "root-cert.pem"
- CACRLNamespaceConfigMapDataName = "ca-crl.pem"
+
+ CACertNamespaceConfigMapDataName = "root-cert.pem"
+ CACRLNamespaceConfigMapDataName = "ca-crl.pem"
PodInfoAnnotationsPath = "./etc/dubbo/pod/annotations"
@@ -42,6 +43,8 @@ const (
PlanetWellKnownDNSCertPath = "./var/run/secrets/dubbod/tls/"
PlanetWellKnownDNSCaCertPath = "./var/run/secrets/dubbod/ca/"
+ ConfigPathDir = "./etc/dubbo/proxy"
+ KeyFilename = "key.pem"
DefaultPlanetTLSCert = PlanetWellKnownDNSCertPath + "tls.crt"
DefaultPlanetTLSKey = PlanetWellKnownDNSCertPath + "tls.key"
DefaultPlanetTLSCaCert = PlanetWellKnownDNSCaCertPath + "root-cert.pem"
@@ -49,7 +52,5 @@ const (
AlwaysReject = "internal.dubbo.apache.org/webhook-always-reject"
- KubeSystemNamespace string = "kube-system"
-
ManagedGatewayControllerLabel = "dubbo.apache.org-gateway-controller"
)
diff --git a/pkg/config/kube/conversion.go b/pkg/config/kube/conversion.go
index c64d1b49..51324056 100644
--- a/pkg/config/kube/conversion.go
+++ b/pkg/config/kube/conversion.go
@@ -21,7 +21,6 @@ import (
"github.com/apache/dubbo-kubernetes/pkg/config/protocol"
"github.com/apache/dubbo-kubernetes/pkg/util/sets"
- corev1 "k8s.io/api/core/v1"
)
const (
@@ -35,11 +34,7 @@ var (
var wellKnownPorts = sets.New[int32](DNS)
-func ConvertProtocol(port int32, portName string, proto corev1.Protocol, appProto *string) protocol.Instance {
- if proto == corev1.ProtocolUDP {
- return protocol.UDP
- }
-
+func ConvertProtocol(port int32, portName string, appProto *string) protocol.Instance {
// If application protocol is set, we will use that
// If not, use the port name
name := portName
@@ -53,8 +48,6 @@ func ConvertProtocol(port int32, portName string, proto corev1.Protocol, appProt
case "kubernetes.io/h2c":
return protocol.HTTP2
// WebSocket over cleartext
- case "kubernetes.io/ws":
- return protocol.HTTP
// WebSocket over TLS
case "kubernetes.io/wss":
return protocol.HTTPS
@@ -75,10 +68,7 @@ func ConvertProtocol(port int32, portName string, proto corev1.Protocol, appProt
p := protocol.Parse(name)
if p == protocol.Unsupported {
- // Make TCP as default protocol for well know ports if protocol is not specified.
- if wellKnownPorts.Contains(port) {
- return protocol.TCP
- }
+ // TODO
}
return p
}
diff --git a/pkg/config/protocol/instance.go b/pkg/config/protocol/instance.go
index 860bc0fe..74733285 100644
--- a/pkg/config/protocol/instance.go
+++ b/pkg/config/protocol/instance.go
@@ -30,26 +30,13 @@ const (
GRPC Instance = "GRPC"
// GRPCWeb declares that the port carries gRPC traffic.
GRPCWeb Instance = "GRPC-Web"
- // HTTP declares that the port carries HTTP/1.1 traffic.
- // Note that HTTP/1.0 or earlier may not be supported by the proxy.
- HTTP Instance = "HTTP"
- // HTTP_PROXY declares that the port is a generic outbound proxy port.
- // Note that this is currently applicable only for defining sidecar egress listeners.
- // nolint
- HTTP_PROXY Instance = "HTTP_PROXY"
// HTTP2 declares that the port carries HTTP/2 traffic.
HTTP2 Instance = "HTTP2"
// HTTPS declares that the port carries HTTPS traffic.
HTTPS Instance = "HTTPS"
- // TCP declares the port uses TCP.
- // This is the default protocol for a service port.
- TCP Instance = "TCP"
// TLS declares that the port carries TLS traffic.
// TLS traffic is assumed to contain SNI as part of the handshake.
TLS Instance = "TLS"
- // UDP declares that the port uses UDP.
- // Note that UDP protocol is not currently supported by the proxy.
- UDP Instance = "UDP"
// Unsupported - value to signify that the protocol is unsupported.
Unsupported Instance = "UnsupportedProtocol"
)
@@ -57,18 +44,10 @@ const (
// Parse from string ignoring case
func Parse(s string) Instance {
switch strings.ToLower(s) {
- case "tcp":
- return TCP
- case "udp":
- return UDP
case "grpc":
return GRPC
case "grpc-web":
return GRPCWeb
- case "http":
- return HTTP
- case "http_proxy":
- return HTTP_PROXY
case "http2":
return HTTP2
case "https":
@@ -79,84 +58,3 @@ func Parse(s string) Instance {
return Unsupported
}
-
-// IsHTTP2 is true for protocols that use HTTP/2 as transport protocol
-func (i Instance) IsHTTP2() bool {
- switch i {
- case HTTP2, GRPC, GRPCWeb:
- return true
- default:
- return false
- }
-}
-
-// IsHTTPOrSniffed is true for protocols that use HTTP as transport protocol, or *can* use it if sniffed to be HTTP
-func (i Instance) IsHTTPOrSniffed() bool {
- return i.IsHTTP() || i.IsUnsupported()
-}
-
-// IsHTTP is true for protocols that use HTTP as transport protocol
-func (i Instance) IsHTTP() bool {
- switch i {
- case HTTP, HTTP2, HTTP_PROXY, GRPC, GRPCWeb:
- return true
- default:
- return false
- }
-}
-
-// IsTCP is true for protocols that use TCP as transport protocol
-func (i Instance) IsTCP() bool {
- switch i {
- case TCP, HTTPS, TLS:
- return true
- default:
- return false
- }
-}
-
-// IsTLS is true for protocols on top of TLS (e.g. HTTPS)
-func (i Instance) IsTLS() bool {
- switch i {
- case HTTPS, TLS:
- return true
- default:
- return false
- }
-}
-
-// IsHTTPS is true if protocol is HTTPS
-func (i Instance) IsHTTPS() bool {
- switch i {
- case HTTPS:
- return true
- default:
- return false
- }
-}
-
-// IsGRPC is true for GRPC protocols.
-func (i Instance) IsGRPC() bool {
- switch i {
- case GRPC, GRPCWeb:
- return true
- default:
- return false
- }
-}
-
-func (i Instance) IsUnsupported() bool {
- return i == Unsupported
-}
-
-// AfterTLSTermination returns the protocol that will be used if TLS is terminated on the current protocol.
-func (i Instance) AfterTLSTermination() Instance {
- switch i {
- case HTTPS:
- return HTTP
- case TLS:
- return TCP
- default:
- return i
- }
-}
diff --git a/pkg/dubbo-agent/xds_proxy.go b/pkg/dubbo-agent/xds_proxy.go
index c3f8cdda..3b6efd02 100644
--- a/pkg/dubbo-agent/xds_proxy.go
+++ b/pkg/dubbo-agent/xds_proxy.go
@@ -426,19 +426,6 @@ func (p *XdsProxy) handleUpstreamRequest(con *ProxyConnection) {
// forward to dubbod
con.sendRequest(req)
if !initialRequestsSent.Load() && req.TypeUrl == model.ListenerType {
- // fire off an initial NDS request
- if _, f := p.handlers[model.NameTableType]; f {
- ndsReq := &discovery.DiscoveryRequest{
- TypeUrl: model.NameTableType,
- }
- // Include Node in internal requests
- con.nodeMutex.RLock()
- if con.node != nil {
- ndsReq.Node = con.node
- }
- con.nodeMutex.RUnlock()
- con.sendRequest(ndsReq)
- }
// fire off an initial PCDS request
if _, f := p.handlers[model.ProxyConfigType]; f {
pcdsReq := &discovery.DiscoveryRequest{
@@ -512,12 +499,6 @@ func (p *XdsProxy) handleUpstreamRequest(con *ProxyConnection) {
// Only log at debug level to reduce noise - these are normal operations
proxyLog.Debugf("connection #%d forwarding request: TypeUrl=%s, Node=%v",
con.conID, model.GetShortType(req.TypeUrl), req.Node != nil && req.Node.Id != "")
- if req.TypeUrl == model.ExtensionConfigurationType {
- if req.VersionInfo != "" {
- p.ecdsLastAckVersion.Store(req.VersionInfo)
- }
- p.ecdsLastNonce.Store(req.ResponseNonce)
- }
if err := con.upstream.Send(req); err != nil {
proxyLog.Errorf("connection #%d failed to send request upstream: TypeUrl=%s, error=%v",
con.conID, model.GetShortType(req.TypeUrl), err)
diff --git a/pkg/dubbo-agent/xds_proxy_delta.go b/pkg/dubbo-agent/xds_proxy_delta.go
index 02aff89d..cd41545a 100644
--- a/pkg/dubbo-agent/xds_proxy_delta.go
+++ b/pkg/dubbo-agent/xds_proxy_delta.go
@@ -177,19 +177,6 @@ func (p *XdsProxy) handleUpstreamDeltaRequest(con *ProxyConnection) {
// forward to dubbod
con.sendDeltaRequest(req)
if !initialRequestsSent.Load() && req.TypeUrl == model.ListenerType {
- // fire off an initial NDS request
- if _, f := p.handlers[model.NameTableType]; f {
- ndsReq := &discovery.DeltaDiscoveryRequest{
- TypeUrl: model.NameTableType,
- }
- // Include Node in internal requests
- con.nodeMutex.RLock()
- if con.node != nil {
- ndsReq.Node = con.node
- }
- con.nodeMutex.RUnlock()
- con.sendDeltaRequest(ndsReq)
- }
// fire off an initial PCDS request
if _, f := p.handlers[model.ProxyConfigType]; f {
pcdsReq := &discovery.DeltaDiscoveryRequest{
@@ -253,10 +240,6 @@ func (p *XdsProxy) handleUpstreamDeltaRequest(con *ProxyConnection) {
len(req.ResourceNamesUnsubscribe),
req.ResponseNonce,
len(req.InitialResourceVersions))
- if req.TypeUrl == model.ExtensionConfigurationType {
- p.ecdsLastNonce.Store(req.ResponseNonce)
- }
-
if err := con.upstreamDeltas.Send(req); err != nil {
err = fmt.Errorf("send error for type url %s: %v", req.TypeUrl, err)
upstreamErr(con, err)
diff --git a/pkg/model/xds.go b/pkg/model/xds.go
index 5164d62b..95e1ccf4 100644
--- a/pkg/model/xds.go
+++ b/pkg/model/xds.go
@@ -17,20 +17,15 @@
package model
const (
- APITypePrefix = "type.googleapis.com/"
- ClusterType = APITypePrefix + "envoy.config.cluster.v3.Cluster"
- EndpointType = APITypePrefix + "envoy.config.endpoint.v3.ClusterLoadAssignment"
- ListenerType = APITypePrefix + "envoy.config.listener.v3.Listener"
- RouteType = APITypePrefix + "envoy.config.route.v3.RouteConfiguration"
- SecretType = APITypePrefix + "envoy.extensions.transport_sockets.tls.v3.Secret"
- ExtensionConfigurationType = APITypePrefix + "envoy.config.core.v3.TypedExtensionConfig"
+ APITypePrefix = "type.googleapis.com/"
+ ClusterType = APITypePrefix + "envoy.config.cluster.v3.Cluster"
+ EndpointType = APITypePrefix + "envoy.config.endpoint.v3.ClusterLoadAssignment"
+ ListenerType = APITypePrefix + "envoy.config.listener.v3.Listener"
+ RouteType = APITypePrefix + "envoy.config.route.v3.RouteConfiguration"
+ SecretType = APITypePrefix + "envoy.extensions.transport_sockets.tls.v3.Secret"
- NameTableType = APITypePrefix + "dubbo.networking.nds.v1.NameTable"
HealthInfoType = APITypePrefix + "dubbo.v1.HealthInformation"
ProxyConfigType = APITypePrefix + "dubbo.mesh.v1alpha1.ProxyConfig"
- DebugType = "dubbo.apache.org/debug"
- AddressType = APITypePrefix + "dubbo.workload.Address"
- WorkloadType = APITypePrefix + "dubbo.workload.Workload"
)
func GetShortType(typeURL string) string {
@@ -45,14 +40,8 @@ func GetShortType(typeURL string) string {
return "EDS"
case SecretType:
return "SDS"
- case NameTableType:
- return "NDS"
case ProxyConfigType:
return "PCDS"
- case ExtensionConfigurationType:
- return "ECDS"
- case AddressType, WorkloadType:
- return "WDS"
default:
return typeURL
}
diff --git a/pkg/xds/server.go b/pkg/xds/server.go
index a1e5ec9c..8a94847e 100644
--- a/pkg/xds/server.go
+++ b/pkg/xds/server.go
@@ -209,12 +209,9 @@ func Receive(ctx ConnectionContext) {
func Send(ctx ConnectionContext, res *discovery.DiscoveryResponse) error {
conn := ctx.XdsConnection()
- sendResponse := func() error {
- return conn.stream.Send(res)
- }
- err := sendResponse()
+ err := conn.stream.Send(res)
if err == nil {
- if res.Nonce != "" && !strings.HasPrefix(res.TypeUrl, model.DebugType) {
+ if res.Nonce != "" {
ctx.Watcher().UpdateWatchedResource(res.TypeUrl, func(wr *WatchedResource) *WatchedResource {
if wr == nil {
wr = &WatchedResource{TypeUrl: res.TypeUrl}
@@ -224,8 +221,6 @@ func Send(ctx ConnectionContext, res *discovery.DiscoveryResponse) error {
return wr
})
}
- } else if status.Convert(err).Code() == codes.DeadlineExceeded {
- log.Infof("Timeout writing %s: %v", conn.conID, model.GetShortType(res.TypeUrl))
}
return err
}
@@ -438,7 +433,7 @@ func shouldUnsubscribe(request *discovery.DiscoveryRequest) bool {
func IsWildcardTypeURL(typeURL string) bool {
switch typeURL {
- case model.SecretType, model.EndpointType, model.RouteType, model.ExtensionConfigurationType:
+ case model.SecretType, model.EndpointType, model.RouteType:
// By XDS spec, these are not wildcard
return false
case model.ClusterType, model.ListenerType:
diff --git a/tools/build-tools/docker/Dockerfile b/tools/build-tools/docker/Dockerfile
index ef8ca32e..b9c80c08 100644
--- a/tools/build-tools/docker/Dockerfile
+++ b/tools/build-tools/docker/Dockerfile
@@ -1,3 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
# hadolint global ignore=SC2086
ARG GOLANG_IMAGE=golang:1.24-bookworm
@@ -61,14 +76,10 @@ RUN --mount=type=cache,target=/tmp/go/pkg/mod \
FROM binary_tools_context_base AS go_tools_2
-# Build Dubbo Kubernetes kubetype-gen tool from source
+# Build Dubbo Kubernetes kubetype-gen and protoc-gen-crd tool from source.
# Copy pre-built kubetype-gen binary from project root
-# IMPORTANT: Build context must be project root (where kubetype-gen exists)
-# IMPORTANT: kubetype-gen must be built for Linux architecture (not macOS)
-# Build command: cd tools/cmd/kubetype-gen && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-extldflags -static -s -w" -o ../../../kubetype-gen .
-# For ARM64: use GOARCH=arm64 instead of amd64
-# Run: cd /path/to/dubbo-kubernetes && nerdctl build -f tools/build-tools/docker/Dockerfile -t build-tools .
-COPY --chmod=755 kubetype-gen /tmp/go/bin/kubetype-gen
+COPY --chmod=755 ./tools/bin/kubetype-gen /tmp/go/bin/kubetype-gen
+COPY --chmod=755 ./tools/bin/protoc-gen-crd /tmp/go/bin/protoc-gen-crd
FROM ubuntu:noble AS base_os_context
diff --git a/tools/cmd/protoc-gen-crd/main.go b/tools/cmd/protoc-gen-crd/main.go
new file mode 100644
index 00000000..619151f5
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/main.go
@@ -0,0 +1,101 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "fmt"
+ "strings"
+
+ plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
+
+ "github.com/apache/dubbo-kubernetes/tools/cmd/protoc-gen-crd/pkg/protocgen"
+ "github.com/apache/dubbo-kubernetes/tools/cmd/protoc-gen-crd/pkg/protomodel"
+)
+
+// Breaks the comma-separated list of key=value pairs
+// in the parameter string into an easy to use map.
+func extractParams(parameter string) map[string]string {
+ m := make(map[string]string)
+ for _, p := range strings.Split(parameter, ",") {
+ if p == "" {
+ continue
+ }
+
+ if i := strings.Index(p, "="); i < 0 {
+ m[p] = ""
+ } else {
+ m[p[0:i]] = p[i+1:]
+ }
+ }
+
+ return m
+}
+
+func generate(request *plugin.CodeGeneratorRequest) (*plugin.CodeGeneratorResponse, error) {
+ includeDescription := true
+ enumAsIntOrString := false
+
+ p := extractParams(request.GetParameter())
+ for k, v := range p {
+ if k == "include_description" {
+ switch strings.ToLower(v) {
+ case "true":
+ includeDescription = true
+ case "false":
+ includeDescription = false
+ default:
+ return nil, fmt.Errorf("unknown value '%s' for include_description", v)
+ }
+ } else if k == "enum_as_int_or_string" {
+ switch strings.ToLower(v) {
+ case "true":
+ enumAsIntOrString = true
+ case "false":
+ enumAsIntOrString = false
+ default:
+ return nil, fmt.Errorf("unknown value '%s' for enum_as_int_or_string", v)
+ }
+ } else {
+ return nil, fmt.Errorf("unknown argument '%s' specified", k)
+ }
+ }
+
+ m := protomodel.NewModel(request, true)
+
+ filesToGen := make(map[*protomodel.FileDescriptor]bool)
+ for _, fileName := range request.FileToGenerate {
+ fd := m.AllFilesByName[fileName]
+ if fd == nil {
+ return nil, fmt.Errorf("unable to find %s", request.FileToGenerate)
+ }
+ filesToGen[fd] = true
+ }
+
+ descriptionConfiguration := &DescriptionConfiguration{
+ IncludeDescriptionInSchema: includeDescription,
+ }
+
+ g := newOpenAPIGenerator(
+ m,
+ descriptionConfiguration,
+ enumAsIntOrString)
+ return g.generateOutput(filesToGen)
+}
+
+func main() {
+ protocgen.Generate(generate)
+}
diff --git a/tools/cmd/protoc-gen-crd/openapiGenerator.go b/tools/cmd/protoc-gen-crd/openapiGenerator.go
new file mode 100644
index 00000000..01e1fe42
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/openapiGenerator.go
@@ -0,0 +1,1025 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "bytes"
+ "encoding/json"
+ "fmt"
+ "log"
+ "math"
+ "slices"
+ "strings"
+
+ "github.com/golang/protobuf/protoc-gen-go/descriptor"
+ plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
+ "github.com/howardjohn/celpp"
+ "github.com/howardjohn/celpp/macros"
+ "golang.org/x/exp/maps"
+ "google.golang.org/genproto/googleapis/api/annotations"
+ "google.golang.org/protobuf/proto"
+ apiextinternal "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
+ apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
+ structuralschema "k8s.io/apiextensions-apiserver/pkg/apiserver/schema"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/apimachinery/pkg/util/sets"
+ "sigs.k8s.io/controller-tools/pkg/crd"
+ crdmarkers "sigs.k8s.io/controller-tools/pkg/crd/markers"
+ "sigs.k8s.io/controller-tools/pkg/markers"
+ "sigs.k8s.io/yaml"
+
+ "github.com/apache/dubbo-kubernetes/tools/cmd/protoc-gen-crd/pkg/protomodel"
+)
+
+// Some special types with predefined schemas.
+// Normally these would result in stack-overflow errors when generating the open api schema
+// The imperfect solution, is to just generate an empty object for these types
+var specialTypes = map[string]*apiext.JSONSchemaProps{
+ "google.protobuf.ListValue": {
+ Items: &apiext.JSONSchemaPropsOrArray{Schema: &apiext.JSONSchemaProps{Type: "object"}},
+ },
+ "google.protobuf.Struct": {
+ Type: "object",
+ XPreserveUnknownFields: Ptr(true),
+ },
+ "google.protobuf.Any": {
+ Type: "object",
+ XPreserveUnknownFields: Ptr(true),
+ },
+ "google.protobuf.Value": {
+ XPreserveUnknownFields: Ptr(true),
+ },
+ "google.protobuf.BoolValue": {
+ Type: "boolean",
+ Nullable: true,
+ },
+ "google.protobuf.StringValue": {
+ Type: "string",
+ Nullable: true,
+ },
+ "google.protobuf.DoubleValue": {
+ Type: "number",
+ Format: "double",
+ Nullable: true,
+ },
+ "google.protobuf.Int32Value": {
+ Type: "integer",
+ Format: "int32",
+ Nullable: true,
+ },
+ "google.protobuf.Int64Value": {
+ Type: "integer",
+ Format: "int64",
+ Nullable: true,
+ },
+ "google.protobuf.UInt32Value": {
+ Type: "integer",
+ Minimum: Ptr(float64(0)),
+ Maximum: Ptr(float64(math.MaxUint32)),
+ Nullable: true,
+ },
+ "google.protobuf.UInt64Value": {
+ Type: "integer",
+ Minimum: Ptr(float64(0)),
+ // TODO: this overflows Kubernetes
+ // schema.Maximum = Ptr(float64(uint64(math.MaxUint64)))
+ Nullable: true,
+ },
+ "google.protobuf.FloatValue": {
+ Type: "number",
+ Format: "double",
+ Nullable: true,
+ },
+ "google.protobuf.Duration": {
+ Type: "string",
+ XValidations: []apiext.ValidationRule{
+ {
+ Rule: "duration(self) >= duration('1ms')",
+ Message: "must be a valid duration greater than 1ms",
+ },
+ },
+ },
+ "google.protobuf.Empty": {
+ Type: "object",
+ MaxProperties: Ptr(int64(0)),
+ },
+ "google.protobuf.Timestamp": {
+ Type: "string",
+ Format: "date-time",
+ },
+}
+
+type openapiGenerator struct {
+ model *protomodel.Model
+
+ // transient state as individual files are processed
+ currentPackage *protomodel.PackageDescriptor
+
+ messages map[string]*protomodel.MessageDescriptor
+
+ descriptionConfiguration *DescriptionConfiguration
+ enumAsIntOrString bool
+ customSchemasByMessageName map[string]*apiext.JSONSchemaProps
+}
+
+type DescriptionConfiguration struct {
+ // Whether or not to include a description in the generated open api schema
+ IncludeDescriptionInSchema bool
+}
+
+func newOpenAPIGenerator(
+ model *protomodel.Model,
+ descriptionConfiguration *DescriptionConfiguration,
+ enumAsIntOrString bool,
+) *openapiGenerator {
+ return &openapiGenerator{
+ model: model,
+ descriptionConfiguration: descriptionConfiguration,
+ enumAsIntOrString: enumAsIntOrString,
+ customSchemasByMessageName: buildCustomSchemasByMessageName(),
+ }
+}
+
+// buildCustomSchemasByMessageName name returns a mapping of message name to a pre-defined openapi schema
+// It includes:
+// 1. `specialTypes`, a set of pre-defined schemas
+func buildCustomSchemasByMessageName() map[string]*apiext.JSONSchemaProps {
+ schemasByMessageName := make(map[string]*apiext.JSONSchemaProps)
+
+ // Initialize the hard-coded values
+ for name, schema := range specialTypes {
+ schemasByMessageName[name] = schema
+ }
+
+ return schemasByMessageName
+}
+
+func (g *openapiGenerator) generateOutput(filesToGen map[*protomodel.FileDescriptor]bool) (*plugin.CodeGeneratorResponse, error) {
+ response := plugin.CodeGeneratorResponse{}
+
+ g.generateSingleFileOutput(filesToGen, &response)
+
+ return &response, nil
+}
+
+func (g *openapiGenerator) getFileContents(
+ file *protomodel.FileDescriptor,
+ messages map[string]*protomodel.MessageDescriptor,
+ enums map[string]*protomodel.EnumDescriptor,
+ descriptions map[string]string,
+) {
+ for _, m := range file.AllMessages {
+ messages[g.relativeName(m)] = m
+ }
+
+ for _, e := range file.AllEnums {
+ enums[g.relativeName(e)] = e
+ }
+ for _, v := range file.Matter.Extra {
+ if _, n, f := strings.Cut(v, "schema: "); f {
+ descriptions[n] = fmt.Sprintf("%v See more details at: %v", file.Matter.Description, file.Matter.HomeLocation)
+ }
+ }
+}
+
+func (g *openapiGenerator) generateSingleFileOutput(filesToGen map[*protomodel.FileDescriptor]bool, response *plugin.CodeGeneratorResponse) {
+ messages := make(map[string]*protomodel.MessageDescriptor)
+ enums := make(map[string]*protomodel.EnumDescriptor)
+ descriptions := make(map[string]string)
+
+ for file, ok := range filesToGen {
+ if ok {
+ g.getFileContents(file, messages, enums, descriptions)
+ }
+ }
+
+ rf := g.generateFile("kubernetes/customresourcedefinitions.gen.yaml", messages, enums, descriptions)
+ response.File = []*plugin.CodeGeneratorResponse_File{&rf}
+}
+
+const (
+ enableCRDGenTag = "+cue-gen"
+)
+
+func cleanComments(lines []string) []string {
+ out := []string{}
+ var prevLine string
+ for _, line := range lines {
+ line = strings.Trim(line, " ")
+
+ if line == "-->" {
+ out = append(out, prevLine)
+ prevLine = ""
+ continue
+ }
+
+ if !strings.HasPrefix(line, enableCRDGenTag) {
+ if prevLine != "" && len(line) != 0 {
+ prevLine += " " + line
+ }
+ continue
+ }
+
+ out = append(out, prevLine)
+
+ prevLine = line
+
+ }
+ if prevLine != "" {
+ out = append(out, prevLine)
+ }
+ return out
+}
+
+func parseGenTags(s string) map[string]string {
+ lines := cleanComments(strings.Split(s, "\n"))
+ res := map[string]string{}
+ for _, line := range lines {
+ if len(line) == 0 {
+ continue
+ }
+ _, contents, f := strings.Cut(line, enableCRDGenTag)
+ if !f {
+ continue
+ }
+ spl := strings.SplitN(contents[1:], ":", 3)
+ if len(spl) < 2 {
+ log.Fatalf("invalid tag: %v", line)
+ }
+ val := ""
+ if len(spl) > 2 {
+ val = spl[2]
+ }
+ if _, f := res[spl[1]]; f {
+ res[spl[1]] += ";;" + val
+ } else {
+ res[spl[1]] = val
+ }
+ }
+ if len(res) == 0 {
+ return nil
+ }
+ return res
+}
+
+// Generate an OpenAPI spec for a collection of cross-linked files.
+func (g *openapiGenerator) generateFile(
+ name string,
+ messages map[string]*protomodel.MessageDescriptor,
+ enums map[string]*protomodel.EnumDescriptor,
+ descriptions map[string]string,
+) plugin.CodeGeneratorResponse_File {
+ g.messages = messages
+
+ allSchemas := make(map[string]*apiext.JSONSchemaProps)
+
+ // Type --> Key --> Value
+ genTags := map[string]map[string]string{}
+
+ for _, message := range messages {
+ // we generate the top-level messages here and the nested messages are generated
+ // inside each top-level message.
+ if message.Parent == nil {
+ g.generateMessage(message, allSchemas)
+ }
+ if gt := parseGenTags(message.Location().GetLeadingComments()); gt != nil {
+ genTags[g.absoluteName(message)] = gt
+ }
+ }
+
+ for _, enum := range enums {
+ // when there is no parent to the enum.
+ if len(enum.QualifiedName()) == 1 {
+ g.generateEnum(enum, allSchemas)
+ }
+ }
+
+ // Name -> CRD
+ crds := map[string]*apiext.CustomResourceDefinition{}
+
+ for name, cfg := range genTags {
+ log.Println("Generating", name)
+ group := cfg["groupName"]
+
+ versionsString := cfg["versions"]
+ versions := strings.Split(versionsString, ",")
+ var storageVersion string
+ if version := cfg["version"]; version != "" {
+ if len(versions) == 0 {
+ log.Fatal("can only set versions or version")
+ }
+ if _, f := cfg["storageVersion"]; f {
+ // Old way: single version specifies explicitly
+ storageVersion = version
+ }
+ versions = []string{version}
+ } else {
+ // New way: first one is the storage version
+ storageVersion = versions[0]
+ }
+ kind := name[strings.LastIndex(name, ".")+1:]
+ singular := strings.ToLower(kind)
+ plural := singular + "s"
+ spec := *allSchemas[name]
+ if d, f := descriptions[name]; f {
+ spec.Description = d
+ }
+ schema := &apiext.JSONSchemaProps{
+ Type: "object",
+ Properties: map[string]apiext.JSONSchemaProps{
+ "spec": spec,
+ },
+ }
+ names := apiext.CustomResourceDefinitionNames{
+ Kind: kind,
+ ListKind: kind + "List",
+ Plural: plural,
+ Singular: singular,
+ }
+
+ if res, f := cfg["resource"]; f {
+ for n, m := range extractKeyValue(res) {
+ switch n {
+ case "categories":
+ names.Categories = mergeSlices(names.Categories, strings.Split(m, ","))
+ case "plural":
+ names.Plural = m
+ case "kind":
+ names.Kind = m
+ case "shortNames":
+ names.ShortNames = mergeSlices(names.ShortNames, strings.Split(m, ","))
+ case "singular":
+ names.Singular = m
+ case "listKind":
+ names.ListKind = m
+ }
+ }
+ }
+ name := names.Plural + "." + group
+ for _, version := range versions {
+ ver := apiext.CustomResourceDefinitionVersion{
+ Name: version,
+ Served: true,
+ Schema: &apiext.CustomResourceValidation{
+ OpenAPIV3Schema: schema.DeepCopy(),
+ },
+ }
+ if pk, f := cfg["printerColumn"]; f {
+ pcs := strings.Split(pk, ";;")
+ for _, pc := range pcs {
+ if pc == "" {
+ continue
+ }
+ column := apiext.CustomResourceColumnDefinition{}
+ for n, m := range extractKeyValue(pc) {
+ switch n {
+ case "name":
+ column.Name = m
+ case "type":
+ column.Type = m
+ case "description":
+ column.Description = m
+ case "JSONPath":
+ column.JSONPath = m
+ }
+ }
+ ver.AdditionalPrinterColumns = append(ver.AdditionalPrinterColumns, column)
+ }
+ }
+ if sr, f := cfg["subresource"]; f {
+ k, v, ok := strings.Cut(sr, "=")
+ if !ok {
+ k = sr
+ }
+ if k == "status" {
+ if v == "" {
+ // Back compat
+ v = "dubbo.meta.v1alpha1.DubboStatus"
+ }
+ ver.Subresources = &apiext.CustomResourceSubresources{Status: &apiext.CustomResourceSubresourceStatus{}}
+ status, f := allSchemas[v]
+ if !f {
+ log.Fatalf("Schema %v not found", v)
+ }
+ // Because status can be written by arbitrary third party controllers, allow unknown fields.
+ // These really should be using `conditions`, which is an unstructured list, but they may not be.
+ // For backwards compat, we make this allow unknown fields.
+ schema := *status.DeepCopy()
+ alwaysTrue := true
+ schema.XPreserveUnknownFields = &alwaysTrue
+ ver.Schema.OpenAPIV3Schema.Properties["status"] = schema
+ }
+ }
+ if sr, f := cfg["spec"]; f {
+ if sr == "required" {
+ ver.Schema.OpenAPIV3Schema.Required = append(ver.Schema.OpenAPIV3Schema.Required, "spec")
+ }
+ }
+ if version == storageVersion {
+ ver.Storage = true
+ }
+ if r, f := cfg["deprecationReplacement"]; f {
+ msg := fmt.Sprintf("%v version %q is deprecated, use %q", name, ver.Name, r)
+ ver.Deprecated = true
+ ver.DeprecationWarning = &msg
+ }
+ if err := validateStructural(ver.Schema.OpenAPIV3Schema); err != nil {
+ log.Fatalf("failed to validate %v as structural: %v", kind, err)
+ }
+
+ crd, f := crds[name]
+ if !f {
+ crd = &apiext.CustomResourceDefinition{
+ TypeMeta: metav1.TypeMeta{
+ APIVersion: "apiextensions.k8s.io/v1",
+ Kind: "CustomResourceDefinition",
+ },
+ ObjectMeta: metav1.ObjectMeta{
+ Annotations: extractKeyValue(cfg["annotations"]),
+ Labels: extractKeyValue(cfg["labels"]),
+ Name: name,
+ },
+ Spec: apiext.CustomResourceDefinitionSpec{
+ Group: group,
+ Names: names,
+ Scope: apiext.NamespaceScoped,
+ },
+ Status: apiext.CustomResourceDefinitionStatus{},
+ }
+ }
+
+ crd.Spec.Versions = append(crd.Spec.Versions, ver)
+ crds[name] = crd
+ slices.SortFunc(crd.Spec.Versions, func(a, b apiext.CustomResourceDefinitionVersion) int {
+ if a.Name == b.Name {
+ log.Fatalf("%v has the version %v twice", name, a.Name)
+ }
+ if a.Name < b.Name {
+ return -1
+ }
+ return 1
+ })
+ }
+ }
+
+ // sort the configs so that the order is deterministic.
+ keys := maps.Keys(crds)
+ slices.SortFunc(keys, func(a, b string) int {
+ if crds[a].Spec.Group+a < crds[b].Spec.Group+b {
+ return -1
+ }
+ return 1
+ })
+
+ bb := &bytes.Buffer{}
+ bb.WriteString("# DO NOT EDIT - Generated by Cue OpenAPI generator based on Dubbo APIs.\n")
+ for i, crdName := range keys {
+ crd := crds[crdName]
+ b, err := yaml.Marshal(crd)
+ if err != nil {
+ log.Fatalf("unable to marshall the output of %v to yaml", name)
+ }
+ b = fixupYaml(b)
+ bb.Write(b)
+ if i != len(crds)-1 {
+ bb.WriteString("---\n")
+ }
+ }
+
+ return plugin.CodeGeneratorResponse_File{
+ Name: proto.String(name),
+ Content: proto.String(bb.String()),
+ }
+}
+
+func mergeSlices(a []string, b []string) []string {
+ have := sets.New(a...)
+ for _, bb := range b {
+ if !have.Has(bb) {
+ a = append(a, bb)
+ }
+ }
+ return a
+}
+
+// extractKeyValue extracts a string to key value pairs
+// e.g. a=b,b=c to map[a:b b:c]
+// and a=b,c,d,e=f to map[a:b,c,d e:f]
+func extractKeyValue(s string) map[string]string {
+ out := map[string]string{}
+ if s == "" {
+ return out
+ }
+ splits := strings.Split(s, "=")
+ if len(splits) == 1 {
+ out[splits[0]] = ""
+ }
+ if strings.Contains(splits[0], ",") {
+ log.Fatalf("cannot parse %v to key value pairs", s)
+ }
+ nextkey := splits[0]
+ for i := 1; i < len(splits); i++ {
+ if splits[i] == "" || splits[i] == "," {
+ log.Fatalf("cannot parse %v to key value paris, invalid value", s)
+ }
+ if !strings.Contains(splits[i], ",") && i != len(splits)-1 {
+ log.Fatalf("cannot parse %v to key value pairs, missing separator", s)
+ }
+ if i == len(splits)-1 {
+ out[nextkey] = strings.Trim(splits[i], "\"'`")
+ continue
+ }
+ index := strings.LastIndex(splits[i], ",")
+ out[nextkey] = strings.Trim(splits[i][:index], "\"'`")
+ nextkey = splits[i][index+1:]
+ if nextkey == "" {
+ log.Fatalf("cannot parse %v to key value pairs, missing key", s)
+ }
+ }
+ return out
+}
+
+const (
+ statusOutput = `
+status:
+ acceptedNames:
+ kind: ""
+ plural: ""
+ conditions: null
+ storedVersions: null`
+
+ creationTimestampOutput = `
+ creationTimestamp: null`
+)
+
+func fixupYaml(y []byte) []byte {
+ // remove the status and creationTimestamp fields from the output. Ideally we could use OrderedMap to remove those.
+ y = bytes.ReplaceAll(y, []byte(statusOutput), []byte(""))
+ y = bytes.ReplaceAll(y, []byte(creationTimestampOutput), []byte(""))
+ // keep the quotes in the output which is required by helm.
+ y = bytes.ReplaceAll(y, []byte("helm.sh/resource-policy: keep"), []byte(`"helm.sh/resource-policy": keep`))
+ return y
+}
+
+func (g *openapiGenerator) generateMessage(message *protomodel.MessageDescriptor, allSchemas map[string]*apiext.JSONSchemaProps) {
+ if o := g.generateMessageSchema(message); o != nil {
+ allSchemas[g.absoluteName(message)] = o
+ }
+}
+
+func (g *openapiGenerator) generateCustomMessageSchema(message *protomodel.MessageDescriptor, customSchema *apiext.JSONSchemaProps) *apiext.JSONSchemaProps {
+ o := customSchema
+ o.Description = g.generateDescription(message)
+
+ return o
+}
+
+func (g *openapiGenerator) generateMessageSchema(message *protomodel.MessageDescriptor) *apiext.JSONSchemaProps {
+ // skip MapEntry message because we handle map using the map's repeated field.
+ if message.GetOptions().GetMapEntry() {
+ return nil
+ }
+ o := &apiext.JSONSchemaProps{
+ Type: "object",
+ Properties: make(map[string]apiext.JSONSchemaProps),
+ }
+ o.Description = g.generateDescription(message)
+
+ const CELOneOf = false
+
+ for _, field := range message.Fields {
+ fn := g.fieldName(field)
+ sr := g.fieldType(field)
+ o.Properties[fn] = *sr
+
+ if isRequired(field) {
+ o.Required = append(o.Required, fn)
+ }
+
+ // Hack: allow "alt names"
+ for _, an := range g.fieldAltNames(field) {
+ o.Properties[an] = *sr
+ }
+ }
+
+ // Generate OneOf
+ // CEL can do this very cleanly but breaks in K8s: https://github.com/kubernetes/kubernetes/issues/120973
+ // OpenAPI can do it with OneOf, but it gets a bit gross to represent "allow none set" as well.
+ // Many oneOfs do end up requiring at least one to be set, though -- perhaps we can simplify these cases.
+ if CELOneOf {
+ oneOfs := make([][]string, len(message.OneofDecl))
+ for _, field := range message.Fields {
+ // Record any oneOfs
+ if field.OneofIndex != nil {
+ oneOfs[*field.OneofIndex] = append(oneOfs[*field.OneofIndex], g.fieldName(field))
+ }
+ }
+ for _, oo := range oneOfs {
+ o.XValidations = append(o.XValidations, apiext.ValidationRule{
+ Rule: buildCELOneOf(oo),
+ Message: fmt.Sprintf("At most one of %v should be set", oo),
+ })
+ }
+ } else {
+ oneOfs := make([]apiext.JSONSchemaProps, len(message.OneofDecl))
+ for _, field := range message.Fields {
+ // Record any oneOfs
+ if field.OneofIndex != nil {
+ oneOfs[*field.OneofIndex].OneOf = append(oneOfs[*field.OneofIndex].OneOf, apiext.JSONSchemaProps{Required: []string{g.fieldName(field)}})
+ }
+ }
+ for i, oo := range oneOfs {
+ oo.OneOf = append([]apiext.JSONSchemaProps{{Not: &apiext.JSONSchemaProps{AnyOf: oo.OneOf}}}, oo.OneOf...)
+ oneOfs[i] = oo
+ }
+ switch len(oneOfs) {
+ case 0:
+ case 1:
+ o.OneOf = oneOfs[0].OneOf
+ default:
+ o.AllOf = oneOfs
+ }
+ }
+
+ applyExtraValidations(o, message, markers.DescribesType)
+
+ return o
+}
+
+func isRequired(fd *protomodel.FieldDescriptor) bool {
+ if fd.Options == nil {
+ return false
+ }
+ if !proto.HasExtension(fd.Options, annotations.E_FieldBehavior) {
+ return false
+ }
+ ext := proto.GetExtension(fd.Options, annotations.E_FieldBehavior)
+ opts, ok := ext.([]annotations.FieldBehavior)
+ if !ok {
+ return false
+ }
+ for _, o := range opts {
+ if o == annotations.FieldBehavior_REQUIRED {
+ return true
+ }
+ }
+ return false
+}
+
+// buildCELOneOf builds a CEL expression to select oneOf the fields below
+// Ex: (has(self.a) ? 1 : 0) + (has(self.b) ? 1 : 0) <= 1
+func buildCELOneOf(names []string) string {
+ clauses := []string{}
+ for _, n := range names {
+ // For each name, count how many are set
+ clauses = append(clauses, fmt.Sprintf("(has(self.%v)?1:0)", n))
+ }
+ // We should have 0 or 1 set.
+ return strings.Join(clauses, "+") + "<=1"
+}
+
+func (g *openapiGenerator) generateEnum(enum *protomodel.EnumDescriptor, allSchemas map[string]*apiext.JSONSchemaProps) {
+ o := g.generateEnumSchema(enum)
+ allSchemas[g.absoluteName(enum)] = o
+}
+
+func (g *openapiGenerator) generateEnumSchema(enum *protomodel.EnumDescriptor) *apiext.JSONSchemaProps {
+ o := &apiext.JSONSchemaProps{Type: "string"}
+ // Enum description is not used in Kubernetes
+ // o.Description = g.generateDescription(enum)
+
+ // If the schema should be int or string, mark it as such
+ if g.enumAsIntOrString {
+ o.XIntOrString = true
+ return o
+ }
+
+ // otherwise, return define the expected string values
+ values := enum.GetValue()
+ for _, v := range values {
+ b, _ := json.Marshal(v.GetName())
+ o.Enum = append(o.Enum, apiext.JSON{Raw: b})
+ }
+ o.Type = "string"
+
+ return o
+}
+
+func (g *openapiGenerator) absoluteName(desc protomodel.CoreDesc) string {
+ typeName := protomodel.DottedName(desc)
+ return desc.PackageDesc().Name + "." + typeName
+}
+
+// converts the first section of the leading comment or the description of the proto
+// to a single line of description.
+func (g *openapiGenerator) generateDescription(desc protomodel.CoreDesc) string {
+ if !g.descriptionConfiguration.IncludeDescriptionInSchema {
+ return ""
+ }
+
+ c := strings.TrimSpace(desc.Location().GetLeadingComments())
+ if strings.Contains(c, "$hide_from_docs") {
+ return ""
+ }
+ words := strings.Fields(c)
+ for i, w := range words {
+ if strings.HasSuffix(w, ".") {
+ return strings.Join(words[:i+1], " ")
+ }
+ }
+ return ""
+}
+
+func (g *openapiGenerator) fieldType(field *protomodel.FieldDescriptor) *apiext.JSONSchemaProps {
+ schema := &apiext.JSONSchemaProps{}
+ var isMap bool
+ switch *field.Type {
+ case descriptor.FieldDescriptorProto_TYPE_FLOAT, descriptor.FieldDescriptorProto_TYPE_DOUBLE:
+ schema.Type = "number"
+ schema.Format = "double"
+ schema.Description = g.generateDescription(field)
+
+ case descriptor.FieldDescriptorProto_TYPE_INT32, descriptor.FieldDescriptorProto_TYPE_SINT32, descriptor.FieldDescriptorProto_TYPE_SFIXED32:
+ schema.Type = "integer"
+ schema.Format = "int32"
+ schema.Description = g.generateDescription(field)
+
+ case descriptor.FieldDescriptorProto_TYPE_INT64, descriptor.FieldDescriptorProto_TYPE_SINT64, descriptor.FieldDescriptorProto_TYPE_SFIXED64:
+ schema.Type = "integer"
+ schema.Format = "int64"
+ schema.Description = g.generateDescription(field)
+
+ case descriptor.FieldDescriptorProto_TYPE_UINT64, descriptor.FieldDescriptorProto_TYPE_FIXED64:
+ schema.Type = "integer"
+ schema.Minimum = Ptr(float64(0))
+ schema.Description = g.generateDescription(field)
+
+ case descriptor.FieldDescriptorProto_TYPE_UINT32, descriptor.FieldDescriptorProto_TYPE_FIXED32:
+ schema.Type = "integer"
+ schema.Minimum = Ptr(float64(0))
+ schema.Maximum = Ptr(float64(math.MaxUint32))
+ schema.Description = g.generateDescription(field)
+
+ case descriptor.FieldDescriptorProto_TYPE_BOOL:
+ schema.Type = "boolean"
+ schema.Description = g.generateDescription(field)
+
+ case descriptor.FieldDescriptorProto_TYPE_STRING:
+ schema.Type = "string"
+ schema.Description = g.generateDescription(field)
+
+ case descriptor.FieldDescriptorProto_TYPE_MESSAGE:
+ msg := field.FieldType.(*protomodel.MessageDescriptor)
+ if customSchema, ok := g.customSchemasByMessageName[g.absoluteName(msg)]; ok {
+ // Deep copy since it is a shared type we may modify later
+ schema = g.generateCustomMessageSchema(msg, customSchema.DeepCopy())
+ } else if msg.GetOptions().GetMapEntry() {
+ isMap = true
+ sr := g.fieldType(msg.Fields[1])
+ schema = sr
+ schema = &apiext.JSONSchemaProps{
+ Type: "object",
+ AdditionalProperties: &apiext.JSONSchemaPropsOrBool{Schema: schema},
+ }
+
+ } else {
+ schema = g.generateMessageSchema(msg)
+ }
+ schema.Description = g.generateDescription(field)
+
+ case descriptor.FieldDescriptorProto_TYPE_BYTES:
+ schema.Type = "string"
+ schema.Format = "byte"
+ schema.Description = g.generateDescription(field)
+
+ case descriptor.FieldDescriptorProto_TYPE_ENUM:
+ enum := field.FieldType.(*protomodel.EnumDescriptor)
+ schema = g.generateEnumSchema(enum)
+ desc := g.generateDescription(field)
+ // Add all options to the description
+ valid := []string{}
+ for i, v := range enum.Values {
+ n := v.GetName()
+ // Allow skipping the default value if its a bogus value.
+ if i == 0 && (strings.Contains(n, "UNSPECIFIED") ||
+ strings.Contains(n, "UNSET") ||
+ strings.Contains(n, "UNDEFINED") ||
+ strings.Contains(n, "INVALID")) {
+ continue
+ }
+ valid = append(valid, n)
+ }
+ schema.Description = desc + fmt.Sprintf("\n\nValid Options: %v", strings.Join(valid, ", "))
+ }
+
+ if field.IsRepeated() && !isMap {
+ schema = &apiext.JSONSchemaProps{
+ // Format: "array",
+ Type: "array",
+ Items: &apiext.JSONSchemaPropsOrArray{Schema: schema},
+ }
+ schema.Description = schema.Items.Schema.Description
+ schema.Items.Schema.Description = ""
+ }
+
+ applyExtraValidations(schema, field, markers.DescribesField)
+
+ return schema
+}
+
+type SchemaApplier interface {
+ ApplyToSchema(schema *apiext.JSONSchemaProps) error
+}
+
+const (
+ KubeBuilderValidationPrefix = "+kubebuilder:validation:"
+ ProtocGenValidationPrefix = "+protoc-gen-crd:"
+ MapValidationPrefix = "+protoc-gen-crd:map-value-validation:"
+ ListValidationPrefix = "+protoc-gen-crd:list-value-validation:"
+ DurationValidationPrefix = "+protoc-gen-crd:duration-validation:"
+ IntOrStringValidation = "+protoc-gen-crd:validation:XIntOrString"
+ // IgnoreSubValidation is a custom validation allowing to refer to a type, but remove some validation
+ // This is useful when we are embedding a different type in a different context.
+ IgnoreSubValidation = "+protoc-gen-crd:validation:IgnoreSubValidation:"
+)
+
+var Celpp = func() *celpp.Preprocessor {
+ p, err := celpp.New(macros.All...)
+ if err != nil {
+ log.Fatalf("failed to build cel preprocessor: %v", err)
+ }
+ return p
+}()
+
+func applyExtraValidations(schema *apiext.JSONSchemaProps, m protomodel.CoreDesc, t markers.TargetType) {
+ for _, line := range strings.Split(m.Location().GetLeadingComments(), "\n") {
+ line = strings.TrimSpace(line)
+ if !strings.Contains(line, KubeBuilderValidationPrefix) &&
+ !strings.Contains(line, "+list") &&
+ !strings.Contains(line, ProtocGenValidationPrefix) {
+ continue
+ }
+ schema := schema
+
+ // Custom logic to apply validations to map values. In go, they just make a type alias and apply policy there; proto cannot do that.
+ if strings.Contains(line, MapValidationPrefix) {
+ schema = schema.AdditionalProperties.Schema
+ line = strings.ReplaceAll(line, MapValidationPrefix, KubeBuilderValidationPrefix)
+ }
+ if strings.Contains(line, ListValidationPrefix) {
+ schema = schema.Items.Schema
+ line = strings.ReplaceAll(line, ListValidationPrefix, KubeBuilderValidationPrefix)
+ }
+ // This is a hack to allow a certain field to opt-out of the default "Duration must be non-zero"
+ if strings.Contains(line, DurationValidationPrefix+"none") {
+ schema.XValidations = nil
+ return
+ }
+ // Kubernetes is very particular about the format for XIntOrString, must match exactly this
+ if strings.Contains(line, IntOrStringValidation) {
+ schema.Format = ""
+ schema.Type = ""
+ schema.AnyOf = []apiext.JSONSchemaProps{
+ {Type: "integer"},
+ {Type: "string"},
+ }
+ line = strings.ReplaceAll(line, ProtocGenValidationPrefix+"validation:", KubeBuilderValidationPrefix)
+ }
+
+ if strings.Contains(line, IgnoreSubValidation) {
+ li := strings.TrimPrefix(line, IgnoreSubValidation)
+ items := []string{}
+ if err := json.Unmarshal([]byte(li), &items); err != nil {
+ log.Fatalf("invalid %v %v: %v", IgnoreSubValidation, line, err)
+ }
+ recursivelyStripValidation(schema, items)
+ continue
+ }
+ if strings.Contains(line, "+kubebuilder:validation:XValidation:") {
+ left, right, ok := strings.Cut(line, ",rule=")
+ if !ok {
+ log.Fatalf("failed to parse marker %v", line)
+ }
+ expr := right[1 : len(right)-1]
+ nexpr, err := Celpp.Process(expr)
+ if err != nil {
+ log.Fatalf("failed to pre-process %v: %v", expr, err)
+ }
+ line = left + ",rule=" + fmt.Sprintf("%q", nexpr)
+ }
+
+ def := markerRegistry.Lookup(line, t)
+ if def == nil {
+ log.Fatalf("unknown validation: %v", line)
+ }
+ a, err := def.Parse(line)
+ if err != nil {
+ log.Fatalf("failed to parse: %v", line)
+ }
+ if err := a.(SchemaApplier).ApplyToSchema(schema); err != nil {
+ log.Fatalf("failed to apply schema %q: %v", schema.Description, err)
+ }
+ }
+}
+
+type stripVisitor struct {
+ removeMessages sets.Set[string]
+}
+
+func (s stripVisitor) Visit(schema *apiext.JSONSchemaProps) crd.SchemaVisitor {
+ if schema != nil && schema.XValidations != nil {
+ schema.XValidations = FilterInPlace(schema.XValidations, func(rule apiext.ValidationRule) bool {
+ return !s.removeMessages.Has(rule.Message)
+ })
+ }
+ return s
+}
+
+func recursivelyStripValidation(schema *apiext.JSONSchemaProps, items []string) {
+ crd.EditSchema(schema, stripVisitor{sets.New(items...)})
+}
+
+func FilterInPlace[E any](s []E, f func(E) bool) []E {
+ n := 0
+ for _, val := range s {
+ if f(val) {
+ s[n] = val
+ n++
+ }
+ }
+
+ // If those elements contain pointers you might consider zeroing those elements
+ // so that objects they reference can be garbage collected."
+ var empty E
+ for i := n; i < len(s); i++ {
+ s[i] = empty
+ }
+
+ s = s[:n]
+ return s
+}
+
+func (g *openapiGenerator) fieldName(field *protomodel.FieldDescriptor) string {
+ return field.GetJsonName()
+}
+
+func (g *openapiGenerator) fieldAltNames(field *protomodel.FieldDescriptor) []string {
+ _, an, f := strings.Cut(field.Location().GetLeadingComments(), "+kubebuilder:altName=")
+ if f {
+ return []string{strings.Fields(an)[0]}
+ }
+ return nil
+}
+
+func (g *openapiGenerator) relativeName(desc protomodel.CoreDesc) string {
+ typeName := protomodel.DottedName(desc)
+ if desc.PackageDesc() == g.currentPackage {
+ return typeName
+ }
+
+ return desc.PackageDesc().Name + "." + typeName
+}
+
+func Ptr[T any](t T) *T {
+ return &t
+}
+
+func validateStructural(s *apiext.JSONSchemaProps) error {
+ out := &apiextinternal.JSONSchemaProps{}
+ if err := apiext.Convert_v1_JSONSchemaProps_To_apiextensions_JSONSchemaProps(s, out, nil); err != nil {
+ return fmt.Errorf("cannot convert v1 JSONSchemaProps to JSONSchemaProps: %v", err)
+ }
+ r, err := structuralschema.NewStructural(out)
+ if err != nil {
+ return fmt.Errorf("cannot convert to a structural schema: %v", err)
+ }
+
+ if errs := structuralschema.ValidateStructural(nil, r); len(errs) != 0 {
+ b, _ := yaml.Marshal(s)
+ return fmt.Errorf("schema is not structural: %v (%+v)", errs.ToAggregate().Error(), string(b))
+ }
+
+ return nil
+}
+
+var markerRegistry = func() *markers.Registry {
+ registry := &markers.Registry{}
+ if err := crdmarkers.Register(registry); err != nil {
+ log.Fatal(err)
+ }
+ return registry
+}()
diff --git a/tools/cmd/protoc-gen-crd/pkg/protocgen/generate.go b/tools/cmd/protoc-gen-crd/pkg/protocgen/generate.go
new file mode 100644
index 00000000..e267e15d
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/pkg/protocgen/generate.go
@@ -0,0 +1,62 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package protocgen
+
+import (
+ "fmt"
+ "io"
+ "os"
+
+ plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
+ "google.golang.org/protobuf/proto"
+)
+
+// GenerateFn is a function definition for encapsulating the ore logic of code generation.
+type GenerateFn func(req *plugin.CodeGeneratorRequest) (*plugin.CodeGeneratorResponse, error)
+
+// Generate is a wrapper for a main function of a protoc generator plugin.
+func Generate(fn GenerateFn) {
+ data, err := io.ReadAll(os.Stdin)
+ if err != nil {
+ fatal("Unable to read input proto: %v\n", err)
+ }
+
+ var request plugin.CodeGeneratorRequest
+ if err = proto.Unmarshal(data, &request); err != nil {
+ fatal("Unable to parse input proto: %v\n", err)
+ }
+
+ response, err := fn(&request)
+ if err != nil {
+ fatal("%v\n", err)
+ }
+
+ data, err = proto.Marshal(response)
+ if err != nil {
+ fatal("Unable to serialize output proto: %v\n", err)
+ }
+
+ _, err = os.Stdout.Write(data)
+ if err != nil {
+ fatal("Unable to write output proto: %v\n", err)
+ }
+}
+
+func fatal(format string, args ...interface{}) {
+ fmt.Fprintf(os.Stderr, "ERROR: "+format, args...)
+ os.Exit(1)
+}
diff --git a/tools/cmd/protoc-gen-crd/pkg/protomodel/baseDesc.go b/tools/cmd/protoc-gen-crd/pkg/protomodel/baseDesc.go
new file mode 100644
index 00000000..3789dd42
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/pkg/protomodel/baseDesc.go
@@ -0,0 +1,125 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package protomodel
+
+import (
+ "strings"
+
+ "github.com/golang/protobuf/protoc-gen-go/descriptor"
+)
+
+// CoreDesc is an interface abstracting the abilities shared by all descriptors
+type CoreDesc interface {
+ PackageDesc() *PackageDescriptor
+ FileDesc() *FileDescriptor
+ QualifiedName() []string
+ IsHidden() bool
+ Class() string
+ Location() LocationDescriptor
+}
+
+// The common data for every descriptor in the model. This implements the coreDesc interface.
+type baseDesc struct {
+ loc *descriptor.SourceCodeInfo_Location
+ hidden bool
+ cl string
+ file *FileDescriptor
+ name []string
+}
+
+func newBaseDesc(file *FileDescriptor, path pathVector, qualifiedName []string) baseDesc {
+ loc := file.find(path)
+ cl := ""
+ com := ""
+
+ if loc != nil {
+ var newCom string
+ com = loc.GetLeadingComments()
+ if com != "" {
+ cl, newCom = getClass(com)
+ if cl != "" {
+ clone := *loc // nolint: govet
+ clone.LeadingComments = &newCom
+ loc = &clone
+ }
+ } else {
+ com = loc.GetTrailingComments()
+ if com != "" {
+ cl, newCom = getClass(com)
+ if cl != "" {
+ clone := *loc // nolint: govet
+ clone.TrailingComments = &newCom
+ loc = &clone
+ }
+ }
+ }
+ }
+
+ return baseDesc{
+ file: file,
+ loc: loc,
+ hidden: strings.Contains(com, "$hide_from_docs") || strings.Contains(com, "[#not-implemented-hide:]"),
+ cl: cl,
+ name: qualifiedName,
+ }
+}
+
+const class = "$class: "
+
+func getClass(com string) (cl string, newCom string) {
+ start := strings.Index(com, class)
+ if start < 0 {
+ return cl, newCom
+ }
+
+ name := start + len(class)
+ end := strings.IndexAny(com[name:], " \t\n") + start + len(class)
+
+ if end < 0 {
+ newCom = com[:start]
+ cl = com[name:]
+ } else {
+ newCom = com[:start] + com[end:]
+ cl = com[name:end]
+ }
+
+ return cl, newCom
+}
+
+func (bd baseDesc) PackageDesc() *PackageDescriptor {
+ return bd.file.Parent
+}
+
+func (bd baseDesc) FileDesc() *FileDescriptor {
+ return bd.file
+}
+
+func (bd baseDesc) QualifiedName() []string {
+ return bd.name
+}
+
+func (bd baseDesc) IsHidden() bool {
+ return bd.hidden
+}
+
+func (bd baseDesc) Class() string {
+ return bd.cl
+}
+
+func (bd baseDesc) Location() LocationDescriptor {
+ return newLocationDescriptor(bd.loc, bd.file)
+}
diff --git a/tools/cmd/protoc-gen-crd/pkg/protomodel/enumDescriptor.go b/tools/cmd/protoc-gen-crd/pkg/protomodel/enumDescriptor.go
new file mode 100644
index 00000000..ac33c36b
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/pkg/protomodel/enumDescriptor.go
@@ -0,0 +1,63 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package protomodel
+
+import (
+ "github.com/golang/protobuf/protoc-gen-go/descriptor"
+)
+
+type EnumDescriptor struct {
+ baseDesc
+ *descriptor.EnumDescriptorProto
+ Values []*EnumValueDescriptor // The values of this enum
+}
+
+type EnumValueDescriptor struct {
+ baseDesc
+ *descriptor.EnumValueDescriptorProto
+}
+
+func newEnumDescriptor(desc *descriptor.EnumDescriptorProto, parent *MessageDescriptor, file *FileDescriptor, path pathVector) *EnumDescriptor {
+ var qualifiedName []string
+ if parent == nil {
+ qualifiedName = []string{desc.GetName()}
+ } else {
+ qualifiedName = make([]string, len(parent.QualifiedName()), len(parent.QualifiedName())+1)
+ copy(qualifiedName, parent.QualifiedName())
+ qualifiedName = append(qualifiedName, desc.GetName())
+ }
+
+ e := &EnumDescriptor{
+ EnumDescriptorProto: desc,
+ baseDesc: newBaseDesc(file, path, qualifiedName),
+ }
+
+ e.Values = make([]*EnumValueDescriptor, 0, len(desc.Value))
+ for i, ev := range desc.Value {
+ nameCopy := make([]string, len(qualifiedName), len(qualifiedName)+1)
+ copy(nameCopy, qualifiedName)
+ nameCopy = append(nameCopy, ev.GetName())
+
+ evd := &EnumValueDescriptor{
+ EnumValueDescriptorProto: ev,
+ baseDesc: newBaseDesc(file, path.append(enumValuePath, i), nameCopy),
+ }
+ e.Values = append(e.Values, evd)
+ }
+
+ return e
+}
diff --git a/tools/cmd/protoc-gen-crd/pkg/protomodel/fileDescriptor.go b/tools/cmd/protoc-gen-crd/pkg/protomodel/fileDescriptor.go
new file mode 100644
index 00000000..97873918
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/pkg/protomodel/fileDescriptor.go
@@ -0,0 +1,97 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package protomodel
+
+import (
+ "github.com/golang/protobuf/protoc-gen-go/descriptor"
+)
+
+type FileDescriptor struct {
+ *descriptor.FileDescriptorProto
+ Parent *PackageDescriptor
+ AllMessages []*MessageDescriptor // All the messages defined in this file
+ AllEnums []*EnumDescriptor // All the enums defined in this file
+ Messages []*MessageDescriptor // Top-level messages defined in this file
+ Enums []*EnumDescriptor // Top-level enums defined in this file
+ Services []*ServiceDescriptor // All services defined in this file
+ Dependencies []*FileDescriptor // Files imported by this file
+ locations map[pathVector]*descriptor.SourceCodeInfo_Location // Provenance
+ Matter FrontMatter // Title, overview, homeLocation, front_matter
+}
+
+func newFileDescriptor(desc *descriptor.FileDescriptorProto, parent *PackageDescriptor) *FileDescriptor {
+ f := &FileDescriptor{
+ FileDescriptorProto: desc,
+ locations: make(map[pathVector]*descriptor.SourceCodeInfo_Location, len(desc.GetSourceCodeInfo().GetLocation())),
+ Parent: parent,
+ }
+
+ // put all the locations in a map for quick lookup
+ for _, loc := range desc.GetSourceCodeInfo().GetLocation() {
+ if len(loc.Path) > 0 {
+ pv := newPathVector(int(loc.Path[0]))
+ for _, v := range loc.Path[1:] {
+ pv = pv.append(int(v))
+ }
+ f.locations[pv] = loc
+ }
+ }
+
+ path := newPathVector(messagePath)
+ for i, md := range desc.MessageType {
+ f.Messages = append(f.Messages, newMessageDescriptor(md, nil, f, path.append(i)))
+ }
+
+ path = newPathVector(enumPath)
+ for i, e := range desc.EnumType {
+ f.Enums = append(f.Enums, newEnumDescriptor(e, nil, f, path.append(i)))
+ }
+
+ path = newPathVector(servicePath)
+ for i, s := range desc.Service {
+ f.Services = append(f.Services, newServiceDescriptor(s, f, path.append(i)))
+ }
+
+ // Find title/overview/etc content in comments and store it explicitly.
+ loc := f.find(newPathVector(packagePath))
+ if loc != nil && loc.LeadingDetachedComments != nil {
+ f.Matter = extractFrontMatter(f.GetName(), loc, f)
+ }
+
+ // get the transitive close of all messages and enums
+ f.aggregateMessages(f.Messages)
+ f.aggregateEnums(f.Enums)
+
+ return f
+}
+
+func (f *FileDescriptor) find(path pathVector) *descriptor.SourceCodeInfo_Location {
+ loc := f.locations[path]
+ return loc
+}
+
+func (f *FileDescriptor) aggregateMessages(messages []*MessageDescriptor) {
+ f.AllMessages = append(f.AllMessages, messages...)
+ for _, msg := range messages {
+ f.aggregateMessages(msg.Messages)
+ f.aggregateEnums(msg.Enums)
+ }
+}
+
+func (f *FileDescriptor) aggregateEnums(enums []*EnumDescriptor) {
+ f.AllEnums = append(f.AllEnums, enums...)
+}
diff --git a/tools/cmd/protoc-gen-crd/pkg/protomodel/frontMatter.go b/tools/cmd/protoc-gen-crd/pkg/protomodel/frontMatter.go
new file mode 100644
index 00000000..0f21050b
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/pkg/protomodel/frontMatter.go
@@ -0,0 +1,116 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package protomodel
+
+import (
+ "fmt"
+ "os"
+ "strings"
+
+ "github.com/golang/protobuf/protoc-gen-go/descriptor"
+)
+
+type Mode string
+
+var (
+ ModeUnset Mode
+ ModeFile Mode = "file"
+ ModePackage Mode = "package"
+ ModeNone Mode = "none"
+)
+
+type FrontMatter struct {
+ Title string
+ Overview string
+ Description string
+ HomeLocation string
+ Extra []string
+ Location LocationDescriptor
+ Mode Mode
+}
+
+const (
+ titleTag = "$title: "
+ overviewTag = "$overview: "
+ descriptionTag = "$description: "
+ locationTag = "$location: "
+ frontMatterTag = "$front_matter: "
+ modeTag = "$mode: "
+)
+
+func checkSingle(name string, old string, line string, tag string) string {
+ result := line[len(tag):]
+ if old != "" {
+ _, _ = fmt.Fprintf(os.Stderr, "%v has more than one %v: %v\n", name, tag, result)
+ }
+ return result
+}
+
+func extractFrontMatter(name string, loc *descriptor.SourceCodeInfo_Location, file *FileDescriptor) FrontMatter {
+ title := ""
+ overview := ""
+ description := ""
+ homeLocation := ""
+ mode := ""
+ var extra []string
+
+ for _, para := range loc.LeadingDetachedComments {
+ lines := strings.Split(para, "\n")
+ for _, l := range lines {
+ l = strings.Trim(l, " ")
+
+ if strings.HasPrefix(l, "$") {
+ if strings.HasPrefix(l, titleTag) {
+ title = checkSingle(name, title, l, titleTag)
+ } else if strings.HasPrefix(l, overviewTag) {
+ overview = checkSingle(name, overview, l, overviewTag)
+ } else if strings.HasPrefix(l, descriptionTag) {
+ description = checkSingle(name, description, l, descriptionTag)
+ } else if strings.HasPrefix(l, locationTag) {
+ homeLocation = checkSingle(name, homeLocation, l, locationTag)
+ } else if strings.HasPrefix(l, frontMatterTag) {
+ // old way to specify custom front-matter
+ extra = append(extra, l[len(frontMatterTag):])
+ } else if strings.HasPrefix(l, modeTag) {
+ mode = checkSingle(name, mode, l, modeTag)
+ } else {
+ extra = append(extra, l[1:])
+ }
+ }
+ }
+ }
+
+ return FrontMatter{
+ Title: title,
+ Overview: overview,
+ Description: description,
+ HomeLocation: homeLocation,
+ Mode: checkMode(mode),
+ Extra: extra,
+ Location: newLocationDescriptor(loc, file),
+ }
+}
+
+func checkMode(single string) Mode {
+ switch Mode(single) {
+ case ModeUnset, ModeFile, ModePackage, ModeNone:
+ return Mode(single)
+ default:
+ fmt.Fprintf(os.Stderr, "unknown mode: %v\n", single)
+ return ModeUnset
+ }
+}
diff --git a/dubbod/planet/pkg/xds/v3/model.go b/tools/cmd/protoc-gen-crd/pkg/protomodel/locationDescriptor.go
similarity index 57%
copy from dubbod/planet/pkg/xds/v3/model.go
copy to tools/cmd/protoc-gen-crd/pkg/protomodel/locationDescriptor.go
index bb1b39be..8c93bc8e 100644
--- a/dubbod/planet/pkg/xds/v3/model.go
+++ b/tools/cmd/protoc-gen-crd/pkg/protomodel/locationDescriptor.go
@@ -14,22 +14,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package v3
+package protomodel
-import "github.com/apache/dubbo-kubernetes/pkg/model"
-
-const (
- ClusterType = model.ClusterType
- ListenerType = model.ListenerType
- EndpointType = model.EndpointType
- RouteType = model.RouteType
- SecretType = model.SecretType
- ExtensionConfigurationType = model.ExtensionConfigurationType
- DebugType = model.DebugType
- HealthInfoType = model.HealthInfoType
- AddressType = model.AddressType
+import (
+ "github.com/golang/protobuf/protoc-gen-go/descriptor"
)
-func GetShortType(typeURL string) string {
- return model.GetShortType(typeURL)
+type LocationDescriptor struct {
+ *descriptor.SourceCodeInfo_Location
+ File *FileDescriptor
+}
+
+func newLocationDescriptor(desc *descriptor.SourceCodeInfo_Location, file *FileDescriptor) LocationDescriptor {
+ return LocationDescriptor{
+ SourceCodeInfo_Location: desc,
+ File: file,
+ }
}
diff --git a/tools/cmd/protoc-gen-crd/pkg/protomodel/messageDescriptor.go b/tools/cmd/protoc-gen-crd/pkg/protomodel/messageDescriptor.go
new file mode 100644
index 00000000..9232b798
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/pkg/protomodel/messageDescriptor.go
@@ -0,0 +1,80 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package protomodel
+
+import (
+ "github.com/golang/protobuf/protoc-gen-go/descriptor"
+)
+
+type MessageDescriptor struct {
+ baseDesc
+ *descriptor.DescriptorProto
+ Parent *MessageDescriptor // The containing message, if any
+ Messages []*MessageDescriptor // Inner messages, if any
+ Enums []*EnumDescriptor // Inner enums, if any
+ Fields []*FieldDescriptor // Fields, if any
+}
+
+type FieldDescriptor struct {
+ baseDesc
+ *descriptor.FieldDescriptorProto
+ FieldType CoreDesc // Type of data held by this field
+}
+
+func newMessageDescriptor(desc *descriptor.DescriptorProto, parent *MessageDescriptor, file *FileDescriptor, path pathVector) *MessageDescriptor {
+ var qualifiedName []string
+ if parent == nil {
+ qualifiedName = []string{desc.GetName()}
+ } else {
+ qualifiedName = make([]string, len(parent.QualifiedName()), len(parent.QualifiedName())+1)
+ copy(qualifiedName, parent.QualifiedName())
+ qualifiedName = append(qualifiedName, desc.GetName())
+ }
+
+ m := &MessageDescriptor{
+ DescriptorProto: desc,
+ Parent: parent,
+ baseDesc: newBaseDesc(file, path, qualifiedName),
+ }
+
+ for i, f := range desc.Field {
+ nameCopy := make([]string, len(qualifiedName), len(qualifiedName)+1)
+ copy(nameCopy, qualifiedName)
+ nameCopy = append(nameCopy, f.GetName())
+
+ fd := &FieldDescriptor{
+ FieldDescriptorProto: f,
+ baseDesc: newBaseDesc(file, path.append(messageFieldPath, i), nameCopy),
+ }
+
+ m.Fields = append(m.Fields, fd)
+ }
+
+ for i, msg := range desc.NestedType {
+ m.Messages = append(m.Messages, newMessageDescriptor(msg, m, file, path.append(messageMessagePath, i)))
+ }
+
+ for i, e := range desc.EnumType {
+ m.Enums = append(m.Enums, newEnumDescriptor(e, m, file, path.append(messageEnumPath, i)))
+ }
+
+ return m
+}
+
+func (f *FieldDescriptor) IsRepeated() bool {
+ return f.Label != nil && *f.Label == descriptor.FieldDescriptorProto_LABEL_REPEATED
+}
diff --git a/tools/cmd/protoc-gen-crd/pkg/protomodel/model.go b/tools/cmd/protoc-gen-crd/pkg/protomodel/model.go
new file mode 100644
index 00000000..b6516a31
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/pkg/protomodel/model.go
@@ -0,0 +1,180 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package protomodel
+
+import (
+ "strings"
+
+ "github.com/golang/protobuf/protoc-gen-go/descriptor"
+ plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
+)
+
+// model represents a resolved in-memory version of all the input protos
+type Model struct {
+ AllFilesByName map[string]*FileDescriptor
+ AllDescByName map[string]CoreDesc
+ Packages []*PackageDescriptor
+}
+
+func NewModel(request *plugin.CodeGeneratorRequest, perFile bool) *Model {
+ m := &Model{
+ AllFilesByName: make(map[string]*FileDescriptor, len(request.ProtoFile)),
+ }
+
+ // organize files by package
+ filesByPackage := map[string][]*descriptor.FileDescriptorProto{}
+ for _, pf := range request.ProtoFile {
+ pkg := packageName(pf)
+ slice := filesByPackage[pkg]
+ filesByPackage[pkg] = append(slice, pf)
+ }
+
+ // create all the package descriptors
+ var allFiles []*FileDescriptor
+ for pkg, files := range filesByPackage {
+ p := newPackageDescriptor(pkg, files, perFile)
+ m.Packages = append(m.Packages, p)
+
+ for _, f := range p.Files {
+ allFiles = append(allFiles, f)
+ m.AllFilesByName[f.GetName()] = f
+ }
+ }
+
+ // prepare a map of name to descriptor
+ m.AllDescByName = createDescMap(allFiles)
+
+ // resolve all type references to nice easily used pointers
+ for _, f := range allFiles {
+ resolveFieldTypes(f.Messages, m.AllDescByName)
+ resolveMethodTypes(f.Services, m.AllDescByName)
+ resolveDependencies(f, m.AllFilesByName)
+ }
+
+ return m
+}
+
+func packageName(f *descriptor.FileDescriptorProto) string {
+ // Does the file have a package clause?
+ if pkg := f.GetPackage(); pkg != "" {
+ return pkg
+ }
+
+ // use the last path element of the name, with the last dotted suffix removed.
+
+ // First, find the last element
+ name := f.GetName()
+ if i := strings.LastIndex(name, "/"); i >= 0 {
+ name = name[i+1:]
+ }
+
+ // Now drop the suffix
+ if i := strings.LastIndex(name, "."); i >= 0 {
+ name = name[0:i]
+ }
+
+ return name
+}
+
+// createDescMap builds a map from qualified names to descriptors.
+// The key names for the map come from the input data, which puts a period at the beginning.
+func createDescMap(files []*FileDescriptor) map[string]CoreDesc {
+ descMap := make(map[string]CoreDesc)
+ for _, f := range files {
+ // The names in this loop are defined by the proto world, not us, so the
+ // package name may be empty. If so, the dotted package name of X will
+ // be ".X"; otherwise it will be ".pkg.X".
+ dottedPkg := "." + f.GetPackage()
+ if dottedPkg != "." {
+ dottedPkg += "."
+ }
+
+ for _, svc := range f.Services {
+ descMap[dottedPkg+DottedName(svc)] = svc
+ }
+
+ recordEnums(f.Enums, descMap, dottedPkg)
+ recordMessages(f.Messages, descMap, dottedPkg)
+ recordServices(f.Services, descMap, dottedPkg)
+ resolveFieldTypes(f.Messages, descMap)
+ }
+
+ return descMap
+}
+
+func recordMessages(messages []*MessageDescriptor, descMap map[string]CoreDesc, dottedPkg string) {
+ for _, msg := range messages {
+ descMap[dottedPkg+DottedName(msg)] = msg
+
+ recordMessages(msg.Messages, descMap, dottedPkg)
+ recordEnums(msg.Enums, descMap, dottedPkg)
+
+ for _, f := range msg.Fields {
+ descMap[dottedPkg+DottedName(f)] = f
+ }
+ }
+}
+
+func recordEnums(enums []*EnumDescriptor, descMap map[string]CoreDesc, dottedPkg string) {
+ for _, e := range enums {
+ descMap[dottedPkg+DottedName(e)] = e
+
+ for _, v := range e.Values {
+ descMap[dottedPkg+DottedName(v)] = v
+ }
+ }
+}
+
+func recordServices(services []*ServiceDescriptor, descMap map[string]CoreDesc, dottedPkg string) {
+ for _, s := range services {
+ descMap[dottedPkg+DottedName(s)] = s
+
+ for _, m := range s.Methods {
+ descMap[dottedPkg+DottedName(m)] = m
+ }
+ }
+}
+
+func resolveFieldTypes(messages []*MessageDescriptor, descMap map[string]CoreDesc) {
+ for _, msg := range messages {
+ for _, field := range msg.Fields {
+ field.FieldType = descMap[field.GetTypeName()]
+ }
+ resolveFieldTypes(msg.Messages, descMap)
+ }
+}
+
+func resolveMethodTypes(services []*ServiceDescriptor, descMap map[string]CoreDesc) {
+ for _, svc := range services {
+ for _, method := range svc.Methods {
+ method.Input = descMap[method.GetInputType()].(*MessageDescriptor)
+ method.Output = descMap[method.GetOutputType()].(*MessageDescriptor)
+ }
+ }
+}
+
+func resolveDependencies(file *FileDescriptor, filesByName map[string]*FileDescriptor) {
+ for _, desc := range file.Dependency {
+ dep := filesByName[desc]
+ file.Dependencies = append(file.Dependencies, dep)
+ }
+}
+
+// DottedName returns a dotted representation of the coreDesc's name
+func DottedName(o CoreDesc) string {
+ return strings.Join(o.QualifiedName(), ".")
+}
diff --git a/tools/cmd/protoc-gen-crd/pkg/protomodel/packageDescriptor.go b/tools/cmd/protoc-gen-crd/pkg/protomodel/packageDescriptor.go
new file mode 100644
index 00000000..f0d8326e
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/pkg/protomodel/packageDescriptor.go
@@ -0,0 +1,73 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package protomodel
+
+import (
+ "fmt"
+ "os"
+ "sort"
+
+ "github.com/golang/protobuf/protoc-gen-go/descriptor"
+)
+
+// PackageDescriptor describes a package, which is a composition of proto files.
+type PackageDescriptor struct {
+ baseDesc
+ Files []*FileDescriptor
+ Name string
+}
+
+func newPackageDescriptor(name string, desc []*descriptor.FileDescriptorProto, perFile bool) *PackageDescriptor {
+ p := &PackageDescriptor{
+ Name: name,
+ }
+
+ for _, fd := range desc {
+ f := newFileDescriptor(fd, p)
+ p.Files = append(p.Files, f)
+
+ // The package's file is one that documents the package statement.
+ // The first file to do this "wins".
+ loc := f.find(newPathVector(packagePath))
+ if loc != nil {
+ if p.loc == nil {
+ if loc.GetLeadingComments() != "" || loc.GetTrailingComments() != "" {
+ p.loc = loc
+ p.file = f
+ // Inherit only f's frontMatter, don't get title from one file
+ }
+ } else if !perFile {
+ leading := loc.GetLeadingComments()
+ trailing := loc.GetTrailingComments()
+ if leading != "" || trailing != "" {
+ _, _ = fmt.Fprintf(os.Stderr, "WARNING: package %v has a conflicting package comment in file %v.\n",
+ name, f.GetName())
+ _, _ = fmt.Fprintf(os.Stderr, "Previous:\n%v\n%v\nCurrent:\n%v\n%v\n", p.loc.GetLeadingComments(), p.loc.GetTrailingComments(), leading, trailing)
+ }
+ }
+ }
+ }
+
+ // Make the documenting file first. This ensures its messages show up first on the output
+ // If we need more granularity with explicitly multiple file ordering, we can add some sort of annotation,
+ // but or now this is sufficient.
+ sort.SliceStable(p.Files, func(i, j int) bool {
+ return p.Files[i] == p.file
+ })
+
+ return p
+}
diff --git a/tools/cmd/protoc-gen-crd/pkg/protomodel/pathVector.go b/tools/cmd/protoc-gen-crd/pkg/protomodel/pathVector.go
new file mode 100644
index 00000000..ce0b290f
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/pkg/protomodel/pathVector.go
@@ -0,0 +1,64 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package protomodel
+
+import (
+ "strconv"
+)
+
+// The SourceCodeInfo messages describes the location of elements of a parsed
+// .proto currentFile by way of a "path", which is a sequence of integers that
+// describe the route from a FileDescriptorProto to the relevant submessage.
+// The path alternates between a field number of a repeated field, and an index
+// into that repeated field. The constants below define the field numbers that
+// are used.
+//
+// See descriptor.proto for more information about this.
+const (
+ // tag numbers in FileDescriptorProto
+ packagePath = 2 // package
+ messagePath = 4 // message_type
+ enumPath = 5 // enum_type
+ servicePath = 6 // service
+
+ // tag numbers in DescriptorProto
+ messageFieldPath = 2 // field
+ messageMessagePath = 3 // nested_type
+ messageEnumPath = 4 // enum_type
+
+ // tag numbers in EnumDescriptorProto
+ enumValuePath = 2 // value
+
+ // tag numbers in ServiceDescriptorProto
+ serviceMethodPath = 2 // method
+)
+
+// A vector of comma-separated integers which identify a particular entry in a
+// given's file location information
+type pathVector string
+
+func newPathVector(v int) pathVector {
+ return pathVector(strconv.Itoa(v))
+}
+
+func (pv pathVector) append(v ...int) pathVector {
+ result := pv
+ for _, val := range v {
+ result += pathVector("," + strconv.Itoa(val))
+ }
+ return result
+}
diff --git a/tools/cmd/protoc-gen-crd/pkg/protomodel/serviceDescriptor.go b/tools/cmd/protoc-gen-crd/pkg/protomodel/serviceDescriptor.go
new file mode 100644
index 00000000..242f22c3
--- /dev/null
+++ b/tools/cmd/protoc-gen-crd/pkg/protomodel/serviceDescriptor.go
@@ -0,0 +1,57 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package protomodel
+
+import (
+ "github.com/golang/protobuf/protoc-gen-go/descriptor"
+)
+
+type ServiceDescriptor struct {
+ baseDesc
+ *descriptor.ServiceDescriptorProto
+ Methods []*MethodDescriptor // Methods, if any
+}
+
+type MethodDescriptor struct {
+ baseDesc
+ *descriptor.MethodDescriptorProto
+ Input *MessageDescriptor
+ Output *MessageDescriptor
+}
+
+func newServiceDescriptor(desc *descriptor.ServiceDescriptorProto, file *FileDescriptor, path pathVector) *ServiceDescriptor {
+ qualifiedName := []string{desc.GetName()}
+
+ s := &ServiceDescriptor{
+ ServiceDescriptorProto: desc,
+ baseDesc: newBaseDesc(file, path, qualifiedName),
+ }
+
+ for i, m := range desc.Method {
+ nameCopy := make([]string, len(qualifiedName), len(qualifiedName)+1)
+ copy(nameCopy, qualifiedName)
+ nameCopy = append(nameCopy, m.GetName())
+
+ md := &MethodDescriptor{
+ MethodDescriptorProto: m,
+ baseDesc: newBaseDesc(file, path.append(serviceMethodPath, i), nameCopy),
+ }
+ s.Methods = append(s.Methods, md)
+ }
+
+ return s
+}
diff --git a/tools/scripts/update_crds.sh b/tools/scripts/update_crds.sh
new file mode 100755
index 00000000..19430cb2
--- /dev/null
+++ b/tools/scripts/update_crds.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+set -ex
+
+rm -f "../../manifests/charts/base/files/crd-all.gen.yaml"
+cp "../../api/kubernetes/customresourcedefinitions.gen.yaml" "../../manifests/charts/base/files/crd-all.gen.yaml"
\ No newline at end of file