alibaba/kt-connect

View on GitHub

Showing 109 of 109 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func getServiceIps(k kubernetes.Interface, namespace string) []string {
serviceList, err := k.CoreV1().Services("").List(context.TODO(), metav1.ListOptions{
Limit: 1000,
TimeoutSeconds: &apiTimeout,
})
Severity: Major
Found in pkg/kt/service/cluster/cidr.go and 1 other location - About 3 hrs to fix
pkg/kt/service/cluster/cidr.go on lines 165..189

Similar blocks of code found in 2 locations. Consider refactoring.
Open

func getPodIps(k kubernetes.Interface, namespace string) []string {
podList, err := k.CoreV1().Pods("").List(context.TODO(), metav1.ListOptions{
Limit: 1000,
TimeoutSeconds: &apiTimeout,
})
Severity: Major
Found in pkg/kt/service/cluster/cidr.go and 1 other location - About 3 hrs to fix
pkg/kt/service/cluster/cidr.go on lines 191..215

Similar blocks of code found in 3 locations. Consider refactoring.
Open

func NewPreviewCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "preview",
Short: "Expose a local service to kubernetes cluster",
PreRunE: func(cmd *cobra.Command, args []string) error {
Severity: Major
Found in pkg/kt/command/preview.go and 2 other locations - About 3 hrs to fix
pkg/kt/command/exchange.go on lines 15..36
pkg/kt/command/mesh.go on lines 15..36

Similar blocks of code found in 3 locations. Consider refactoring.
Open

func NewExchangeCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "exchange",
Short: "Redirect all requests of specified kubernetes service to local",
PreRunE: func(cmd *cobra.Command, args []string) error {
Severity: Major
Found in pkg/kt/command/exchange.go and 2 other locations - About 3 hrs to fix
pkg/kt/command/mesh.go on lines 15..36
pkg/kt/command/preview.go on lines 16..37

Similar blocks of code found in 3 locations. Consider refactoring.
Open

func NewMeshCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "mesh",
Short: "Redirect marked requests of specified kubernetes service to local",
PreRunE: func(cmd *cobra.Command, args []string) error {
Severity: Major
Found in pkg/kt/command/mesh.go and 2 other locations - About 3 hrs to fix
pkg/kt/command/exchange.go on lines 15..36
pkg/kt/command/preview.go on lines 16..37

Function cleanShadowPodAndConfigMap has a Cognitive Complexity of 38 (exceeds 20 allowed). Consider refactoring.
Open

func cleanShadowPodAndConfigMap() {
var err error
if opt.Store.Shadow != "" {
shouldDelWithShared := false
if opt.Get().Connect.ShareShadow {
Severity: Minor
Found in pkg/kt/command/general/teardown.go - About 3 hrs to fix

Function GlobalFlags has 100 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func GlobalFlags() []OptionConfig {
flags := []OptionConfig{
{
Target: "Namespace",
Alias: "n",
Severity: Major
Found in pkg/kt/command/options/global.go - About 3 hrs to fix

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

    func (k *Kubernetes) UpdateDeploymentHeartBeat(name, namespace string) {
    key := "deployment_" + name
    if _, err := k.Clientset.AppsV1().Deployments(namespace).
    Patch(context.TODO(), name, types.JSONPatchType, []byte(resourceHeartbeatPatch()), metav1.PatchOptions{}); err != nil {
    if healthy, exists := LastHeartBeatStatus.Get(key); healthy || !exists {
    Severity: Major
    Found in pkg/kt/service/cluster/deployment.go and 3 other locations - About 2 hrs to fix
    pkg/kt/service/cluster/configmap.go on lines 34..48
    pkg/kt/service/cluster/pod.go on lines 75..89
    pkg/kt/service/cluster/service.go on lines 76..90

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

    func (k *Kubernetes) UpdateServiceHeartBeat(name, namespace string) {
    key := "service_" + name
    if _, err := k.Clientset.CoreV1().Services(namespace).
    Patch(context.TODO(), name, types.JSONPatchType, []byte(resourceHeartbeatPatch()), metav1.PatchOptions{}); err != nil {
    if healthy, exists := LastHeartBeatStatus.Get(key); healthy || !exists {
    Severity: Major
    Found in pkg/kt/service/cluster/service.go and 3 other locations - About 2 hrs to fix
    pkg/kt/service/cluster/configmap.go on lines 34..48
    pkg/kt/service/cluster/deployment.go on lines 88..102
    pkg/kt/service/cluster/pod.go on lines 75..89

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

    func (k *Kubernetes) UpdateConfigMapHeartBeat(name, namespace string) {
    key := "configmap_" + name
    if _, err := k.Clientset.CoreV1().ConfigMaps(namespace).
    Patch(context.TODO(), name, types.JSONPatchType, []byte(resourceHeartbeatPatch()), metav1.PatchOptions{}); err != nil {
    if healthy, exists := LastHeartBeatStatus.Get(key); healthy || !exists {
    Severity: Major
    Found in pkg/kt/service/cluster/configmap.go and 3 other locations - About 2 hrs to fix
    pkg/kt/service/cluster/deployment.go on lines 88..102
    pkg/kt/service/cluster/pod.go on lines 75..89
    pkg/kt/service/cluster/service.go on lines 76..90

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

    func (k *Kubernetes) UpdatePodHeartBeat(name, namespace string) {
    key := "pod_" + name
    if _, err := k.Clientset.CoreV1().Pods(namespace).
    Patch(context.TODO(), name, types.JSONPatchType, []byte(resourceHeartbeatPatch()), metav1.PatchOptions{}); err != nil {
    if healthy, exists := LastHeartBeatStatus.Get(key); healthy || !exists {
    Severity: Major
    Found in pkg/kt/service/cluster/pod.go and 3 other locations - About 2 hrs to fix
    pkg/kt/service/cluster/configmap.go on lines 34..48
    pkg/kt/service/cluster/deployment.go on lines 88..102
    pkg/kt/service/cluster/service.go on lines 76..90

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func NewCleanCommand() *cobra.Command {
    cmd := &cobra.Command{
    Use: "clean",
    Short: "Delete unavailing resources created by kt from kubernetes cluster",
    PreRunE: func(cmd *cobra.Command, args []string) error {
    Severity: Major
    Found in pkg/kt/command/clean.go and 1 other location - About 2 hrs to fix
    pkg/kt/command/birdseye.go on lines 15..34

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func NewBirdseyeCommand() *cobra.Command {
    cmd := &cobra.Command{
    Use: "birdseye",
    Short: "Show summary of services status in cluster",
    PreRunE: func(cmd *cobra.Command, args []string) error {
    Severity: Major
    Found in pkg/kt/command/birdseye.go and 1 other location - About 2 hrs to fix
    pkg/kt/command/clean.go on lines 14..33

    Function ConnectFlags has 86 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func ConnectFlags() []OptionConfig {
    flags := []OptionConfig{
    {
    Target: "Mode",
    DefaultValue: util.ConnectModeTun2Socks,
    Severity: Major
    Found in pkg/kt/command/options/connect.go - About 2 hrs to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      func (k *Kubernetes) IncreasePodRef(name string, namespace string) error {
      pod, err := k.GetPod(name, namespace)
      if err != nil {
      return err
      }
      Severity: Major
      Found in pkg/kt/service/cluster/pod.go and 1 other location - About 2 hrs to fix
      pkg/kt/service/cluster/deployment.go on lines 48..64

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      func (k *Kubernetes) IncreaseDeploymentRef(name string, namespace string) error {
      app, err := k.GetDeployment(name, namespace)
      if err != nil {
      return err
      }
      Severity: Major
      Found in pkg/kt/service/cluster/deployment.go and 1 other location - About 2 hrs to fix
      pkg/kt/service/cluster/pod.go on lines 135..151

      Function mergeOptions has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
      Open

      func mergeOptions(opt *DaemonOptions, data []byte) {
      config := make(map[string]map[string]string)
      err := yaml.Unmarshal(data, &config)
      if err != nil {
      log.Warn().Msgf("Invalid config content, skipping ...")
      Severity: Minor
      Found in pkg/kt/command/options/options.go - About 1 hr to fix

      Method Kubernetes.ClusterCidr has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
      Open

      func (k *Kubernetes) ClusterCidr(namespace string) ([]string, []string) {
      ips := getServiceIps(k.Clientset, namespace)
      log.Debug().Msgf("Found %d IPs", len(ips))
      svcCidr := calculateMinimalIpRange(ips)
      log.Debug().Msgf("Service ips are: %v", ips)
      Severity: Minor
      Found in pkg/kt/service/cluster/cidr.go - About 1 hr to fix

      Function getServiceHosts has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
      Open

      func getServiceHosts(namespace string, shortDomainOnly bool) (map[string]string, []string) {
      hosts := make(map[string]string)
      podNames := make([]string, 0)
      services, err := cluster.Ins().GetAllServiceInNamespace(namespace)
      if err == nil {
      Severity: Minor
      Found in pkg/kt/command/connect/common.go - About 1 hr to fix

      Function UpdateServiceSelector has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
      Open

      func UpdateServiceSelector(svcName, namespace string, selector map[string]string) error {
      svc, err := cluster.Ins().GetService(svcName, namespace)
      if err != nil {
      return err
      }
      Severity: Minor
      Found in pkg/kt/command/general/resource.go - About 1 hr to fix
      Severity
      Category
      Status
      Source
      Language