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

feat(operator): Refactor Task, Evaluation handling + adapt span attributes setting #287

Merged
merged 29 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a21f15e
metrics refactoring
odubajDT Oct 31, 2022
2560b5a
refactor
odubajDT Oct 31, 2022
b8464c3
refactored metrics functions
odubajDT Oct 31, 2022
07bf97d
adapt main
odubajDT Oct 31, 2022
1fae96e
refactor taskhandler
odubajDT Nov 2, 2022
5276c56
refactor spanHandler
odubajDT Nov 2, 2022
06d683a
refactor evaluationHandler
odubajDT Nov 2, 2022
9bafe1e
minor cleanup
odubajDT Nov 2, 2022
7d1ef16
Merge branch 'main' into feat-task-refactor
odubajDT Nov 7, 2022
a9375c8
fix after rebase
odubajDT Nov 7, 2022
8b30909
adapt imports after renaming
odubajDT Nov 7, 2022
fc34cfe
minor fix
odubajDT Nov 7, 2022
964bb56
refactor app and workload
odubajDT Nov 7, 2022
d79a8fa
refactor job definition
odubajDT Nov 7, 2022
05d1bbd
Merge branch 'main' into feat-task-refactor
odubajDT Nov 9, 2022
c3865bc
fixed merge problems
odubajDT Nov 9, 2022
01babef
fix
odubajDT Nov 9, 2022
a373dbb
interface covered with tests
odubajDT Nov 9, 2022
05c3719
test for workload and app
odubajDT Nov 9, 2022
51783d3
test for appversion
odubajDT Nov 9, 2022
4dff3c1
tests for workloadinstance
odubajDT Nov 9, 2022
6422dc0
tests for task and evaluation
odubajDT Nov 9, 2022
26821e4
added tests
odubajDT Nov 11, 2022
466e3ff
Merge remote-tracking branch 'origin/main' into feat-task-refactor
odubajDT Nov 11, 2022
20580ea
Merge branch 'main' into feat-task-refactor
odubajDT Nov 11, 2022
25d8f05
fixed copy-paste errors in WI
odubajDT Nov 14, 2022
d0d8c09
fix tests
odubajDT Nov 14, 2022
89b40e9
pr review
odubajDT Nov 14, 2022
0a95d74
adapt receivers
odubajDT Nov 14, 2022
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
4 changes: 4 additions & 0 deletions operator/api/v1alpha1/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ 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
Expand Down
32 changes: 32 additions & 0 deletions operator/api/v1alpha1/keptnapp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package v1alpha1
import (
"strings"

"github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1/common"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -73,3 +76,32 @@ func init() {
func (w KeptnApp) GetAppVersionName() string {
return strings.ToLower(w.Name + "-" + w.Spec.Version)
}

func (v KeptnApp) SetSpanAttributes(span trace.Span) {
attributes := v.GetSpanAttributes()
for _, attribute := range attributes {
span.SetAttributes(attribute)
}
odubajDT marked this conversation as resolved.
Show resolved Hide resolved
}

func (v KeptnApp) GenerateAppVersion(previousVersion string, traceContextCarrier map[string]string) KeptnAppVersion {
return KeptnAppVersion{
ObjectMeta: metav1.ObjectMeta{
Annotations: traceContextCarrier,
Name: v.GetAppVersionName(),
Namespace: v.Namespace,
},
Spec: KeptnAppVersionSpec{
KeptnAppSpec: v.Spec,
AppName: v.Name,
PreviousVersion: previousVersion,
},
}
}

func (v KeptnApp) GetSpanAttributes() []attribute.KeyValue {
return []attribute.KeyValue{
common.AppName.String(v.Name),
common.AppVersion.String(v.Spec.Version),
}
}
87 changes: 84 additions & 3 deletions operator/api/v1alpha1/keptnappversion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (

"github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1/common"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -221,6 +223,42 @@ func (v KeptnAppVersion) GetState() common.KeptnState {
return v.Status.Status
}

func (v KeptnAppVersion) GetPreDeploymentTasks() []string {
return v.Spec.PreDeploymentTasks
}

func (v KeptnAppVersion) GetPostDeploymentTasks() []string {
return v.Spec.PostDeploymentTasks
}

func (v KeptnAppVersion) GetPreDeploymentTaskStatus() []TaskStatus {
return v.Status.PreDeploymentTaskStatus
}

func (v KeptnAppVersion) GetPostDeploymentTaskStatus() []TaskStatus {
return v.Status.PostDeploymentTaskStatus
}

func (v KeptnAppVersion) GetPreDeploymentEvaluations() []string {
return v.Spec.PreDeploymentEvaluations
}

func (v KeptnAppVersion) GetPostDeploymentEvaluations() []string {
return v.Spec.PostDeploymentEvaluations
}

func (v KeptnAppVersion) GetPreDeploymentEvaluationTaskStatus() []EvaluationStatus {
return v.Status.PreDeploymentEvaluationTaskStatus
}

func (v KeptnAppVersion) GetPostDeploymentEvaluationTaskStatus() []EvaluationStatus {
return v.Status.PostDeploymentEvaluationTaskStatus
}

func (v KeptnAppVersion) GetAppName() string {
return v.Spec.AppName
}

func (v KeptnAppVersion) GetPreviousVersion() string {
return v.Spec.PreviousVersion
}
Expand Down Expand Up @@ -262,7 +300,51 @@ func (v KeptnAppVersion) GetVersion() string {
}

func (v KeptnAppVersion) GetSpanKey(phase string) string {
return fmt.Sprintf("%s.%s.%s.%s", v.Spec.TraceId, v.Spec.AppName, v.Spec.Version, phase)
return fmt.Sprintf("%s.%s.%s.%s", v.Spec.TraceId["traceparent"], v.Spec.AppName, v.Spec.Version, phase)
}

func (v KeptnAppVersion) GenerateTask(traceContextCarrier propagation.MapCarrier, taskDefinition string, checkType common.CheckType) KeptnTask {
return KeptnTask{
ObjectMeta: metav1.ObjectMeta{
Name: common.GenerateTaskName(checkType, taskDefinition),
Namespace: v.Namespace,
Annotations: traceContextCarrier,
},
Spec: KeptnTaskSpec{
AppVersion: v.GetVersion(),
AppName: v.GetParentName(),
TaskDefinition: taskDefinition,
Parameters: TaskParameters{},
SecureParameters: SecureParameters{},
Type: checkType,
},
}
}

func (v KeptnAppVersion) SetSpanAttributes(span trace.Span) {
attributes := v.GetSpanAttributes()
for _, attribute := range attributes {
span.SetAttributes(attribute)
}
}

func (v KeptnAppVersion) GenerateEvaluation(traceContextCarrier propagation.MapCarrier, evaluationDefinition string, checkType common.CheckType) KeptnEvaluation {
return KeptnEvaluation{
ObjectMeta: metav1.ObjectMeta{
Name: common.GenerateEvaluationName(checkType, evaluationDefinition),
Namespace: v.Namespace,
Annotations: traceContextCarrier,
},
Spec: KeptnEvaluationSpec{
AppVersion: v.Spec.Version,
AppName: v.Spec.AppName,
EvaluationDefinition: evaluationDefinition,
Type: checkType,
RetryInterval: metav1.Duration{
Duration: 5 * time.Second,
},
},
}
}

func (v KeptnAppVersion) GetSpanName(phase string) string {
Expand All @@ -273,7 +355,6 @@ func (v KeptnAppVersion) GetSpanAttributes() []attribute.KeyValue {
return []attribute.KeyValue{
common.AppName.String(v.Spec.AppName),
common.AppVersion.String(v.Spec.Version),
common.WorkloadVersion.String(v.Spec.PreviousVersion),
common.WorkloadVersion.String(v.Namespace),
common.AppNamespace.String(v.Namespace),
}
}
22 changes: 22 additions & 0 deletions operator/api/v1alpha1/keptnevaluation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1/common"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -144,6 +145,27 @@ func (e *KeptnEvaluation) AddEvaluationStatus(objective Objective) {
evaluationStatusItem := EvaluationStatusItem{
Status: common.StatePending,
}
if e.Status.EvaluationStatus == nil {
e.Status.EvaluationStatus = make(map[string]EvaluationStatusItem)
}
e.Status.EvaluationStatus[objective.Name] = evaluationStatusItem

}

func (t KeptnEvaluation) SetSpanAttributes(span trace.Span) {
attributes := t.GetSpanAttributes()
for _, attribute := range attributes {
span.SetAttributes(attribute)
}
}

func (t KeptnEvaluation) GetSpanAttributes() []attribute.KeyValue {
return []attribute.KeyValue{
common.AppName.String(t.Spec.AppName),
common.AppVersion.String(t.Spec.AppVersion),
common.WorkloadName.String(t.Spec.Workload),
common.WorkloadVersion.String(t.Spec.WorkloadVersion),
common.EvaluationName.String(t.Name),
common.EvaluationType.String(string(t.Spec.Type)),
}
}
35 changes: 35 additions & 0 deletions operator/api/v1alpha1/keptntask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1/common"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -141,3 +142,37 @@ func (i KeptnTask) GetMetricsAttributes() []attribute.KeyValue {
common.TaskStatus.String(string(i.Status.Status)),
}
}

func (t KeptnTask) SetSpanAttributes(span trace.Span) {
attributes := t.GetSpanAttributes()
for _, attribute := range attributes {
span.SetAttributes(attribute)
}
}

func (t KeptnTask) CreateKeptnLabels() map[string]string {
if t.Spec.Workload != "" {
return map[string]string{
common.AppAnnotation: t.Spec.AppName,
common.WorkloadAnnotation: t.Spec.Workload,
common.VersionAnnotation: t.Spec.WorkloadVersion,
common.TaskNameAnnotation: t.Name,
}
}
return map[string]string{
common.AppAnnotation: t.Spec.AppName,
common.VersionAnnotation: t.Spec.AppVersion,
common.TaskNameAnnotation: t.Name,
}
}

func (t KeptnTask) GetSpanAttributes() []attribute.KeyValue {
return []attribute.KeyValue{
common.AppName.String(t.Spec.AppName),
common.AppVersion.String(t.Spec.AppVersion),
common.WorkloadName.String(t.Spec.Workload),
common.WorkloadVersion.String(t.Spec.WorkloadVersion),
common.TaskName.String(t.Name),
common.TaskType.String(string(t.Spec.Type)),
}
}
33 changes: 33 additions & 0 deletions operator/api/v1alpha1/keptnworkload_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package v1alpha1
import (
"strings"

"github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1/common"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
Expand Down Expand Up @@ -77,3 +80,33 @@ func init() {
func (w KeptnWorkload) GetWorkloadInstanceName() string {
return strings.ToLower(w.Name + "-" + w.Spec.Version)
}

func (v KeptnWorkload) SetSpanAttributes(span trace.Span) {
attributes := v.GetSpanAttributes()
for _, attribute := range attributes {
span.SetAttributes(attribute)
}
}

func (v KeptnWorkload) GenerateWorkloadInstance(previousVersion string, traceContextCarrier map[string]string) KeptnWorkloadInstance {
return KeptnWorkloadInstance{
ObjectMeta: metav1.ObjectMeta{
Annotations: traceContextCarrier,
Name: v.GetWorkloadInstanceName(),
Namespace: v.Namespace,
},
Spec: KeptnWorkloadInstanceSpec{
KeptnWorkloadSpec: v.Spec,
WorkloadName: v.Name,
PreviousVersion: previousVersion,
},
}
}

func (i KeptnWorkload) GetSpanAttributes() []attribute.KeyValue {
odubajDT marked this conversation as resolved.
Show resolved Hide resolved
return []attribute.KeyValue{
common.AppName.String(i.Spec.AppName),
common.WorkloadName.String(i.Name),
common.WorkloadVersion.String(i.Spec.Version),
}
}
Loading