diff --git a/Tiltfile b/Tiltfile index 060ea89d32..bbd5daae0a 100644 --- a/Tiltfile +++ b/Tiltfile @@ -4,7 +4,7 @@ load('ext://namespace', 'namespace_create') set_team('52cc75cc-c4ed-462f-8ea7-a543d398a381') -version = '0.6.0-dev1' +version = '0.6.0' config.define_string_list('allowedContexts') config.define_string_list('opniChartValues') config.define_string('defaultRegistry') diff --git a/go.mod b/go.mod index c23f8e1a1e..eefec03566 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,8 @@ require ( github.com/gin-gonic/gin v1.8.1 github.com/go-kit/log v0.2.1 github.com/go-logr/logr v1.2.3 - github.com/go-logr/zapr v1.2.0 + github.com/go-logr/zapr v1.2.3 + github.com/go-openapi/strfmt v0.21.3 github.com/go-playground/validator/v10 v10.11.0 github.com/go-test/deep v1.0.8 github.com/golang/mock v1.6.1-0.20220512030613-73266f9366fc @@ -93,9 +94,9 @@ require ( github.com/rancher/charts-build-scripts v0.0.0-00010101000000-000000000000 github.com/rancher/kubernetes-provider-detector v0.1.5 github.com/samber/lo v1.28.2 - github.com/spf13/cobra v1.5.0 + github.com/spf13/cobra v1.6.0 github.com/spf13/pflag v1.0.5 - github.com/steveteuber/kubectl-graph v0.5.0 + github.com/steveteuber/kubectl-graph v0.5.1-0.20221017172852-ec06c2bf0516 github.com/tidwall/gjson v1.14.2 github.com/tidwall/sjson v1.2.4 github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31 @@ -129,17 +130,18 @@ require ( gopkg.in/ini.v1 v1.66.6 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 - k8s.io/api v0.25.1 + k8s.io/api v0.25.3 k8s.io/apiextensions-apiserver v0.24.2 - k8s.io/apimachinery v0.25.1 - k8s.io/client-go v0.25.1 - k8s.io/component-base v0.24.3 - k8s.io/kubectl v0.24.3 + k8s.io/apimachinery v0.25.3 + k8s.io/cli-runtime v0.25.3 + k8s.io/client-go v0.25.3 + k8s.io/component-base v0.25.3 + k8s.io/kubectl v0.25.3 k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed opensearch.opster.io v0.0.0-00010101000000-000000000000 sigs.k8s.io/controller-runtime v0.11.1 sigs.k8s.io/controller-tools v0.8.1-0.20220428122951-32ad71090a62 - sigs.k8s.io/kustomize/kustomize/v4 v4.5.4 + sigs.k8s.io/kustomize/kustomize/v4 v4.5.7 sigs.k8s.io/yaml v1.3.0 ) @@ -190,7 +192,7 @@ require ( github.com/cenkalti/backoff/v4 v4.1.3 // indirect github.com/cespare/xxhash v1.1.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect - github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 // indirect + github.com/chai2010/gettext-go v1.0.2 // indirect github.com/cheggaaa/pb v1.0.29 // indirect github.com/cockroachdb/apd/v2 v2.0.1 // indirect github.com/containerd/cgroups v1.0.3 // indirect @@ -253,7 +255,6 @@ require ( github.com/go-openapi/loads v0.21.1 // indirect github.com/go-openapi/runtime v0.23.1 // indirect github.com/go-openapi/spec v0.20.4 // indirect - github.com/go-openapi/strfmt v0.21.3 // indirect github.com/go-openapi/swag v0.21.1 // indirect github.com/go-openapi/validate v0.21.0 // indirect github.com/go-playground/locales v0.14.0 // indirect @@ -306,7 +307,7 @@ require ( github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect github.com/huandu/xstrings v1.3.2 // indirect github.com/iancoleman/orderedmap v0.2.0 // indirect - github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.0.1 // indirect github.com/jaypipes/pcidb v1.0.0 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jessevdk/go-flags v1.5.0 // indirect @@ -462,7 +463,7 @@ require ( go.uber.org/multierr v1.8.0 // indirect golang.org/x/net v0.0.0-20220923203811-8be639271d50 // indirect golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect - golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect + golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect golang.org/x/time v0.0.0-20220920022843-2ce7c2934d45 // indirect golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect @@ -479,7 +480,6 @@ require ( helm.sh/helm/v3 v3.9.4 // indirect howett.net/plist v1.0.0 // indirect k8s.io/apiserver v0.24.2 // indirect - k8s.io/cli-runtime v0.24.3 // indirect k8s.io/cri-api v0.23.1 // indirect k8s.io/klog v1.0.0 // indirect k8s.io/klog/v2 v2.80.0 // indirect @@ -489,9 +489,9 @@ require ( rsc.io/binaryregexp v0.2.0 // indirect sigs.k8s.io/gateway-api v0.4.1 // indirect sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect - sigs.k8s.io/kustomize/api v0.11.4 // indirect - sigs.k8s.io/kustomize/cmd/config v0.10.6 // indirect - sigs.k8s.io/kustomize/kyaml v0.13.6 // indirect + sigs.k8s.io/kustomize/api v0.12.1 // indirect + sigs.k8s.io/kustomize/cmd/config v0.10.9 // indirect + sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sourcegraph.com/sourcegraph/appdash v0.0.0-20211028080628-e2786a622600 // indirect ) diff --git a/go.sum b/go.sum index 5f1756c61d..b58a5fce01 100644 --- a/go.sum +++ b/go.sum @@ -408,8 +408,9 @@ github.com/cespare/xxhash/v2 v2.1.0/go.mod h1:dgIUBU3pDso/gPgZ1osOZ0iQf77oPR28Tj github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5 h1:7aWHqerlJ41y6FOsEUvknqgXnGmJyJSbjhAWq5pO4F8= github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5/go.mod h1:/iP1qXHoty45bqomnu2LM+VVyAEdWN+vtSHGlQgyxbw= +github.com/chai2010/gettext-go v1.0.2 h1:1Lwwip6Q2QGsAdl/ZKPCwTe9fe0CjlUbqj5bFNSjIRk= +github.com/chai2010/gettext-go v1.0.2/go.mod h1:y+wnP2cHYaVj19NZhYKAwEMH2CI1gNHeQQ+5AjwawxA= github.com/charmbracelet/bubbles v0.14.0 h1:DJfCwnARfWjZLvMglhSQzo76UZ2gucuHPy9jLWX45Og= github.com/charmbracelet/bubbles v0.14.0/go.mod h1:bbeTiXwPww4M031aGi8UK2HT9RDWoiNibae+1yCMtcc= github.com/charmbracelet/bubbletea v0.21.0/go.mod h1:GgmJMec61d08zXsOhqRC/AiOx4K4pmz+VIcRIm1FKr4= @@ -891,8 +892,9 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-logr/zapr v0.2.0/go.mod h1:qhKdvif7YF5GI9NWEpyxTSSBdGmzkNguibrdCNVPunU= github.com/go-logr/zapr v0.4.0/go.mod h1:tabnROwaDl0UNxkVeFRbY8bwB37GwRv0P8lg6aAiEnk= -github.com/go-logr/zapr v1.2.0 h1:n4JnPI1T3Qq1SFEi/F8rwLrZERp2bso19PJZDB9dayk= github.com/go-logr/zapr v1.2.0/go.mod h1:Qa4Bsj2Vb+FAVeAKsLD8RLQ+YRJB8YDmOAKxaBQf7Ro= +github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A= +github.com/go-logr/zapr v1.2.3/go.mod h1:eIauM6P8qSvTw5o2ez6UEAfGjQKrxQTl5EoK+Qa2oG4= github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= @@ -1674,8 +1676,9 @@ github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= -github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= +github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/influxdata/flux v0.65.0/go.mod h1:BwN2XG2lMszOoquQaFdPET8FRQfrXiZsWmcMO9rkaVY= github.com/influxdata/flux v0.65.1/go.mod h1:J754/zds0vvpfwuq7Gc2wRdVwEodfpCFM7mYlOw2LqY= github.com/influxdata/flux v0.131.0/go.mod h1:CKvnYe6FHpTj/E0YGI7TcOZdGiYHoToOPSnoa12RtKI= @@ -2685,8 +2688,8 @@ github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJ github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo= github.com/spf13/cobra v1.2.1/go.mod h1:ExllRjgxM/piMAM+3tAZvg8fsklGAf3tPfi+i8t68Nk= github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= -github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= -github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= +github.com/spf13/cobra v1.6.0 h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI= +github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= @@ -2708,8 +2711,8 @@ github.com/square/go-jose/v3 v3.0.0-20200630053402-0a67ce9b0693/go.mod h1:6hSY48 github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4= github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI= github.com/stefanberger/go-pkcs11uri v0.0.0-20201008174630-78d3cae3a980/go.mod h1:AO3tvPzVZ/ayst6UlUKUv6rcPQInYe3IknH3jYhAKu8= -github.com/steveteuber/kubectl-graph v0.5.0 h1:ylcIQBuoh0VeJBIEKogjf+OvDKr6hfGcsWqhfb7t1tY= -github.com/steveteuber/kubectl-graph v0.5.0/go.mod h1:76pDyMZiX1aufCmt0cMvfO2ECTr5MulBDSUFOKEc930= +github.com/steveteuber/kubectl-graph v0.5.1-0.20221017172852-ec06c2bf0516 h1:wVBK5maMZBac9iabvqi/KIfqP2D3UVFVMhtkfPUcbzg= +github.com/steveteuber/kubectl-graph v0.5.1-0.20221017172852-ec06c2bf0516/go.mod h1:SuaTI2sE5N401PlaOSz6jqWDxo98YwZzAfUYnpWsHbo= github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/handy v0.0.0-20200128134331-0f66f006fb2e/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= @@ -3516,8 +3519,8 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 h1:CBpWXWQpIRjzmkkA+M7q9Fqnwd2mZr3AFqexg8YTfoM= -golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc= +golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -3989,9 +3992,9 @@ k8s.io/apimachinery v0.23.0/go.mod h1:fFCTTBKvKcwTPFzjlcxp91uPFZr+JA0FubU4fLzzFY k8s.io/apimachinery v0.23.1/go.mod h1:SADt2Kl8/sttJ62RRsi9MIV4o8f5S3coArm0Iu3fBno= k8s.io/apimachinery v0.23.5/go.mod h1:BEuFMMBaIbcOqVIJqNZJXGFTP4W6AycEpb5+m/97hrM= k8s.io/apimachinery v0.24.2/go.mod h1:82Bi4sCzVBdpYjyI4jY6aHX+YCUchUIrZrXKedjd2UM= -k8s.io/apimachinery v0.24.3/go.mod h1:82Bi4sCzVBdpYjyI4jY6aHX+YCUchUIrZrXKedjd2UM= -k8s.io/apimachinery v0.25.1 h1:t0XrnmCEHVgJlR2arwO8Awp9ylluDic706WePaYCBTI= k8s.io/apimachinery v0.25.1/go.mod h1:hqqA1X0bsgsxI6dXsJ4HnNTBOmJNxyPp8dw3u2fSHwA= +k8s.io/apimachinery v0.25.3 h1:7o9ium4uyUOM76t6aunP0nZuex7gDf8VGwkR5RcJnQc= +k8s.io/apimachinery v0.25.3/go.mod h1:jaF9C/iPNM1FuLl7Zuy5b9v+n35HGSh6AQ4HYRkCqwo= k8s.io/apiserver v0.19.2/go.mod h1:FreAq0bJ2vtZFj9Ago/X0oNGC51GfubKK/ViOKfVAOA= k8s.io/apiserver v0.19.4/go.mod h1:X8WRHCR1UGZDd7HpV0QDc1h/6VbbpAeAGyxSh8yzZXw= k8s.io/apiserver v0.20.1/go.mod h1:ro5QHeQkgMS7ZGpvf4tSMx6bBOgPfE+f52KwvXfScaU= @@ -4008,8 +4011,8 @@ k8s.io/cli-runtime v0.19.4/go.mod h1:m8G32dVbKOeaX1foGhleLEvNd6REvU7YnZyWn5//9rw k8s.io/cli-runtime v0.20.4/go.mod h1:dz38e1CM4uuIhy8PMFUZv7qsvIdoE3ByZYlmbHNCkt4= k8s.io/cli-runtime v0.22.1/go.mod h1:YqwGrlXeEk15Yn3em2xzr435UGwbrCw5x+COQoTYfoo= k8s.io/cli-runtime v0.23.1/go.mod h1:r9r8H/qfXo9w+69vwUL7LokKlLRKW5D6A8vUKCx+YL0= -k8s.io/cli-runtime v0.24.3 h1:O9YvUHrDSCQUPlsqVmaqDrueqjpJ7IO6Yas9B6xGSoo= -k8s.io/cli-runtime v0.24.3/go.mod h1:In84wauoMOqa7JDvDSXGbf8lTNlr70fOGpYlYfJtSqA= +k8s.io/cli-runtime v0.25.3 h1:Zs7P7l7db/5J+KDePOVtDlArAa9pZXaDinGWGZl0aM8= +k8s.io/cli-runtime v0.25.3/go.mod h1:InHHsjkyW5hQsILJGpGjeruiDZT/R0OkROQgD6GzxO4= k8s.io/client-go v0.25.1 h1:uFj4AJKtE1/ckcSKz8IhgAuZTdRXZDKev8g387ndD58= k8s.io/client-go v0.25.1/go.mod h1:rdFWTLV/uj2C74zGbQzOsmXPUtMAjSf7ajil4iJUNKo= k8s.io/code-generator v0.0.0-20190717022600-77f3a1fe56bb/go.mod h1:cDx5jQmWH25Ff74daM7NVYty9JWw9dvIS9zT9eIubCY= @@ -4024,7 +4027,6 @@ k8s.io/code-generator v0.22.1/go.mod h1:eV77Y09IopzeXOJzndrDyCI88UBok2h6WxAlBwpx k8s.io/code-generator v0.23.0/go.mod h1:vQvOhDXhuzqiVfM/YHp+dmg10WDZCchJVObc9MvowsE= k8s.io/code-generator v0.23.1/go.mod h1:V7yn6VNTCWW8GqodYCESVo95fuiEg713S8B7WacWZDA= k8s.io/code-generator v0.24.2/go.mod h1:dpVhs00hTuTdTY6jvVxvTFCk6gSMrtfRydbhZwHI15w= -k8s.io/code-generator v0.24.3/go.mod h1:dpVhs00hTuTdTY6jvVxvTFCk6gSMrtfRydbhZwHI15w= k8s.io/component-base v0.19.2/go.mod h1:g5LrsiTiabMLZ40AR6Hl45f088DevyGY+cCE2agEIVo= k8s.io/component-base v0.19.4/go.mod h1:ZzuSLlsWhajIDEkKF73j64Gz/5o0AgON08FgRbEPI70= k8s.io/component-base v0.20.1/go.mod h1:guxkoJnNoh8LNrbtiQOlyp2Y2XFCZQmrcg2n/DeYNLk= @@ -4036,11 +4038,10 @@ k8s.io/component-base v0.22.5/go.mod h1:VK3I+TjuF9eaa+Ln67dKxhGar5ynVbwnGrUiNF4M k8s.io/component-base v0.23.0/go.mod h1:DHH5uiFvLC1edCpvcTDV++NKULdYYU6pR9Tt3HIKMKI= k8s.io/component-base v0.23.1/go.mod h1:6llmap8QtJIXGDd4uIWJhAq0Op8AtQo6bDW2RrNMTeo= k8s.io/component-base v0.24.2/go.mod h1:ucHwW76dajvQ9B7+zecZAP3BVqvrHoOxm8olHEg0nmM= -k8s.io/component-base v0.24.3 h1:u99WjuHYCRJjS1xeLOx72DdRaghuDnuMgueiGMFy1ec= -k8s.io/component-base v0.24.3/go.mod h1:bqom2IWN9Lj+vwAkPNOv2TflsP1PeVDIwIN0lRthxYY= +k8s.io/component-base v0.25.3 h1:UrsxciGdrCY03ULT1h/S/gXFCOPnLhUVwSyx+hM/zq4= +k8s.io/component-base v0.25.3/go.mod h1:WYoS8L+IlTZgU7rhAl5Ctpw0WdMxDfCC5dkxcEFa/TI= k8s.io/component-helpers v0.20.4/go.mod h1:S7jGg8zQp3kwvSzfuGtNaQAMVmvzomXDioTm5vABn9g= k8s.io/component-helpers v0.22.1/go.mod h1:QvBcDbX+qU5I2tMZABBF5fRwAlQwiv771IGBHK9WYh4= -k8s.io/component-helpers v0.24.3/go.mod h1:/1WNW8TfBOijQ1ED2uCHb4wtXYWDVNMqUll8h36iNVo= k8s.io/cri-api v0.17.3/go.mod h1:X1sbHmuXhwaHs9xxYffLqJogVsnI+f6cPRcgPel7ywM= k8s.io/cri-api v0.20.1/go.mod h1:2JRbKt+BFLTjtrILYVqQK5jqhI+XNdF6UiGMgczeBCI= k8s.io/cri-api v0.20.4/go.mod h1:2JRbKt+BFLTjtrILYVqQK5jqhI+XNdF6UiGMgczeBCI= @@ -4089,13 +4090,12 @@ k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1/go.mod h1:C/N6wCaBHeBHkHU k8s.io/kubectl v0.19.4/go.mod h1:XPmlu4DJEYgD83pvZFeKF8+MSvGnYGqunbFSrJsqHv0= k8s.io/kubectl v0.20.4/go.mod h1:yCC5lUQyXRmmtwyxfaakryh9ezzp/bT0O14LeoFLbGo= k8s.io/kubectl v0.22.1/go.mod h1:mjAOgEbMNMtZWxnfM6jd+nPjPsaoLqO5xanc78WcSbw= -k8s.io/kubectl v0.24.3 h1:PqY8ho/S/KuE2/hCC3Iee7X+lOtARYo0LQsNzvV/edE= -k8s.io/kubectl v0.24.3/go.mod h1:PYLcvw96sC1NLbxZEDbdlOEd6/C76VIWjGmWV5QjSk0= +k8s.io/kubectl v0.25.3 h1:HnWJziEtmsm4JaJiKT33kG0kadx68MXxUE8UEbXnN4U= +k8s.io/kubectl v0.25.3/go.mod h1:glU7PiVj/R6Ud4A9FJdTcJjyzOtCJyc0eO7Mrbh3jlI= k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= k8s.io/metrics v0.19.4/go.mod h1:a0gvAzrxQPw2ouBqnXI7X9qlggpPkKAFgWU/Py+KZiU= k8s.io/metrics v0.20.4/go.mod h1:DDXS+Ls+2NAxRcVhXKghRPa3csljyJRjDRjPe6EOg/g= k8s.io/metrics v0.22.1/go.mod h1:i/ZNap89UkV1gLa26dn7fhKAdheJaKy+moOqJbiif7E= -k8s.io/metrics v0.24.3/go.mod h1:p1M0lhMySWfhISkSd3HEj8xIgrVnJTK3PPhFq2rA3To= k8s.io/utils v0.0.0-20200414100711-2df71ebbae66/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20200729134348-d5654de09c73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= k8s.io/utils v0.0.0-20200912215256-4140de9c8800/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= @@ -4154,18 +4154,18 @@ sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h6 sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU= sigs.k8s.io/kustomize/api v0.8.11/go.mod h1:a77Ls36JdfCWojpUqR6m60pdGY1AYFix4AH83nJtY1g= sigs.k8s.io/kustomize/api v0.10.1/go.mod h1:2FigT1QN6xKdcnGS2Ppp1uIWrtWN28Ms8A3OZUZhwr8= -sigs.k8s.io/kustomize/api v0.11.4 h1:/0Mr3kfBBNcNPOW5Qwk/3eb8zkswCwnqQxxKtmrTkRo= -sigs.k8s.io/kustomize/api v0.11.4/go.mod h1:k+8RsqYbgpkIrJ4p9jcdPqe8DprLxFUUO0yNOq8C+xI= +sigs.k8s.io/kustomize/api v0.12.1 h1:7YM7gW3kYBwtKvoY216ZzY+8hM+lV53LUayghNRJ0vM= +sigs.k8s.io/kustomize/api v0.12.1/go.mod h1:y3JUhimkZkR6sbLNwfJHxvo1TCLwuwm14sCYnkH6S1s= sigs.k8s.io/kustomize/cmd/config v0.9.13/go.mod h1:7547FLF8W/lTaDf0BDqFTbZxM9zqwEJqCKN9sSR0xSs= -sigs.k8s.io/kustomize/cmd/config v0.10.6 h1:Qjs7z/Q1NrVmW86tavmhM7wZtgWJ7aitLMARlUKrj98= -sigs.k8s.io/kustomize/cmd/config v0.10.6/go.mod h1:/S4A4nUANUa4bZJ/Edt7ZQTyKOY9WCER0uBS1SW2Rco= +sigs.k8s.io/kustomize/cmd/config v0.10.9 h1:LV8AUwZPuvqhGfia50uNwsPwNg1xOy9koEf5hyBnYs4= +sigs.k8s.io/kustomize/cmd/config v0.10.9/go.mod h1:T0s850zPV3wKfBALA0dyeP/K74jlJcoP8Pr9ZWwE3MQ= sigs.k8s.io/kustomize/kustomize/v4 v4.2.0/go.mod h1:MOkR6fmhwG7hEDRXBYELTi5GSFcLwfqwzTRHW3kv5go= -sigs.k8s.io/kustomize/kustomize/v4 v4.5.4 h1:rzGrL+DA4k8bT6SMz7/U+2z3iiZf1t2RaYJWx8OeTmE= -sigs.k8s.io/kustomize/kustomize/v4 v4.5.4/go.mod h1:Zo/Xc5FKD6sHl0lilbrieeGeZHVYCA4BzxeAaLI05Bg= +sigs.k8s.io/kustomize/kustomize/v4 v4.5.7 h1:cDW6AVMl6t/SLuQaezMET8hgnadZGIAr8tUrxFVOrpg= +sigs.k8s.io/kustomize/kustomize/v4 v4.5.7/go.mod h1:VSNKEH9D9d9bLiWEGbS6Xbg/Ih0tgQalmPvntzRxZ/Q= sigs.k8s.io/kustomize/kyaml v0.11.0/go.mod h1:GNMwjim4Ypgp/MueD3zXHLRJEjz7RvtPae0AwlvEMFM= sigs.k8s.io/kustomize/kyaml v0.13.0/go.mod h1:FTJxEZ86ScK184NpGSAQcfEqee0nul8oLCK30D47m4E= -sigs.k8s.io/kustomize/kyaml v0.13.6 h1:eF+wsn4J7GOAXlvajv6OknSunxpcOBQQqsnPxObtkGs= -sigs.k8s.io/kustomize/kyaml v0.13.6/go.mod h1:yHP031rn1QX1lr/Xd934Ri/xdVNG8BE2ECa78Ht/kEg= +sigs.k8s.io/kustomize/kyaml v0.13.9 h1:Qz53EAaFFANyNgyOEJbT/yoIHygK40/ZcvU3rgry2Tk= +sigs.k8s.io/kustomize/kyaml v0.13.9/go.mod h1:QsRbD0/KcU+wdk0/L0fIp2KLnohkVzs6fQ85/nOXac4= sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= sigs.k8s.io/structured-merge-diff/v2 v2.0.1/go.mod h1:Wb7vfKAodbKgf6tn1Kl0VvGj7mRH6DGaRcixXEJXTsE= sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw= diff --git a/pkg/topology/graph/graph.go b/pkg/topology/graph/graph.go index 81eef9fe17..bdb3e71a3f 100644 --- a/pkg/topology/graph/graph.go +++ b/pkg/topology/graph/graph.go @@ -1,20 +1,28 @@ package graph import ( + "bytes" + + "github.com/rancher/opni/pkg/topology/serialization" + "github.com/rancher/opni/pkg/util" "github.com/steveteuber/kubectl-graph/pkg/graph" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/cli-runtime/pkg/genericclioptions" cmdutil "k8s.io/kubectl/pkg/cmd/util" // Import to initialize client auth plugins + "k8s.io/client-go/kubernetes" _ "k8s.io/client-go/plugin/pkg/client/auth" + "k8s.io/client-go/rest" ) -func Run(f cmdutil.Factory) (*graph.Graph, error) { - // config, err := f.ToRESTConfig() - // if err != nil { - // return nil, err - // } - clientSet, err := f.KubernetesClientSet() +func NewRuntimeFactory() cmdutil.Factory { + return cmdutil.NewFactory(&genericclioptions.ConfigFlags{}) +} + +// panics if run outside a kubernetes cluster LOL +func TraverseTopology(f cmdutil.Factory) (*graph.Graph, error) { + clientSet, err := kubernetes.NewForConfig(util.Must(rest.InClusterConfig())) if err != nil { return nil, err } @@ -22,6 +30,7 @@ func Run(f cmdutil.Factory) (*graph.Graph, error) { r := f.NewBuilder(). Unstructured(). NamespaceParam("").DefaultNamespace().AllNamespaces(true). + //FIXME: reimplement these at a later date // FilenameParam(o.ExplicitNamespace, &o.FilenameOptions). // LabelSelectorParam(o.LabelSelector). // FieldSelectorParam(o.FieldSelector). @@ -51,3 +60,14 @@ func Run(f cmdutil.Factory) (*graph.Graph, error) { } return graph, nil } + +func RenderKubectlGraphTopology(g graph.Graph) (bytes.Buffer, error) { + var b bytes.Buffer + err := serialization.Templates.ExecuteTemplate(&b, "graphviz_default.tmpl", g) + if err != nil { + return b, err + } + + // TODO (Topology) + return b, nil +} diff --git a/pkg/topology/serialization/serialization.go b/pkg/topology/serialization/serialization.go index 20325fb518..5c74ea9c40 100644 --- a/pkg/topology/serialization/serialization.go +++ b/pkg/topology/serialization/serialization.go @@ -1,12 +1,49 @@ package serialization -// go:embed templates/graphviz.tmpl -var graphvizDigraph []byte +import ( + "crypto/md5" + "embed" + "encoding/json" + "fmt" + "regexp" + "strings" + "text/template" -func init() { - // TODO(topology) : convert templates to text/template + "gopkg.in/yaml.v2" +) + +var ( + //go:embed templates/*.tmpl + templateFiles embed.FS + Templates *template.Template +) - // TODO(topology) : set up a map of GraphRepr -> GraphSerailization Objects +func init() { + Templates = template.New("output").Funcs(template.FuncMap{ + "json": func(i interface{}) string { + b, err := json.Marshal(i) + if err != nil { + return err.Error() + } + return string(b) + }, + "yaml": func(i interface{}) string { + b, err := yaml.Marshal(i) + if err != nil { + return err.Error() + } + return strings.Trim(string(b), "\n") + }, + "underscore": func(s string) string { + re := regexp.MustCompile(`[^A-Za-z0-9]+`) + return re.ReplaceAllString(strings.ToLower(s), "_") + }, + "color": func(s string) string { + hash := md5.Sum([]byte(s)) + return fmt.Sprintf("#%x", hash[:3]) + }, + }) + template.Must(Templates.ParseFS(templateFiles, "templates/*.tmpl")) } type GraphSeralization interface { diff --git a/pkg/topology/serialization/templates/graphviz.tmpl b/pkg/topology/serialization/templates/graphviz_default.tmpl similarity index 100% rename from pkg/topology/serialization/templates/graphviz.tmpl rename to pkg/topology/serialization/templates/graphviz_default.tmpl diff --git a/pkg/topology/store/object.go b/pkg/topology/store/object.go new file mode 100644 index 0000000000..0c24d01607 --- /dev/null +++ b/pkg/topology/store/object.go @@ -0,0 +1,51 @@ +package store + +import ( + "errors" + "fmt" + + "github.com/nats-io/nats.go" + corev1 "github.com/rancher/opni/pkg/apis/core/v1" +) + +const ( + ReprHeaderKey = "repr" + TopologyObjectStoreId = "downstream-topology" +) + +func NewTopologyObjectStore(nc *nats.Conn) (nats.ObjectStore, error) { + mgr, err := nc.JetStream() + if err != nil { + return nil, err + } + if obj, err := mgr.ObjectStore(TopologyObjectStoreId); errors.Is(err, nats.ErrStreamNotFound) { + objSt, err := mgr.CreateObjectStore(&nats.ObjectStoreConfig{ + Bucket: TopologyObjectStoreId, + Description: "Store downstream kubernetes topology, indexed by cluster id", + }) + if err != nil { + return nil, err + } + return objSt, nil + } else if err != nil { + return nil, err + } else { + return obj, nil + } +} + +func GetTopologyObjectStore(nc *nats.Conn) (nats.ObjectStore, error) { + mgr, err := nc.JetStream() + if err != nil { + return nil, err + } + obj, err := mgr.ObjectStore(TopologyObjectStoreId) + if err != nil { + return nil, err + } + return obj, nil +} + +func NewClusterKey(clusterId *corev1.Reference) string { + return fmt.Sprintf("topology-%s", clusterId.GetId()) +} diff --git a/pkg/util/future/future.go b/pkg/util/future/future.go index 76e2693848..c00643e1c4 100644 --- a/pkg/util/future/future.go +++ b/pkg/util/future/future.go @@ -84,6 +84,9 @@ func (f *future[T]) GetContext(ctx context.Context) (_ T, err error) { return f.object, nil } +func Wait1[T any](f1 Future[T], callback func(T)) { + go func() { callback(f1.Get()) }() +} func Wait2[T, U any](f1 Future[T], f2 Future[U], callback func(T, U)) { go func() { callback(f1.Get(), f2.Get()) }() } diff --git a/plugins/topology/pkg/apis/remote/remote.pb.go b/plugins/topology/pkg/apis/remote/remote.pb.go index 25d712a85b..fb75c12b21 100644 --- a/plugins/topology/pkg/apis/remote/remote.pb.go +++ b/plugins/topology/pkg/apis/remote/remote.pb.go @@ -121,9 +121,9 @@ type TopologyGraph struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id *v1.Reference `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` - Repr GraphRepr `protobuf:"varint,3,opt,name=repr,proto3,enum=remote.topology.GraphRepr" json:"repr,omitempty"` + ClusterId *v1.Reference `protobuf:"bytes,1,opt,name=clusterId,proto3" json:"clusterId,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + Repr GraphRepr `protobuf:"varint,3,opt,name=repr,proto3,enum=remote.topology.GraphRepr" json:"repr,omitempty"` } func (x *TopologyGraph) Reset() { @@ -158,9 +158,9 @@ func (*TopologyGraph) Descriptor() ([]byte, []int) { return file_github_com_rancher_opni_plugins_topology_pkg_apis_remote_remote_proto_rawDescGZIP(), []int{1} } -func (x *TopologyGraph) GetId() *v1.Reference { +func (x *TopologyGraph) GetClusterId() *v1.Reference { if x != nil { - return x.Id + return x.ClusterId } return nil } @@ -196,30 +196,31 @@ var file_github_com_rancher_opni_plugins_topology_pkg_apis_remote_remote_proto_r 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x34, 0x0a, 0x05, 0x67, 0x72, 0x61, 0x70, 0x68, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2e, 0x54, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x47, - 0x72, 0x61, 0x70, 0x68, 0x52, 0x05, 0x67, 0x72, 0x61, 0x70, 0x68, 0x22, 0x74, 0x0a, 0x0d, 0x54, - 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x47, 0x72, 0x61, 0x70, 0x68, 0x12, 0x1f, 0x0a, 0x02, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, - 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, - 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, - 0x61, 0x12, 0x2e, 0x0a, 0x04, 0x72, 0x65, 0x70, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, - 0x1a, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, - 0x79, 0x2e, 0x47, 0x72, 0x61, 0x70, 0x68, 0x52, 0x65, 0x70, 0x72, 0x52, 0x04, 0x72, 0x65, 0x70, - 0x72, 0x2a, 0x27, 0x0a, 0x09, 0x47, 0x72, 0x61, 0x70, 0x68, 0x52, 0x65, 0x70, 0x72, 0x12, 0x08, - 0x0a, 0x04, 0x4e, 0x6f, 0x6e, 0x65, 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x4b, 0x75, 0x62, 0x65, - 0x63, 0x74, 0x6c, 0x47, 0x72, 0x61, 0x70, 0x68, 0x10, 0x01, 0x32, 0x8c, 0x01, 0x0a, 0x0e, 0x52, - 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x54, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x12, 0x38, 0x0a, - 0x04, 0x50, 0x75, 0x73, 0x68, 0x12, 0x18, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x74, - 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x1a, - 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, - 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x40, 0x0a, 0x0c, 0x53, 0x79, 0x6e, 0x63, 0x54, - 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x12, 0x18, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, - 0x2e, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, - 0x64, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, - 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x72, 0x2f, - 0x6f, 0x70, 0x6e, 0x69, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x2f, 0x74, 0x6f, 0x70, - 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x73, 0x2f, 0x72, - 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x61, 0x70, 0x68, 0x52, 0x05, 0x67, 0x72, 0x61, 0x70, 0x68, 0x22, 0x82, 0x01, 0x0a, 0x0d, + 0x54, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x47, 0x72, 0x61, 0x70, 0x68, 0x12, 0x2d, 0x0a, + 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0f, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, + 0x65, 0x52, 0x09, 0x63, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x49, 0x64, 0x12, 0x12, 0x0a, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x12, 0x2e, 0x0a, 0x04, 0x72, 0x65, 0x70, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1a, + 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, + 0x2e, 0x47, 0x72, 0x61, 0x70, 0x68, 0x52, 0x65, 0x70, 0x72, 0x52, 0x04, 0x72, 0x65, 0x70, 0x72, + 0x2a, 0x27, 0x0a, 0x09, 0x47, 0x72, 0x61, 0x70, 0x68, 0x52, 0x65, 0x70, 0x72, 0x12, 0x08, 0x0a, + 0x04, 0x4e, 0x6f, 0x6e, 0x65, 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x4b, 0x75, 0x62, 0x65, 0x63, + 0x74, 0x6c, 0x47, 0x72, 0x61, 0x70, 0x68, 0x10, 0x01, 0x32, 0x8c, 0x01, 0x0a, 0x0e, 0x52, 0x65, + 0x6d, 0x6f, 0x74, 0x65, 0x54, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x12, 0x38, 0x0a, 0x04, + 0x50, 0x75, 0x73, 0x68, 0x12, 0x18, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, 0x74, 0x6f, + 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x1a, 0x16, + 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, + 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x40, 0x0a, 0x0c, 0x53, 0x79, 0x6e, 0x63, 0x54, 0x6f, + 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x12, 0x18, 0x2e, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x2e, + 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2e, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, + 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x3a, 0x5a, 0x38, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x72, 0x2f, 0x6f, + 0x70, 0x6e, 0x69, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x2f, 0x74, 0x6f, 0x70, 0x6f, + 0x6c, 0x6f, 0x67, 0x79, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x73, 0x2f, 0x72, 0x65, + 0x6d, 0x6f, 0x74, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -245,7 +246,7 @@ var file_github_com_rancher_opni_plugins_topology_pkg_apis_remote_remote_proto_g } var file_github_com_rancher_opni_plugins_topology_pkg_apis_remote_remote_proto_depIdxs = []int32{ 2, // 0: remote.topology.Payload.graph:type_name -> remote.topology.TopologyGraph - 3, // 1: remote.topology.TopologyGraph.id:type_name -> core.Reference + 3, // 1: remote.topology.TopologyGraph.clusterId:type_name -> core.Reference 0, // 2: remote.topology.TopologyGraph.repr:type_name -> remote.topology.GraphRepr 1, // 3: remote.topology.RemoteTopology.Push:input_type -> remote.topology.Payload 1, // 4: remote.topology.RemoteTopology.SyncTopology:input_type -> remote.topology.Payload diff --git a/plugins/topology/pkg/apis/remote/remote.proto b/plugins/topology/pkg/apis/remote/remote.proto index 3ef7c3e6ef..6177df462b 100644 --- a/plugins/topology/pkg/apis/remote/remote.proto +++ b/plugins/topology/pkg/apis/remote/remote.proto @@ -19,7 +19,7 @@ message Payload { //FIXME: copied from orchestrator.proto due to duplicate symbol bug message TopologyGraph { - core.Reference id = 1; + core.Reference clusterId = 1; bytes data = 2; GraphRepr repr = 3; } diff --git a/plugins/topology/pkg/apis/representation/representation.pb.go b/plugins/topology/pkg/apis/representation/representation.pb.go index 25538283f1..2347a4c6ee 100644 --- a/plugins/topology/pkg/apis/representation/representation.pb.go +++ b/plugins/topology/pkg/apis/representation/representation.pb.go @@ -11,7 +11,7 @@ import ( _ "google.golang.org/genproto/googleapis/api/annotations" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - emptypb "google.golang.org/protobuf/types/known/emptypb" + _ "google.golang.org/protobuf/types/known/emptypb" reflect "reflect" sync "sync" ) @@ -132,16 +132,16 @@ func (x *TopologyGraph) GetRepr() GraphRepr { return GraphRepr_None } -type GraphHtml struct { +type GraphSVG struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Html string `protobuf:"bytes,1,opt,name=html,proto3" json:"html,omitempty"` + RawSVG string `protobuf:"bytes,1,opt,name=rawSVG,proto3" json:"rawSVG,omitempty"` } -func (x *GraphHtml) Reset() { - *x = GraphHtml{} +func (x *GraphSVG) Reset() { + *x = GraphSVG{} if protoimpl.UnsafeEnabled { mi := &file_github_com_rancher_opni_pkg_plugins_topology_pkg_apis_representation_representation_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -149,13 +149,13 @@ func (x *GraphHtml) Reset() { } } -func (x *GraphHtml) String() string { +func (x *GraphSVG) String() string { return protoimpl.X.MessageStringOf(x) } -func (*GraphHtml) ProtoMessage() {} +func (*GraphSVG) ProtoMessage() {} -func (x *GraphHtml) ProtoReflect() protoreflect.Message { +func (x *GraphSVG) ProtoReflect() protoreflect.Message { mi := &file_github_com_rancher_opni_pkg_plugins_topology_pkg_apis_representation_representation_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) @@ -167,14 +167,14 @@ func (x *GraphHtml) ProtoReflect() protoreflect.Message { return mi.MessageOf(x) } -// Deprecated: Use GraphHtml.ProtoReflect.Descriptor instead. -func (*GraphHtml) Descriptor() ([]byte, []int) { +// Deprecated: Use GraphSVG.ProtoReflect.Descriptor instead. +func (*GraphSVG) Descriptor() ([]byte, []int) { return file_github_com_rancher_opni_pkg_plugins_topology_pkg_apis_representation_representation_proto_rawDescGZIP(), []int{1} } -func (x *GraphHtml) GetHtml() string { +func (x *GraphSVG) GetRawSVG() string { if x != nil { - return x.Html + return x.RawSVG } return "" } @@ -204,36 +204,28 @@ var file_github_com_rancher_opni_pkg_plugins_topology_pkg_apis_representation_re 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x2d, 0x0a, 0x04, 0x72, 0x65, 0x70, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x19, 0x2e, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x47, 0x72, 0x61, 0x70, 0x68, 0x52, 0x65, 0x70, - 0x72, 0x52, 0x04, 0x72, 0x65, 0x70, 0x72, 0x22, 0x1f, 0x0a, 0x09, 0x47, 0x72, 0x61, 0x70, 0x68, - 0x48, 0x74, 0x6d, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x74, 0x6d, 0x6c, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x04, 0x68, 0x74, 0x6d, 0x6c, 0x2a, 0x27, 0x0a, 0x09, 0x47, 0x72, 0x61, 0x70, - 0x68, 0x52, 0x65, 0x70, 0x72, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x6f, 0x6e, 0x65, 0x10, 0x00, 0x12, - 0x10, 0x0a, 0x0c, 0x4b, 0x75, 0x62, 0x65, 0x63, 0x74, 0x6c, 0x47, 0x72, 0x61, 0x70, 0x68, 0x10, - 0x01, 0x32, 0xbb, 0x02, 0x0a, 0x16, 0x54, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x52, 0x65, - 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x59, 0x0a, 0x08, - 0x47, 0x65, 0x74, 0x47, 0x72, 0x61, 0x70, 0x68, 0x12, 0x0f, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, - 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x1a, 0x1d, 0x2e, 0x72, 0x65, 0x70, 0x72, - 0x65, 0x73, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x54, 0x6f, 0x70, 0x6f, 0x6c, - 0x6f, 0x67, 0x79, 0x47, 0x72, 0x61, 0x70, 0x68, 0x22, 0x1d, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x17, - 0x12, 0x15, 0x2f, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2f, 0x6f, 0x62, 0x6a, 0x65, - 0x63, 0x74, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x12, 0x60, 0x0a, 0x0a, 0x53, 0x74, 0x6f, 0x72, 0x65, - 0x47, 0x72, 0x61, 0x70, 0x68, 0x12, 0x1d, 0x2e, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, - 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x54, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x47, - 0x72, 0x61, 0x70, 0x68, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x1b, 0x82, 0xd3, - 0xe4, 0x93, 0x02, 0x15, 0x3a, 0x01, 0x2a, 0x22, 0x10, 0x2f, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, - 0x67, 0x79, 0x2f, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x64, 0x0a, 0x0b, 0x52, 0x65, 0x6e, - 0x64, 0x65, 0x72, 0x47, 0x72, 0x61, 0x70, 0x68, 0x12, 0x1d, 0x2e, 0x72, 0x65, 0x70, 0x72, 0x65, - 0x73, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x54, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, - 0x67, 0x79, 0x47, 0x72, 0x61, 0x70, 0x68, 0x1a, 0x19, 0x2e, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, - 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x47, 0x72, 0x61, 0x70, 0x68, 0x48, 0x74, - 0x6d, 0x6c, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x3a, 0x01, 0x2a, 0x22, 0x10, 0x2f, - 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2f, 0x72, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x42, - 0x46, 0x5a, 0x44, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x61, - 0x6e, 0x63, 0x68, 0x65, 0x72, 0x2f, 0x6f, 0x70, 0x6e, 0x69, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, - 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x2f, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2f, - 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x73, 0x2f, 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, - 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x52, 0x04, 0x72, 0x65, 0x70, 0x72, 0x22, 0x22, 0x0a, 0x08, 0x47, 0x72, 0x61, 0x70, 0x68, + 0x53, 0x56, 0x47, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x61, 0x77, 0x53, 0x56, 0x47, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x61, 0x77, 0x53, 0x56, 0x47, 0x2a, 0x27, 0x0a, 0x09, 0x47, + 0x72, 0x61, 0x70, 0x68, 0x52, 0x65, 0x70, 0x72, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x6f, 0x6e, 0x65, + 0x10, 0x00, 0x12, 0x10, 0x0a, 0x0c, 0x4b, 0x75, 0x62, 0x65, 0x63, 0x74, 0x6c, 0x47, 0x72, 0x61, + 0x70, 0x68, 0x10, 0x01, 0x32, 0xad, 0x01, 0x0a, 0x16, 0x54, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, + 0x79, 0x52, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, + 0x3c, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x47, 0x72, 0x61, 0x70, 0x68, 0x12, 0x0f, 0x2e, 0x63, 0x6f, + 0x72, 0x65, 0x2e, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x1a, 0x1d, 0x2e, 0x72, + 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x54, 0x6f, + 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x47, 0x72, 0x61, 0x70, 0x68, 0x22, 0x00, 0x12, 0x55, 0x0a, + 0x0b, 0x52, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x47, 0x72, 0x61, 0x70, 0x68, 0x12, 0x0f, 0x2e, 0x63, + 0x6f, 0x72, 0x65, 0x2e, 0x52, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x1a, 0x18, 0x2e, + 0x72, 0x65, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x47, + 0x72, 0x61, 0x70, 0x68, 0x53, 0x56, 0x47, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, 0x3a, + 0x01, 0x2a, 0x22, 0x10, 0x2f, 0x74, 0x6f, 0x70, 0x6f, 0x6c, 0x6f, 0x67, 0x79, 0x2f, 0x72, 0x65, + 0x6e, 0x64, 0x65, 0x72, 0x42, 0x46, 0x5a, 0x44, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x72, 0x61, 0x6e, 0x63, 0x68, 0x65, 0x72, 0x2f, 0x6f, 0x70, 0x6e, 0x69, 0x2f, + 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x73, 0x2f, 0x74, 0x6f, 0x70, 0x6f, + 0x6c, 0x6f, 0x67, 0x79, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x61, 0x70, 0x69, 0x73, 0x2f, 0x72, 0x65, + 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -253,21 +245,18 @@ var file_github_com_rancher_opni_pkg_plugins_topology_pkg_apis_representation_re var file_github_com_rancher_opni_pkg_plugins_topology_pkg_apis_representation_representation_proto_goTypes = []interface{}{ (GraphRepr)(0), // 0: representation.GraphRepr (*TopologyGraph)(nil), // 1: representation.TopologyGraph - (*GraphHtml)(nil), // 2: representation.GraphHtml + (*GraphSVG)(nil), // 2: representation.GraphSVG (*v1.Reference)(nil), // 3: core.Reference - (*emptypb.Empty)(nil), // 4: google.protobuf.Empty } var file_github_com_rancher_opni_pkg_plugins_topology_pkg_apis_representation_representation_proto_depIdxs = []int32{ 3, // 0: representation.TopologyGraph.id:type_name -> core.Reference 0, // 1: representation.TopologyGraph.repr:type_name -> representation.GraphRepr 3, // 2: representation.TopologyRepresentation.GetGraph:input_type -> core.Reference - 1, // 3: representation.TopologyRepresentation.StoreGraph:input_type -> representation.TopologyGraph - 1, // 4: representation.TopologyRepresentation.RenderGraph:input_type -> representation.TopologyGraph - 1, // 5: representation.TopologyRepresentation.GetGraph:output_type -> representation.TopologyGraph - 4, // 6: representation.TopologyRepresentation.StoreGraph:output_type -> google.protobuf.Empty - 2, // 7: representation.TopologyRepresentation.RenderGraph:output_type -> representation.GraphHtml - 5, // [5:8] is the sub-list for method output_type - 2, // [2:5] is the sub-list for method input_type + 3, // 3: representation.TopologyRepresentation.RenderGraph:input_type -> core.Reference + 1, // 4: representation.TopologyRepresentation.GetGraph:output_type -> representation.TopologyGraph + 2, // 5: representation.TopologyRepresentation.RenderGraph:output_type -> representation.GraphSVG + 4, // [4:6] is the sub-list for method output_type + 2, // [2:4] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name 2, // [2:2] is the sub-list for extension extendee 0, // [0:2] is the sub-list for field type_name @@ -294,7 +283,7 @@ func file_github_com_rancher_opni_pkg_plugins_topology_pkg_apis_representation_r } } file_github_com_rancher_opni_pkg_plugins_topology_pkg_apis_representation_representation_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GraphHtml); i { + switch v := v.(*GraphSVG); i { case 0: return &v.state case 1: diff --git a/plugins/topology/pkg/apis/representation/representation.pb.gw.go b/plugins/topology/pkg/apis/representation/representation.pb.gw.go index a49eb9f802..b29b39143d 100644 --- a/plugins/topology/pkg/apis/representation/representation.pb.gw.go +++ b/plugins/topology/pkg/apis/representation/representation.pb.gw.go @@ -32,94 +32,8 @@ var _ = runtime.String var _ = utilities.NewDoubleArray var _ = metadata.Join -func request_TopologyRepresentation_GetGraph_0(ctx context.Context, marshaler runtime.Marshaler, client TopologyRepresentationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v1.Reference - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := client.GetGraph(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_TopologyRepresentation_GetGraph_0(ctx context.Context, marshaler runtime.Marshaler, server TopologyRepresentationServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq v1.Reference - var metadata runtime.ServerMetadata - - var ( - val string - ok bool - err error - _ = err - ) - - val, ok = pathParams["id"] - if !ok { - return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id") - } - - protoReq.Id, err = runtime.String(val) - if err != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err) - } - - msg, err := server.GetGraph(ctx, &protoReq) - return msg, metadata, err - -} - -func request_TopologyRepresentation_StoreGraph_0(ctx context.Context, marshaler runtime.Marshaler, client TopologyRepresentationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq TopologyGraph - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := client.StoreGraph(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_TopologyRepresentation_StoreGraph_0(ctx context.Context, marshaler runtime.Marshaler, server TopologyRepresentationServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq TopologyGraph - var metadata runtime.ServerMetadata - - newReader, berr := utilities.IOReaderFactory(req.Body) - if berr != nil { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) - } - if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { - return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) - } - - msg, err := server.StoreGraph(ctx, &protoReq) - return msg, metadata, err - -} - func request_TopologyRepresentation_RenderGraph_0(ctx context.Context, marshaler runtime.Marshaler, client TopologyRepresentationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq TopologyGraph + var protoReq v1.Reference var metadata runtime.ServerMetadata newReader, berr := utilities.IOReaderFactory(req.Body) @@ -136,7 +50,7 @@ func request_TopologyRepresentation_RenderGraph_0(ctx context.Context, marshaler } func local_request_TopologyRepresentation_RenderGraph_0(ctx context.Context, marshaler runtime.Marshaler, server TopologyRepresentationServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq TopologyGraph + var protoReq v1.Reference var metadata runtime.ServerMetadata newReader, berr := utilities.IOReaderFactory(req.Body) @@ -158,56 +72,6 @@ func local_request_TopologyRepresentation_RenderGraph_0(ctx context.Context, mar // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterTopologyRepresentationHandlerFromEndpoint instead. func RegisterTopologyRepresentationHandlerServer(ctx context.Context, mux *runtime.ServeMux, server TopologyRepresentationServer) error { - mux.Handle("GET", pattern_TopologyRepresentation_GetGraph_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/representation.TopologyRepresentation/GetGraph", runtime.WithHTTPPathPattern("/topology/object/{id}")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_TopologyRepresentation_GetGraph_0(annotatedContext, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - - forward_TopologyRepresentation_GetGraph_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_TopologyRepresentation_StoreGraph_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/representation.TopologyRepresentation/StoreGraph", runtime.WithHTTPPathPattern("/topology/object")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_TopologyRepresentation_StoreGraph_0(annotatedContext, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - - forward_TopologyRepresentation_StoreGraph_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("POST", pattern_TopologyRepresentation_RenderGraph_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -274,50 +138,6 @@ func RegisterTopologyRepresentationHandler(ctx context.Context, mux *runtime.Ser // "TopologyRepresentationClient" to call the correct interceptors. func RegisterTopologyRepresentationHandlerClient(ctx context.Context, mux *runtime.ServeMux, client TopologyRepresentationClient) error { - mux.Handle("GET", pattern_TopologyRepresentation_GetGraph_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/representation.TopologyRepresentation/GetGraph", runtime.WithHTTPPathPattern("/topology/object/{id}")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_TopologyRepresentation_GetGraph_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - - forward_TopologyRepresentation_GetGraph_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("POST", pattern_TopologyRepresentation_StoreGraph_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - var err error - var annotatedContext context.Context - annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/representation.TopologyRepresentation/StoreGraph", runtime.WithHTTPPathPattern("/topology/object")) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_TopologyRepresentation_StoreGraph_0(annotatedContext, inboundMarshaler, client, req, pathParams) - annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) - if err != nil { - runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) - return - } - - forward_TopologyRepresentation_StoreGraph_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("POST", pattern_TopologyRepresentation_RenderGraph_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -344,17 +164,9 @@ func RegisterTopologyRepresentationHandlerClient(ctx context.Context, mux *runti } var ( - pattern_TopologyRepresentation_GetGraph_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"topology", "object", "id"}, "")) - - pattern_TopologyRepresentation_StoreGraph_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"topology", "object"}, "")) - pattern_TopologyRepresentation_RenderGraph_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"topology", "render"}, "")) ) var ( - forward_TopologyRepresentation_GetGraph_0 = runtime.ForwardResponseMessage - - forward_TopologyRepresentation_StoreGraph_0 = runtime.ForwardResponseMessage - forward_TopologyRepresentation_RenderGraph_0 = runtime.ForwardResponseMessage ) diff --git a/plugins/topology/pkg/apis/representation/representation.proto b/plugins/topology/pkg/apis/representation/representation.proto index 67455085fc..71b7a72d6d 100644 --- a/plugins/topology/pkg/apis/representation/representation.proto +++ b/plugins/topology/pkg/apis/representation/representation.proto @@ -9,20 +9,11 @@ import "github.com/rancher/opni/pkg/apis/core/v1/core.proto"; package representation; service TopologyRepresentation { - rpc GetGraph(core.Reference) returns (TopologyGraph) { - option(google.api.http) = { - get: "/topology/object/{id}" - }; - } - - rpc StoreGraph(TopologyGraph) returns (google.protobuf.Empty) { - option(google.api.http) = { - post: "/topology/object" - body: "*" - }; - } + // opni internal use + rpc GetGraph(core.Reference) returns (TopologyGraph) {} - rpc RenderGraph(TopologyGraph) returns (GraphHtml) { + // cluster id --> kubernetes graph SVG + rpc RenderGraph(core.Reference) returns (GraphSVG) { option(google.api.http) = { post: "/topology/render" body: "*" @@ -42,6 +33,6 @@ enum GraphRepr { KubectlGraph = 1; } -message GraphHtml { - string html = 1; +message GraphSVG { + string rawSVG = 1; } diff --git a/plugins/topology/pkg/apis/representation/representation_grpc.pb.go b/plugins/topology/pkg/apis/representation/representation_grpc.pb.go index e34c464936..177b1054e3 100644 --- a/plugins/topology/pkg/apis/representation/representation_grpc.pb.go +++ b/plugins/topology/pkg/apis/representation/representation_grpc.pb.go @@ -12,7 +12,6 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" - emptypb "google.golang.org/protobuf/types/known/emptypb" ) // This is a compile-time assertion to ensure that this generated file @@ -24,9 +23,10 @@ const _ = grpc.SupportPackageIsVersion7 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type TopologyRepresentationClient interface { + // opni internal use GetGraph(ctx context.Context, in *v1.Reference, opts ...grpc.CallOption) (*TopologyGraph, error) - StoreGraph(ctx context.Context, in *TopologyGraph, opts ...grpc.CallOption) (*emptypb.Empty, error) - RenderGraph(ctx context.Context, in *TopologyGraph, opts ...grpc.CallOption) (*GraphHtml, error) + // cluster id --> kubernetes graph SVG + RenderGraph(ctx context.Context, in *v1.Reference, opts ...grpc.CallOption) (*GraphSVG, error) } type topologyRepresentationClient struct { @@ -46,17 +46,8 @@ func (c *topologyRepresentationClient) GetGraph(ctx context.Context, in *v1.Refe return out, nil } -func (c *topologyRepresentationClient) StoreGraph(ctx context.Context, in *TopologyGraph, opts ...grpc.CallOption) (*emptypb.Empty, error) { - out := new(emptypb.Empty) - err := c.cc.Invoke(ctx, "/representation.TopologyRepresentation/StoreGraph", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *topologyRepresentationClient) RenderGraph(ctx context.Context, in *TopologyGraph, opts ...grpc.CallOption) (*GraphHtml, error) { - out := new(GraphHtml) +func (c *topologyRepresentationClient) RenderGraph(ctx context.Context, in *v1.Reference, opts ...grpc.CallOption) (*GraphSVG, error) { + out := new(GraphSVG) err := c.cc.Invoke(ctx, "/representation.TopologyRepresentation/RenderGraph", in, out, opts...) if err != nil { return nil, err @@ -68,9 +59,10 @@ func (c *topologyRepresentationClient) RenderGraph(ctx context.Context, in *Topo // All implementations must embed UnimplementedTopologyRepresentationServer // for forward compatibility type TopologyRepresentationServer interface { + // opni internal use GetGraph(context.Context, *v1.Reference) (*TopologyGraph, error) - StoreGraph(context.Context, *TopologyGraph) (*emptypb.Empty, error) - RenderGraph(context.Context, *TopologyGraph) (*GraphHtml, error) + // cluster id --> kubernetes graph SVG + RenderGraph(context.Context, *v1.Reference) (*GraphSVG, error) mustEmbedUnimplementedTopologyRepresentationServer() } @@ -81,10 +73,7 @@ type UnimplementedTopologyRepresentationServer struct { func (UnimplementedTopologyRepresentationServer) GetGraph(context.Context, *v1.Reference) (*TopologyGraph, error) { return nil, status.Errorf(codes.Unimplemented, "method GetGraph not implemented") } -func (UnimplementedTopologyRepresentationServer) StoreGraph(context.Context, *TopologyGraph) (*emptypb.Empty, error) { - return nil, status.Errorf(codes.Unimplemented, "method StoreGraph not implemented") -} -func (UnimplementedTopologyRepresentationServer) RenderGraph(context.Context, *TopologyGraph) (*GraphHtml, error) { +func (UnimplementedTopologyRepresentationServer) RenderGraph(context.Context, *v1.Reference) (*GraphSVG, error) { return nil, status.Errorf(codes.Unimplemented, "method RenderGraph not implemented") } func (UnimplementedTopologyRepresentationServer) mustEmbedUnimplementedTopologyRepresentationServer() { @@ -119,26 +108,8 @@ func _TopologyRepresentation_GetGraph_Handler(srv interface{}, ctx context.Conte return interceptor(ctx, in, info, handler) } -func _TopologyRepresentation_StoreGraph_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(TopologyGraph) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(TopologyRepresentationServer).StoreGraph(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/representation.TopologyRepresentation/StoreGraph", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(TopologyRepresentationServer).StoreGraph(ctx, req.(*TopologyGraph)) - } - return interceptor(ctx, in, info, handler) -} - func _TopologyRepresentation_RenderGraph_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(TopologyGraph) + in := new(v1.Reference) if err := dec(in); err != nil { return nil, err } @@ -150,7 +121,7 @@ func _TopologyRepresentation_RenderGraph_Handler(srv interface{}, ctx context.Co FullMethod: "/representation.TopologyRepresentation/RenderGraph", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(TopologyRepresentationServer).RenderGraph(ctx, req.(*TopologyGraph)) + return srv.(TopologyRepresentationServer).RenderGraph(ctx, req.(*v1.Reference)) } return interceptor(ctx, in, info, handler) } @@ -166,10 +137,6 @@ var TopologyRepresentation_ServiceDesc = grpc.ServiceDesc{ MethodName: "GetGraph", Handler: _TopologyRepresentation_GetGraph_Handler, }, - { - MethodName: "StoreGraph", - Handler: _TopologyRepresentation_StoreGraph_Handler, - }, { MethodName: "RenderGraph", Handler: _TopologyRepresentation_RenderGraph_Handler, diff --git a/plugins/topology/pkg/topology/agent/node.go b/plugins/topology/pkg/topology/agent/node.go index 1cc8d224e5..2012fbd0e8 100644 --- a/plugins/topology/pkg/topology/agent/node.go +++ b/plugins/topology/pkg/topology/agent/node.go @@ -6,7 +6,6 @@ import ( "strings" "sync" - "github.com/gogo/status" capabilityv1 "github.com/rancher/opni/pkg/apis/capability/v1" controlv1 "github.com/rancher/opni/pkg/apis/control/v1" corev1 "github.com/rancher/opni/pkg/apis/core/v1" @@ -15,6 +14,7 @@ import ( "github.com/rancher/opni/pkg/util" "github.com/rancher/opni/plugins/topology/pkg/apis/node" "golang.org/x/exp/slices" + "google.golang.org/grpc/status" "go.uber.org/zap" "google.golang.org/grpc/codes" diff --git a/plugins/topology/pkg/topology/agent/stream.go b/plugins/topology/pkg/topology/agent/stream.go index 8d447309bb..a360ac85ba 100644 --- a/plugins/topology/pkg/topology/agent/stream.go +++ b/plugins/topology/pkg/topology/agent/stream.go @@ -3,6 +3,7 @@ package agent import ( capabilityv1 "github.com/rancher/opni/pkg/apis/capability/v1" // "github.com/rancher/opni/pkg/clients" + controlv1 "github.com/rancher/opni/pkg/apis/control/v1" streamext "github.com/rancher/opni/pkg/plugins/apis/apiextensions/stream" "github.com/rancher/opni/plugins/topology/pkg/apis/node" @@ -22,7 +23,6 @@ func (p *Plugin) StreamServers() []streamext.Server { func (p *Plugin) UseStreamClient(cc grpc.ClientConnInterface) { p.topologyStreamer.SetRemoteWriteClient(remote.NewRemoteTopologyClient(cc)) - - nodeClient := node.NewNodeTopologyCapabilityClient(cc) - p.node.SetClient(nodeClient) + p.topologyStreamer.SetIdentityClient(controlv1.NewIdentityClient(cc)) + p.node.SetClient(node.NewNodeTopologyCapabilityClient(cc)) } diff --git a/plugins/topology/pkg/topology/agent/topology.go b/plugins/topology/pkg/topology/agent/topology.go index 3b287e7c72..d44e90aff1 100644 --- a/plugins/topology/pkg/topology/agent/topology.go +++ b/plugins/topology/pkg/topology/agent/topology.go @@ -1,25 +1,49 @@ package agent import ( + "bytes" "context" + "encoding/json" "sync" + "time" + controlv1 "github.com/rancher/opni/pkg/apis/control/v1" "github.com/rancher/opni/pkg/health" + "github.com/rancher/opni/pkg/topology/graph" "github.com/rancher/opni/plugins/topology/pkg/apis/node" "github.com/rancher/opni/plugins/topology/pkg/apis/remote" "go.uber.org/zap" + "google.golang.org/protobuf/types/known/emptypb" + + "sigs.k8s.io/controller-runtime/pkg/client" ) +type BatchingConfig struct { + maxSize int + timeout time.Duration +} + type TopologyStreamer struct { logger *zap.SugaredLogger conditions health.ConditionTracker + v chan client.Object + eventWatchClient client.WithWatch + + identityClientMu sync.Mutex + identityClient controlv1.IdentityClient remoteWriteClientMu sync.Mutex remoteWriteClient remote.RemoteTopologyClient } func NewTopologyStreamer(ct health.ConditionTracker, lg *zap.SugaredLogger) *TopologyStreamer { return &TopologyStreamer{ + // FIXME: reintroduce this when we want to monitor kubernetes events + // eventWatchClient: util.Must(client.NewWithWatch( + // util.Must(rest.InClusterConfig()), + // client.Options{ + // Scheme: apis.NewScheme(), + // })), logger: lg, conditions: ct, } @@ -31,6 +55,13 @@ func (s *TopologyStreamer) SetRemoteWriteClient(client remote.RemoteTopologyClie s.remoteWriteClient = client } +func (s *TopologyStreamer) SetIdentityClient(identityClient controlv1.IdentityClient) { + s.identityClientMu.Lock() + defer s.identityClientMu.Unlock() + s.identityClient = identityClient + +} + func (s *TopologyStreamer) Run(ctx context.Context, spec *node.TopologyCapabilitySpec) error { lg := s.logger if spec == nil { @@ -38,6 +69,8 @@ func (s *TopologyStreamer) Run(ctx context.Context, spec *node.TopologyCapabilit // set some sensible defaults } + tick := time.NewTicker(30 * time.Second) + defer tick.Stop() // blocking action for { @@ -47,6 +80,43 @@ func (s *TopologyStreamer) Run(ctx context.Context, spec *node.TopologyCapabilit zap.Error(ctx.Err()), ).Warn("topology stream closing") return nil + case <-tick.C: + // this will panic when not in a cluster : ruh roh + // need to refactor to cluster driver + + g, err := graph.TraverseTopology(graph.NewRuntimeFactory()) + if err != nil { + lg.With( + zap.Error(err), + ).Error("Could not construct topology graph") + } + var b bytes.Buffer + err = json.NewEncoder(&b).Encode(g) + if err != nil { + lg.With( + zap.Error(err), + ).Warn("failed to encode kubernetes graph") + continue + } + s.identityClientMu.Lock() + thisCluster, err := s.identityClient.Whoami(ctx, &emptypb.Empty{}) + if err != nil { + lg.With( + zap.Error(err), + ).Warn("failed to get cluster identity") + continue + } + s.identityClientMu.Unlock() + + s.remoteWriteClientMu.Lock() + s.remoteWriteClient.Push(ctx, &remote.Payload{ + Graph: &remote.TopologyGraph{ + ClusterId: thisCluster, + Data: b.Bytes(), + Repr: remote.GraphRepr_KubectlGraph, + }, + }) + s.remoteWriteClientMu.Unlock() } } } diff --git a/plugins/topology/pkg/topology/gateway/apis.go b/plugins/topology/pkg/topology/gateway/apis.go index d9719086c5..58aa833ebe 100644 --- a/plugins/topology/pkg/topology/gateway/apis.go +++ b/plugins/topology/pkg/topology/gateway/apis.go @@ -6,28 +6,62 @@ Orchestrator API implementation import ( "context" + "encoding/json" corev1 "github.com/rancher/opni/pkg/apis/core/v1" + "github.com/rancher/opni/pkg/topology/store" "github.com/rancher/opni/plugins/topology/pkg/apis/orchestrator" "github.com/rancher/opni/plugins/topology/pkg/apis/representation" + "github.com/steveteuber/kubectl-graph/pkg/graph" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/emptypb" ) -func (p *Plugin) StoreGraph(ctx context.Context, graph *representation.TopologyGraph) (*emptypb.Empty, error) { - // TODO(topology) : implement me - return nil, status.Error(codes.Unimplemented, "method not implemented") -} - func (p *Plugin) GetGraph(ctx context.Context, ref *corev1.Reference) (*representation.TopologyGraph, error) { // TODO(topology) : implement me return nil, status.Error(codes.Unimplemented, "method not implemented") } -func (p *Plugin) RenderGraph(ctx context.Context, graph *representation.TopologyGraph) (*representation.GraphHtml, error) { - // TODO(topology) : implement me - return nil, status.Error(codes.Unimplemented, "method not implemented") +func (p *Plugin) RenderGraph(ctx context.Context, clusterRef *corev1.Reference) (*representation.GraphSVG, error) { + if !p.topologyRemoteWrite.Initialized() { + return nil, status.Error(codes.Unavailable, "topology remote write not initialized") + } + ctxCa, cancel := context.WithCancel(ctx) + defer cancel() + mgr, err := p.nc.GetContext(ctxCa) + if err != nil { + return nil, status.Error(codes.Internal, err.Error()) + } + obj, err := store.GetTopologyObjectStore(mgr) + if err != nil { + return nil, err + } + objInfo, err := obj.GetInfo(store.NewClusterKey(clusterRef)) + if err != nil { + return nil, err + } + reprKey := objInfo.Headers.Get(store.ReprHeaderKey) + if reprKey == "" { + return nil, status.Error( + codes.Internal, + "no representation header found for the cluster", + ) + } + graphObj, err := obj.Get(store.NewClusterKey(clusterRef)) + if err != nil { + return nil, err + } + var g graph.Graph + if err := json.NewDecoder(graphObj).Decode(&g); err != nil { + return nil, err + } + switch reprKey { + case representation.GraphRepr_KubectlGraph.String(): + return nil, status.Error(codes.Unimplemented, "rendering kubectl graph not implemented yet") + default: + return nil, status.Error(codes.Internal, "invalid representation key") + } } func (p *Plugin) GetClusterStatus(ctx context.Context, _ *emptypb.Empty) (*orchestrator.InstallStatus, error) { diff --git a/plugins/topology/pkg/topology/gateway/plugin.go b/plugins/topology/pkg/topology/gateway/plugin.go index 07e6dbcdbd..18a2be196f 100644 --- a/plugins/topology/pkg/topology/gateway/plugin.go +++ b/plugins/topology/pkg/topology/gateway/plugin.go @@ -64,9 +64,11 @@ func NewPlugin(ctx context.Context) *Plugin { clusterDriver: future.New[drivers.ClusterDriver](), topologyBackend: backend.TopologyBackend{}, } - - p.topologyRemoteWrite.Initialize(stream.TopologyRemoteWriteConfig{ - Logger: p.logger.Named("remote-write-server"), + future.Wait1(p.nc, func(nc *nats.Conn) { + p.topologyRemoteWrite.Initialize(stream.TopologyRemoteWriteConfig{ + Logger: p.logger.Named("remote-write-server"), + Nc: nc, + }) }) future.Wait2(p.storageBackend, p.uninstallController, diff --git a/plugins/topology/pkg/topology/gateway/stream/stream.go b/plugins/topology/pkg/topology/gateway/stream/stream.go index 2a91134af3..e6d87de83a 100644 --- a/plugins/topology/pkg/topology/gateway/stream/stream.go +++ b/plugins/topology/pkg/topology/gateway/stream/stream.go @@ -8,8 +8,15 @@ to stream to. */ import ( + "bytes" "context" + "fmt" + "os" + "github.com/nats-io/nats.go" + corev1 "github.com/rancher/opni/pkg/apis/core/v1" + "github.com/rancher/opni/pkg/slo/shared" + "github.com/rancher/opni/pkg/topology/store" "github.com/rancher/opni/pkg/util" "github.com/rancher/opni/plugins/topology/pkg/apis/remote" "go.uber.org/zap" @@ -19,12 +26,15 @@ import ( type TopologyRemoteWriteConfig struct { Logger *zap.SugaredLogger + Nc *nats.Conn } type TopologyRemoteWriter struct { remote.UnsafeRemoteTopologyServer TopologyRemoteWriteConfig + topologyObjectStore nats.ObjectStore + util.Initializer } @@ -32,17 +42,42 @@ var _ remote.RemoteTopologyServer = (*TopologyRemoteWriter)(nil) func (t *TopologyRemoteWriter) Initialize(conf TopologyRemoteWriteConfig) { t.InitOnce(func() { - // TODO(topology) : initialization code goes here + objStore, err := store.NewTopologyObjectStore(conf.Nc) + if err != nil { + conf.Logger.With("error", err).Error("failed to initialize topology object store") + os.Exit(1) + } + t.topologyObjectStore = objStore }) } +func (t *TopologyRemoteWriter) objectDef(clusterId *corev1.Reference, repr remote.GraphRepr) *nats.ObjectMeta { + return &nats.ObjectMeta{ + Name: store.NewClusterKey(clusterId), + Description: fmt.Sprintf( + "topology for cluster %s, in representation form %s", + clusterId.GetId(), + repr.String()), + Headers: nats.Header{ + store.ReprHeaderKey: []string{repr.String()}, + }, + } +} + func (t *TopologyRemoteWriter) Push(ctx context.Context, payload *remote.Payload) (*emptypb.Empty, error) { if !t.Initialized() { return nil, util.StatusError(codes.Unavailable) } - // TODO(topology) : implement me - return nil, nil + info, err := t.topologyObjectStore.Put( + t.objectDef(payload.Graph.ClusterId, payload.Graph.Repr), + bytes.NewReader(payload.Graph.Data), + ) + if err != nil { + return nil, err + } + t.Logger.With("info", info).Debug("successfully pushed topology data") + return &emptypb.Empty{}, nil } func (t *TopologyRemoteWriter) SyncTopology(ctx context.Context, payload *remote.Payload) (*emptypb.Empty, error) { @@ -52,5 +87,5 @@ func (t *TopologyRemoteWriter) SyncTopology(ctx context.Context, payload *remote // TODO(topology) : implement me - return nil, nil + return nil, shared.WithUnimplementedError("method not implemented") } diff --git a/plugins/topology/pkg/topology/gateway/system.go b/plugins/topology/pkg/topology/gateway/system.go index 9680c4f930..ac18123c3b 100644 --- a/plugins/topology/pkg/topology/gateway/system.go +++ b/plugins/topology/pkg/topology/gateway/system.go @@ -3,11 +3,7 @@ package gateway import ( "context" "os" - "time" - "github.com/cenkalti/backoff" - backoffv2 "github.com/lestrrat-go/backoff/v2" - "github.com/nats-io/nats.go" capabilityv1 "github.com/rancher/opni/pkg/apis/capability/v1" corev1 "github.com/rancher/opni/pkg/apis/core/v1" managementv1 "github.com/rancher/opni/pkg/apis/management/v1" @@ -15,6 +11,7 @@ import ( "github.com/rancher/opni/pkg/machinery" "github.com/rancher/opni/pkg/plugins/apis/system" "github.com/rancher/opni/pkg/task" + natsutil "github.com/rancher/opni/pkg/util/nats" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/protobuf/proto" @@ -54,10 +51,6 @@ func (p *Plugin) UseManagementAPI(client managementv1.ManagementClient) { } func (p *Plugin) UseKeyValueStore(client system.KeyValueStoreClient) { - var ( - nc *nats.Conn - err error - ) // set other futures before trying to acquire NATS connection ctrl, err := task.NewController( p.ctx, @@ -76,54 +69,17 @@ func (p *Plugin) UseKeyValueStore(client system.KeyValueStoreClient) { Placeholder: system.NewKVStoreClient[proto.Message](client), }) - retrier := backoffv2.Exponential( - backoffv2.WithMaxRetries(0), - backoffv2.WithMinInterval(5*time.Second), - backoffv2.WithMaxInterval(1*time.Minute), - backoffv2.WithMultiplier(1.1), - ) - b := retrier.Start(p.ctx) - for backoffv2.Continue(b) { - nc, err = p.newNatsConnection() - if err != nil { - break - } - p.logger.Error("failed to connect to NATs, retrying") + nc, err := natsutil.AcquireNATSConnection(p.ctx) + if err != nil { + p.logger.With( + zap.Error(err), + ).Error("fatal : failed to acquire NATS connection") + os.Exit(1) } p.nc.Set(nc) <-p.ctx.Done() } -func (p *Plugin) newNatsConnection() (*nats.Conn, error) { - natsURL := os.Getenv("NATS_SERVER_URL") - natsSeedPath := os.Getenv("NATS_SEED_FILENAME") - - opt, err := nats.NkeyOptionFromSeed(natsSeedPath) - if err != nil { - return nil, err - } - - retryBackoff := backoff.NewExponentialBackOff() - return nats.Connect( - natsURL, - opt, - nats.MaxReconnects(-1), - nats.CustomReconnectDelay( - func(i int) time.Duration { - if i == 1 { - retryBackoff.Reset() - } - return retryBackoff.NextBackOff() - }, - ), - nats.DisconnectErrHandler( - func(nc *nats.Conn, err error) { - p.logger.With("err", err).Warn("nats disconnected") - }, - ), - ) -} - func (p *Plugin) UseNodeManagerClient(client capabilityv1.NodeManagerClient) { p.nodeManagerClient.Set(client) <-p.ctx.Done()