diff --git a/cmd/objectfinder-tester/main.go b/cmd/objectfinder-tester/main.go index c8e5af883..dc7cfcbb5 100644 --- a/cmd/objectfinder-tester/main.go +++ b/cmd/objectfinder-tester/main.go @@ -73,7 +73,7 @@ func NewClient() (kubernetes.Interface, client.Client, error) { return kc, rtc, err } -func main() { +func main_5() { baseURL := "https://172.104.39.12/" token := "5311e401d" caCert := []byte(`-----BEGIN CERTIFICATE----- @@ -315,3 +315,69 @@ func findServiceMonitorForPrometheus() error { } return nil } + +func main() { + //_, kc, err := NewClient() + //if err != nil { + // panic(err) + //} + // + //var result unstructured.UnstructuredList + //result.SetGroupVersionKind(schema.GroupVersionKind{ + // Group: "policy", + // Version: "v1beta1", + // Kind: "PodSecurityPolicy.", + //}) + //err = kc.List(context.TODO(), &result) + //if err != nil { + // panic(err) + //} + //fmt.Printf("%+v\n", result) + + err := findForPostgres() + if err != nil { + panic(err) + } +} + +func findForPostgres() error { + _, kc, err := NewClient() + if err != nil { + return err + } + + /* + apiVersion: monitoring.coreos.com/v1 + kind: Prometheus + */ + rd, err := resourcedescriptors.LoadByGVR(schema.GroupVersionResource{ + Group: "kubedb.com", + Version: "v1", + Resource: "postgreses", + }) + if err != nil { + return err + } + + var src unstructured.Unstructured + src.SetAPIVersion("kubedb.com/v1") + src.SetKind("Postgres") + + key := client.ObjectKey{ + Namespace: "ace", + Name: "ace-db", + } + err = kc.Get(context.TODO(), key, &src) + if err != nil { + return err + } + + finder := graph.ObjectFinder{Client: kc} + + result, err := finder.ListConnectedObjectIDs(&src, rd.Spec.Connections) + if err != nil { + return err + } + fmt.Printf("%+v\n", result) + return nil +} diff --git a/go.mod b/go.mod index 2c505317c..579fd275a 100644 --- a/go.mod +++ b/go.mod @@ -48,7 +48,7 @@ require ( kmodules.xyz/custom-resources v0.30.0 kmodules.xyz/go-containerregistry v0.0.12 kmodules.xyz/monitoring-agent-api v0.29.0 - kmodules.xyz/resource-metadata v0.18.13-0.20240823065501-8e023c7e0197 + kmodules.xyz/resource-metadata v0.18.13-0.20240823113925-d6c4a55d03cb kmodules.xyz/resource-metrics v0.30.2 kmodules.xyz/resource-metrics/utils v0.30.1 kmodules.xyz/sets v0.29.0 diff --git a/go.sum b/go.sum index 76a578d9c..a8a0a800c 100644 --- a/go.sum +++ b/go.sum @@ -920,8 +920,8 @@ kmodules.xyz/monitoring-agent-api v0.29.0 h1:gpFl6OZrlMLb/ySMHdREI9EwGtnJ91oZBn9 kmodules.xyz/monitoring-agent-api v0.29.0/go.mod h1:iNbvaMTgVFOI5q2LJtGK91j4Dmjv4ZRiRdasGmWLKQI= kmodules.xyz/offshoot-api v0.29.4 h1:WQV2BIUIoVKKiqZNmZ4gAy367jEdwBhEl3dFCLZM1qA= kmodules.xyz/offshoot-api v0.29.4/go.mod h1:e+NQ0s4gW/YTPWBWEfdISZcmk+tlTq8IjvP5SLdqvko= -kmodules.xyz/resource-metadata v0.18.13-0.20240823065501-8e023c7e0197 h1:LBFFr7xRF/VefO2CIFFrquUwTX/sHEs+MHF/FeOzhjA= -kmodules.xyz/resource-metadata v0.18.13-0.20240823065501-8e023c7e0197/go.mod h1:VvUjfIzmM08SZ9ssZKhduzSrggKjY93ES2Bk+/m04hs= +kmodules.xyz/resource-metadata v0.18.13-0.20240823113925-d6c4a55d03cb h1:SNCaWXTAtb62gnyboHa69xjZj59FabzVvssX86YnCKE= +kmodules.xyz/resource-metadata v0.18.13-0.20240823113925-d6c4a55d03cb/go.mod h1:VvUjfIzmM08SZ9ssZKhduzSrggKjY93ES2Bk+/m04hs= kmodules.xyz/resource-metrics v0.30.2 h1:EGJapJa7Sh2ePc/WyHziLVh9xtuh4vWPBoSGxVZ8uC8= kmodules.xyz/resource-metrics v0.30.2/go.mod h1:UYcQQLN+3o8rNPQJwJa2D9bt5ihJCeo5bCDuQ4O3MPY= kmodules.xyz/resource-metrics/utils v0.30.1 h1:iRnAKNMMdAi7QYjMQrK9W3vNMhSC21RWNx9yS3qlpTA= diff --git a/pkg/graph/lib.go b/pkg/graph/lib.go index 5b7f49b61..ca4f5392a 100644 --- a/pkg/graph/lib.go +++ b/pkg/graph/lib.go @@ -871,6 +871,7 @@ func ParseResourceRefs(records [][]string) ([]ResourceRef, error) { var refs []ResourceRef var cols int +NEXT: for i, rec := range records { n := len(rec) if i == 0 { @@ -879,6 +880,12 @@ func ParseResourceRefs(records [][]string) ([]ResourceRef, error) { return nil, errors.New("all rows must have same number of columns") } + for _, v := range rec { + if v == "" { + continue NEXT + } + } + switch n { case 0: return nil, errors.New("must have at least one column") diff --git a/vendor/kmodules.xyz/resource-metadata/hub/resourcedescriptors/rbac.authorization.k8s.io/v1/roles.yaml b/vendor/kmodules.xyz/resource-metadata/hub/resourcedescriptors/rbac.authorization.k8s.io/v1/roles.yaml index 49dbd166f..4587b5f90 100644 --- a/vendor/kmodules.xyz/resource-metadata/hub/resourcedescriptors/rbac.authorization.k8s.io/v1/roles.yaml +++ b/vendor/kmodules.xyz/resource-metadata/hub/resourcedescriptors/rbac.authorization.k8s.io/v1/roles.yaml @@ -9,17 +9,6 @@ metadata: k8s.io/version: v1 name: rbac.authorization.k8s.io-v1-roles spec: - connections: - - labels: - - policy - namespace: - path: metadata.namespace - references: - - '{range .rules[?(@.resources[*]=="podsecuritypolicies")]}{range @.resourceNames[*]}{@}{"\n"}{end}{end}' - target: - apiVersion: policy/v1beta1 - kind: PodSecurityPolicy - type: MatchRef resource: group: rbac.authorization.k8s.io kind: Role diff --git a/vendor/modules.txt b/vendor/modules.txt index 999fa0b30..961217960 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1985,7 +1985,7 @@ kmodules.xyz/monitoring-agent-api/client ## explicit; go 1.22.0 kmodules.xyz/offshoot-api/api/v1 kmodules.xyz/offshoot-api/api/v2 -# kmodules.xyz/resource-metadata v0.18.13-0.20240823065501-8e023c7e0197 +# kmodules.xyz/resource-metadata v0.18.13-0.20240823113925-d6c4a55d03cb ## explicit; go 1.22.1 kmodules.xyz/resource-metadata/apis/core/install kmodules.xyz/resource-metadata/apis/core/v1alpha1