Skip to content

Commit

Permalink
chore(operator): Add workload and app version to KeptnTask (#201)
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed Oct 20, 2022
1 parent 55fa4e9 commit fde0c67
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
16 changes: 10 additions & 6 deletions operator/api/v1alpha1/keptntask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import (

// KeptnTaskSpec defines the desired state of KeptnTask
type KeptnTaskSpec struct {
Workload string `json:"workload,omitempty"`
Version string `json:"version"`
AppName string `json:"app,omitempty"`
Workload string `json:"workload"`
WorkloadVersion string `json:"workloadVersion"`
AppName string `json:"app"`
AppVersion string `json:"appVersion"`
TaskDefinition string `json:"taskDefinition"`
Context TaskContext `json:"context"`
Parameters TaskParameters `json:"parameters,omitempty"`
Expand Down Expand Up @@ -70,8 +71,9 @@ type KeptnTaskStatus struct {
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="AppName",type=string,JSONPath=`.spec.app`
// +kubebuilder:printcolumn:name="AppVersion",type=string,JSONPath=`.spec.appVersion`
// +kubebuilder:printcolumn:name="WorkloadName",type=string,JSONPath=`.spec.workload`
// +kubebuilder:printcolumn:name="Version",type=string,JSONPath=`.spec.version`
// +kubebuilder:printcolumn:name="WorkloadVersion",type=string,JSONPath=`.spec.workloadVersion`
// +kubebuilder:printcolumn:name="Job Name",type=string,JSONPath=`.status.jobName`
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status`

Expand Down Expand Up @@ -120,8 +122,9 @@ func (i *KeptnTask) IsEndTimeSet() bool {
func (i KeptnTask) GetActiveMetricsAttributes() []attribute.KeyValue {
return []attribute.KeyValue{
common.AppName.String(i.Spec.AppName),
common.AppVersion.String(i.Spec.AppVersion),
common.WorkloadName.String(i.Spec.Workload),
common.WorkloadVersion.String(i.Spec.Version),
common.WorkloadVersion.String(i.Spec.WorkloadVersion),
common.TaskName.String(i.Name),
common.TaskType.String(string(i.Spec.Type)),
}
Expand All @@ -130,8 +133,9 @@ func (i KeptnTask) GetActiveMetricsAttributes() []attribute.KeyValue {
func (i KeptnTask) GetMetricsAttributes() []attribute.KeyValue {
return []attribute.KeyValue{
common.AppName.String(i.Spec.AppName),
common.AppVersion.String(i.Spec.AppVersion),
common.WorkloadName.String(i.Spec.Workload),
common.WorkloadVersion.String(i.Spec.Version),
common.WorkloadVersion.String(i.Spec.WorkloadVersion),
common.TaskName.String(i.Name),
common.TaskType.String(string(i.Spec.Type)),
common.TaskStatus.String(string(i.Status.Status)),
Expand Down
3 changes: 2 additions & 1 deletion operator/api/v1alpha1/semconv/semconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ func AddAttributeFromAppVersion(s trace.Span, a v1alpha1.KeptnAppVersion) {

func AddAttributeFromTask(s trace.Span, t v1alpha1.KeptnTask) {
s.SetAttributes(common.AppName.String(t.Spec.AppName))
s.SetAttributes(common.AppVersion.String(t.Spec.AppVersion))
s.SetAttributes(common.WorkloadName.String(t.Spec.Workload))
s.SetAttributes(common.WorkloadVersion.String(t.Spec.Version))
s.SetAttributes(common.WorkloadVersion.String(t.Spec.WorkloadVersion))
s.SetAttributes(common.TaskName.String(t.Name))
s.SetAttributes(common.TaskType.String(string(t.Spec.Type)))
}
Expand Down
18 changes: 13 additions & 5 deletions operator/config/crd/bases/lifecycle.keptn.sh_keptntasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ spec:
- jsonPath: .spec.app
name: AppName
type: string
- jsonPath: .spec.appVersion
name: AppVersion
type: string
- jsonPath: .spec.workload
name: WorkloadName
type: string
- jsonPath: .spec.version
name: Version
- jsonPath: .spec.workloadVersion
name: WorkloadVersion
type: string
- jsonPath: .status.jobName
name: Job Name
Expand Down Expand Up @@ -53,6 +56,8 @@ spec:
properties:
app:
type: string
appVersion:
type: string
checkType:
type: string
context:
Expand Down Expand Up @@ -91,14 +96,17 @@ spec:
type: object
taskDefinition:
type: string
version:
type: string
workload:
type: string
workloadVersion:
type: string
required:
- app
- appVersion
- context
- taskDefinition
- version
- workload
- workloadVersion
type: object
status:
description: KeptnTaskStatus defines the observed state of KeptnTask
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keptnappversion
import (
"context"
"fmt"

"github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1/semconv"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
Expand Down Expand Up @@ -147,7 +148,7 @@ func (r *KeptnAppVersionReconciler) createKeptnTask(ctx context.Context, namespa
Annotations: traceContextCarrier,
},
Spec: klcv1alpha1.KeptnTaskSpec{
Version: appVersion.Spec.Version,
AppVersion: appVersion.Spec.Version,
AppName: appVersion.Spec.AppName,
TaskDefinition: taskDefinition,
Parameters: klcv1alpha1.TaskParameters{},
Expand Down
15 changes: 11 additions & 4 deletions operator/controllers/keptntask/job_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func (r *KeptnTaskReconciler) createFunctionJob(ctx context.Context, req ctrl.Re

if task.Spec.Workload != "" {
taskContext.WorkloadName = task.Spec.Workload
taskContext.WorkloadVersion = task.Spec.Version
taskContext.WorkloadVersion = task.Spec.WorkloadVersion
taskContext.ObjectType = "Workload"

} else {
taskContext.ObjectType = "Application"
taskContext.AppVersion = task.Spec.Version
taskContext.AppVersion = task.Spec.AppVersion
}
taskContext.AppName = task.Spec.AppName

Expand Down Expand Up @@ -134,10 +134,17 @@ func (r *KeptnTaskReconciler) getJob(ctx context.Context, jobName string, namesp
}

func createKeptnLabels(task klcv1alpha1.KeptnTask) map[string]string {
if task.Spec.Workload != "" {
return map[string]string{
common.AppAnnotation: task.Spec.AppName,
common.WorkloadAnnotation: task.Spec.Workload,
common.VersionAnnotation: task.Spec.WorkloadVersion,
common.TaskNameAnnotation: task.Name,
}
}
return map[string]string{
common.AppAnnotation: task.Spec.AppName,
common.WorkloadAnnotation: task.Spec.Workload,
common.VersionAnnotation: task.Spec.Version,
common.VersionAnnotation: task.Spec.AppVersion,
common.TaskNameAnnotation: task.Name,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func (r *KeptnWorkloadInstanceReconciler) createKeptnTask(ctx context.Context, n
Annotations: traceContextCarrier,
},
Spec: klcv1alpha1.KeptnTaskSpec{
Version: workloadInstance.Spec.Version,
Workload: workloadInstance.Spec.WorkloadName,
AppName: workloadInstance.Spec.AppName,
WorkloadVersion: workloadInstance.Spec.Version,
Workload: workloadInstance.Spec.WorkloadName,
TaskDefinition: taskDefinition,
Parameters: klcv1alpha1.TaskParameters{},
SecureParameters: klcv1alpha1.SecureParameters{},
Expand Down

0 comments on commit fde0c67

Please sign in to comment.