xetys/hetzner-kube

View on GitHub

Showing 19 of 34 total issues

Method Manager.InstallWorkers has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.
Open

func (manager *Manager) InstallWorkers(nodes []Node) error {
    node, err := manager.clusterProvider.GetMasterNode()
    if err != nil {
        return err
    }
Severity: Minor
Found in pkg/clustermanager/cluster.go - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

func TestGenerateMasterConfiguration(t *testing.T) {
    expectedConf := `apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: v1.19.2
networking:
Severity: Major
Found in pkg/clustermanager/configs_test.go - About 2 hrs to fix

    Function RunClusterCreate has 67 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func RunClusterCreate(cmd *cobra.Command, args []string) {
        workerCount, _ := cmd.Flags().GetInt("worker-count")
        masterCount, _ := cmd.Flags().GetInt("master-count")
        etcdCount := 0
        haEnabled, _ := cmd.Flags().GetBool("ha-enabled")
    Severity: Minor
    Found in cmd/cluster_create.go - About 1 hr to fix

      Function validateClusterCreateFlags has a Cognitive Complexity of 28 (exceeds 20 allowed). Consider refactoring.
      Open

      func validateClusterCreateFlags(cmd *cobra.Command, args []string) error {
      
          var (
              sshKey, masterServerType, workerServerType, cloudInit string
          )
      Severity: Minor
      Found in cmd/cluster_create.go - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function validateClusterCreateFlags has 12 return statements (exceeds 4 allowed).
      Open

      func validateClusterCreateFlags(cmd *cobra.Command, args []string) error {
      
          var (
              sshKey, masterServerType, workerServerType, cloudInit string
          )
      Severity: Major
      Found in cmd/cluster_create.go - About 1 hr to fix

        Method Manager.InstallWorkers has 54 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (manager *Manager) InstallWorkers(nodes []Node) error {
            node, err := manager.clusterProvider.GetMasterNode()
            if err != nil {
                return err
            }
        Severity: Minor
        Found in pkg/clustermanager/cluster.go - About 1 hr to fix

          Function GenerateMasterConfiguration has 53 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func GenerateMasterConfiguration(masterNode Node, masterNodes []Node, etcdNodes []Node, kubernetesVersion string) string {
              masterConfigTpl := `apiVersion: kubeadm.k8s.io/v1beta1
          kind: ClusterConfiguration
          kubernetesVersion: v%s
          networking:
          Severity: Minor
          Found in pkg/clustermanager/configs.go - About 1 hr to fix

            Function NewClusterManager has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            func NewClusterManager(provider ClusterProvider, nodeCommunicator NodeCommunicator, eventService EventService, name string, haEnabled bool, isolatedEtcd bool, cloudInitFile string) *Manager {
            Severity: Major
            Found in pkg/clustermanager/cluster.go - About 50 mins to fix

              Method Provider.runCreateServer has 7 return statements (exceeds 4 allowed).
              Confirmed

              func (provider *Provider) runCreateServer(opts *hcloud.ServerCreateOpts) (*hcloud.ServerCreateResult, error) {
                  log.Printf("creating server '%s'...", opts.Name)
                  server, _, err := provider.client.Server.GetByName(provider.context, opts.Name)
                  if err != nil {
                      return nil, err
              Severity: Major
              Found in pkg/hetzner/hetzner_provider.go - About 45 mins to fix

                Method Manager.installMasterStep has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                func (manager *Manager) installMasterStep(node Node, numMaster int, masterNode Node, commands []NodeCommand, trueChan chan bool, errChan chan error) {
                Severity: Minor
                Found in pkg/clustermanager/cluster.go - About 45 mins to fix

                  Function validateFlags has 7 return statements (exceeds 4 allowed).
                  Open

                  func validateFlags(cmd *cobra.Command, args []string) error {
                      if err := AppConf.assertActiveContext(); err != nil {
                          return err
                      }
                  
                  
                  Severity: Major
                  Found in cmd/ssh_key_add.go - About 45 mins to fix

                    Function validateAddonSubCommand has 6 return statements (exceeds 4 allowed).
                    Open

                    func validateAddonSubCommand(cmd *cobra.Command, args []string) error {
                        name, err := cmd.Flags().GetString("name")
                        if err != nil {
                            return nil
                        }
                    Severity: Major
                    Found in cmd/cluster_addon.go - About 40 mins to fix

                      Method NodeProvisioner.prepareAndInstall has 6 return statements (exceeds 4 allowed).
                      Open

                      func (provisioner *NodeProvisioner) prepareAndInstall() error {
                      
                          err := provisioner.waitForCloudInitCompletion()
                          if err != nil {
                              return err
                      Severity: Major
                      Found in pkg/clustermanager/provision_node.go - About 40 mins to fix

                        Method Provider.CreateWorkerNodes has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        func (provider *Provider) CreateWorkerNodes(sshKeyName string, workerServerType string, datacenters []string, count int, offset int) ([]clustermanager.Node, error) {
                        Severity: Minor
                        Found in pkg/hetzner/hetzner_provider.go - About 35 mins to fix

                          Method Provider.CreateNodes has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          func (provider *Provider) CreateNodes(suffix string, template clustermanager.Node, datacenters []string, count int, offset int) ([]clustermanager.Node, error) {
                          Severity: Minor
                          Found in pkg/hetzner/hetzner_provider.go - About 35 mins to fix

                            Method Provider.CreateMasterNodes has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                            func (provider *Provider) CreateMasterNodes(sshKeyName string, masterServerType string, datacenters []string, count int, isEtcd bool) ([]clustermanager.Node, error) {
                            Severity: Minor
                            Found in pkg/hetzner/hetzner_provider.go - About 35 mins to fix

                              Method SSHCommunicator.CapturePassphrase has 5 return statements (exceeds 4 allowed).
                              Open

                              func (sshComm *SSHCommunicator) CapturePassphrase(sshKeyName string) error {
                                  index, privateKey := sshComm.findPrivateKeyByName(sshKeyName)
                                  if index < 0 {
                                      return fmt.Errorf("could not find SSH key '%s'", sshKeyName)
                                  }
                              Severity: Major
                              Found in pkg/clustermanager/ssh_communicator.go - About 35 mins to fix

                                Method Provider.CreateNodes has 5 return statements (exceeds 4 allowed).
                                Open

                                func (provider *Provider) CreateNodes(suffix string, template clustermanager.Node, datacenters []string, count int, offset int) ([]clustermanager.Node, error) {
                                    sshKey, _, err := provider.client.SSHKey.Get(provider.context, template.SSHKeyName)
                                
                                    if err != nil {
                                        return nil, err
                                Severity: Major
                                Found in pkg/hetzner/hetzner_provider.go - About 35 mins to fix

                                  Method Manager.InstallMasters has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                                  Open

                                  func (manager *Manager) InstallMasters(keepCerts KeepCerts) error {
                                      commands := []NodeCommand{
                                          {"sysctl settings", `printf '# Strict RPF mode as required by canal/Calico\nnet.ipv4.conf.default.rp_filter=1\nnet.ipv4.conf.all.rp_filter=1\n' >/etc/sysctl.d/50-canal-calico.conf && sysctl --load=/etc/sysctl.d/50-canal-calico.conf`},
                                          {"kubeadm init", "kubectl version > /dev/null &> /dev/null || kubeadm init --ignore-preflight-errors=all --config /root/master-config.yaml"},
                                          {"configure kubectl", "rm -rf $HOME/.kube && mkdir -p $HOME/.kube && cp -i /etc/kubernetes/admin.conf $HOME/.kube/config && chown $(id -u):$(id -g) $HOME/.kube/config"},
                                  Severity: Minor
                                  Found in pkg/clustermanager/cluster.go - About 35 mins to fix

                                  Cognitive Complexity

                                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                                  A method's cognitive complexity is based on a few simple rules:

                                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                                  • Code is considered more complex for each "break in the linear flow of the code"
                                  • Code is considered more complex when "flow breaking structures are nested"

                                  Further reading

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language