🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■
    pkg/service/grade.go
    skipped 33 lines
    34 34   Host: cluster.SpecConf.LbKubeApiserverIp,
    35 35   Port: cluster.SpecConf.KubeApiServerPort,
    36 36   Token: cluster.Secret.KubernetesToken,
     37 + 
     38 + AuthenticationMode: cluster.SpecConf.AuthenticationMode,
     39 + CertDataStr: cluster.Secret.CertDataStr,
     40 + KeyDataStr: cluster.Secret.KeyDataStr,
     41 + ConfigContent: cluster.Secret.ConfigContent,
    37 42   })
    38 43   if err != nil {
    39 44   return nil, err
    skipped 7 lines
  • ■ ■ ■ ■ ■
    pkg/util/polaris/grade.go
    skipped 2 lines
    3 3  import (
    4 4   "context"
    5 5   "fmt"
     6 + 
     7 + "github.com/KubeOperator/KubeOperator/pkg/constant"
    6 8   "github.com/KubeOperator/KubeOperator/pkg/dto"
     9 + "github.com/KubeOperator/KubeOperator/pkg/util/cluster"
    7 10   conf "github.com/fairwindsops/polaris/pkg/config"
    8 11   "github.com/fairwindsops/polaris/pkg/kube"
    9 12   "github.com/fairwindsops/polaris/pkg/validator"
    10 13   "k8s.io/client-go/dynamic"
    11 14   "k8s.io/client-go/kubernetes"
    12 15   "k8s.io/client-go/rest"
     16 + "k8s.io/client-go/tools/clientcmd"
     17 + "k8s.io/client-go/tools/clientcmd/api"
    13 18  )
    14 19   
    15 20  type Config struct {
    16 21   Host string
    17 22   Token string
    18 23   Port int
     24 + 
     25 + AuthenticationMode string
     26 + CertDataStr string
     27 + KeyDataStr string
     28 + ConfigContent string
    19 29  }
    20 30   
    21 31  func NewResourceProvider(c *Config) (*kube.ResourceProvider, error) {
    22  - 
    23  - kubeConf := &rest.Config{
    24  - Host: fmt.Sprintf("%s:%d", c.Host, c.Port),
    25  - BearerToken: c.Token,
    26  - TLSClientConfig: rest.TLSClientConfig{
    27  - Insecure: true,
    28  - },
     32 + var connConf rest.Config
     33 + connConf.Insecure = true
     34 + switch c.AuthenticationMode {
     35 + case constant.AuthenticationModeBearer:
     36 + connConf.Host = fmt.Sprintf("%s:%d", c.Host, c.Port)
     37 + connConf.BearerToken = c.Token
     38 + case constant.AuthenticationModeCertificate:
     39 + connConf.CertData = []byte(c.CertDataStr)
     40 + connConf.KeyData = []byte(c.KeyDataStr)
     41 + case constant.AuthenticationModeConfigFile:
     42 + apiConfig, err := cluster.PauseConfigApi(&c.ConfigContent)
     43 + if err != nil {
     44 + return nil, err
     45 + }
     46 + getter := func() (*api.Config, error) {
     47 + return apiConfig, nil
     48 + }
     49 + itemConfig, err := clientcmd.BuildConfigFromKubeconfigGetter("", getter)
     50 + if err != nil {
     51 + return nil, err
     52 + }
     53 + connConf = *itemConfig
    29 54   }
    30  - api, err := kubernetes.NewForConfig(kubeConf)
     55 + 
     56 + api, err := kubernetes.NewForConfig(&connConf)
    31 57   if err != nil {
    32 58   return nil, err
    33 59   }
    34  - dynamicInterface, err := dynamic.NewForConfig(kubeConf)
     60 + dynamicInterface, err := dynamic.NewForConfig(&connConf)
    35 61   if err != nil {
    36 62   return nil, err
    37 63   }
    skipped 174 lines
Please wait...
Page is in error, reload to recover