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
}
- Read upRead up
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:
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")
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
)
- Read upRead up
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
)
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
}
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:
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 {
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
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) {
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
}
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
}
Method NodeProvisioner.prepareAndInstall
has 6 return statements (exceeds 4 allowed). Open
func (provisioner *NodeProvisioner) prepareAndInstall() error {
err := provisioner.waitForCloudInitCompletion()
if err != nil {
return err
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) {
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) {
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) {
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)
}
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
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"},
- Read upRead up
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"