feat: add Resource Relationships for kustomize (#4849)

Signed-off-by: chengleqi <chengleqi5g@hotmail.com>

Signed-off-by: chengleqi <chengleqi5g@hotmail.com>
This commit is contained in:
chengleqi
2022-10-11 19:57:09 +08:00
committed by GitHub
parent bbdce2f6ee
commit 2d5871cfeb

View File

@@ -163,6 +163,49 @@ func init() {
DefaultGenListOptionFunc: helmRelease2AnyListOption,
DisableFilterByOwnerReference: true,
},
ChildrenResourcesRule{
GroupResourceType: GroupResourceType{Group: "kustomize.toolkit.fluxcd.io", Kind: "Kustomization"},
SubResources: buildSubResources([]*SubResourceSelector{
{
ResourceType: ResourceType{APIVersion: "apps/v1", Kind: "Deployment"},
},
{
ResourceType: ResourceType{APIVersion: "apps/v1", Kind: "StatefulSet"},
},
{
ResourceType: ResourceType{APIVersion: "v1", Kind: "ConfigMap"},
},
{
ResourceType: ResourceType{APIVersion: "v1", Kind: "Secret"},
},
{
ResourceType: ResourceType{APIVersion: "v1", Kind: "Service"},
},
{
ResourceType: ResourceType{APIVersion: "v1", Kind: "PersistentVolumeClaim"},
},
{
ResourceType: ResourceType{APIVersion: "networking.k8s.io/v1", Kind: "Ingress"},
},
{
ResourceType: ResourceType{APIVersion: "gateway.networking.k8s.io/v1alpha2", Kind: "HTTPRoute"},
},
{
ResourceType: ResourceType{APIVersion: "gateway.networking.k8s.io/v1alpha2", Kind: "Gateway"},
},
{
ResourceType: ResourceType{APIVersion: "v1", Kind: "ServiceAccount"},
},
{
ResourceType: ResourceType{APIVersion: "rbac.authorization.k8s.io/v1", Kind: "Role"},
},
{
ResourceType: ResourceType{APIVersion: "rbac.authorization.k8s.io/v1", Kind: "RoleBinding"},
},
}),
DefaultGenListOptionFunc: kustomization2AnyListOption,
DisableFilterByOwnerReference: true,
},
)
}
@@ -301,6 +344,17 @@ var helmRelease2AnyListOption = func(obj unstructured.Unstructured) (client.List
return client.ListOptions{LabelSelector: hrSelector}, nil
}
var kustomization2AnyListOption = func(obj unstructured.Unstructured) (client.ListOptions, error) {
kusSelector, err := v1.LabelSelectorAsSelector(&v1.LabelSelector{MatchLabels: map[string]string{
"kustomize.toolkit.fluxcd.io/name": obj.GetName(),
"kustomize.toolkit.fluxcd.io/namespace": obj.GetNamespace(),
}})
if err != nil {
return client.ListOptions{}, err
}
return client.ListOptions{LabelSelector: kusSelector}, nil
}
type healthyCheckFunc func(obj unstructured.Unstructured) (*types.HealthStatus, error)
var checkPodStatus = func(obj unstructured.Unstructured) (*types.HealthStatus, error) {