diff --git a/.idea/kubetools.iml b/.idea/kubetools.iml index c956989..5e764c4 100644 --- a/.idea/kubetools.iml +++ b/.idea/kubetools.iml @@ -1,5 +1,6 @@ + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 580e6d4..f56fa19 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,8 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - - - - - - - - - - - - - - - - - - - - - + @@ -83,7 +119,7 @@ - + @@ -147,23 +183,6 @@ - - - - - - - - - - - - - - - - - @@ -173,6 +192,7 @@ - - true + true \ No newline at end of file diff --git a/Taskfile.yml b/Taskfile.yml index 07915e4..2b32af2 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -4,7 +4,7 @@ version: '2' vars: BINARY_NAME: kubemqctl - VERSION: v3.5.1 + VERSION: v3.6.0 tasks: check_update: diff --git a/cmd/create/create.go b/cmd/create/create.go index 4f9db33..8c65421 100644 --- a/cmd/create/create.go +++ b/cmd/create/create.go @@ -4,7 +4,6 @@ import ( "context" "github.com/kubemq-io/kubemqctl/cmd/create/cluster" "github.com/kubemq-io/kubemqctl/cmd/create/connector" - "github.com/kubemq-io/kubemqctl/cmd/create/dashboard" "github.com/kubemq-io/kubemqctl/cmd/create/operator" "github.com/kubemq-io/kubemqctl/pkg/config" "github.com/kubemq-io/kubemqctl/pkg/utils" @@ -44,7 +43,6 @@ func NewCmdCreate(ctx context.Context, cfg *config.Config) *cobra.Command { } cmd.AddCommand(cluster.NewCmdCreate(ctx, cfg)) cmd.AddCommand(operator.NewCmdCreate(ctx, cfg)) - cmd.AddCommand(dashboard.NewCmdCreate(ctx, cfg)) cmd.AddCommand(connector.NewCmdCreate(ctx, cfg)) return cmd diff --git a/cmd/create/dashboard/dashboard.go b/cmd/create/dashboard/dashboard.go deleted file mode 100644 index 2080df6..0000000 --- a/cmd/create/dashboard/dashboard.go +++ /dev/null @@ -1,121 +0,0 @@ -package dashboard - -import ( - "context" - "github.com/kubemq-io/kubemqctl/pkg/config" - "github.com/kubemq-io/kubemqctl/pkg/k8s/client" - "github.com/kubemq-io/kubemqctl/pkg/k8s/manager/dashboard" - "github.com/kubemq-io/kubemqctl/pkg/k8s/manager/operator" - operatorTypes "github.com/kubemq-io/kubemqctl/pkg/k8s/types/operator" - "github.com/kubemq-io/kubemqctl/pkg/utils" - "github.com/spf13/cobra" - "reflect" -) - -type CreateOptions struct { - cfg *config.Config - isDryRun bool - deployOpts *deployOptions -} - -var createExamples = ` - # Create default Kubemq Dashboard - kubemqctl create dashboard - - # Create Kubemq dashboard with options - get all flags - kubemqctl create dashboard --help -` -var createLong = `Create command allows to deploy a Kubemq Dashboard with configuration options` -var createShort = `Create a Kubemq dashboard command` - -func NewCmdCreate(ctx context.Context, cfg *config.Config) *cobra.Command { - o := &CreateOptions{ - cfg: cfg, - } - cmd := &cobra.Command{ - - Use: "dashboard", - Aliases: []string{"d", "dash", "dashboards"}, - Short: createShort, - Long: createLong, - Example: createExamples, - Run: func(cmd *cobra.Command, args []string) { - ctx, cancel := context.WithCancel(ctx) - defer cancel() - utils.CheckErr(o.Complete(args), cmd) - utils.CheckErr(o.Validate()) - utils.CheckErr(o.Run(ctx)) - }, - } - - o.deployOpts = defaultDeployOptions(cmd) - cmd.PersistentFlags().BoolVarP(&o.isDryRun, "dry-run", "", false, "generate dashboard configuration without execute") - - return cmd -} - -func (o *CreateOptions) Complete(args []string) error { - - if err := o.deployOpts.complete(); err != nil { - return err - } - - return nil -} - -func (o *CreateOptions) Validate() error { - if err := o.deployOpts.validate(); err != nil { - return err - } - return nil -} - -func (o *CreateOptions) Run(ctx context.Context) error { - newClient, err := client.NewClient(o.cfg.KubeConfigPath) - if err != nil { - return err - } - dashabordManager, err := dashboard.NewManager(newClient) - if err != nil { - return err - } - operatorManager, err := operator.NewManager(newClient) - if err != nil { - return err - } - dep := o.deployOpts.getDashboardDeployment() - if o.isDryRun { - utils.PrintlnfNoTitle(dep.String()) - return nil - } - if !operatorManager.IsKubemqOperatorExists(dep.Namespace) { - operatorDeployment, err := operatorTypes.CreateDeployment("kubemq-operator", dep.Namespace) - if err != nil { - return err - } - _, _, err = operatorManager.CreateOrUpdateKubemqOperator(operatorDeployment) - if err != nil { - return err - } - utils.Printlnf("Kubemq operator %s/kubemq-operator created.", dep.Namespace) - } else { - utils.Printlnf("Kubemq operator %s/kubemq-operator exists", dep.Namespace) - } - - dashboard, isUpdate, err := dashabordManager.CreateOrUpdateKubemqDashboard(dep) - if err != nil { - return err - } - if isUpdate { - utils.Printlnf("kubemq dashboard %s/%s configured.", dashboard.Namespace, dashboard.Name) - } else { - utils.Printlnf("kubemq dashboard %s/%s created.", dashboard.Namespace, dashboard.Name) - } - utils.Println("run: 'kubemqctl get dashboard' for opening dashboard in default browser (it might take couple seconds to load all components") - return nil - -} - -func isDefault(a, b interface{}) bool { - return reflect.DeepEqual(a, b) -} diff --git a/cmd/create/dashboard/deploy.go b/cmd/create/dashboard/deploy.go deleted file mode 100644 index d907d84..0000000 --- a/cmd/create/dashboard/deploy.go +++ /dev/null @@ -1,75 +0,0 @@ -package dashboard - -import ( - "github.com/kubemq-io/kubemqctl/pkg/k8s/types/kubemqdashboard" - "github.com/spf13/cobra" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type deployOptions struct { - name string - namespace string - port int32 - prometheus *deployPrometheusOptions - grafana *deployGrafanaOptions -} - -func defaultDeployOptions(cmd *cobra.Command) *deployOptions { - o := &deployOptions{ - port: 0, - prometheus: setPrometheusConfig(cmd), - grafana: setGrafanaConfig(cmd), - } - cmd.PersistentFlags().StringVarP(&o.name, "name", "", "kubemq-dashboard", "set kubemq dashboard name") - cmd.PersistentFlags().StringVarP(&o.namespace, "namespace", "n", "kubemq", "set kubemq dashboard namespace") - cmd.PersistentFlags().Int32VarP(&o.port, "port", "p", 0, "set kubemq dashboard port") - return o -} - -func (o *deployOptions) validate() error { - - if err := o.prometheus.validate(); err != nil { - return err - } - - if err := o.grafana.validate(); err != nil { - return err - } - return nil -} - -func (o *deployOptions) complete() error { - - if err := o.prometheus.complete(); err != nil { - return err - } - - if err := o.grafana.complete(); err != nil { - return err - } - return nil -} - -func (o *deployOptions) getDashboardDeployment() *kubemqdashboard.KubemqDashboard { - - deployment := &kubemqdashboard.KubemqDashboard{ - TypeMeta: v1.TypeMeta{ - Kind: "KubemqDashboard", - APIVersion: "core.k8s.kubemq.io/v1alpha1", - }, - ObjectMeta: v1.ObjectMeta{ - Name: o.name, - Namespace: o.namespace, - }, - Spec: kubemqdashboard.KubemqDashboardSpec{ - Port: o.port, - Prometheus: nil, - Grafana: nil, - }, - Status: kubemqdashboard.KubemqDashboardStatus{}, - } - o.prometheus.setConfig(deployment) - o.grafana.setConfig(deployment) - - return deployment -} diff --git a/cmd/create/dashboard/grafana.go b/cmd/create/dashboard/grafana.go deleted file mode 100644 index dd75a53..0000000 --- a/cmd/create/dashboard/grafana.go +++ /dev/null @@ -1,46 +0,0 @@ -package dashboard - -import ( - "github.com/kubemq-io/kubemqctl/pkg/k8s/types/kubemqdashboard" - "github.com/spf13/cobra" -) - -var defaultGrafanaOptions = &deployGrafanaOptions{ - dashboardUrl: "", - image: "", -} - -type deployGrafanaOptions struct { - dashboardUrl string - image string -} - -func setGrafanaConfig(cmd *cobra.Command) *deployGrafanaOptions { - o := &deployGrafanaOptions{ - dashboardUrl: "", - image: "", - } - - cmd.PersistentFlags().StringVarP(&o.image, "grafana-image", "", "", "set grafana docker image") - cmd.PersistentFlags().StringVarP(&o.dashboardUrl, "grafana-dashboard-url", "", "", "set grafana dashboard url image") - return o -} - -func (o *deployGrafanaOptions) validate() error { - return nil -} -func (o *deployGrafanaOptions) complete() error { - return nil -} - -func (o *deployGrafanaOptions) setConfig(deployment *kubemqdashboard.KubemqDashboard) *deployGrafanaOptions { - if isDefault(o, defaultGrafanaOptions) { - return o - } - - deployment.Spec.Grafana = &kubemqdashboard.GrafanaConfig{ - DashboardUrl: o.dashboardUrl, - Image: o.image, - } - return o -} diff --git a/cmd/create/dashboard/prometheus.go b/cmd/create/dashboard/prometheus.go deleted file mode 100644 index bd2b973..0000000 --- a/cmd/create/dashboard/prometheus.go +++ /dev/null @@ -1,45 +0,0 @@ -package dashboard - -import ( - "github.com/kubemq-io/kubemqctl/pkg/k8s/types/kubemqdashboard" - "github.com/spf13/cobra" -) - -var defaultPrometheusOptions = &deployPrometheusOptions{ - nodePort: 0, - image: "", -} - -type deployPrometheusOptions struct { - nodePort int32 - image string -} - -func setPrometheusConfig(cmd *cobra.Command) *deployPrometheusOptions { - o := &deployPrometheusOptions{ - nodePort: 0, - image: "", - } - cmd.PersistentFlags().Int32VarP(&o.nodePort, "prometheus-port", "", 0, "set export prometheus port") - cmd.PersistentFlags().StringVarP(&o.image, "prometheus-image", "", "", "set prometheus docker image") - return o -} - -func (o *deployPrometheusOptions) validate() error { - return nil -} -func (o *deployPrometheusOptions) complete() error { - return nil -} - -func (o *deployPrometheusOptions) setConfig(deployment *kubemqdashboard.KubemqDashboard) *deployPrometheusOptions { - if isDefault(o, defaultPrometheusOptions) { - return o - } - - deployment.Spec.Prometheus = &kubemqdashboard.PrometheusConfig{ - NodePort: o.nodePort, - Image: o.image, - } - return o -} diff --git a/cmd/delete/dashboard/dashboard.go b/cmd/delete/dashboard/dashboard.go deleted file mode 100644 index 75d4755..0000000 --- a/cmd/delete/dashboard/dashboard.go +++ /dev/null @@ -1,133 +0,0 @@ -package dashboard - -import ( - "context" - "fmt" - "github.com/AlecAivazis/survey/v2" - "github.com/kubemq-io/kubemqctl/pkg/config" - client2 "github.com/kubemq-io/kubemqctl/pkg/k8s/client" - "github.com/kubemq-io/kubemqctl/pkg/k8s/manager/dashboard" - "github.com/kubemq-io/kubemqctl/pkg/k8s/manager/operator" - operatorTypes "github.com/kubemq-io/kubemqctl/pkg/k8s/types/operator" - "github.com/kubemq-io/kubemqctl/pkg/utils" - "github.com/spf13/cobra" -) - -type DeleteOptions struct { - cfg *config.Config -} - -var deleteExamples = ` - # Delete Kubemq dashboard - kubemqctl delete dashboard -` -var deleteLong = `Delete one or more Kubemq dashboards` -var deleteShort = `Delete Kubemq dashboard` - -func NewCmdDelete(ctx context.Context, cfg *config.Config) *cobra.Command { - o := &DeleteOptions{ - cfg: cfg, - } - cmd := &cobra.Command{ - - Use: "dashboard", - Aliases: []string{"d", "dash", "dashboards"}, - Short: deleteShort, - Long: deleteLong, - Example: deleteExamples, - Run: func(cmd *cobra.Command, args []string) { - ctx, cancel := context.WithCancel(ctx) - defer cancel() - utils.CheckErr(o.Complete(args), cmd) - utils.CheckErr(o.Validate()) - utils.CheckErr(o.Run(ctx)) - }, - } - - return cmd -} - -func (o *DeleteOptions) Complete(args []string) error { - return nil -} - -func (o *DeleteOptions) Validate() error { - - return nil -} - -func (o *DeleteOptions) Run(ctx context.Context) error { - client, err := client2.NewClient(o.cfg.KubeConfigPath) - if err != nil { - return err - } - dashboardManager, err := dashboard.NewManager(client) - if err != nil { - return err - } - operatorManager, err := operator.NewManager(client) - if err != nil { - return err - } - dashboards, err := dashboardManager.GetKubemqDashboardes() - if err != nil { - return err - } - if len(dashboards.List()) == 0 { - return fmt.Errorf("no Kubemq dashboards were found to delete") - } - - selection := []string{} - multiSelected := &survey.MultiSelect{ - Renderer: survey.Renderer{}, - Message: "Select Kubemq dashboards to delete", - Options: dashboards.List(), - Default: nil, - Help: "Select Kubemq dashboards to delete", - PageSize: 0, - VimMode: false, - FilterMessage: "", - Filter: nil, - } - err = survey.AskOne(multiSelected, &selection) - if err != nil { - return err - } - - areYouSure := false - promptConfirm := &survey.Confirm{ - Renderer: survey.Renderer{}, - Message: "Are you sure ?", - Default: false, - Help: "Confirm Kubemq dashboard deletion", - } - err = survey.AskOne(promptConfirm, &areYouSure) - if err != nil { - return err - } - if !areYouSure { - return nil - } - for _, selected := range selection { - dashboard := dashboards.Dashboard(selected) - if !operatorManager.IsKubemqOperatorExists(dashboard.Namespace) { - operatorDeployment, err := operatorTypes.CreateDeployment("kubemq-operator", dashboard.Namespace) - if err != nil { - return err - } - _, _, err = operatorManager.CreateOrUpdateKubemqOperator(operatorDeployment) - if err != nil { - return err - } - utils.Printlnf("Kubemq operator %s/kubemq-operator created.", dashboard.Namespace) - } else { - utils.Printlnf("Kubemq operator %s/kubemq-operator exists", dashboard.Namespace) - } - err := dashboardManager.DeleteKubemqDashboard(dashboard) - if err != nil { - return err - } - utils.Printlnf("Kubemq dashboard %s deleted.", selected) - } - return nil -} diff --git a/cmd/delete/delete.go b/cmd/delete/delete.go index 71ddd3e..073101b 100644 --- a/cmd/delete/delete.go +++ b/cmd/delete/delete.go @@ -5,7 +5,6 @@ import ( "github.com/kubemq-io/kubemqctl/cmd/delete/cluster" "github.com/kubemq-io/kubemqctl/cmd/delete/components" "github.com/kubemq-io/kubemqctl/cmd/delete/connector" - "github.com/kubemq-io/kubemqctl/cmd/delete/dashboard" "github.com/kubemq-io/kubemqctl/cmd/delete/operator" "github.com/kubemq-io/kubemqctl/pkg/config" "github.com/kubemq-io/kubemqctl/pkg/utils" @@ -48,7 +47,6 @@ func NewCmdDelete(ctx context.Context, cfg *config.Config) *cobra.Command { } cmd.AddCommand(cluster.NewCmdDelete(ctx, cfg)) cmd.AddCommand(operator.NewCmdDelete(ctx, cfg)) - cmd.AddCommand(dashboard.NewCmdDelete(ctx, cfg)) cmd.AddCommand(connector.NewCmdDelete(ctx, cfg)) cmd.AddCommand(components.NewCmdDelete(ctx, cfg)) return cmd diff --git a/cmd/generate/authentication/jwt.go b/cmd/generate/authentication/jwt.go index 2b04965..c523935 100644 --- a/cmd/generate/authentication/jwt.go +++ b/cmd/generate/authentication/jwt.go @@ -2,7 +2,7 @@ package authentication import ( "fmt" - "github.com/dgrijalva/jwt-go" + jwt "github.com/golang-jwt/jwt/v4" ) var JWTSignMethods = map[string]jwt.SigningMethod{ diff --git a/cmd/generate/authentication/token.go b/cmd/generate/authentication/token.go index 497a599..4042b2f 100644 --- a/cmd/generate/authentication/token.go +++ b/cmd/generate/authentication/token.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "github.com/AlecAivazis/survey/v2" - "github.com/dgrijalva/jwt-go" + "github.com/golang-jwt/jwt/v4" "github.com/google/uuid" "io/ioutil" "strconv" diff --git a/cmd/get/dashboard/dashboard.go b/cmd/get/dashboard/dashboard.go index 4664fa4..66ff5ad 100644 --- a/cmd/get/dashboard/dashboard.go +++ b/cmd/get/dashboard/dashboard.go @@ -4,11 +4,10 @@ import ( "context" "fmt" "github.com/AlecAivazis/survey/v2" - "github.com/kubemq-io/kubemqctl/cmd/get/dashboard/describe" "github.com/kubemq-io/kubemqctl/pkg/config" "github.com/kubemq-io/kubemqctl/pkg/k8s" "github.com/kubemq-io/kubemqctl/pkg/k8s/client" - "github.com/kubemq-io/kubemqctl/pkg/k8s/manager/dashboard" + "github.com/kubemq-io/kubemqctl/pkg/k8s/manager/cluster" "github.com/kubemq-io/kubemqctl/pkg/utils" "github.com/pkg/browser" "github.com/spf13/cobra" @@ -20,11 +19,11 @@ type getOptions struct { } var getExamples = ` - # Get status of Kubemq of dashboards - kubemqctl get dashboards + # Get KubeMQ web interface + kubemqctl get dashboard ` -var getLong = `Get information of Kubemq dashboard resources` -var getShort = `Get information of Kubemq dashboard resources` +var getLong = `Get access to KubeMQ dashboard` +var getShort = `Get access to KubeMQ dashboard` func NewCmdGet(ctx context.Context, cfg *config.Config) *cobra.Command { o := &getOptions{ @@ -45,11 +44,11 @@ func NewCmdGet(ctx context.Context, cfg *config.Config) *cobra.Command { utils.CheckErr(o.Run(ctx)) }, } - cmd.AddCommand(describe.NewCmdDescribe(ctx, cfg)) return cmd } func (o *getOptions) Complete(args []string) error { + return nil } @@ -59,55 +58,69 @@ func (o *getOptions) Validate() error { } func (o *getOptions) Run(ctx context.Context) error { - client, err := client.NewClient(o.cfg.KubeConfigPath) + namespace, clusterName := "", "" + c, err := client.NewClient(o.cfg.KubeConfigPath) if err != nil { return err } - dashboardManager, err := dashboard.NewManager(client) + clusterManager, err := cluster.NewManager(c) if err != nil { return err } - dashboards, err := dashboardManager.GetKubemqDashboardes() + clusters, err := clusterManager.GetKubemqClusters() if err != nil { return err } - if len(dashboards.List()) == 0 { - return fmt.Errorf("no Kubemq dashboards were found") - } - var ns, name string - if len(dashboards.List()) == 1 { - ns, name = StringSplit(dashboards.List()[0]) + if len(clusters.List()) == 0 { + return fmt.Errorf("no Kubemq clusters were found") + } + if len(clusters.List()) == 1 { + pair := clusters.List()[0] + namespace, clusterName = StringSplit(pair) } else { selection := "" - selected := &survey.Select{ - Renderer: survey.Renderer{}, - Message: "Select dashboard to launch", - Options: dashboards.List(), - Default: dashboards.List()[0], - PageSize: 0, - VimMode: false, - FilterMessage: "", - Filter: nil, + prompt := &survey.Select{ + Renderer: survey.Renderer{}, + Message: "Show Dashboard for KubeMQ cluster:", + Options: clusters.List(), + Default: clusters.List()[0], } - err = survey.AskOne(selected, &selection) + err = survey.AskOne(prompt, &selection) if err != nil { return err } - ns, name = StringSplit(selection) + pair := strings.Split(selection, "/") + namespace = pair[0] + clusterName = pair[1] } - grafnaPort, _, err := k8s.GetDashboardTransport(ctx, o.cfg, ns, name) + fmt.Printf("Opening Dashboard for Kubemq cluster: %s/%s\n", namespace, clusterName) + proxyOptions := &k8s.ProxyOptions{ + KubeConfig: o.cfg.KubeConfigPath, + Namespace: namespace, + StatefulSet: clusterName, + Pod: "", + Ports: []string{"8080"}, + } + errCh := make(chan error, 1) + err = k8s.SetConcurrentProxy(ctx, proxyOptions, errCh) if err != nil { return err } - err = browser.OpenURL(fmt.Sprintf("http://localhost:%s/d/kubemqdashboard/kubemq-dashboard", grafnaPort)) + err = browser.OpenURL("http://localhost:8080") if err != nil { return err + } - <-ctx.Done() - return nil + select { + case err := <-errCh: + return err + case <-ctx.Done(): + return nil + } + } func StringSplit(input string) (string, string) { diff --git a/cmd/get/dashboard/describe/describe.go b/cmd/get/dashboard/describe/describe.go deleted file mode 100644 index 44ed1f9..0000000 --- a/cmd/get/dashboard/describe/describe.go +++ /dev/null @@ -1,99 +0,0 @@ -package describe - -import ( - "context" - "fmt" - "github.com/AlecAivazis/survey/v2" - "github.com/kubemq-io/kubemqctl/pkg/config" - "github.com/kubemq-io/kubemqctl/pkg/k8s/client" - "github.com/kubemq-io/kubemqctl/pkg/k8s/manager/dashboard" - "github.com/kubemq-io/kubemqctl/pkg/utils" - "github.com/spf13/cobra" -) - -type DescribeOptions struct { - cfg *config.Config -} - -var describeExamples = ` - # Describe Kubemq dashboard to console - kubemqctl get dashboard describe -` -var describeLong = `Describe command allows describing a Kubemq dashboard to console` -var describeShort = `Describe Kubemq dashboard command` - -func NewCmdDescribe(ctx context.Context, cfg *config.Config) *cobra.Command { - o := &DescribeOptions{ - cfg: cfg, - } - cmd := &cobra.Command{ - - Use: "describe", - Aliases: []string{"des", "d"}, - Short: describeShort, - Long: describeLong, - Example: describeExamples, - Run: func(cmd *cobra.Command, args []string) { - ctx, cancel := context.WithCancel(ctx) - defer cancel() - utils.CheckErr(o.Complete(args), cmd) - utils.CheckErr(o.Validate()) - utils.CheckErr(o.Run(ctx)) - }, - } - - return cmd -} - -func (o *DescribeOptions) Complete(args []string) error { - return nil -} - -func (o *DescribeOptions) Validate() error { - - return nil -} - -func (o *DescribeOptions) Run(ctx context.Context) error { - c, err := client.NewClient(o.cfg.KubeConfigPath) - if err != nil { - return err - } - dashboardManager, err := dashboard.NewManager(c) - if err != nil { - return err - } - dashboards, err := dashboardManager.GetKubemqDashboardes() - if err != nil { - return err - } - - if len(dashboards.List()) == 0 { - return fmt.Errorf("no Kubemq dashboards were found to describe") - } - - selection := "" - if len(dashboards.List()) == 1 { - selection = dashboards.List()[0] - } else { - selected := &survey.Select{ - Renderer: survey.Renderer{}, - Message: "Select Kubemq dashboard to describe", - Options: dashboards.List(), - Default: dashboards.List()[0], - PageSize: 0, - VimMode: false, - FilterMessage: "", - Filter: nil, - } - err = survey.AskOne(selected, &selection) - if err != nil { - return err - } - - } - - spec := dashboards.Dashboard(selection) - utils.PrintlnfNoTitle(spec.String()) - return nil -} diff --git a/go.mod b/go.mod index e02fa4e..739e9d3 100644 --- a/go.mod +++ b/go.mod @@ -1,31 +1,109 @@ module github.com/kubemq-io/kubemqctl require ( - github.com/AlecAivazis/survey/v2 v2.2.7 - github.com/dgrijalva/jwt-go v3.2.0+incompatible - github.com/fatih/color v1.10.0 + github.com/AlecAivazis/survey/v2 v2.3.6 + github.com/fatih/color v1.13.0 github.com/ghodss/yaml v1.0.0 - github.com/go-resty/resty/v2 v2.4.0 + github.com/go-resty/resty/v2 v2.7.0 + github.com/golang-jwt/jwt/v4 v4.2.0 github.com/google/uuid v1.2.0 - github.com/gorilla/websocket v1.4.2 - github.com/json-iterator/go v1.1.10 - github.com/kubemq-hub/builder v0.6.2 - github.com/kubemq-io/kubemq-go v1.4.7 - github.com/pelletier/go-toml v1.4.0 // indirect - github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 + github.com/gorilla/websocket v1.5.0 + github.com/json-iterator/go v1.1.12 + github.com/kubemq-hub/builder v0.7.2 + github.com/kubemq-io/kubemq-go v1.7.6 + github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/pkg/errors v0.9.1 - github.com/spf13/cobra v1.1.1 - github.com/spf13/jwalterweatherman v1.1.0 // indirect - github.com/spf13/viper v1.7.1 - github.com/stretchr/testify v1.5.1 - gopkg.in/yaml.v2 v2.3.0 - k8s.io/api v0.17.4 - k8s.io/apiextensions-apiserver v0.17.4 - k8s.io/apimachinery v0.17.4 - k8s.io/client-go v0.17.4 + github.com/spf13/cobra v1.5.0 + github.com/spf13/viper v1.13.0 + github.com/stretchr/testify v1.8.0 + gopkg.in/yaml.v2 v2.4.0 + k8s.io/api v0.25.2 + k8s.io/apiextensions-apiserver v0.25.2 + k8s.io/apimachinery v0.25.2 + k8s.io/client-go v0.25.2 +) +require ( + cloud.google.com/go/compute v1.6.1 // indirect + github.com/Azure/go-autorest v14.2.0+incompatible // indirect + github.com/Azure/go-autorest/autorest v0.11.27 // indirect + github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect + github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect + github.com/Azure/go-autorest/logger v0.2.1 // indirect + github.com/Azure/go-autorest/tracing v0.6.0 // indirect + github.com/Masterminds/goutils v1.1.0 // indirect + github.com/Masterminds/semver v1.5.0 // indirect + github.com/Masterminds/sprig v2.22.0+incompatible // indirect + github.com/PuerkitoBio/purell v1.1.1 // indirect + github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect + github.com/emicklei/go-restful/v3 v3.8.0 // indirect + github.com/fsnotify/fsnotify v1.5.4 // indirect + github.com/go-logr/logr v1.2.3 // indirect + github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/jsonreference v0.19.5 // indirect + github.com/go-openapi/swag v0.19.14 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/google/gnostic v0.5.7-v3refs // indirect + github.com/google/go-cmp v0.5.8 // indirect + github.com/google/gofuzz v1.1.0 // indirect + github.com/gookit/color v1.3.1 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect + github.com/huandu/xstrings v1.3.2 // indirect + github.com/imdario/mergo v0.3.11 // indirect + github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect + github.com/kubemq-io/protobuf v1.3.1 // indirect + github.com/magiconair/properties v1.8.6 // indirect + github.com/mailru/easyjson v0.7.6 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mattn/go-runewidth v0.0.9 // indirect + github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect + github.com/mitchellh/copystructure v1.0.0 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mitchellh/reflectwalk v1.0.0 // indirect + github.com/moby/spdystream v0.2.0 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/nats-io/nuid v1.0.1 // indirect + github.com/pelletier/go-toml v1.9.5 // indirect + github.com/pelletier/go-toml/v2 v2.0.5 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/spf13/afero v1.8.2 // indirect + github.com/spf13/cast v1.5.0 // indirect + github.com/spf13/jwalterweatherman v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.4.1 // indirect + go.opencensus.io v0.23.0 // indirect + go.uber.org/atomic v1.9.0 // indirect + golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect + golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect + golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect + golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect + golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect + golang.org/x/text v0.3.7 // indirect + golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect + google.golang.org/appengine v1.6.7 // indirect + google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect + google.golang.org/grpc v1.47.0 // indirect + google.golang.org/protobuf v1.28.0 // indirect + gopkg.in/inf.v0 v0.9.1 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + k8s.io/klog/v2 v2.70.1 // indirect + k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect + k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect + sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect + sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect + sigs.k8s.io/yaml v1.2.0 // indirect ) -go 1.15 +go 1.18 //replace github.com/kubemq-hub/builder => ../../kubemq-hub/builder diff --git a/pkg/k8s/client/client.go b/pkg/k8s/client/client.go index 68cfaf5..54ce4bb 100644 --- a/pkg/k8s/client/client.go +++ b/pkg/k8s/client/client.go @@ -2,6 +2,7 @@ package client import ( "bytes" + "context" "github.com/kubemq-io/kubemqctl/pkg/k8s/client/v1alpha1" "github.com/kubemq-io/kubemqctl/pkg/k8s/types" @@ -117,7 +118,7 @@ func (c *Client) SwitchContext(contextName string) error { } func (c *Client) GetPods(ns string, name string) (map[string]apiv1.Pod, error) { - pods, err := c.ClientSet.CoreV1().Pods(ns).List(metav1.ListOptions{}) + pods, err := c.ClientSet.CoreV1().Pods(ns).List(context.Background(), metav1.ListOptions{}) if err != nil { return nil, err } @@ -131,7 +132,21 @@ func (c *Client) GetPods(ns string, name string) (map[string]apiv1.Pod, error) { } return list, err } - +func (c *Client) GetServices(ns string, name string) (map[string]apiv1.Service, error) { + pods, err := c.ClientSet.CoreV1().Services(ns).List(context.Background(), metav1.ListOptions{}) + if err != nil { + return nil, err + } + list := map[string]apiv1.Service{} + items := pods.Items + for i := 0; i < len(items); i++ { + item := items[i] + if item.Name == name { + list[fmt.Sprintf("%s/%s", item.Namespace, item.Name)] = item + } + } + return list, err +} func (c *Client) ForwardPorts(ns string, name string, ports []string, stopChan chan struct{}, outCh chan string, errOutCh chan string) error { restConfig, err := c.ClientConfig.ClientConfig() if err != nil { diff --git a/pkg/k8s/client/ingress.go b/pkg/k8s/client/ingress.go index 41afe16..da002dd 100644 --- a/pkg/k8s/client/ingress.go +++ b/pkg/k8s/client/ingress.go @@ -1,6 +1,7 @@ package client import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/utils" net "k8s.io/api/networking/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -9,14 +10,14 @@ import ( func (c *Client) DeleteIngressForStatefulSet(name string) error { pair := strings.Split(name, "/") - ingressList, err := c.ClientSet.NetworkingV1beta1().Ingresses(pair[0]).List(metav1.ListOptions{}) + ingressList, err := c.ClientSet.NetworkingV1beta1().Ingresses(pair[0]).List(context.Background(), metav1.ListOptions{}) if err != nil { return err } for _, ingress := range ingressList.Items { if strings.Contains(ingress.Name, pair[1]) { - err := c.ClientSet.NetworkingV1beta1().Ingresses(pair[0]).Delete(ingress.Name, metav1.NewDeleteOptions(0)) + err := c.ClientSet.NetworkingV1beta1().Ingresses(pair[0]).Delete(context.Background(), ingress.Name, metav1.DeleteOptions{}) if err != nil { utils.Printlnf("Ingress %s/%s not deleted. Error: %s", ingress.Namespace, ingress.Namespace, utils.Title(err.Error())) continue @@ -33,18 +34,18 @@ func (c *Client) CreateOrUpdateIngress(ingress *net.Ingress) (*net.Ingress, bool Name: name, Namespace: ns, } - oldIngress, err := c.ClientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Get(ingress.Name, metav1.GetOptions{}) + oldIngress, err := c.ClientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Get(context.Background(), ingress.Name, metav1.GetOptions{}) if err == nil && oldIngress != nil { ingress.ResourceVersion = oldIngress.ResourceVersion - newIngress, err := c.ClientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Update(ingress) + newIngress, err := c.ClientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Update(context.Background(), ingress, metav1.UpdateOptions{}) if err != nil { return nil, true, err } return newIngress, true, nil } - createdIngress, err := c.ClientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Create(ingress) + createdIngress, err := c.ClientSet.NetworkingV1beta1().Ingresses(ingress.Namespace).Create(context.Background(), ingress, metav1.CreateOptions{}) if err != nil { return nil, false, err } @@ -53,7 +54,7 @@ func (c *Client) CreateOrUpdateIngress(ingress *net.Ingress) (*net.Ingress, bool func (c *Client) GetIngress(ns string, stsName string) ([]*net.Ingress, error) { ingressList := []*net.Ingress{} - list, err := c.ClientSet.NetworkingV1beta1().Ingresses(ns).List(metav1.ListOptions{}) + list, err := c.ClientSet.NetworkingV1beta1().Ingresses(ns).List(context.Background(), metav1.ListOptions{}) if err != nil { return nil, err } diff --git a/pkg/k8s/client/namespace.go b/pkg/k8s/client/namespace.go index 0c7a67a..1f89a3f 100644 --- a/pkg/k8s/client/namespace.go +++ b/pkg/k8s/client/namespace.go @@ -1,12 +1,13 @@ package client import ( + "context" apiv1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func (c *Client) GetNamespace(name string) (*apiv1.Namespace, bool, error) { - ns, err := c.ClientSet.CoreV1().Namespaces().Get(name, metav1.GetOptions{}) + ns, err := c.ClientSet.CoreV1().Namespaces().Get(context.Background(), name, metav1.GetOptions{}) if err == nil && ns != nil { return ns, true, nil } @@ -26,12 +27,12 @@ func (c *Client) GetNamespace(name string) (*apiv1.Namespace, bool, error) { } func (c *Client) CheckAndCreateNamespace(namespace *apiv1.Namespace) (*apiv1.Namespace, bool, error) { - ns, err := c.ClientSet.CoreV1().Namespaces().Get(namespace.Name, metav1.GetOptions{}) + ns, err := c.ClientSet.CoreV1().Namespaces().Get(context.Background(), namespace.Name, metav1.GetOptions{}) if err == nil && ns != nil { return ns, false, nil } - createNs, err := c.ClientSet.CoreV1().Namespaces().Create(namespace) + createNs, err := c.ClientSet.CoreV1().Namespaces().Create(context.Background(), namespace, metav1.CreateOptions{}) if err != nil { return nil, false, err } @@ -40,7 +41,7 @@ func (c *Client) CheckAndCreateNamespace(namespace *apiv1.Namespace) (*apiv1.Nam } func (c *Client) CreateIfNotPresentNamespace(namespace string) error { - ns, err := c.ClientSet.CoreV1().Namespaces().Get(namespace, metav1.GetOptions{}) + ns, err := c.ClientSet.CoreV1().Namespaces().Get(context.Background(), namespace, metav1.GetOptions{}) if err == nil && ns != nil { return nil } @@ -53,7 +54,7 @@ func (c *Client) CreateIfNotPresentNamespace(namespace string) error { Spec: apiv1.NamespaceSpec{}, Status: apiv1.NamespaceStatus{}, } - _, err = c.ClientSet.CoreV1().Namespaces().Create(ns) + _, err = c.ClientSet.CoreV1().Namespaces().Create(context.Background(), ns, metav1.CreateOptions{}) if err != nil { return err } @@ -61,7 +62,7 @@ func (c *Client) CreateIfNotPresentNamespace(namespace string) error { return nil } func (c *Client) GetNamespaceList() ([]string, error) { - list, err := c.ClientSet.CoreV1().Namespaces().List(metav1.ListOptions{}) + list, err := c.ClientSet.CoreV1().Namespaces().List(context.Background(), metav1.ListOptions{}) if err != nil { return nil, err } diff --git a/pkg/k8s/client/secret.go b/pkg/k8s/client/secret.go index 449818e..088704a 100644 --- a/pkg/k8s/client/secret.go +++ b/pkg/k8s/client/secret.go @@ -1,6 +1,7 @@ package client import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/utils" apiv1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -9,14 +10,14 @@ import ( func (c *Client) DeleteSecretsForStatefulSet(name string) error { pair := strings.Split(name, "/") - secs, err := c.ClientSet.CoreV1().Secrets(pair[0]).List(metav1.ListOptions{}) + secs, err := c.ClientSet.CoreV1().Secrets(pair[0]).List(context.Background(), metav1.ListOptions{}) if err != nil { return err } for _, sec := range secs.Items { if strings.Contains(sec.Name, pair[1]) { - err := c.ClientSet.CoreV1().Secrets(pair[0]).Delete(sec.Name, metav1.NewDeleteOptions(0)) + err := c.ClientSet.CoreV1().Secrets(pair[0]).Delete(context.Background(), sec.Name, metav1.DeleteOptions{}) if err != nil { utils.Printlnf("Secret %s/%s not deleted. Error: %s", sec.Namespace, sec.Namespace, utils.Title(err.Error())) continue @@ -33,15 +34,15 @@ func (c *Client) CreateOrUpdateSecret(sec *apiv1.Secret) (*apiv1.Secret, bool, e Name: name, Namespace: ns, } - oldSec, err := c.ClientSet.CoreV1().Secrets(sec.Namespace).Get(sec.Name, metav1.GetOptions{}) + oldSec, err := c.ClientSet.CoreV1().Secrets(sec.Namespace).Get(context.Background(), sec.Name, metav1.GetOptions{}) if err == nil && oldSec != nil { - newSec, err := c.ClientSet.CoreV1().Secrets(sec.Namespace).Update(sec) + newSec, err := c.ClientSet.CoreV1().Secrets(sec.Namespace).Update(context.Background(), sec, metav1.UpdateOptions{}) if err != nil { return nil, true, err } return newSec, true, nil } - createSec, err := c.ClientSet.CoreV1().Secrets(sec.Namespace).Create(sec) + createSec, err := c.ClientSet.CoreV1().Secrets(sec.Namespace).Create(context.Background(), sec, metav1.CreateOptions{}) if err != nil { return nil, false, err } @@ -51,7 +52,7 @@ func (c *Client) CreateOrUpdateSecret(sec *apiv1.Secret) (*apiv1.Secret, bool, e func (c *Client) GetSecrets(ns string, stsName string) ([]*apiv1.Secret, error) { secList := []*apiv1.Secret{} - secs, err := c.ClientSet.CoreV1().Secrets(ns).List(metav1.ListOptions{}) + secs, err := c.ClientSet.CoreV1().Secrets(ns).List(context.Background(), metav1.ListOptions{}) if err != nil { return nil, err } diff --git a/pkg/k8s/client/v1alpha1/kubemqcluster.go b/pkg/k8s/client/v1alpha1/kubemqcluster.go index 966c624..ffe55d6 100644 --- a/pkg/k8s/client/v1alpha1/kubemqcluster.go +++ b/pkg/k8s/client/v1alpha1/kubemqcluster.go @@ -1,6 +1,7 @@ package v1alpha1 import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/k8s/types/kubemqcluster" autoscalingv1 "k8s.io/api/autoscaling/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -33,7 +34,7 @@ func (c *kubemqCluster) List(opts metav1.ListOptions) (*kubemqcluster.KubemqClus Namespace(c.ns). Resource("kubemqclusters"). VersionedParams(&opts, scheme.ParameterCodec). - Do(). + Do(context.Background()). Into(&result) return &result, err @@ -47,7 +48,7 @@ func (c *kubemqCluster) Get(clusterName string, opts metav1.GetOptions) (*kubemq Resource("kubemqclusters"). Name(clusterName). VersionedParams(&opts, scheme.ParameterCodec). - Do(). + Do(context.Background()). Into(&result) return &result, err @@ -60,7 +61,7 @@ func (c *kubemqCluster) Create(cluster *kubemqcluster.KubemqCluster) (*kubemqclu Namespace(c.ns). Resource("kubemqclusters"). Body(cluster). - Do(). + Do(context.Background()). Into(result) return result, err @@ -74,7 +75,7 @@ func (c *kubemqCluster) Update(cluster *kubemqcluster.KubemqCluster) (*kubemqclu Name(cluster.Name). Resource("kubemqclusters"). Body(cluster). - Do(). + Do(context.Background()). Into(result) return result, err @@ -85,7 +86,7 @@ func (c *kubemqCluster) Delete(name string, opts *metav1.DeleteOptions) error { Resource("kubemqclusters"). Name(name). Body(opts). - Do(). + Do(context.Background()). Error() return err @@ -102,7 +103,7 @@ func (c *kubemqCluster) Watch(opts metav1.ListOptions) (watch.Interface, error) Resource("kubemqclusters"). VersionedParams(&opts, scheme.ParameterCodec). Timeout(timeout). - Watch() + Watch(context.Background()) } func (c *kubemqCluster) GetScale(clusterName string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) { @@ -113,7 +114,7 @@ func (c *kubemqCluster) GetScale(clusterName string, options metav1.GetOptions) Name(clusterName). SubResource("scale"). VersionedParams(&options, scheme.ParameterCodec). - Do(). + Do(context.Background()). Into(result) return } @@ -127,7 +128,7 @@ func (c *kubemqCluster) UpdateScale(clusterName string, scale *autoscalingv1.Sca Name(clusterName). SubResource("scale"). Body(scale). - Do(). + Do(context.Background()). Into(result) return } diff --git a/pkg/k8s/client/v1alpha1/kubemqconnector.go b/pkg/k8s/client/v1alpha1/kubemqconnector.go index 2eb7d85..28fa41c 100644 --- a/pkg/k8s/client/v1alpha1/kubemqconnector.go +++ b/pkg/k8s/client/v1alpha1/kubemqconnector.go @@ -1,6 +1,7 @@ package v1alpha1 import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/k8s/types/kubemqconnector" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/watch" @@ -30,7 +31,7 @@ func (c *kubemqConnector) List(opts metav1.ListOptions) (*kubemqconnector.Kubemq Namespace(c.ns). Resource("kubemqconnectors"). VersionedParams(&opts, scheme.ParameterCodec). - Do(). + Do(context.Background()). Into(&result) return &result, err @@ -44,7 +45,7 @@ func (c *kubemqConnector) Get(clusterName string, opts metav1.GetOptions) (*kube Resource("kubemqconnectors"). Name(clusterName). VersionedParams(&opts, scheme.ParameterCodec). - Do(). + Do(context.Background()). Into(&result) return &result, err @@ -57,7 +58,7 @@ func (c *kubemqConnector) Create(cluster *kubemqconnector.KubemqConnector) (*kub Namespace(c.ns). Resource("kubemqconnectors"). Body(cluster). - Do(). + Do(context.Background()). Into(result) return result, err @@ -71,7 +72,7 @@ func (c *kubemqConnector) Update(cluster *kubemqconnector.KubemqConnector) (*kub Name(cluster.Name). Resource("kubemqconnectors"). Body(cluster). - Do(). + Do(context.Background()). Into(result) return result, err @@ -82,7 +83,7 @@ func (c *kubemqConnector) Delete(name string, opts *metav1.DeleteOptions) error Resource("kubemqconnectors"). Name(name). Body(opts). - Do(). + Do(context.Background()). Error() return err @@ -99,5 +100,5 @@ func (c *kubemqConnector) Watch(opts metav1.ListOptions) (watch.Interface, error Resource("kubemqconnectors"). VersionedParams(&opts, scheme.ParameterCodec). Timeout(timeout). - Watch() + Watch(context.Background()) } diff --git a/pkg/k8s/client/v1alpha1/kubemqdashboard.go b/pkg/k8s/client/v1alpha1/kubemqdashboard.go index 8b3c0b9..aecc216 100644 --- a/pkg/k8s/client/v1alpha1/kubemqdashboard.go +++ b/pkg/k8s/client/v1alpha1/kubemqdashboard.go @@ -1,6 +1,7 @@ package v1alpha1 import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/k8s/types/kubemqdashboard" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/watch" @@ -30,7 +31,7 @@ func (c *kubemqDashboard) List(opts metav1.ListOptions) (*kubemqdashboard.Kubemq Namespace(c.ns). Resource("kubemqdashboards"). VersionedParams(&opts, scheme.ParameterCodec). - Do(). + Do(context.Background()). Into(&result) return &result, err @@ -44,7 +45,7 @@ func (c *kubemqDashboard) Get(clusterName string, opts metav1.GetOptions) (*kube Resource("kubemqdashboards"). Name(clusterName). VersionedParams(&opts, scheme.ParameterCodec). - Do(). + Do(context.Background()). Into(&result) return &result, err @@ -57,7 +58,7 @@ func (c *kubemqDashboard) Create(cluster *kubemqdashboard.KubemqDashboard) (*kub Namespace(c.ns). Resource("kubemqdashboards"). Body(cluster). - Do(). + Do(context.Background()). Into(result) return result, err @@ -71,7 +72,7 @@ func (c *kubemqDashboard) Update(cluster *kubemqdashboard.KubemqDashboard) (*kub Name(cluster.Name). Resource("kubemqdashboards"). Body(cluster). - Do(). + Do(context.Background()). Into(result) return result, err @@ -82,7 +83,7 @@ func (c *kubemqDashboard) Delete(name string, opts *metav1.DeleteOptions) error Resource("kubemqdashboards"). Name(name). Body(opts). - Do(). + Do(context.Background()). Error() return err @@ -99,5 +100,5 @@ func (c *kubemqDashboard) Watch(opts metav1.ListOptions) (watch.Interface, error Resource("kubemqdashboards"). VersionedParams(&opts, scheme.ParameterCodec). Timeout(timeout). - Watch() + Watch(context.Background()) } diff --git a/pkg/k8s/logs/tail.go b/pkg/k8s/logs/tail.go index badd7bd..ed5f07f 100644 --- a/pkg/k8s/logs/tail.go +++ b/pkg/k8s/logs/tail.go @@ -86,7 +86,7 @@ func (t *Tail) Start(ctx context.Context, i v1.PodInterface) { TailLines: t.Options.TailLines, }) - stream, err := req.Stream() + stream, err := req.Stream(context.Background()) if err != nil { fmt.Println(errors.Wrapf(err, "Error opening stream to %s/%s: %s\n", t.Namespace, t.PodName, t.ContainerName)) return diff --git a/pkg/k8s/logs/watch.go b/pkg/k8s/logs/watch.go index d5b911b..5ecb0ce 100644 --- a/pkg/k8s/logs/watch.go +++ b/pkg/k8s/logs/watch.go @@ -30,7 +30,7 @@ func (t *Target) GetID() string { // containers/pods. The first result is targets added, the second is targets // removed func Watch(ctx context.Context, i v1.PodInterface, podFilter *regexp.Regexp, containerFilter *regexp.Regexp, labelSelector labels.Selector) (chan *Target, chan *Target, error) { - watcher, err := i.Watch(metav1.ListOptions{Watch: true, LabelSelector: labelSelector.String()}) + watcher, err := i.Watch(context.Background(), metav1.ListOptions{Watch: true, LabelSelector: labelSelector.String()}) if err != nil { return nil, nil, errors.Wrap(err, "failed to set up attach") } diff --git a/pkg/k8s/manager/operator/cluster_role.go b/pkg/k8s/manager/operator/cluster_role.go index 7b17d70..bd74899 100644 --- a/pkg/k8s/manager/operator/cluster_role.go +++ b/pkg/k8s/manager/operator/cluster_role.go @@ -1,6 +1,7 @@ package operator import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/k8s/client" rbac "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -11,16 +12,16 @@ type clusterRoleManager struct { } func (m *clusterRoleManager) CreateOrUpdateClusterRole(role *rbac.ClusterRole) (*rbac.ClusterRole, bool, error) { - found, err := m.ClientSet.RbacV1().ClusterRoles().Get(role.Name, metav1.GetOptions{}) + found, err := m.ClientSet.RbacV1().ClusterRoles().Get(context.Background(), role.Name, metav1.GetOptions{}) if err == nil && found != nil { - updatedRole, err := m.ClientSet.RbacV1().ClusterRoles().Update(role) + updatedRole, err := m.ClientSet.RbacV1().ClusterRoles().Update(context.Background(), role, metav1.UpdateOptions{}) if err != nil { return nil, true, err } return updatedRole, true, nil } - newRole, err := m.ClientSet.RbacV1().ClusterRoles().Create(role) + newRole, err := m.ClientSet.RbacV1().ClusterRoles().Create(context.Background(), role, metav1.CreateOptions{}) if err != nil { return nil, false, err } @@ -28,16 +29,16 @@ func (m *clusterRoleManager) CreateOrUpdateClusterRole(role *rbac.ClusterRole) ( } func (m *clusterRoleManager) DeleteClusterRole(role *rbac.ClusterRole) error { - found, err := m.ClientSet.RbacV1().ClusterRoles().Get(role.Name, metav1.GetOptions{}) + found, err := m.ClientSet.RbacV1().ClusterRoles().Get(context.Background(), role.Name, metav1.GetOptions{}) if err == nil && found != nil { - return m.ClientSet.RbacV1().ClusterRoles().Delete(role.Name, metav1.NewDeleteOptions(0)) + return m.ClientSet.RbacV1().ClusterRoles().Delete(context.Background(), role.Name, metav1.DeleteOptions{}) } return nil } func (m *clusterRoleManager) GetClusterRole(name string) (*rbac.ClusterRole, error) { - role, err := m.ClientSet.RbacV1().ClusterRoles().Get(name, metav1.GetOptions{}) + role, err := m.ClientSet.RbacV1().ClusterRoles().Get(context.Background(), name, metav1.GetOptions{}) if err != nil { return nil, err } diff --git a/pkg/k8s/manager/operator/cluster_role_binding.go b/pkg/k8s/manager/operator/cluster_role_binding.go index ffe8070..3b789bc 100644 --- a/pkg/k8s/manager/operator/cluster_role_binding.go +++ b/pkg/k8s/manager/operator/cluster_role_binding.go @@ -1,6 +1,7 @@ package operator import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/k8s/client" rbac "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -11,16 +12,16 @@ type clusterRoleBindingManager struct { } func (m *clusterRoleBindingManager) CreateOrUpdateClusterRoleBinding(roleBinding *rbac.ClusterRoleBinding) (*rbac.ClusterRoleBinding, bool, error) { - found, err := m.ClientSet.RbacV1().ClusterRoleBindings().Get(roleBinding.Name, metav1.GetOptions{}) + found, err := m.ClientSet.RbacV1().ClusterRoleBindings().Get(context.Background(), roleBinding.Name, metav1.GetOptions{}) if err == nil && found != nil { - updatedRoleBinding, err := m.ClientSet.RbacV1().ClusterRoleBindings().Update(roleBinding) + updatedRoleBinding, err := m.ClientSet.RbacV1().ClusterRoleBindings().Update(context.Background(), roleBinding, metav1.UpdateOptions{}) if err != nil { return nil, true, err } return updatedRoleBinding, true, nil } - newRoleBinding, err := m.ClientSet.RbacV1().ClusterRoleBindings().Create(roleBinding) + newRoleBinding, err := m.ClientSet.RbacV1().ClusterRoleBindings().Create(context.Background(), roleBinding, metav1.CreateOptions{}) if err != nil { return nil, false, err } @@ -28,15 +29,15 @@ func (m *clusterRoleBindingManager) CreateOrUpdateClusterRoleBinding(roleBinding } func (m *clusterRoleBindingManager) DeleteClusterRoleBinding(roleBinding *rbac.ClusterRoleBinding) error { - found, err := m.ClientSet.RbacV1().ClusterRoleBindings().Get(roleBinding.Name, metav1.GetOptions{}) + found, err := m.ClientSet.RbacV1().ClusterRoleBindings().Get(context.Background(), roleBinding.Name, metav1.GetOptions{}) if err == nil && found != nil { - return m.ClientSet.RbacV1().ClusterRoleBindings().Delete(roleBinding.Name, metav1.NewDeleteOptions(0)) + return m.ClientSet.RbacV1().ClusterRoleBindings().Delete(context.Background(), roleBinding.Name, metav1.DeleteOptions{}) } return nil } func (m *clusterRoleBindingManager) GetClusterRoleBinding(name, namespace string) (*rbac.ClusterRoleBinding, error) { - role, err := m.ClientSet.RbacV1().ClusterRoleBindings().Get(name, metav1.GetOptions{}) + role, err := m.ClientSet.RbacV1().ClusterRoleBindings().Get(context.Background(), name, metav1.GetOptions{}) if err != nil { return nil, err } diff --git a/pkg/k8s/manager/operator/crd.go b/pkg/k8s/manager/operator/crd.go index 3aef342..9135cb7 100644 --- a/pkg/k8s/manager/operator/crd.go +++ b/pkg/k8s/manager/operator/crd.go @@ -1,6 +1,7 @@ package operator import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/k8s/client" v1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -11,17 +12,17 @@ type crdManager struct { } func (m *crdManager) CreateOrUpdateCRD(crd *v1beta1.CustomResourceDefinition) (*v1beta1.CustomResourceDefinition, bool, error) { - found, err := m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{}) + found, err := m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.Background(), crd.Name, metav1.GetOptions{}) if err == nil && found != nil { crd.ResourceVersion = found.ResourceVersion - updatedCrd, err := m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Update(crd) + updatedCrd, err := m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Update(context.Background(), crd, metav1.UpdateOptions{}) if err != nil { return nil, true, err } return updatedCrd, true, nil } - newCrd, err := m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd) + newCrd, err := m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Create(context.Background(), crd, metav1.CreateOptions{}) if err != nil { return nil, false, err } @@ -29,15 +30,15 @@ func (m *crdManager) CreateOrUpdateCRD(crd *v1beta1.CustomResourceDefinition) (* } func (m *crdManager) DeleteCrd(crd *v1beta1.CustomResourceDefinition) error { - found, err := m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Get(crd.Name, metav1.GetOptions{}) + found, err := m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.Background(), crd.Name, metav1.GetOptions{}) if err == nil && found != nil { - return m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Delete(crd.Name, metav1.NewDeleteOptions(0)) + return m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Delete(context.Background(), crd.Name, metav1.DeleteOptions{}) } return nil } func (m *crdManager) GetCrd(name, namespace string) (*v1beta1.CustomResourceDefinition, error) { - crd, err := m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Get(name, metav1.GetOptions{}) + crd, err := m.ClientApiExtension.ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.Background(), name, metav1.GetOptions{}) if err != nil { return nil, err } diff --git a/pkg/k8s/manager/operator/operator.go b/pkg/k8s/manager/operator/operator.go index 6a7b556..1dd9836 100644 --- a/pkg/k8s/manager/operator/operator.go +++ b/pkg/k8s/manager/operator/operator.go @@ -1,6 +1,7 @@ package operator import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/k8s/client" appsv1 "k8s.io/api/apps/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -11,16 +12,16 @@ type operatorManager struct { } func (m *operatorManager) CreateOrUpdateOperator(operator *appsv1.Deployment) (*appsv1.Deployment, bool, error) { - found, err := m.ClientSet.AppsV1().Deployments(operator.Namespace).Get(operator.Name, metav1.GetOptions{}) + found, err := m.ClientSet.AppsV1().Deployments(operator.Namespace).Get(context.Background(), operator.Name, metav1.GetOptions{}) if err == nil && found != nil { - updatedOperator, err := m.ClientSet.AppsV1().Deployments(operator.Namespace).Update(operator) + updatedOperator, err := m.ClientSet.AppsV1().Deployments(operator.Namespace).Update(context.Background(), operator, metav1.UpdateOptions{}) if err != nil { return nil, true, err } return updatedOperator, true, nil } - newOperator, err := m.ClientSet.AppsV1().Deployments(operator.Namespace).Create(operator) + newOperator, err := m.ClientSet.AppsV1().Deployments(operator.Namespace).Create(context.Background(), operator, metav1.CreateOptions{}) if err != nil { return nil, false, err } @@ -28,15 +29,15 @@ func (m *operatorManager) CreateOrUpdateOperator(operator *appsv1.Deployment) (* } func (m *operatorManager) DeleteOperator(operator *appsv1.Deployment) error { - found, err := m.ClientSet.AppsV1().Deployments(operator.Namespace).Get(operator.Name, metav1.GetOptions{}) + found, err := m.ClientSet.AppsV1().Deployments(operator.Namespace).Get(context.Background(), operator.Name, metav1.GetOptions{}) if err == nil && found != nil { - return m.ClientSet.AppsV1().Deployments(operator.Namespace).Delete(operator.Name, metav1.NewDeleteOptions(0)) + return m.ClientSet.AppsV1().Deployments(operator.Namespace).Delete(context.Background(), operator.Name, metav1.DeleteOptions{}) } return nil } func (m *operatorManager) GetOperator(name, namespace string) (*appsv1.Deployment, error) { - operator, err := m.ClientSet.AppsV1().Deployments(namespace).Get(name, metav1.GetOptions{}) + operator, err := m.ClientSet.AppsV1().Deployments(namespace).Get(context.Background(), name, metav1.GetOptions{}) if err != nil { return nil, err } diff --git a/pkg/k8s/manager/operator/role.go b/pkg/k8s/manager/operator/role.go index 368b547..b48b12b 100644 --- a/pkg/k8s/manager/operator/role.go +++ b/pkg/k8s/manager/operator/role.go @@ -1,6 +1,7 @@ package operator import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/k8s/client" rbac "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -11,16 +12,16 @@ type roleManager struct { } func (m *roleManager) CreateOrUpdateRole(role *rbac.Role) (*rbac.Role, bool, error) { - found, err := m.ClientSet.RbacV1().Roles(role.Namespace).Get(role.Name, metav1.GetOptions{}) + found, err := m.ClientSet.RbacV1().Roles(role.Namespace).Get(context.Background(), role.Name, metav1.GetOptions{}) if err == nil && found != nil { - updatedRole, err := m.ClientSet.RbacV1().Roles(role.Namespace).Update(role) + updatedRole, err := m.ClientSet.RbacV1().Roles(role.Namespace).Update(context.Background(), role, metav1.UpdateOptions{}) if err != nil { return nil, true, err } return updatedRole, true, nil } - newRole, err := m.ClientSet.RbacV1().Roles(role.Namespace).Create(role) + newRole, err := m.ClientSet.RbacV1().Roles(role.Namespace).Create(context.Background(), role, metav1.CreateOptions{}) if err != nil { return nil, false, err } @@ -28,16 +29,16 @@ func (m *roleManager) CreateOrUpdateRole(role *rbac.Role) (*rbac.Role, bool, err } func (m *roleManager) DeleteRole(role *rbac.Role) error { - found, err := m.ClientSet.RbacV1().Roles(role.Namespace).Get(role.Name, metav1.GetOptions{}) + found, err := m.ClientSet.RbacV1().Roles(role.Namespace).Get(context.Background(), role.Name, metav1.GetOptions{}) if err == nil && found != nil { - return m.ClientSet.RbacV1().Roles(role.Namespace).Delete(role.Name, metav1.NewDeleteOptions(0)) + return m.ClientSet.RbacV1().Roles(role.Namespace).Delete(context.Background(), role.Name, metav1.DeleteOptions{}) } return nil } func (m *roleManager) GetRole(name, namespace string) (*rbac.Role, error) { - role, err := m.ClientSet.RbacV1().Roles(namespace).Get(name, metav1.GetOptions{}) + role, err := m.ClientSet.RbacV1().Roles(namespace).Get(context.Background(), name, metav1.GetOptions{}) if err != nil { return nil, err } diff --git a/pkg/k8s/manager/operator/role_binding.go b/pkg/k8s/manager/operator/role_binding.go index c08fd24..13fb964 100644 --- a/pkg/k8s/manager/operator/role_binding.go +++ b/pkg/k8s/manager/operator/role_binding.go @@ -1,6 +1,7 @@ package operator import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/k8s/client" rbac "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -11,16 +12,16 @@ type roleBindingManager struct { } func (m *roleBindingManager) CreateOrUpdateRoleBinding(roleBinding *rbac.RoleBinding) (*rbac.RoleBinding, bool, error) { - found, err := m.ClientSet.RbacV1().RoleBindings(roleBinding.Namespace).Get(roleBinding.Name, metav1.GetOptions{}) + found, err := m.ClientSet.RbacV1().RoleBindings(roleBinding.Namespace).Get(context.Background(), roleBinding.Name, metav1.GetOptions{}) if err == nil && found != nil { - updatedRoleBinding, err := m.ClientSet.RbacV1().RoleBindings(roleBinding.Namespace).Update(roleBinding) + updatedRoleBinding, err := m.ClientSet.RbacV1().RoleBindings(roleBinding.Namespace).Update(context.Background(), roleBinding, metav1.UpdateOptions{}) if err != nil { return nil, true, err } return updatedRoleBinding, true, nil } - newRoleBinding, err := m.ClientSet.RbacV1().RoleBindings(roleBinding.Namespace).Create(roleBinding) + newRoleBinding, err := m.ClientSet.RbacV1().RoleBindings(roleBinding.Namespace).Create(context.Background(), roleBinding, metav1.CreateOptions{}) if err != nil { return nil, false, err } @@ -28,15 +29,15 @@ func (m *roleBindingManager) CreateOrUpdateRoleBinding(roleBinding *rbac.RoleBin } func (m *roleBindingManager) DeleteRoleBinding(roleBinding *rbac.RoleBinding) error { - found, err := m.ClientSet.RbacV1().RoleBindings(roleBinding.Namespace).Get(roleBinding.Name, metav1.GetOptions{}) + found, err := m.ClientSet.RbacV1().RoleBindings(roleBinding.Namespace).Get(context.Background(), roleBinding.Name, metav1.GetOptions{}) if err == nil && found != nil { - return m.ClientSet.RbacV1().RoleBindings(roleBinding.Namespace).Delete(roleBinding.Name, metav1.NewDeleteOptions(0)) + return m.ClientSet.RbacV1().RoleBindings(roleBinding.Namespace).Delete(context.Background(), roleBinding.Name, metav1.DeleteOptions{}) } return nil } func (m *roleBindingManager) GetRoleBinding(name, namespace string) (*rbac.RoleBinding, error) { - role, err := m.ClientSet.RbacV1().RoleBindings(namespace).Get(name, metav1.GetOptions{}) + role, err := m.ClientSet.RbacV1().RoleBindings(namespace).Get(context.Background(), name, metav1.GetOptions{}) if err != nil { return nil, err } diff --git a/pkg/k8s/manager/operator/service_account.go b/pkg/k8s/manager/operator/service_account.go index 3af57d3..dd3b010 100644 --- a/pkg/k8s/manager/operator/service_account.go +++ b/pkg/k8s/manager/operator/service_account.go @@ -1,6 +1,7 @@ package operator import ( + "context" "github.com/kubemq-io/kubemqctl/pkg/k8s/client" apiv1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -11,16 +12,16 @@ type serviceAccountManager struct { } func (m *serviceAccountManager) CreateOrUpdateServiceAccount(serviceAccount *apiv1.ServiceAccount) (*apiv1.ServiceAccount, bool, error) { - found, err := m.ClientSet.CoreV1().ServiceAccounts(serviceAccount.Namespace).Get(serviceAccount.Name, metav1.GetOptions{}) + found, err := m.ClientSet.CoreV1().ServiceAccounts(serviceAccount.Namespace).Get(context.Background(), serviceAccount.Name, metav1.GetOptions{}) if err == nil && found != nil { - updatedServiceAccount, err := m.ClientSet.CoreV1().ServiceAccounts(serviceAccount.Namespace).Update(serviceAccount) + updatedServiceAccount, err := m.ClientSet.CoreV1().ServiceAccounts(serviceAccount.Namespace).Update(context.Background(), serviceAccount, metav1.UpdateOptions{}) if err != nil { return nil, true, err } return updatedServiceAccount, true, nil } - newServiceAccount, err := m.ClientSet.CoreV1().ServiceAccounts(serviceAccount.Namespace).Create(serviceAccount) + newServiceAccount, err := m.ClientSet.CoreV1().ServiceAccounts(serviceAccount.Namespace).Create(context.Background(), serviceAccount, metav1.CreateOptions{}) if err != nil { return nil, false, err } @@ -28,15 +29,15 @@ func (m *serviceAccountManager) CreateOrUpdateServiceAccount(serviceAccount *api } func (m *serviceAccountManager) DeleteServiceAccount(serviceAccount *apiv1.ServiceAccount) error { - found, err := m.ClientSet.CoreV1().ServiceAccounts(serviceAccount.Namespace).Get(serviceAccount.Name, metav1.GetOptions{}) + found, err := m.ClientSet.CoreV1().ServiceAccounts(serviceAccount.Namespace).Get(context.Background(), serviceAccount.Name, metav1.GetOptions{}) if err == nil && found != nil { - return m.ClientSet.CoreV1().ServiceAccounts(serviceAccount.Namespace).Delete(serviceAccount.Name, metav1.NewDeleteOptions(0)) + return m.ClientSet.CoreV1().ServiceAccounts(serviceAccount.Namespace).Delete(context.Background(), serviceAccount.Name, metav1.DeleteOptions{}) } return nil } func (m *serviceAccountManager) GetServiceAccount(name, namespace string) (*apiv1.ServiceAccount, error) { - serviceAccount, err := m.ClientSet.CoreV1().ServiceAccounts(namespace).Get(name, metav1.GetOptions{}) + serviceAccount, err := m.ClientSet.CoreV1().ServiceAccounts(namespace).Get(context.Background(), name, metav1.GetOptions{}) if err != nil { return nil, err } diff --git a/pkg/k8s/proxy.go b/pkg/k8s/proxy.go index 9f90f7c..ddf6a7b 100644 --- a/pkg/k8s/proxy.go +++ b/pkg/k8s/proxy.go @@ -70,3 +70,54 @@ func SetProxy(ctx context.Context, opts *ProxyOptions) error { } } +func SetConcurrentProxy(ctx context.Context, opts *ProxyOptions, errCh chan error) error { + + c, err := client.NewClient(opts.KubeConfig) + if err != nil { + return err + } + if opts.Pod == "" { + opts.Namespace, opts.Pod, err = GetRunningClusterPod(c, opts.Namespace, opts.StatefulSet) + if err != nil { + return err + } + } + + stopCh := make(chan struct{}) + outCh, errOutCh := make(chan string, 1), make(chan string, 1) + err = c.ForwardPorts(opts.Namespace, opts.Pod, opts.Ports, stopCh, outCh, errOutCh) + if err != nil { + return err + } + + select { + case <-outCh: + + case errstr := <-errOutCh: + return fmt.Errorf(errstr) + + case <-time.After(30 * time.Second): + return fmt.Errorf("timeout during setting of proxy layer to kubernetes cluster") + + case <-ctx.Done(): + close(stopCh) + return nil + } + + go func() { + for { + select { + case <-outCh: + + case errstr := <-errOutCh: + errCh <- fmt.Errorf(errstr) + return + case <-ctx.Done(): + close(stopCh) + return + } + } + }() + + return nil +} diff --git a/pkg/k8s/transport.go b/pkg/k8s/transport.go index bbbad6b..ddb8fe2 100644 --- a/pkg/k8s/transport.go +++ b/pkg/k8s/transport.go @@ -120,6 +120,21 @@ func GetRunningClusterPod(client *client.Client, ns, name string) (string, strin return "", "", fmt.Errorf("no running pods available in %s/%s", ns, name) } + +func GetRunningClusterServices(client *client.Client, ns, name string) (map[string]int32, error) { + services, err := client.GetServices(ns, name) + if err != nil { + return nil, err + } + servicesMap := map[string]int32{} + for _, service := range services { + for _, a := range service.Spec.Ports { + servicesMap[service.Name] = a.Port + + } + } + return servicesMap, nil +} func GetRunningDashboardPod(client *client.Client, ns, name string) (string, string, error) { pods, err := client.GetPods(ns, name) if err != nil {