portainer/portainer

View on GitHub
app/kubernetes/helpers/application/index.js

Summary

Maintainability
F
4 days
Test Coverage

File index.js has 485 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import _ from 'lodash-es';
import { KubernetesPortMapping, KubernetesPortMappingPort } from 'Kubernetes/models/port/models';
import { KubernetesService, KubernetesServicePort, KubernetesServiceTypes } from 'Kubernetes/models/service/models';
import { KubernetesConfigurationKinds } from 'Kubernetes/models/configuration/models';
import {
Severity: Minor
Found in app/kubernetes/helpers/application/index.js - About 7 hrs to fix

    Function generateEnvOrVolumesFromConfigurations has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static generateEnvOrVolumesFromConfigurations(app, configMaps, secrets) {
        const configurations = [...configMaps, ...secrets];
        let finalEnv = [];
        let finalVolumes = [];
        let finalMounts = [];
    Severity: Major
    Found in app/kubernetes/helpers/application/index.js - About 2 hrs to fix

      KubernetesApplicationHelper has 21 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class KubernetesApplicationHelper {
        /* #region  UTILITY FUNCTIONS */
        static isExternalApplication(application) {
          return !application.ApplicationOwner;
        }
      Severity: Minor
      Found in app/kubernetes/helpers/application/index.js - About 2 hrs to fix

        Function generateConfigurationFormValuesFromEnvAndVolumes has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          static generateConfigurationFormValuesFromEnvAndVolumes(env, volumes, configurations, configurationKind) {
            const filterCondition = configurationKind === KubernetesConfigurationKinds.CONFIGMAP ? 'valueFrom.configMapKeyRef.name' : 'valueFrom.secretKeyRef.name';
            const finalRes = _.flatMap(configurations, (cfg) => {
              const cfgEnv = _.filter(env, [filterCondition, cfg.Name]);
              const cfgVol = volumes.filter((volume) => volume.configurationName === cfg.Name && volume.configurationType === configurationKind);
        Severity: Major
        Found in app/kubernetes/helpers/application/index.js - About 2 hrs to fix

          Function finalRes has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              const finalRes = _.flatMap(configurations, (cfg) => {
                const cfgEnv = _.filter(env, [filterCondition, cfg.Name]);
                const cfgVol = volumes.filter((volume) => volume.configurationName === cfg.Name && volume.configurationType === configurationKind);
                if (!cfgEnv.length && !cfgVol.length) {
                  return;
          Severity: Minor
          Found in app/kubernetes/helpers/application/index.js - About 1 hr to fix

            Function generateAffinityFromPlacements has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

              static generateAffinityFromPlacements(app, formValues) {
                if (formValues.DeploymentType === KubernetesApplicationDeploymentTypes.Replicated) {
                  const placements = formValues.Placements;
                  const res = new KubernetesPodNodeAffinityPayload();
                  let expressions = _.map(placements, (p) => {
            Severity: Minor
            Found in app/kubernetes/helpers/application/index.js - 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 generateServicesFormValuesFromServices has 44 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              static generateServicesFormValuesFromServices(app, ingresses) {
                let services = [];
                if (app.Services) {
                  app.Services.forEach(function (service) {
                    //skip generate formValues if service = headless service ( clusterIp === "None" )
            Severity: Minor
            Found in app/kubernetes/helpers/application/index.js - About 1 hr to fix

              Function generateAffinityFromPlacements has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                static generateAffinityFromPlacements(app, formValues) {
                  if (formValues.DeploymentType === KubernetesApplicationDeploymentTypes.Replicated) {
                    const placements = formValues.Placements;
                    const res = new KubernetesPodNodeAffinityPayload();
                    let expressions = _.map(placements, (p) => {
              Severity: Minor
              Found in app/kubernetes/helpers/application/index.js - About 1 hr to fix

                Function getHelmApplications has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  static getHelmApplications(applications) {
                    // filter out all the applications that are managed by helm
                    // to identify the helm managed applications, we need to check if the applications pod labels include
                    // `app.kubernetes.io/instance` and `app.kubernetes.io/managed-by` = `helm`
                    const helmManagedApps = applications.filter(
                Severity: Minor
                Found in app/kubernetes/helpers/application/index.js - About 1 hr to fix

                  Function generatePlacementsFormValuesFromAffinity has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    static generatePlacementsFormValuesFromAffinity(formValues, podAffinity) {
                      let placements = formValues.Placements;
                      let type = formValues.PlacementType;
                      const affinity = podAffinity.nodeAffinity;
                      if (affinity && affinity.requiredDuringSchedulingIgnoredDuringExecution) {
                  Severity: Minor
                  Found in app/kubernetes/helpers/application/index.js - About 1 hr to fix

                    Function generatePublishedPortsFormValuesFromPublishedPorts has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      static generatePublishedPortsFormValuesFromPublishedPorts(serviceType, publishedPorts, ingress) {
                        const generatePort = (port, rule) => {
                          const res = new KubernetesApplicationPublishedPortFormValue();
                          res.IsNew = false;
                          if (rule) {
                    Severity: Minor
                    Found in app/kubernetes/helpers/application/index.js - About 1 hr to fix

                      Function generatePublishedPortsFormValuesFromPublishedPorts has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                        static generatePublishedPortsFormValuesFromPublishedPorts(serviceType, publishedPorts, ingress) {
                          const generatePort = (port, rule) => {
                            const res = new KubernetesApplicationPublishedPortFormValue();
                            res.IsNew = false;
                            if (rule) {
                      Severity: Minor
                      Found in app/kubernetes/helpers/application/index.js - 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

                      Function portMappingsFromApplications has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        static portMappingsFromApplications(applications) {
                          const res = _.reduce(
                            applications,
                            (acc, app) => {
                              if (app.PublishedPorts.length > 0) {
                      Severity: Minor
                      Found in app/kubernetes/helpers/application/index.js - About 25 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

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

                            container.ConfigurationVolumes = _.without(
                              _.map(app.ConfigurationVolumes, (cv) => {
                                if (cv.rootMountPath && _.includes(_.map(container.VolumeMounts, 'mountPath'), cv.rootMountPath)) {
                                  return cv;
                                }
                      Severity: Major
                      Found in app/kubernetes/helpers/application/index.js and 1 other location - About 2 hrs to fix
                      app/kubernetes/helpers/application/index.js on lines 50..57

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 83.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

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

                            container.PersistedFolders = _.without(
                              _.map(app.PersistedFolders, (pf) => {
                                if (pf.MountPath && _.includes(_.map(container.VolumeMounts, 'mountPath'), pf.MountPath)) {
                                  return pf;
                                }
                      Severity: Major
                      Found in app/kubernetes/helpers/application/index.js and 1 other location - About 2 hrs to fix
                      app/kubernetes/helpers/application/index.js on lines 59..66

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 83.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

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

                              _.forEach(term.preference.matchExpressions, (exp) => {
                                const placement = new KubernetesApplicationPlacementFormValue();
                                placement.label = exp.key;
                                placement.value = exp.values[0];
                                placement.isNew = false;
                      Severity: Major
                      Found in app/kubernetes/helpers/application/index.js and 1 other location - About 1 hr to fix
                      app/kubernetes/helpers/application/index.js on lines 438..444

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 73.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

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

                              _.forEach(term.matchExpressions, (exp) => {
                                const placement = new KubernetesApplicationPlacementFormValue();
                                placement.label = exp.key;
                                placement.value = exp.values[0];
                                placement.isNew = false;
                      Severity: Major
                      Found in app/kubernetes/helpers/application/index.js and 1 other location - About 1 hr to fix
                      app/kubernetes/helpers/application/index.js on lines 449..455

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 73.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

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

                                if (isBasic) {
                                  res.valueFrom.configMapKeyRef.name = config.selectedConfiguration.metadata.name;
                                  res.valueFrom.configMapKeyRef.key = item.key;
                                } else {
                      Severity: Major
                      Found in app/kubernetes/helpers/application/index.js and 1 other location - About 1 hr to fix
                      app/kubernetes/helpers/application/index.js on lines 232..235

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 57.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

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

                                } else {
                                  res.valueFrom.secretKeyRef.name = config.selectedConfiguration.metadata.name;
                                  res.valueFrom.secretKeyRef.key = item.key;
                                }
                      Severity: Major
                      Found in app/kubernetes/helpers/application/index.js and 1 other location - About 1 hr to fix
                      app/kubernetes/helpers/application/index.js on lines 229..232

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 57.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

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

                                } else {
                                  res.valueFrom.secretKeyRef.name = config.selectedConfiguration.metadata.name;
                                  res.valueFrom.secretKeyRef.key = item;
                                }
                      Severity: Minor
                      Found in app/kubernetes/helpers/application/index.js and 1 other location - About 55 mins to fix
                      app/kubernetes/helpers/application/index.js on lines 215..218

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 53.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

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

                                if (isBasic) {
                                  res.valueFrom.configMapKeyRef.name = config.selectedConfiguration.metadata.name;
                                  res.valueFrom.configMapKeyRef.key = item;
                                } else {
                      Severity: Minor
                      Found in app/kubernetes/helpers/application/index.js and 1 other location - About 55 mins to fix
                      app/kubernetes/helpers/application/index.js on lines 218..221

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 53.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      There are no issues that match your filters.

                      Category
                      Status