diff --git a/charts/fsm/templates/fsm-rbac.yaml b/charts/fsm/templates/fsm-rbac.yaml index 2536409e6..32d09c7f1 100644 --- a/charts/fsm/templates/fsm-rbac.yaml +++ b/charts/fsm/templates/fsm-rbac.yaml @@ -156,13 +156,13 @@ rules: # GatewayAPI Extension - apiGroups: [ "extension.gateway.flomesh.io" ] - resources: [ "filters", "filterdefinitions", "listenerfilters", "circuitbreakers", "faultinjections", "ratelimits", "httplogs", "metrics" ] + resources: [ "filters", "filterdefinitions", "listenerfilters", "circuitbreakers", "faultinjections", "ratelimits", "httplogs", "metrics", "zipkins" ] verbs: [ "get", "list", "watch", "create", "update", "patch", "delete" ] - apiGroups: [ "extension.gateway.flomesh.io" ] - resources: [ "filters/finalizers", "filterdefinitions/finalizers", "listenerfilters/finalizers", "circuitbreakers/finalizers", "faultinjections/finalizers", "ratelimits/finalizers", "httplogs/finalizers", "metrics/finalizers" ] + resources: [ "filters/finalizers", "filterdefinitions/finalizers", "listenerfilters/finalizers", "circuitbreakers/finalizers", "faultinjections/finalizers", "ratelimits/finalizers", "httplogs/finalizers", "metrics/finalizers", "zipkins/finalizers" ] verbs: [ "update" ] - apiGroups: [ "extension.gateway.flomesh.io" ] - resources: [ "filters/status", "filterdefinitions/status", "listenerfilters/status", "circuitbreakers/status", "faultinjections/status", "ratelimits/status", "httplogs/status", "metrics/status" ] + resources: [ "filters/status", "filterdefinitions/status", "listenerfilters/status", "circuitbreakers/status", "faultinjections/status", "ratelimits/status", "httplogs/status", "metrics/status", "zipkins/status" ] verbs: [ "get", "patch", "update" ] # PolicyAttachment diff --git a/cmd/fsm-bootstrap/crds/extension.gateway.flomesh.io_zipkins.yaml b/cmd/fsm-bootstrap/crds/extension.gateway.flomesh.io_zipkins.yaml new file mode 100644 index 000000000..e6ec53fa1 --- /dev/null +++ b/cmd/fsm-bootstrap/crds/extension.gateway.flomesh.io_zipkins.yaml @@ -0,0 +1,139 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.15.0 + labels: + app.kubernetes.io/name: flomesh.io + name: zipkins.extension.gateway.flomesh.io +spec: + group: extension.gateway.flomesh.io + names: + categories: + - gateway-api + kind: Zipkin + listKind: ZipkinList + plural: zipkins + singular: zipkin + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1alpha1 + schema: + openAPIV3Schema: + description: Zipkin is the Schema for the Zipkin API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: ZipkinSpec defines the desired state of Zipkin + properties: + samplePercentage: + default: 10 + format: int32 + maximum: 100 + minimum: 1 + type: integer + type: object + status: + description: ZipkinStatus defines the observed state of Zipkin + properties: + conditions: + description: Conditions describe the current conditions of the Zipkin. + items: + description: "Condition contains details for one aspect of the current + state of this API Resource.\n---\nThis struct is intended for + direct use as an array at the field path .status.conditions. For + example,\n\n\n\ttype FooStatus struct{\n\t // Represents the + observations of a foo's current state.\n\t // Known .status.conditions.type + are: \"Available\", \"Progressing\", and \"Degraded\"\n\t // + +patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t + \ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\" + patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t + \ // other fields\n\t}" + properties: + lastTransitionTime: + description: |- + lastTransitionTime is the last time the condition transitioned from one status to another. + This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable. + format: date-time + type: string + message: + description: |- + message is a human readable message indicating details about the transition. + This may be an empty string. + maxLength: 32768 + type: string + observedGeneration: + description: |- + observedGeneration represents the .metadata.generation that the condition was set based upon. + For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date + with respect to the current state of the instance. + format: int64 + minimum: 0 + type: integer + reason: + description: |- + reason contains a programmatic identifier indicating the reason for the condition's last transition. + Producers of specific condition types may define expected values and meanings for this field, + and whether the values are considered a guaranteed API. + The value should be a CamelCase string. + This field may not be empty. + maxLength: 1024 + minLength: 1 + pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ + type: string + status: + description: status of the condition, one of True, False, Unknown. + enum: + - "True" + - "False" + - Unknown + type: string + type: + description: |- + type of condition in CamelCase or in foo.example.com/CamelCase. + --- + Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be + useful (see .node.status.conditions), the ability to deconflict is important. + The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) + maxLength: 316 + pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ + type: string + required: + - lastTransitionTime + - message + - reason + - status + - type + type: object + maxItems: 8 + type: array + x-kubernetes-list-map-keys: + - type + x-kubernetes-list-type: map + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/pkg/announcements/types.go b/pkg/announcements/types.go index 0794371cf..e61dcf74c 100644 --- a/pkg/announcements/types.go +++ b/pkg/announcements/types.go @@ -666,6 +666,17 @@ const ( // GatewayMetricsUpdated is the type of announcement emitted when we observe an update to metrics.extension.gateway.flomesh.io GatewayMetricsUpdated Kind = "gatewaymetrics-updated" + + // -- + + // GatewayZipkinAdded is the type of announcement emitted when we observe an addition of zipkins.extension.gateway.flomesh.io + GatewayZipkinAdded Kind = "gatewayzipkin-added" + + // GatewayZipkinDeleted the type of announcement emitted when we observe a deletion of zipkins.extension.gateway.flomesh.io + GatewayZipkinDeleted Kind = "gatewayzipkin-deleted" + + // GatewayZipkinUpdated is the type of announcement emitted when we observe an update to zipkins.extension.gateway.flomesh.io + GatewayZipkinUpdated Kind = "gatewayzipkin-updated" ) // Announcement is a struct for messages between various components of FSM signaling a need for a change in Sidecar proxy configuration diff --git a/pkg/apis/extension/v1alpha1/zipkin.go b/pkg/apis/extension/v1alpha1/zipkin.go new file mode 100644 index 000000000..84c36a15e --- /dev/null +++ b/pkg/apis/extension/v1alpha1/zipkin.go @@ -0,0 +1,53 @@ +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// ZipkinSpec defines the desired state of Zipkin +type ZipkinSpec struct { + // +optional + // +kubebuilder:default=10 + // +kubebuilder:validation:Minimum=1 + // +kubebuilder:validation:Maximum=100 + SamplePercentage *int32 `json:"samplePercentage,omitempty"` +} + +// ZipkinStatus defines the observed state of Zipkin +type ZipkinStatus struct { + // Conditions describe the current conditions of the Zipkin. + // + // +optional + // +listType=map + // +listMapKey=type + // +kubebuilder:validation:MaxItems=8 + Conditions []metav1.Condition `json:"conditions,omitempty"` +} + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:storageversion +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:resource:scope=Namespaced,categories=gateway-api +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` +// +kubebuilder:metadata:labels={app.kubernetes.io/name=flomesh.io} + +// Zipkin is the Schema for the Zipkin API +type Zipkin struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ZipkinSpec `json:"spec,omitempty"` + Status ZipkinStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ZipkinList contains a list of Zipkin +type ZipkinList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []Zipkin `json:"items"` +} diff --git a/pkg/apis/extension/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/extension/v1alpha1/zz_generated.deepcopy.go index 7cd7ab4aa..07c0f439d 100644 --- a/pkg/apis/extension/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/extension/v1alpha1/zz_generated.deepcopy.go @@ -1158,3 +1158,108 @@ func (in *RateLimitStatus) DeepCopy() *RateLimitStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Zipkin) DeepCopyInto(out *Zipkin) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Zipkin. +func (in *Zipkin) DeepCopy() *Zipkin { + if in == nil { + return nil + } + out := new(Zipkin) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Zipkin) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ZipkinList) DeepCopyInto(out *ZipkinList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Zipkin, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ZipkinList. +func (in *ZipkinList) DeepCopy() *ZipkinList { + if in == nil { + return nil + } + out := new(ZipkinList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ZipkinList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ZipkinSpec) DeepCopyInto(out *ZipkinSpec) { + *out = *in + if in.SamplePercentage != nil { + in, out := &in.SamplePercentage, &out.SamplePercentage + *out = new(int32) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ZipkinSpec. +func (in *ZipkinSpec) DeepCopy() *ZipkinSpec { + if in == nil { + return nil + } + out := new(ZipkinSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ZipkinStatus) DeepCopyInto(out *ZipkinStatus) { + *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]v1.Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ZipkinStatus. +func (in *ZipkinStatus) DeepCopy() *ZipkinStatus { + if in == nil { + return nil + } + out := new(ZipkinStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/extension/v1alpha1/zz_generated.register.go b/pkg/apis/extension/v1alpha1/zz_generated.register.go index 34c6e00d4..24e613e57 100644 --- a/pkg/apis/extension/v1alpha1/zz_generated.register.go +++ b/pkg/apis/extension/v1alpha1/zz_generated.register.go @@ -74,6 +74,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &MetricsList{}, &RateLimit{}, &RateLimitList{}, + &Zipkin{}, + &ZipkinList{}, ) // AddToGroupVersion allows the serialization of client types like ListOptions. v1.AddToGroupVersion(scheme, SchemeGroupVersion) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 963b215e6..f7a46404b 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -479,6 +479,9 @@ const ( // GatewayMetricsKind is the kind name of Metrics used in Flomesh API GatewayMetricsKind = "Metrics" + + // GatewayZipkinKind is the kind name of Zipkin used in Flomesh API + GatewayZipkinKind = "Zipkin" ) // Gateway API Annotations and Labels diff --git a/pkg/controllers/extension/v1alpha1/zipkin_controller.go b/pkg/controllers/extension/v1alpha1/zipkin_controller.go new file mode 100644 index 000000000..86e71425a --- /dev/null +++ b/pkg/controllers/extension/v1alpha1/zipkin_controller.go @@ -0,0 +1,89 @@ +package v1alpha1 + +import ( + "context" + + "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/tools/record" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + + extv1alpha1 "github.com/flomesh-io/fsm/pkg/apis/extension/v1alpha1" + fctx "github.com/flomesh-io/fsm/pkg/context" + "github.com/flomesh-io/fsm/pkg/controllers" +) + +type zipkinReconciler struct { + recorder record.EventRecorder + fctx *fctx.ControllerContext +} + +func (r *zipkinReconciler) NeedLeaderElection() bool { + return true +} + +// NewZipkinReconciler returns a new Zipkin Reconciler +func NewZipkinReconciler(ctx *fctx.ControllerContext) controllers.Reconciler { + return &zipkinReconciler{ + recorder: ctx.Manager.GetEventRecorderFor("Zipkin"), + fctx: ctx, + } +} + +// Reconcile reads that state of the cluster for a Zipkin object and makes changes based on the state read +func (r *zipkinReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + zipkin := &extv1alpha1.Zipkin{} + err := r.fctx.Get(ctx, req.NamespacedName, zipkin) + if errors.IsNotFound(err) { + r.fctx.GatewayEventHandler.OnDelete(&extv1alpha1.Zipkin{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: req.Namespace, + Name: req.Name, + }}) + return reconcile.Result{}, nil + } + + if zipkin.DeletionTimestamp != nil { + r.fctx.GatewayEventHandler.OnDelete(zipkin) + return ctrl.Result{}, nil + } + + // As Zipkin has no status, we don't need to update it + + r.fctx.GatewayEventHandler.OnAdd(zipkin, false) + + return ctrl.Result{}, nil +} + +// SetupWithManager sets up the controller with the Manager. +func (r *zipkinReconciler) SetupWithManager(mgr ctrl.Manager) error { + if err := ctrl.NewControllerManagedBy(mgr). + For(&extv1alpha1.Zipkin{}). + Complete(r); err != nil { + return err + } + + return addZipkinIndexers(context.Background(), mgr) +} + +func addZipkinIndexers(ctx context.Context, mgr manager.Manager) error { + //if err := mgr.GetFieldIndexer().IndexField(ctx, &extv1alpha1.ListenerZipkin{}, constants.GatewayListenerZipkinIndex, func(obj client.Object) []string { + // zipkin := obj.(*extv1alpha1.ListenerZipkin) + // + // var gateways []string + // for _, targetRef := range zipkin.Spec.TargetRefs { + // if string(targetRef.Kind) == constants.GatewayAPIGatewayKind && + // string(targetRef.Group) == gwv1.GroupName { + // gateways = append(gateways, fmt.Sprintf("%s/%d", string(targetRef.Name), targetRef.Port)) + // } + // } + // + // return gateways + //}); err != nil { + // return err + //} + + return nil +} diff --git a/pkg/gateway/client.go b/pkg/gateway/client.go index 8379de97f..3c3f36216 100644 --- a/pkg/gateway/client.go +++ b/pkg/gateway/client.go @@ -103,6 +103,7 @@ func newClient(ctx *cctx.ControllerContext) *client { fsminformers.InformerKeyRateLimit: &extv1alpha1.RateLimit{}, fsminformers.InformerKeyGatewayHTTPLog: &extv1alpha1.HTTPLog{}, fsminformers.InformerKeyGatewayMetrics: &extv1alpha1.Metrics{}, + fsminformers.InformerKeyGatewayZipkin: &extv1alpha1.Zipkin{}, } if version.IsEndpointSliceEnabled(ctx.KubeClient) { diff --git a/pkg/gateway/informers.go b/pkg/gateway/informers.go index ae363e308..b9ce34590 100644 --- a/pkg/gateway/informers.go +++ b/pkg/gateway/informers.go @@ -71,6 +71,8 @@ func getEventTypesByObjectType(obj interface{}) *k8s.EventTypes { return getEventTypesByInformerKey(fsminformers.InformerKeyGatewayHTTPLog) case *extv1alpha1.Metrics: return getEventTypesByInformerKey(fsminformers.InformerKeyGatewayMetrics) + case *extv1alpha1.Zipkin: + return getEventTypesByInformerKey(fsminformers.InformerKeyGatewayZipkin) } return nil @@ -235,6 +237,12 @@ func getEventTypesByInformerKey(informerKey fsminformers.InformerKey) *k8s.Event Update: announcements.GatewayMetricsUpdated, Delete: announcements.GatewayMetricsDeleted, } + case fsminformers.InformerKeyGatewayZipkin: + return &k8s.EventTypes{ + Add: announcements.GatewayZipkinAdded, + Update: announcements.GatewayZipkinUpdated, + Delete: announcements.GatewayZipkinDeleted, + } } return nil diff --git a/pkg/gateway/processor/triggers/extension/zipkins_trigger.go b/pkg/gateway/processor/triggers/extension/zipkins_trigger.go new file mode 100644 index 000000000..ab0e7b992 --- /dev/null +++ b/pkg/gateway/processor/triggers/extension/zipkins_trigger.go @@ -0,0 +1,34 @@ +package extension + +import ( + "sigs.k8s.io/controller-runtime/pkg/client" + + extv1alpha1 "github.com/flomesh-io/fsm/pkg/apis/extension/v1alpha1" + + "github.com/flomesh-io/fsm/pkg/gateway/processor" +) + +// ZipkinTrigger is a processor for Zipkin objects +type ZipkinTrigger struct{} + +// Insert adds a Zipkin object to the processor and returns true if the processor is changed +func (p *ZipkinTrigger) Insert(obj interface{}, processor processor.Processor) bool { + config, ok := obj.(*extv1alpha1.Zipkin) + if !ok { + log.Error().Msgf("unexpected object type %T", obj) + return false + } + + return processor.IsFilterConfigReferred(config.Kind, client.ObjectKeyFromObject(config)) +} + +// Delete removes a Zipkin object from the processor and returns true if the processor is changed +func (p *ZipkinTrigger) Delete(obj interface{}, processor processor.Processor) bool { + config, ok := obj.(*extv1alpha1.Zipkin) + if !ok { + log.Error().Msgf("unexpected object type %T", obj) + return false + } + + return processor.IsFilterConfigReferred(config.Kind, client.ObjectKeyFromObject(config)) +} diff --git a/pkg/gateway/processor/v2/filters.go b/pkg/gateway/processor/v2/filters.go index 93998e3c1..b5eed6c73 100644 --- a/pkg/gateway/processor/v2/filters.go +++ b/pkg/gateway/processor/v2/filters.go @@ -121,6 +121,14 @@ func (c *ConfigGenerator) resolveFilterConfig(ref *gwv1.LocalObjectReference) ma } return toMap("metrics", &m2) + case constants.GatewayZipkinKind: + obj := &extv1alpha1.Zipkin{} + if err := c.client.Get(ctx, key, obj); err != nil { + log.Error().Msgf("Failed to resolve Zipkin: %s", err) + return map[string]interface{}{} + } + + return toMap("zipkin", &obj.Spec) } return map[string]interface{}{} diff --git a/pkg/gateway/processor/v2/processor.go b/pkg/gateway/processor/v2/processor.go index 8ca2e5b2c..daf098e30 100644 --- a/pkg/gateway/processor/v2/processor.go +++ b/pkg/gateway/processor/v2/processor.go @@ -86,6 +86,7 @@ func NewGatewayProcessor(ctx *cctx.ControllerContext) *GatewayProcessor { informers.RateLimitsResourceType: &extensiontrigger.RateLimitTrigger{}, informers.HTTPLogsResourceType: &extensiontrigger.HTTPLogTrigger{}, informers.MetricsResourceType: &extensiontrigger.MetricsTrigger{}, + informers.ZipkinResourceType: &extensiontrigger.ZipkinTrigger{}, }, mutex: new(sync.RWMutex), @@ -167,6 +168,8 @@ func (c *GatewayProcessor) getTrigger(obj interface{}) processor.Trigger { return c.triggers[informers.HTTPLogsResourceType] case *extv1alpha1.Metrics: return c.triggers[informers.MetricsResourceType] + case *extv1alpha1.Zipkin: + return c.triggers[informers.ZipkinResourceType] } return nil diff --git a/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/extension_client.go b/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/extension_client.go index 5aa926d68..b298722af 100644 --- a/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/extension_client.go +++ b/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/extension_client.go @@ -33,6 +33,7 @@ type ExtensionV1alpha1Interface interface { ListenerFiltersGetter MetricsesGetter RateLimitsGetter + ZipkinsGetter } // ExtensionV1alpha1Client is used to interact with features provided by the extension.gateway.flomesh.io group. @@ -72,6 +73,10 @@ func (c *ExtensionV1alpha1Client) RateLimits(namespace string) RateLimitInterfac return newRateLimits(c, namespace) } +func (c *ExtensionV1alpha1Client) Zipkins(namespace string) ZipkinInterface { + return newZipkins(c, namespace) +} + // NewForConfig creates a new ExtensionV1alpha1Client for the given config. // NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), // where httpClient was generated with rest.HTTPClientFor(c). diff --git a/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/fake/fake_extension_client.go b/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/fake/fake_extension_client.go index 3f0a60efd..461775a34 100644 --- a/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/fake/fake_extension_client.go +++ b/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/fake/fake_extension_client.go @@ -57,6 +57,10 @@ func (c *FakeExtensionV1alpha1) RateLimits(namespace string) v1alpha1.RateLimitI return &FakeRateLimits{c, namespace} } +func (c *FakeExtensionV1alpha1) Zipkins(namespace string) v1alpha1.ZipkinInterface { + return &FakeZipkins{c, namespace} +} + // RESTClient returns a RESTClient that is used to communicate // with API server by this client implementation. func (c *FakeExtensionV1alpha1) RESTClient() rest.Interface { diff --git a/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/fake/fake_zipkin.go b/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/fake/fake_zipkin.go new file mode 100644 index 000000000..afb82ecd2 --- /dev/null +++ b/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/fake/fake_zipkin.go @@ -0,0 +1,138 @@ +/* +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1alpha1 "github.com/flomesh-io/fsm/pkg/apis/extension/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeZipkins implements ZipkinInterface +type FakeZipkins struct { + Fake *FakeExtensionV1alpha1 + ns string +} + +var zipkinsResource = v1alpha1.SchemeGroupVersion.WithResource("zipkins") + +var zipkinsKind = v1alpha1.SchemeGroupVersion.WithKind("Zipkin") + +// Get takes name of the zipkin, and returns the corresponding zipkin object, and an error if there is any. +func (c *FakeZipkins) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Zipkin, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(zipkinsResource, c.ns, name), &v1alpha1.Zipkin{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Zipkin), err +} + +// List takes label and field selectors, and returns the list of Zipkins that match those selectors. +func (c *FakeZipkins) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ZipkinList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(zipkinsResource, zipkinsKind, c.ns, opts), &v1alpha1.ZipkinList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.ZipkinList{ListMeta: obj.(*v1alpha1.ZipkinList).ListMeta} + for _, item := range obj.(*v1alpha1.ZipkinList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested zipkins. +func (c *FakeZipkins) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(zipkinsResource, c.ns, opts)) + +} + +// Create takes the representation of a zipkin and creates it. Returns the server's representation of the zipkin, and an error, if there is any. +func (c *FakeZipkins) Create(ctx context.Context, zipkin *v1alpha1.Zipkin, opts v1.CreateOptions) (result *v1alpha1.Zipkin, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(zipkinsResource, c.ns, zipkin), &v1alpha1.Zipkin{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Zipkin), err +} + +// Update takes the representation of a zipkin and updates it. Returns the server's representation of the zipkin, and an error, if there is any. +func (c *FakeZipkins) Update(ctx context.Context, zipkin *v1alpha1.Zipkin, opts v1.UpdateOptions) (result *v1alpha1.Zipkin, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(zipkinsResource, c.ns, zipkin), &v1alpha1.Zipkin{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Zipkin), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeZipkins) UpdateStatus(ctx context.Context, zipkin *v1alpha1.Zipkin, opts v1.UpdateOptions) (*v1alpha1.Zipkin, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(zipkinsResource, "status", c.ns, zipkin), &v1alpha1.Zipkin{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Zipkin), err +} + +// Delete takes name of the zipkin and deletes it. Returns an error if one occurs. +func (c *FakeZipkins) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(zipkinsResource, c.ns, name, opts), &v1alpha1.Zipkin{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeZipkins) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(zipkinsResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.ZipkinList{}) + return err +} + +// Patch applies the patch and returns the patched zipkin. +func (c *FakeZipkins) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Zipkin, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(zipkinsResource, c.ns, name, pt, data, subresources...), &v1alpha1.Zipkin{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.Zipkin), err +} diff --git a/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/generated_expansion.go b/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/generated_expansion.go index 4cbf45867..53e818ffc 100644 --- a/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/generated_expansion.go +++ b/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/generated_expansion.go @@ -30,3 +30,5 @@ type ListenerFilterExpansion interface{} type MetricsExpansion interface{} type RateLimitExpansion interface{} + +type ZipkinExpansion interface{} diff --git a/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/zipkin.go b/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/zipkin.go new file mode 100644 index 000000000..af10cda5e --- /dev/null +++ b/pkg/gen/client/extension/clientset/versioned/typed/extension/v1alpha1/zipkin.go @@ -0,0 +1,192 @@ +/* +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "github.com/flomesh-io/fsm/pkg/apis/extension/v1alpha1" + scheme "github.com/flomesh-io/fsm/pkg/gen/client/extension/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// ZipkinsGetter has a method to return a ZipkinInterface. +// A group's client should implement this interface. +type ZipkinsGetter interface { + Zipkins(namespace string) ZipkinInterface +} + +// ZipkinInterface has methods to work with Zipkin resources. +type ZipkinInterface interface { + Create(ctx context.Context, zipkin *v1alpha1.Zipkin, opts v1.CreateOptions) (*v1alpha1.Zipkin, error) + Update(ctx context.Context, zipkin *v1alpha1.Zipkin, opts v1.UpdateOptions) (*v1alpha1.Zipkin, error) + UpdateStatus(ctx context.Context, zipkin *v1alpha1.Zipkin, opts v1.UpdateOptions) (*v1alpha1.Zipkin, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.Zipkin, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.ZipkinList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Zipkin, err error) + ZipkinExpansion +} + +// zipkins implements ZipkinInterface +type zipkins struct { + client rest.Interface + ns string +} + +// newZipkins returns a Zipkins +func newZipkins(c *ExtensionV1alpha1Client, namespace string) *zipkins { + return &zipkins{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the zipkin, and returns the corresponding zipkin object, and an error if there is any. +func (c *zipkins) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Zipkin, err error) { + result = &v1alpha1.Zipkin{} + err = c.client.Get(). + Namespace(c.ns). + Resource("zipkins"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of Zipkins that match those selectors. +func (c *zipkins) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.ZipkinList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.ZipkinList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("zipkins"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested zipkins. +func (c *zipkins) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("zipkins"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a zipkin and creates it. Returns the server's representation of the zipkin, and an error, if there is any. +func (c *zipkins) Create(ctx context.Context, zipkin *v1alpha1.Zipkin, opts v1.CreateOptions) (result *v1alpha1.Zipkin, err error) { + result = &v1alpha1.Zipkin{} + err = c.client.Post(). + Namespace(c.ns). + Resource("zipkins"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(zipkin). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a zipkin and updates it. Returns the server's representation of the zipkin, and an error, if there is any. +func (c *zipkins) Update(ctx context.Context, zipkin *v1alpha1.Zipkin, opts v1.UpdateOptions) (result *v1alpha1.Zipkin, err error) { + result = &v1alpha1.Zipkin{} + err = c.client.Put(). + Namespace(c.ns). + Resource("zipkins"). + Name(zipkin.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(zipkin). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *zipkins) UpdateStatus(ctx context.Context, zipkin *v1alpha1.Zipkin, opts v1.UpdateOptions) (result *v1alpha1.Zipkin, err error) { + result = &v1alpha1.Zipkin{} + err = c.client.Put(). + Namespace(c.ns). + Resource("zipkins"). + Name(zipkin.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(zipkin). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the zipkin and deletes it. Returns an error if one occurs. +func (c *zipkins) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("zipkins"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *zipkins) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("zipkins"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched zipkin. +func (c *zipkins) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Zipkin, err error) { + result = &v1alpha1.Zipkin{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("zipkins"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/gen/client/extension/informers/externalversions/extension/v1alpha1/interface.go b/pkg/gen/client/extension/informers/externalversions/extension/v1alpha1/interface.go index 512fd9a00..5307e6d4d 100644 --- a/pkg/gen/client/extension/informers/externalversions/extension/v1alpha1/interface.go +++ b/pkg/gen/client/extension/informers/externalversions/extension/v1alpha1/interface.go @@ -37,6 +37,8 @@ type Interface interface { Metricses() MetricsInformer // RateLimits returns a RateLimitInformer. RateLimits() RateLimitInformer + // Zipkins returns a ZipkinInformer. + Zipkins() ZipkinInformer } type version struct { @@ -89,3 +91,8 @@ func (v *version) Metricses() MetricsInformer { func (v *version) RateLimits() RateLimitInformer { return &rateLimitInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } + +// Zipkins returns a ZipkinInformer. +func (v *version) Zipkins() ZipkinInformer { + return &zipkinInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/gen/client/extension/informers/externalversions/extension/v1alpha1/zipkin.go b/pkg/gen/client/extension/informers/externalversions/extension/v1alpha1/zipkin.go new file mode 100644 index 000000000..38ced4081 --- /dev/null +++ b/pkg/gen/client/extension/informers/externalversions/extension/v1alpha1/zipkin.go @@ -0,0 +1,87 @@ +/* +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + time "time" + + extensionv1alpha1 "github.com/flomesh-io/fsm/pkg/apis/extension/v1alpha1" + versioned "github.com/flomesh-io/fsm/pkg/gen/client/extension/clientset/versioned" + internalinterfaces "github.com/flomesh-io/fsm/pkg/gen/client/extension/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/flomesh-io/fsm/pkg/gen/client/extension/listers/extension/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// ZipkinInformer provides access to a shared informer and lister for +// Zipkins. +type ZipkinInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.ZipkinLister +} + +type zipkinInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewZipkinInformer constructs a new informer for Zipkin type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewZipkinInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredZipkinInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredZipkinInformer constructs a new informer for Zipkin type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredZipkinInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExtensionV1alpha1().Zipkins(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ExtensionV1alpha1().Zipkins(namespace).Watch(context.TODO(), options) + }, + }, + &extensionv1alpha1.Zipkin{}, + resyncPeriod, + indexers, + ) +} + +func (f *zipkinInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredZipkinInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *zipkinInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&extensionv1alpha1.Zipkin{}, f.defaultInformer) +} + +func (f *zipkinInformer) Lister() v1alpha1.ZipkinLister { + return v1alpha1.NewZipkinLister(f.Informer().GetIndexer()) +} diff --git a/pkg/gen/client/extension/informers/externalversions/generic.go b/pkg/gen/client/extension/informers/externalversions/generic.go index 136f5d6bd..514164022 100644 --- a/pkg/gen/client/extension/informers/externalversions/generic.go +++ b/pkg/gen/client/extension/informers/externalversions/generic.go @@ -66,6 +66,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Extension().V1alpha1().Metricses().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("ratelimits"): return &genericInformer{resource: resource.GroupResource(), informer: f.Extension().V1alpha1().RateLimits().Informer()}, nil + case v1alpha1.SchemeGroupVersion.WithResource("zipkins"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Extension().V1alpha1().Zipkins().Informer()}, nil } diff --git a/pkg/gen/client/extension/listers/extension/v1alpha1/expansion_generated.go b/pkg/gen/client/extension/listers/extension/v1alpha1/expansion_generated.go index c8041be09..5b91fa30e 100644 --- a/pkg/gen/client/extension/listers/extension/v1alpha1/expansion_generated.go +++ b/pkg/gen/client/extension/listers/extension/v1alpha1/expansion_generated.go @@ -74,3 +74,11 @@ type RateLimitListerExpansion interface{} // RateLimitNamespaceListerExpansion allows custom methods to be added to // RateLimitNamespaceLister. type RateLimitNamespaceListerExpansion interface{} + +// ZipkinListerExpansion allows custom methods to be added to +// ZipkinLister. +type ZipkinListerExpansion interface{} + +// ZipkinNamespaceListerExpansion allows custom methods to be added to +// ZipkinNamespaceLister. +type ZipkinNamespaceListerExpansion interface{} diff --git a/pkg/gen/client/extension/listers/extension/v1alpha1/zipkin.go b/pkg/gen/client/extension/listers/extension/v1alpha1/zipkin.go new file mode 100644 index 000000000..4c867589b --- /dev/null +++ b/pkg/gen/client/extension/listers/extension/v1alpha1/zipkin.go @@ -0,0 +1,96 @@ +/* +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/flomesh-io/fsm/pkg/apis/extension/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// ZipkinLister helps list Zipkins. +// All objects returned here must be treated as read-only. +type ZipkinLister interface { + // List lists all Zipkins in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.Zipkin, err error) + // Zipkins returns an object that can list and get Zipkins. + Zipkins(namespace string) ZipkinNamespaceLister + ZipkinListerExpansion +} + +// zipkinLister implements the ZipkinLister interface. +type zipkinLister struct { + indexer cache.Indexer +} + +// NewZipkinLister returns a new ZipkinLister. +func NewZipkinLister(indexer cache.Indexer) ZipkinLister { + return &zipkinLister{indexer: indexer} +} + +// List lists all Zipkins in the indexer. +func (s *zipkinLister) List(selector labels.Selector) (ret []*v1alpha1.Zipkin, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Zipkin)) + }) + return ret, err +} + +// Zipkins returns an object that can list and get Zipkins. +func (s *zipkinLister) Zipkins(namespace string) ZipkinNamespaceLister { + return zipkinNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// ZipkinNamespaceLister helps list and get Zipkins. +// All objects returned here must be treated as read-only. +type ZipkinNamespaceLister interface { + // List lists all Zipkins in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.Zipkin, err error) + // Get retrieves the Zipkin from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.Zipkin, error) + ZipkinNamespaceListerExpansion +} + +// zipkinNamespaceLister implements the ZipkinNamespaceLister +// interface. +type zipkinNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Zipkins in the indexer for a given namespace. +func (s zipkinNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Zipkin, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Zipkin)) + }) + return ret, err +} + +// Get retrieves the Zipkin from the indexer for a given namespace and name. +func (s zipkinNamespaceLister) Get(name string) (*v1alpha1.Zipkin, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("zipkin"), name) + } + return obj.(*v1alpha1.Zipkin), nil +} diff --git a/pkg/k8s/informers/types.go b/pkg/k8s/informers/types.go index 8a87db409..53a6ce3a9 100644 --- a/pkg/k8s/informers/types.go +++ b/pkg/k8s/informers/types.go @@ -154,6 +154,8 @@ const ( InformerKeyGatewayHTTPLog InformerKey = "Gateway-HTTPLog" // InformerKeyGatewayMetrics is the InformerKey for a Metrics informer InformerKeyGatewayMetrics InformerKey = "Gateway-Metrics" + // InformerKeyGatewayZipkin is the InformerKey for a Zipkin informer + InformerKeyGatewayZipkin InformerKey = "Gateway-Zipkin" ) const ( @@ -270,4 +272,7 @@ const ( // MetricsResourceType is the type used to represent the metrics resource MetricsResourceType ResourceType = "metrics" + + // ZipkinResourceType is the type used to represent the zipkin tracing resource + ZipkinResourceType ResourceType = "zipkins" ) diff --git a/pkg/manager/reconciler/registers.go b/pkg/manager/reconciler/registers.go index 0e0c8fcba..4cb55e413 100644 --- a/pkg/manager/reconciler/registers.go +++ b/pkg/manager/reconciler/registers.go @@ -314,6 +314,8 @@ func getRegisters(regCfg *whtypes.RegisterConfig, mc configurator.Configurator) reconcilers[GatewayAPIExtensionMetrics] = extensionv1alpha1.NewMetricsReconciler(ctx) + reconcilers[GatewayAPIExtensionZipkin] = extensionv1alpha1.NewZipkinReconciler(ctx) + webhooks[GatewayAPIExtensionFaultInjection] = extwhv1alpha1.NewFaultInjectionWebhook(regCfg) reconcilers[GatewayAPIExtensionFaultInjection] = extensionv1alpha1.NewFaultInjectionReconciler(ctx) } diff --git a/pkg/manager/reconciler/types.go b/pkg/manager/reconciler/types.go index 224608259..e4953c38d 100644 --- a/pkg/manager/reconciler/types.go +++ b/pkg/manager/reconciler/types.go @@ -30,6 +30,7 @@ const ( GatewayAPIExtensionRateLimit ResourceType = "GatewayAPIExtension(RateLimit)" GatewayAPIExtensionHTTPLog ResourceType = "GatewayAPIExtension(HTTPLog)" GatewayAPIExtensionMetrics ResourceType = "GatewayAPIExtension(Metrics)" + GatewayAPIExtensionZipkin ResourceType = "GatewayAPIExtension(Zipkin)" PolicyAttachmentHealthCheck ResourceType = "PolicyAttachment(HealthCheck)" PolicyAttachmentRetry ResourceType = "PolicyAttachment(Retry)" PolicyAttachmentBackendLB ResourceType = "PolicyAttachment(BackendLB)" diff --git a/pkg/messaging/broker.go b/pkg/messaging/broker.go index f679eff67..6579d72ac 100644 --- a/pkg/messaging/broker.go +++ b/pkg/messaging/broker.go @@ -1198,6 +1198,8 @@ func getGatewayUpdateEvent(msg events.PubSubMessage) *gatewayUpdateEvent { announcements.GatewayHTTPLogAdded, announcements.GatewayHTTPLogDeleted, announcements.GatewayHTTPLogUpdated, // Metrics event announcements.GatewayMetricsAdded, announcements.GatewayMetricsDeleted, announcements.GatewayMetricsUpdated, + // Zipkin event + announcements.GatewayZipkinAdded, announcements.GatewayZipkinDeleted, announcements.GatewayZipkinUpdated, // // MultiCluster events