cloudfoundry-incubator/eirini

View on GitHub

Showing 59 of 59 total issues

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

func (c *PodDisruptionBudget) Get(ctx context.Context, namespace, name string) (*policyv1beta1.PodDisruptionBudget, error) {
    ctx, cancel := context.WithTimeout(ctx, k8sTimeout)
    defer cancel()

    return c.clientSet.PolicyV1beta1().PodDisruptionBudgets(namespace).Get(ctx, name, metav1.GetOptions{})
Severity: Minor
Found in k8s/client/pod_disruption_budget_client.go and 2 other locations - About 40 mins to fix
k8s/client/secret_client.go on lines 23..28
k8s/client/statefulset_client.go on lines 36..41

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 108.

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 3 locations. Consider refactoring.
Open

func (c *StatefulSet) Get(ctx context.Context, namespace, name string) (*appsv1.StatefulSet, error) {
    ctx, cancel := context.WithTimeout(ctx, k8sTimeout)
    defer cancel()

    return c.clientSet.AppsV1().StatefulSets(namespace).Get(ctx, name, metav1.GetOptions{})
Severity: Minor
Found in k8s/client/statefulset_client.go and 2 other locations - About 40 mins to fix
k8s/client/pod_disruption_budget_client.go on lines 24..29
k8s/client/secret_client.go on lines 23..28

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 108.

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

Function do has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

func do(ctx context.Context, client *http.Client, method string, uri string, body interface{}) error {
Severity: Minor
Found in k8s/utils/http.go - About 35 mins to fix

    Function NewGetter has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        logger lager.Logger,
        statefulSetGetter StatefulSetByLRPIdentifierGetter,
        podGetter PodGetter,
        eventGetter EventGetter,
        statefulsetToLrpConverter StatefulSetToLRPConverter,
    Severity: Minor
    Found in k8s/stset/get.go - About 35 mins to fix

      Method Executor.migrateObjects has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      func (e *Executor) migrateObjects(ctx context.Context, logger lager.Logger, objects []runtime.Object, objectType ObjectType, setAnnotationFn func(context.Context, runtime.Object, int) error) error {
      Severity: Minor
      Found in migrations/executor.go - About 35 mins to fix

        Function NewDesirer has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            logger lager.Logger,
            secrets SecretsClient,
            statefulSets StatefulSetCreator,
            lrpToStatefulSetConverter LRPToStatefulSetConverter,
            podDisruptionBudgetCreator PodDisruptionBudgetUpdater,
        Severity: Minor
        Found in k8s/stset/desire.go - About 35 mins to fix

          Method Executor.Migrate has 5 return statements (exceeds 4 allowed).
          Open

          func (e *Executor) Migrate(ctx context.Context, logger lager.Logger) error {
              logger.Info("migration-start")
              defer logger.Info("migration-end")
          
              if err := e.verifySequenceIDs(); err != nil {
          Severity: Major
          Found in migrations/executor.go - About 35 mins to fix

            Method AdoptPDB.Apply has 5 return statements (exceeds 4 allowed).
            Open

            func (m AdoptPDB) Apply(ctx context.Context, obj runtime.Object) error {
                stSet, ok := obj.(*appsv1.StatefulSet)
                if !ok {
                    return fmt.Errorf("expected *v1.StatefulSet, got: %T", obj)
                }
            Severity: Major
            Found in migrations/adopt_pdb.go - About 35 mins to fix

              Function Fetch has 5 return statements (exceeds 4 allowed).
              Open

              func Fetch(dockerRef string, sysCtx types.SystemContext) (*v1.ImageConfig, error) {
                  ref, err := docker.ParseReference(dockerRef)
                  if err != nil {
                      return nil, errors.Wrap(err, "failed to parse docker reference")
                  }
              Severity: Major
              Found in stager/docker/fetcher.go - About 35 mins to fix

                Method InstanceIndexEnvInjector.Handle has 5 return statements (exceeds 4 allowed).
                Open

                func (i *InstanceIndexEnvInjector) Handle(ctx context.Context, req admission.Request) admission.Response {
                    logger := i.logger.Session("handle-webhook-request")
                
                    if req.Operation != admissionv1.Create {
                        return admission.Allowed("pod was already created")
                Severity: Major
                Found in k8s/webhook/instance_index_injector.go - About 35 mins to fix

                  Function do has 5 return statements (exceeds 4 allowed).
                  Open

                  func do(ctx context.Context, client *http.Client, method string, uri string, body interface{}) error {
                      bodyJSON, err := json.Marshal(body)
                      if err != nil {
                          return errors.Wrap(err, "cannot marshal body")
                      }
                  Severity: Major
                  Found in k8s/utils/http.go - About 35 mins to fix

                    Method Stopper.StopInstance has 5 return statements (exceeds 4 allowed).
                    Open

                    func (s *Stopper) StopInstance(ctx context.Context, identifier api.LRPIdentifier, index uint) error {
                        logger := s.logger.Session("stopInstance", lager.Data{"guid": identifier.GUID, "version": identifier.Version, "index": index})
                        statefulset, err := s.getStatefulSet(ctx, identifier)
                    
                        if errors.Is(err, eirini.ErrNotFound) {
                    Severity: Major
                    Found in k8s/stset/stop.go - About 35 mins to fix

                      Method Desirer.Desire has 5 return statements (exceeds 4 allowed).
                      Open

                      func (d *Desirer) Desire(ctx context.Context, namespace string, task *api.Task, opts ...shared.Option) error {
                          logger := d.logger.Session("desire-task", lager.Data{"guid": task.GUID, "name": task.Name, "namespace": namespace})
                      
                          var (
                              err                   error
                      Severity: Major
                      Found in k8s/jobs/desire.go - About 35 mins to fix

                        Method RetryableJSONClient.Post has 5 return statements (exceeds 4 allowed).
                        Open

                        func (c *RetryableJSONClient) Post(ctx context.Context, url string, data interface{}) error {
                            jsonBody, err := json.Marshal(data)
                            if err != nil {
                                return errors.Wrap(err, "failed to marshal json body")
                            }
                        Severity: Major
                        Found in util/retryable_json_client.go - About 35 mins to fix

                          Method Updater.update has 5 return statements (exceeds 4 allowed).
                          Open

                          func (u *Updater) update(ctx context.Context, lrp *api.LRP) error {
                              logger := u.logger.Session("update", lager.Data{"guid": lrp.GUID, "version": lrp.Version})
                          
                              statefulSet, err := u.getStatefulSet(ctx, api.LRPIdentifier{GUID: lrp.GUID, Version: lrp.Version})
                              if err != nil {
                          Severity: Major
                          Found in k8s/stset/update.go - About 35 mins to fix

                            Method Getter.GetInstances has 5 return statements (exceeds 4 allowed).
                            Open

                            func (g *Getter) GetInstances(ctx context.Context, identifier api.LRPIdentifier) ([]*api.Instance, error) {
                                logger := g.logger.Session("get-instance", lager.Data{"guid": identifier.GUID, "version": identifier.Version})
                                if _, err := g.getLRP(ctx, logger, identifier); errors.Is(err, eirini.ErrNotFound) {
                                    return nil, err
                                }
                            Severity: Major
                            Found in k8s/stset/get.go - About 35 mins to fix

                              Method Executor.migrateObjects has 5 return statements (exceeds 4 allowed).
                              Open

                              func (e *Executor) migrateObjects(ctx context.Context, logger lager.Logger, objects []runtime.Object, objectType ObjectType, setAnnotationFn func(context.Context, runtime.Object, int) error) error {
                                  logger.Info("start")
                                  defer logger.Info("end")
                              
                                  for i := range objects {
                              Severity: Major
                              Found in migrations/executor.go - About 35 mins to fix

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

                                func (c *PodDisruptionBudget) Delete(ctx context.Context, namespace string, name string) error {
                                    ctx, cancel := context.WithTimeout(ctx, k8sTimeout)
                                    defer cancel()
                                
                                    return c.clientSet.PolicyV1beta1().PodDisruptionBudgets(namespace).Delete(ctx, name, metav1.DeleteOptions{})
                                Severity: Minor
                                Found in k8s/client/pod_disruption_budget_client.go and 1 other location - About 35 mins to fix
                                k8s/client/secret_client.go on lines 44..49

                                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 103.

                                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

                                func (c *Secret) Delete(ctx context.Context, namespace string, name string) error {
                                    ctx, cancel := context.WithTimeout(ctx, k8sTimeout)
                                    defer cancel()
                                
                                    return c.clientSet.CoreV1().Secrets(namespace).Delete(ctx, name, metav1.DeleteOptions{})
                                Severity: Minor
                                Found in k8s/client/secret_client.go and 1 other location - About 35 mins to fix
                                k8s/client/pod_disruption_budget_client.go on lines 38..43

                                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 103.

                                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

                                Severity
                                Category
                                Status
                                Source
                                Language