Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lifecycle-operator): clean up unused API logic #3351

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/scripts/.helm-tests/default/result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,8 @@ spec:
MapCarrier is a TextMapCarrier that uses a map held in memory as a storage
medium for propagated key-value pairs.
type: object
description: PhaseTraceID is a map storing TraceIDs of OpenTelemetry
spans in lifecycle phases
type: object
postDeploymentEvaluationStatus:
default: Pending
Expand Down
2 changes: 2 additions & 0 deletions .github/scripts/.helm-tests/lifecycle-only/result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,8 @@ spec:
MapCarrier is a TextMapCarrier that uses a map held in memory as a storage
medium for propagated key-value pairs.
type: object
description: PhaseTraceID is a map storing TraceIDs of OpenTelemetry
spans in lifecycle phases
type: object
postDeploymentEvaluationStatus:
default: Pending
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,8 @@ spec:
MapCarrier is a TextMapCarrier that uses a map held in memory as a storage
medium for propagated key-value pairs.
type: object
description: PhaseTraceID is a map storing TraceIDs of OpenTelemetry
spans in lifecycle phases
type: object
postDeploymentEvaluationStatus:
default: Pending
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,8 @@ spec:
MapCarrier is a TextMapCarrier that uses a map held in memory as a storage
medium for propagated key-value pairs.
type: object
description: PhaseTraceID is a map storing TraceIDs of OpenTelemetry
spans in lifecycle phases
type: object
postDeploymentEvaluationStatus:
default: Pending
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/reference/api-reference/lifecycle/v1/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ _Appears in:_

_Underlying type:_ _[MapCarrier](https://pkg.go.dev/go.opentelemetry.io/otel/propagation#MapCarrier)_


PhaseTraceID is a map storing TraceIDs of OpenTelemetry spans in lifecycle phases



Expand Down
10 changes: 0 additions & 10 deletions docs/docs/reference/api-reference/lifecycle/v1alpha1/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ _Appears in:_
| `configMap` _string_ | || ✓ | |






#### HttpReference


Expand Down Expand Up @@ -499,10 +495,6 @@ _Appears in:_
| `endTime` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#time-v1-meta)_ | || ✓ | |






#### KeptnState

_Underlying type:_ _string_
Expand Down Expand Up @@ -931,8 +923,6 @@ _Appears in:_
| `secret` _string_ | || ✓ | |




#### TaskContext


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,6 @@ _Appears in:_
| `endTime` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#time-v1-meta)_ | || ✓ | |






#### KeptnState

_Underlying type:_ _string_
Expand Down Expand Up @@ -882,7 +878,7 @@ _Appears in:_

_Underlying type:_ _[MapCarrier](https://pkg.go.dev/go.opentelemetry.io/otel/propagation#MapCarrier)_


PhaseTraceID is a map storing TraceIDs of OpenTelemetry spans in lifecycle phases



Expand Down Expand Up @@ -928,8 +924,6 @@ _Appears in:_
| `secret` _string_ | || ✓ | |




#### TaskContext


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ Package v1alpha3 contains API Schema definitions for the lifecycle v1alpha3 API





#### AutomountServiceAccountTokenSpec


Expand Down Expand Up @@ -560,8 +558,6 @@ _Appears in:_
| `endTime` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#time-v1-meta)_ | EndTime represents the time at which the KeptnEvaluation finished. || ✓ | |




#### KeptnMetricReference


Expand All @@ -579,8 +575,6 @@ _Appears in:_
| `namespace` _string_ | Namespace is the namespace where the referenced KeptnMetric is located. || ✓ | |




#### KeptnState

_Underlying type:_ _string_
Expand Down Expand Up @@ -969,7 +963,7 @@ _Appears in:_

_Underlying type:_ _[MapCarrier](https://pkg.go.dev/go.opentelemetry.io/otel/propagation#MapCarrier)_


PhaseTraceID is a map storing TraceIDs of OpenTelemetry spans in lifecycle phases



Expand Down Expand Up @@ -1053,8 +1047,6 @@ _Appears in:_
| `name` _string_ | || x | |




#### TaskContext


Expand Down
10 changes: 1 addition & 9 deletions docs/docs/reference/api-reference/lifecycle/v1beta1/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ Package v1beta1 contains API Schema definitions for the lifecycle v1beta1 API gr





#### AutomountServiceAccountTokenSpec


Expand Down Expand Up @@ -679,8 +677,6 @@ _Appears in:_
| `endTime` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#time-v1-meta)_ | EndTime represents the time at which the KeptnEvaluation finished. || ✓ | |




#### KeptnMetricReference


Expand All @@ -698,8 +694,6 @@ _Appears in:_
| `namespace` _string_ | Namespace is the namespace where the referenced KeptnMetric is located. || ✓ | |




#### KeptnState

_Underlying type:_ _string_
Expand Down Expand Up @@ -1092,7 +1086,7 @@ _Appears in:_

_Underlying type:_ _[MapCarrier](https://pkg.go.dev/go.opentelemetry.io/otel/propagation#MapCarrier)_


PhaseTraceID is a map storing TraceIDs of OpenTelemetry spans in lifecycle phases



Expand Down Expand Up @@ -1176,8 +1170,6 @@ _Appears in:_
| `name` _string_ | || x | |




#### TaskContext


Expand Down
1 change: 1 addition & 0 deletions lifecycle-operator/apis/lifecycle/v1/common/phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ var (
PhaseDeprecated = KeptnPhaseType{LongName: "Deprecated", ShortName: "Deprecated"}
)

// PhaseTraceID is a map storing TraceIDs of OpenTelemetry spans in lifecycle phases
type PhaseTraceID map[string]propagation.MapCarrier

func (pid PhaseTraceID) SetPhaseTraceID(phase string, carrier propagation.MapCarrier) {
Expand Down
3 changes: 0 additions & 3 deletions lifecycle-operator/apis/lifecycle/v1/keptnapp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// KeptnAppSpec defines the desired state of KeptnApp
type KeptnAppSpec struct {
// Version defines the version of the application. For automatically created KeptnApps,
Expand Down
168 changes: 3 additions & 165 deletions lifecycle-operator/apis/lifecycle/v1alpha1/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,179 +5,17 @@ package common

import (
"errors"
"fmt"
"math/rand"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/propagation"
)

const WorkloadAnnotation = "keptn.sh/workload"
const VersionAnnotation = "keptn.sh/version"
const AppAnnotation = "keptn.sh/app"
const PreDeploymentTaskAnnotation = "keptn.sh/pre-deployment-tasks"
const PostDeploymentTaskAnnotation = "keptn.sh/post-deployment-tasks"
const K8sRecommendedWorkloadAnnotations = "app.kubernetes.io/name"
const K8sRecommendedVersionAnnotations = "app.kubernetes.io/version"
const K8sRecommendedAppAnnotations = "app.kubernetes.io/part-of"
const PreDeploymentEvaluationAnnotation = "keptn.sh/pre-deployment-evaluations"
const PostDeploymentEvaluationAnnotation = "keptn.sh/post-deployment-evaluations"
const TaskNameAnnotation = "keptn.sh/task-name"
const NamespaceEnabledAnnotation = "keptn.sh/lifecycle-toolkit"

const CreateAppTaskSpanName = "create_%s_app_task"
const CreateWorkloadTaskSpanName = "create_%s_deployment_task"
const CreateAppEvalSpanName = "create_%s_app_evaluation"
const CreateWorkloadEvalSpanName = "create_%s_deployment_evaluation"

const MaxAppNameLength = 25
const MaxWorkloadNameLength = 25
const MaxTaskNameLength = 25
const MaxVersionLength = 12

var ErrCannotCastKeptnAppVersion = errors.New("cannot cast KeptnAppVersion to v1")
var ErrCannotCastKeptnApp = errors.New("cannot cast KeptnApp to v1")

// KeptnState is a string containing current Phase state (Progressing/Succeeded/Failed/Unknown/Pending/Cancelled)
type KeptnState string

const (
StateProgressing KeptnState = "Progressing"
StateSucceeded KeptnState = "Succeeded"
StateFailed KeptnState = "Failed"
StateUnknown KeptnState = "Unknown"
StatePending KeptnState = "Pending"
StateCancelled KeptnState = "Cancelled"
)

func (k KeptnState) IsCompleted() bool {
return k == StateSucceeded || k == StateFailed || k == StateCancelled
}

func (k KeptnState) IsSucceeded() bool {
return k == StateSucceeded
}

func (k KeptnState) IsFailed() bool {
return k == StateFailed
}

func (k KeptnState) IsCancelled() bool {
return k == StateCancelled
}

func (k KeptnState) IsPending() bool {
return k == StatePending
}

type StatusSummary struct {
Total int
Progressing int
Failed int
Succeeded int
Pending int
Unknown int
Cancelled int
}

func UpdateStatusSummary(status KeptnState, summary StatusSummary) StatusSummary {
switch status {
case StateFailed:
summary.Failed++
case StateCancelled:
summary.Cancelled++
case StateSucceeded:
summary.Succeeded++
case StateProgressing:
summary.Progressing++
case StatePending, "":
summary.Pending++
case StateUnknown:
summary.Unknown++
}
return summary
}

func (s StatusSummary) GetTotalCount() int {
return s.Failed + s.Succeeded + s.Progressing + s.Pending + s.Unknown + s.Cancelled
}

func GetOverallState(s StatusSummary) KeptnState {
if s.Failed > 0 || s.Cancelled > 0 {
return StateFailed
}
if s.Progressing > 0 {
return StateProgressing
}
if s.Pending > 0 {
return StatePending
}
if s.Unknown > 0 || s.GetTotalCount() != s.Total {
return StateUnknown
}
return StateSucceeded
}

func TruncateString(s string, max int) string {
if len(s) > max {
return s[:max]
}
return s
}

type CheckType string

const PreDeploymentCheckType CheckType = "pre"
const PostDeploymentCheckType CheckType = "post"
const PreDeploymentEvaluationCheckType CheckType = "pre-eval"
const PostDeploymentEvaluationCheckType CheckType = "post-eval"

type KeptnMeters struct {
TaskCount metric.Int64Counter
TaskDuration metric.Float64Histogram
DeploymentCount metric.Int64Counter
DeploymentDuration metric.Float64Histogram
AppCount metric.Int64Counter
AppDuration metric.Float64Histogram
EvaluationCount metric.Int64Counter
EvaluationDuration metric.Float64Histogram
}

const (
AppName attribute.Key = attribute.Key("keptn.deployment.app.name")
AppVersion attribute.Key = attribute.Key("keptn.deployment.app.version")
AppNamespace attribute.Key = attribute.Key("keptn.deployment.app.namespace")
AppStatus attribute.Key = attribute.Key("keptn.deployment.app.status")
AppPreviousVersion attribute.Key = attribute.Key("keptn.deployment.app.previousversion")
WorkloadName attribute.Key = attribute.Key("keptn.deployment.workload.name")
WorkloadVersion attribute.Key = attribute.Key("keptn.deployment.workload.version")
WorkloadPreviousVersion attribute.Key = attribute.Key("keptn.deployment.workload.previousversion")
WorkloadNamespace attribute.Key = attribute.Key("keptn.deployment.workload.namespace")
WorkloadStatus attribute.Key = attribute.Key("keptn.deployment.workload.status")
TaskStatus attribute.Key = attribute.Key("keptn.deployment.task.status")
TaskName attribute.Key = attribute.Key("keptn.deployment.task.name")
TaskType attribute.Key = attribute.Key("keptn.deployment.task.type")
EvaluationStatus attribute.Key = attribute.Key("keptn.deployment.evaluation.status")
EvaluationName attribute.Key = attribute.Key("keptn.deployment.evaluation.name")
EvaluationType attribute.Key = attribute.Key("keptn.deployment.evaluation.type")
)

func GenerateTaskName(checkType CheckType, taskName string) string {
randomId := rand.Intn(99_999-10_000) + 10000
return fmt.Sprintf("%s-%s-%d", checkType, TruncateString(taskName, 32), randomId)
}

func GenerateEvaluationName(checkType CheckType, evalName string) string {
randomId := rand.Intn(99_999-10_000) + 10000
return fmt.Sprintf("%s-%s-%d", checkType, TruncateString(evalName, 27), randomId)
}

type GaugeValue struct {
Value int64
Attributes []attribute.KeyValue
}

type GaugeFloatValue struct {
Value float64
Attributes []attribute.KeyValue
}
// PhaseTraceID is a map storing TraceIDs of OpenTelemetry spans in lifecycle phases
type PhaseTraceID map[string]propagation.MapCarrier
odubajDT marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading