horizoncd/horizon

View on GitHub
pkg/cd/util.go

Summary

Maintainability
D
2 days
Test Coverage

Showing 11 of 11 total issues

File util.go has 588 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Copyright © 2023 Horizoncd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Severity: Minor
Found in pkg/cd/util.go - About 4 hrs to fix

    Function parsePod has 99 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func parsePod(ctx context.Context, clusterInfo *ClusterState,
    pod *corev1.Pod, events []*corev1.Event) (err error) {
    const deploymentPodTemplateHash = "pod-template-hash"
    const rolloutPodTemplateHash = "rollouts-pod-template-hash"
     
     
    Severity: Major
    Found in pkg/cd/util.go - About 2 hrs to fix

      Function parsePodLifeCycle has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
      Open

      func parsePodLifeCycle(pod corev1.Pod) []*LifeCycleItem {
      var lifeCycle []*LifeCycleItem
      // if DeletionTimestamp is set, pod is Terminating
      if pod.DeletionTimestamp != nil {
      lifeCycle = []*LifeCycleItem{
      Severity: Minor
      Found in pkg/cd/util.go - About 2 hrs to fix

      Function parsePodLifeCycle has 87 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func parsePodLifeCycle(pod corev1.Pod) []*LifeCycleItem {
      var lifeCycle []*LifeCycleItem
      // if DeletionTimestamp is set, pod is Terminating
      if pod.DeletionTimestamp != nil {
      lifeCycle = []*LifeCycleItem{
      Severity: Major
      Found in pkg/cd/util.go - About 2 hrs to fix

        Function podMapping has 56 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func podMapping(pod corev1.Pod) *ClusterPod {
        clusterPod := &ClusterPod{
        Metadata: PodMetadata{
        CreationTimestamp: pod.CreationTimestamp,
        Namespace: pod.Namespace,
        Severity: Minor
        Found in pkg/cd/util.go - About 1 hr to fix

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

          func computeRolloutStepHash(rollout *rolloutsV1alpha1.Rollout) string {
          if rollout.Spec.Strategy.BlueGreen != nil || rollout.Spec.Strategy.Canary == nil {
          return ""
          }
          rolloutStepHasher := fnv.New32a()
          Severity: Major
          Found in pkg/cd/util.go and 1 other location - About 1 hr to fix
          pkg/workload/rollout/util.go on lines 28..42

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

          if rollout.Status.CurrentStepHash == computeRolloutStepHash(rollout) &&
          rollout.Status.CurrentStepIndex != nil {
          index := float64(*rollout.Status.CurrentStepIndex)
          index = math.Min(index, float64(len(rollout.Spec.Strategy.Canary.Steps)))
          for i := 0; i < int(index); i++ {
          Severity: Major
          Found in pkg/cd/util.go and 1 other location - About 1 hr to fix
          pkg/workload/rollout/rollout.go on lines 245..254

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

          clusterPod := &ClusterPod{
          Metadata: PodMetadata{
          CreationTimestamp: pod.CreationTimestamp,
          Namespace: pod.Namespace,
          Annotations: pod.Annotations,
          Severity: Major
          Found in pkg/cd/util.go and 1 other location - About 1 hr to fix
          pkg/cd/util.go on lines 424..441

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

          clusterPod := &ClusterPod{
          Metadata: PodMetadata{
          CreationTimestamp: pod.CreationTimestamp,
          Namespace: pod.Namespace,
          Annotations: pod.Annotations,
          Severity: Major
          Found in pkg/cd/util.go and 1 other location - About 1 hr to fix
          pkg/cd/util.go on lines 72..89

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

          case e.ValueFrom.ConfigMapKeyRef != nil:
          optional := e.ValueFrom.ConfigMapKeyRef.Optional != nil && *e.ValueFrom.ConfigMapKeyRef.Optional
          env = append(env, corev1.EnvVar{
          Name: e.Name,
          Value: fmt.Sprintf("<set to the key '%s' of config map '%s'>\tOptional: %t\n",
          Severity: Minor
          Found in pkg/cd/util.go and 1 other location - About 50 mins to fix
          pkg/cd/util.go on lines 678..684

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

          case e.ValueFrom.SecretKeyRef != nil:
          optional := e.ValueFrom.SecretKeyRef.Optional != nil && *e.ValueFrom.SecretKeyRef.Optional
          env = append(env, corev1.EnvVar{
          Name: e.Name,
          Value: fmt.Sprintf("<set to the key '%s' in secret '%s'>\tOptional: %t\n",
          Severity: Minor
          Found in pkg/cd/util.go and 1 other location - About 50 mins to fix
          pkg/cd/util.go on lines 685..691
          Category
          Status