Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add topology with cue rules for resources #60

Merged
merged 6 commits into from
Mar 15, 2023

Conversation

FogDong
Copy link
Member

@FogDong FogDong commented Mar 13, 2023

Get resource topology with rules like:

rules: [{
	group: "apps",
	resource: "Deployment",
	subResources: [{
		group: "apps",
		resource: "StatefulSet",
		selector: {
			ownerReference: true,
		},
	}],
	peerResources: [{
		group: "",
		resource: "ConfigMap",
		selector: {
			name: context.data.metadata.name,
		},
	}, {
		group: "",
		resource: "ConfigMap",
		selector: {
			namespace: "cm",
		},
	}, {
		group: "",
		resource: "ConfigMap",
		selector: {
			annotations: "anno": "value",
		},
	},  {
		group: "",
		resource: "ConfigMap",
		selector: {
			labels: "label": "value",
		},
	}, {
		group: "",
		resource: "Service",
		selector: {
			builtin: "service"
		}
	}],
}, {
	group: "apps",
	resource: "StatefulSet",
	subResources: [{
		group: "",
		resource: "Pod",
		selector: {
			ownerReference: true,
		},
	}],
}]

@FogDong FogDong requested a review from Somefive as a code owner March 13, 2023 08:51
Copy link
Collaborator

@Somefive Somefive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

util/k8s/resource.go Outdated Show resolved Hide resolved
util/topology/topology.go Outdated Show resolved Hide resolved
util/topology/topology.go Outdated Show resolved Hide resolved
@wangyikewxgm
Copy link

wangyikewxgm commented Mar 14, 2023

Could you provide an example of what the rules should look like to support the FluxCD Helm component?

@FogDong
Copy link
Member Author

FogDong commented Mar 14, 2023

Could you provide an example of what the rules should look like to support the FluxCD Helm component?

If it is a FluxCD Helm component, then its rule should be like this:

rules: [{
	group: "fluxcd",
	resource: "HelmRelease",
	peerResources: [{
		group: "fluxcd",
		resource: "HelmRepo",
		selector: {
			name: context.data.metadata.name,
		},
	},
}]

But I'm not sure you want these two resources or the whole resources that created by a Helm Chart.

@codecov
Copy link

codecov bot commented Mar 14, 2023

Codecov Report

Patch coverage: 93.09% and project coverage change: +0.38 🎉

Comparison is base (a2c10c3) 90.04% compared to head (ea246ed) 90.43%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #60      +/-   ##
==========================================
+ Coverage   90.04%   90.43%   +0.38%     
==========================================
  Files          62       64       +2     
  Lines        2110     2414     +304     
==========================================
+ Hits         1900     2183     +283     
- Misses        154      168      +14     
- Partials       56       63       +7     
Flag Coverage Δ
unit-test 90.43% <93.09%> (+0.38%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
util/k8s/resource.go 75.67% <75.67%> (ø)
util/resourcetoplogy/topology.go 95.50% <95.50%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@wangyikewxgm
Copy link

wangyikewxgm commented Mar 14, 2023

Could you provide an example of what the rules should look like to support the FluxCD Helm component?

If it is a FluxCD Helm component, then its rule should be like this:

rules: [{
	group: "fluxcd",
	resource: "HelmRelease",
	peerResources: [{
		group: "fluxcd",
		resource: "HelmRepo",
		selector: {
			name: context.data.metadata.name,
		},
	},
}]

But I'm not sure you want these two resources or the whole resources that created by a Helm Chart.

I mean how to list resources deployed by fluxcd helmRelease, the resources has a special labels point to the helmRelease. Such as this deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
 annotations:
   deployment.kubernetes.io/revision: "1"
   meta.helm.sh/release-name: nginx-ingress
   meta.helm.sh/release-namespace: vela-system
 labels:
   helm.toolkit.fluxcd.io/name: nginx-ingress
   helm.toolkit.fluxcd.io/namespace: vela-system
 name: nginx-ingress-ingress-nginx-controller
 namespace: vela-system

Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
@FogDong FogDong merged commit 593d2b4 into kubevela:main Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants