Skip to content

Commit

Permalink
feat: Support StorageClass relationships
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Toh <tohjustin@hotmail.com>
  • Loading branch information
tohjustin committed Oct 12, 2021
1 parent 5d7684b commit ce3aa87
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ List of supported relationships used for discovering dependent objects:
- [Pod References](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/)
- [Service References](https://kubernetes.io/docs/reference/kubernetes-api/service-resources/service-v1/)
- [ServiceAccount References](https://kubernetes.io/docs/reference/kubernetes-api/authentication-resources/service-account-v1/)
- [StorageClass References](https://kubernetes.io/docs/reference/kubernetes-api/config-and-storage-resources/storage-class-v1/)
- Helm
- [Release References](https://helm.sh/docs/intro/using_helm/#three-big-concepts) & [Storage References](https://helm.sh/docs/topics/advanced/#storage-backends)

Expand Down
7 changes: 7 additions & 0 deletions internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,13 @@ func ResolveDependents(m meta.RESTMapper, objects []unstructuredv1.Unstructured,
klog.V(4).Infof("Failed to get relationships for csinode named \"%s\": %s: %s", node.Name, err)
continue
}
// Populate dependents based on StorageClass relationships
case node.Group == "storage.k8s.io" && node.Kind == "StorageClass":
rmap, err = getStorageClassRelationships(node)
if err != nil {
klog.V(4).Infof("Failed to get relationships for storageclass named \"%s\": %s: %s", node.Name, err)
continue
}
default:
continue
}
Expand Down
27 changes: 27 additions & 0 deletions internal/graph/kubernetes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package graph

import (
"strings"

admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
corev1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
Expand Down Expand Up @@ -60,6 +62,9 @@ const (
// Kubernetes ServiceAccount relationships.
RelationshipServiceAccountSecret Relationship = "ServiceAccountSecret"
RelationshipServiceAccountImagePullSecret Relationship = "ServiceAccountImagePullSecret"

// Kubernetes StorageClass relationships.
RelationshipStorageClassProvisioner Relationship = "StorageClassProvisioner"
)

// getClusterRoleRelationships returns a map of relationships that this
Expand Down Expand Up @@ -549,6 +554,28 @@ func getServiceAccountRelationships(n *Node) (*RelationshipMap, error) {
return &result, nil
}

// getStorageClassRelationships returns a map of relationships that this
// StorageClass has with other objects, based on what was referenced in its
// manifest.
func getStorageClassRelationships(n *Node) (*RelationshipMap, error) {
var sc storagev1.StorageClass
err := runtime.DefaultUnstructuredConverter.FromUnstructured(n.UnstructuredContent(), &sc)
if err != nil {
return nil, err
}

var ref ObjectReference
result := newRelationshipMap()

// RelationshipStorageClassProvisioner (external provisioners only)
if p := sc.Provisioner; len(p) > 0 && !strings.HasPrefix(p, "kubernetes.io/") {
ref = ObjectReference{Group: "storage.k8s.io", Kind: "CSIDriver", Name: p}
result.AddDependencyByKey(ref.Key(), RelationshipStorageClassProvisioner)
}

return &result, nil
}

// getValidatingWebhookConfigurationRelationships returns a map of relationships
// that this ValidatingWebhookConfiguration has with other objects, based on
// what was referenced in its manifest.
Expand Down

0 comments on commit ce3aa87

Please sign in to comment.