Skip to content

Commit

Permalink
feat(linker): add LinkRule linker
Browse files Browse the repository at this point in the history
  • Loading branch information
SOF3 committed Oct 6, 2023
1 parent 64f1cd0 commit 2d56e80
Show file tree
Hide file tree
Showing 46 changed files with 2,549 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto
pkg/crds/client linguist-generated=true
zz_generated*.go linguist-generated=true
35 changes: 34 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ endif

LINKER_WORKER_COUNT ?= 1

CONTROLLERS ?= audit-consumer,audit-producer,audit-webhook,event-informer,annotation-linker,owner-linker,resource-object-tag,resource-event-tag,diff-decorator,diff-controller,diff-api,pprof,jaeger-storage-plugin,jaeger-redirect-server,kelemetrix
CONTROLLERS ?= audit-consumer,audit-producer,audit-webhook,event-informer,annotation-linker,owner-linker,rule-linker,resource-object-tag,resource-event-tag,diff-decorator,diff-controller,diff-api,pprof,jaeger-storage-plugin,jaeger-redirect-server,kelemetrix
ifeq ($(CONTROLLERS),)
ENABLE_ARGS ?=
else
Expand Down Expand Up @@ -181,3 +181,36 @@ fmt:
golines -m140 --base-formatter=gofumpt -w .
goimports -l -w .
gci write -s standard -s default -s 'prefix(github.com/kubewharf/kelemetry)' .

generate:
go run sigs.k8s.io/controller-tools/cmd/controller-gen \
crd \
paths=./pkg/crds/apis/... \
output:crd:dir=./crds/config
go run k8s.io/code-generator/cmd/deepcopy-gen \
-o /tmp/kelemetry-gen/github.com/kubewharf/kelemetry \
--input-dirs=./pkg/crds/apis/v1alpha1 \
--output-file-base=zz_generated.deepcopy \
-h ./hack/boilerplate.txt
go run k8s.io/code-generator/cmd/client-gen \
-o /tmp/kelemetry-gen \
--input=github.com/kubewharf/kelemetry/pkg/crds/apis/v1alpha1 \
--input-base= \
--output-package=github.com/kubewharf/kelemetry/pkg/crds/client/clientset \
--clientset-name=versioned \
-h ./hack/boilerplate.txt
go run k8s.io/code-generator/cmd/lister-gen \
-o /tmp/kelemetry-gen \
--input-dirs=github.com/kubewharf/kelemetry/pkg/crds/apis/v1alpha1 \
--output-package=github.com/kubewharf/kelemetry/pkg/crds/client/listers \
-h ./hack/boilerplate.txt
go run k8s.io/code-generator/cmd/informer-gen \
-o /tmp/kelemetry-gen \
--input-dirs=github.com/kubewharf/kelemetry/pkg/crds/apis/v1alpha1 \
--output-package=github.com/kubewharf/kelemetry/pkg/crds/client/informers \
--versioned-clientset-package=github.com/kubewharf/kelemetry/pkg/crds/client/clientset/versioned \
--listers-package=github.com/kubewharf/kelemetry/pkg/crds/client/listers \
-h ./hack/boilerplate.txt
cp -r /tmp/kelemetry-gen/github.com/kubewharf/kelemetry/pkg/crds -T pkg/crds
rm -r /tmp/kelemetry-gen
$(MAKE) fmt
1 change: 1 addition & 0 deletions charts/kelemetry/crds
163 changes: 163 additions & 0 deletions crds/config/kelemetry.kubewharf.io_linkrules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.0
name: linkrules.kelemetry.kubewharf.io
spec:
group: kelemetry.kubewharf.io
names:
kind: LinkRule
listKind: LinkRuleList
plural: linkrules
singular: linkrule
scope: Cluster
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: "LinkRule instructs Kelemetry to display multiple objects (the
\"source\" and the \"target\") in the same trace by looking up the \"target\"
when the span of the \"source\" object gets created. \n LinkRule is bidirectional.
Once the link is recorded, searching \"source\" or \"target\" would both
display the other trace in the link as long as the link is not filtered
out by tfconfig."
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
link:
description: Link specifies how the two objects are linked together.
properties:
class:
description: "If Class is non empty, a pseudospan named the given
value is inserted in the hierarchy between the target and source
objects. \n Multiple links with the same nonempty Class share the
same pseudospan."
type: string
targetRole:
default: Child
description: "TargetRole selects the display position of the target
object. \n One of the target objects will be arbitrarily selected
if there are multiple links with preferTargetParent=true."
type: string
required:
- targetRole
type: object
metadata:
type: object
sourceFilter:
description: SourceFilter determines whether a source object matches this
rule.
properties:
resources:
description: Resources are the possible resource types that a child
object may belong to.
items:
description: GroupResource specifies a Group and a Resource, but
does not force a version. This is useful for identifying concepts
during lookup stages without having partially valid types
properties:
group:
type: string
resource:
type: string
required:
- group
- resource
type: object
type: array
selector:
description: Selector selects matching child objects by label.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: A label selector requirement is a selector that
contains values, a key, and an operator that relates the key
and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship to
a set of values. Valid operators are In, NotIn, Exists
and DoesNotExist.
type: string
values:
description: values is an array of string values. If the
operator is In or NotIn, the values array must be non-empty.
If the operator is Exists or DoesNotExist, the values
array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs. A single
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
type: object
targetTemplate:
description: TargetTemplate indicates how to find the target object from
a matched source object.
properties:
clusterTemplate:
description: "ClusterTemplate is a Go text template string to compute
the cluster name of the target object. \n The context of the template
is the child object that matched the rule. \n If empty or unspecified,
uses the cluster of the child object."
type: string
group:
type: string
nameTemplate:
description: "NameTemplate is a Go text template string to compute
the target object name. \n The context of the template is the child
object that matched the rule."
type: string
namespaceTemplate:
description: "NamespaceTemplate is a Go text template string to compute
the target object name. \n If the namespace is empty, the target
object is expected to be cluster-scoped."
type: string
resource:
type: string
version:
type: string
required:
- group
- nameTemplate
- namespaceTemplate
- resource
- version
type: object
required:
- link
- sourceFilter
- targetTemplate
type: object
served: true
storage: true
17 changes: 17 additions & 0 deletions crds/samples/helm-release-link-rule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: kelemetry.kubewharf.io/v1alpha1
kind: LinkRule
metadata:
name: helm-release
sourceFilter:
selector:
matchLabels:
app.kubernetes.io/managed-by: Helm
targetTemplate:
group: ""
version: v1
resource: secrets
namespaceTemplate: '{{.metadata.annotations["meta.helm.sh/release-namespace"]}}'
nameTemplate: '{{.metadata.annotations["meta.helm.sh/release-name"]}}'
link:
targetRole: Parent
class: templates
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/eapache/queue v1.1.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
Expand All @@ -61,6 +61,7 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/gobuffalo/flect v1.0.2 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gocql/gocql v1.3.2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
Expand All @@ -84,6 +85,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
Expand Down Expand Up @@ -115,6 +117,7 @@ require (
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
Expand All @@ -132,12 +135,14 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.8.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98 // indirect
Expand All @@ -147,7 +152,11 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.27.1 // indirect
k8s.io/code-generator v0.27.3 // indirect
k8s.io/gengo v0.0.0-20220902162205-c0856e24416d // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
sigs.k8s.io/controller-tools v0.12.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
Loading

0 comments on commit 2d56e80

Please sign in to comment.