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): Introduce KeptnEvaluation Controller + CRD #168

Merged
merged 29 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
54db85f
feat(operator): Introduce KeptnEvaluation Controller + CRD
odubajDT Oct 14, 2022
f4fa0e2
additional fields to CRD
odubajDT Oct 14, 2022
108affc
controller in separate dir
odubajDT Oct 14, 2022
0ba247f
prepare structures
odubajDT Oct 14, 2022
31560fe
set up everything except logic
odubajDT Oct 14, 2022
7e18a8a
first draft without evaluation logic
odubajDT Oct 14, 2022
1c627ca
chore: init evaluation status
RealAnna Oct 14, 2022
798adf8
chore: note TODOS
RealAnna Oct 14, 2022
a15569e
chore: fixed namespaced resources
RealAnna Oct 14, 2022
c1052fd
chore: fixed queryEvaluation to always return false for now
RealAnna Oct 14, 2022
363c2a6
chore: added rebac and generated resources
RealAnna Oct 14, 2022
c99d8fc
chore: added rebac and generated resources
RealAnna Oct 14, 2022
c609780
chore: fixed copypasta
RealAnna Oct 14, 2022
03ad539
feat: added few events ordered controller
RealAnna Oct 14, 2022
2d42716
feat: added few events ordered controller
RealAnna Oct 14, 2022
3884cb4
implement timeFrame and retryCount functionality
odubajDT Oct 17, 2022
c928f1b
polish duration
odubajDT Oct 17, 2022
c194d39
feat: added print app version and status
RealAnna Oct 17, 2022
9dea1c5
feat: added default timeframe
RealAnna Oct 17, 2022
4600961
feat: added default timeframe
RealAnna Oct 17, 2022
fe030eb
feat: added default timeframe
RealAnna Oct 17, 2022
fff6e4d
feat: added default timeframe
RealAnna Oct 17, 2022
4fc2322
feat: added default timeframe
RealAnna Oct 17, 2022
6b5adf3
feat: added endtime in case of failure, change status to map in evalu…
RealAnna Oct 17, 2022
a3672f5
feat: added endtime in case of failure, change status to map in evalu…
RealAnna Oct 17, 2022
5c79b6d
feat: added endtime in case of failure, change status to map in evalu…
RealAnna Oct 17, 2022
72952cc
rename analysis to evaluation
odubajDT Oct 17, 2022
1da4179
go mod tidy
odubajDT Oct 17, 2022
ea4a33e
make generate
odubajDT Oct 17, 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
9 changes: 9 additions & 0 deletions operator/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,13 @@ resources:
kind: KeptnEvaluationProvider
path: github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: keptn.sh
group: lifecycle
kind: KeptnEvaluation
path: github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1
version: v1alpha1
version: "3"
12 changes: 10 additions & 2 deletions operator/api/v1alpha1/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ 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 PreDeploymentAnalysisAnnotation = "keptn.sh/pre-deployment-analysis"
const PostDeploymentAnalysisAnnotation = "keptn.sh/post-deployment-analysis"
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-evaluation"
const PostDeploymentEvaluationAnnotation = "keptn.sh/post-deployment-evaluation"
const TaskNameAnnotation = "keptn.sh/task-name"
const NamespaceEnabledAnnotation = "keptn.sh/lifecycle-controller"

Expand Down Expand Up @@ -107,6 +107,8 @@ type CheckType string

const PreDeploymentCheckType CheckType = "pre"
const PostDeploymentCheckType CheckType = "post"
const PreEvaluationCheckType CheckType = "pre"
const PostEvaluationCheckType CheckType = "post"

type KeptnMeters struct {
TaskCount syncint64.Counter
Expand All @@ -118,6 +120,9 @@ type KeptnMeters struct {
AppCount syncint64.Counter
AppDuration syncfloat64.Histogram
AppActive syncint64.UpDownCounter
EvaluationCount syncint64.Counter
EvaluationDuration syncfloat64.Histogram
EvaluationActive syncint64.UpDownCounter
}

const (
Expand All @@ -132,6 +137,9 @@ const (
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 {
Expand Down
4 changes: 4 additions & 0 deletions operator/api/v1alpha1/common/phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ type KeptnPhaseType struct {
var (
PhaseWorkloadPreDeployment = KeptnPhaseType{LongName: "Workload Pre-Deployment", ShortName: "WorkloadPreDeploy"}
PhaseWorkloadPostDeployment = KeptnPhaseType{LongName: "Workload Post-Deployment", ShortName: "WorkloadPostDeploy"}
PhaseWorkloadPreEvaluation = KeptnPhaseType{LongName: "Workload Pre-Evaluation", ShortName: "WorkloadPreEvaluation"}
PhaseWorkloadPostEvaluation = KeptnPhaseType{LongName: "Workload Post-Evaluation", ShortName: "WorkloadPostEvaluation"}
PhaseWorkloadDeployment = KeptnPhaseType{LongName: "Workload Deployment", ShortName: "WorkloadDeploy"}
PhaseAppPreDeployment = KeptnPhaseType{LongName: "App Pre-Deployment", ShortName: "AppPreDeploy"}
PhaseAppPostDeployment = KeptnPhaseType{LongName: "App Post-Deployment", ShortName: "AppPostDeploy"}
PhaseAppPreEvaluation = KeptnPhaseType{LongName: "App Pre-Evaluation", ShortName: "AppPreEvaluation"}
PhaseAppPostEvaluation = KeptnPhaseType{LongName: "App Post-Evaluation", ShortName: "AppPostEvaluation"}
PhaseAppDeployment = KeptnPhaseType{LongName: "App Deployment", ShortName: "AppDeploy"}
)
12 changes: 6 additions & 6 deletions operator/api/v1alpha1/keptnapp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import (

// KeptnAppSpec defines the desired state of KeptnApp
type KeptnAppSpec struct {
Version string `json:"version"`
Workloads []KeptnWorkloadRef `json:"workloads,omitempty"`
PreDeploymentTasks []string `json:"preDeploymentTasks,omitempty"`
PostDeploymentTasks []string `json:"postDeploymentTasks,omitempty"`
PreDeploymentAnalysis []string `json:"preDeploymentAnalysis,omitempty"`
PostDeploymentAnalysis []string `json:"postDeploymentAnalysis,omitempty"`
Version string `json:"version"`
Workloads []KeptnWorkloadRef `json:"workloads,omitempty"`
PreDeploymentTasks []string `json:"preDeploymentTasks,omitempty"`
PostDeploymentTasks []string `json:"postDeploymentTasks,omitempty"`
PreDeploymentEvaluation []string `json:"preDeploymentEvaluation,omitempty"`
PostDeploymentEvaluation []string `json:"postDeploymentEvaluation,omitempty"`
}

// KeptnAppStatus defines the observed state of KeptnApp
Expand Down
145 changes: 145 additions & 0 deletions operator/api/v1alpha1/keptnevaluation_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*
Copyright 2022.

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

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"time"

"github.com/keptn-sandbox/lifecycle-controller/operator/api/v1alpha1/common"
"go.opentelemetry.io/otel/attribute"
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.

// KeptnEvaluationSpec defines the desired state of KeptnEvaluation
type KeptnEvaluationSpec struct {
Workload string `json:"workload,omitempty"`
WorkloadVersion string `json:"workloadVersion"`
AppName string `json:"app,omitempty"`
AppVersion string `json:"appVersion,omitempty"`
EvaluationDefinition string `json:"evaluationDefinition"`
// +kubebuilder:default:=10
Retries int `json:"retries,omitempty"`
// +optional
// +kubebuilder:default:="5s"
// +kubebuilder:validation:Pattern="^0|([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
// +kubebuilder:validation:Type:=string
// +optional
RetryInterval metav1.Duration `json:"retryInterval,omitempty"`
FailAction string `json:"failAction,omitempty"`
Type common.CheckType `json:"checkType,omitempty"`
}

// KeptnEvaluationStatus defines the observed state of KeptnEvaluation
type KeptnEvaluationStatus struct {
// +kubebuilder:default:=0
RetryCount int `json:"retryCount"`
EvaluationStatus map[string]EvaluationStatusItem `json:"evaluationStatus"`
// +kubebuilder:default:=Pending
OverallStatus common.KeptnState `json:"overallStatus"`
StartTime metav1.Time `json:"startTime,omitempty"`
EndTime metav1.Time `json:"endTime,omitempty"`
}

type EvaluationStatusItem struct {
Value string `json:"value"`
Status common.KeptnState `json:"status"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:path=keptnevaluations,shortName=ke
//+kubebuilder:printcolumn:name="AppName",type=string,JSONPath=`.spec.appName`
// +kubebuilder:printcolumn:name="AppVersion",type=string,JSONPath=`.spec.appVersion`
// +kubebuilder:printcolumn:name="EvaluationStatus",type=string,JSONPath=`.status.evaluationStatus`
// +kubebuilder:printcolumn:name="OverallStatus",type=string,JSONPath=`.status.overallStatus`

// KeptnEvaluation is the Schema for the keptnevaluations API
type KeptnEvaluation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KeptnEvaluationSpec `json:"spec,omitempty"`
Status KeptnEvaluationStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// KeptnEvaluationList contains a list of KeptnEvaluation
type KeptnEvaluationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []KeptnEvaluation `json:"items"`
}

func init() {
SchemeBuilder.Register(&KeptnEvaluation{}, &KeptnEvaluationList{})
}

func (i *KeptnEvaluation) SetStartTime() {
if i.Status.StartTime.IsZero() {
i.Status.StartTime = metav1.NewTime(time.Now().UTC())
}
}

func (i *KeptnEvaluation) SetEndTime() {
if i.Status.EndTime.IsZero() {
i.Status.EndTime = metav1.NewTime(time.Now().UTC())
}
}

func (i *KeptnEvaluation) IsStartTimeSet() bool {
return !i.Status.StartTime.IsZero()
}

func (i *KeptnEvaluation) IsEndTimeSet() bool {
return !i.Status.EndTime.IsZero()
}

func (i KeptnEvaluation) 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.WorkloadVersion),
common.EvaluationName.String(i.Name),
common.EvaluationType.String(string(i.Spec.Type)),
}
}

func (i KeptnEvaluation) 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.WorkloadVersion),
common.EvaluationName.String(i.Name),
common.EvaluationType.String(string(i.Spec.Type)),
common.EvaluationStatus.String(string(i.Status.OverallStatus)),
}
}

func (e *KeptnEvaluation) AddEvaluationStatus(objective Objective) {

evaluationStatusItem := EvaluationStatusItem{
Status: common.StatePending,
}
e.Status.EvaluationStatus[objective.Name] = evaluationStatusItem

}
4 changes: 2 additions & 2 deletions operator/api/v1alpha1/keptntask_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (

// KeptnTaskSpec defines the desired state of KeptnTask
type KeptnTaskSpec struct {
Workload string `json:"workload,omitempty"` //TODO make autofill logic
Workload string `json:"workload,omitempty"`
Version string `json:"version"`
AppName string `json:"app,omitempty"` //TODO make autofill logic
AppName string `json:"app,omitempty"`
TaskDefinition string `json:"taskDefinition"`
Context TaskContext `json:"context"`
Parameters TaskParameters `json:"parameters,omitempty"`
Expand Down
14 changes: 7 additions & 7 deletions operator/api/v1alpha1/keptnworkload_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (

// KeptnWorkloadSpec defines the desired state of KeptnWorkload
type KeptnWorkloadSpec struct {
AppName string `json:"app"`
Version string `json:"version"`
PreDeploymentTasks []string `json:"preDeploymentTasks,omitempty"`
PostDeploymentTasks []string `json:"postDeploymentTasks,omitempty"`
PreDeploymentAnalysis []string `json:"preDeploymentAnalysis,omitempty"`
PostDeploymentAnalysis []string `json:"postDeploymentAnalysis,omitempty"`
ResourceReference ResourceReference `json:"resourceReference"`
AppName string `json:"app"`
Version string `json:"version"`
PreDeploymentTasks []string `json:"preDeploymentTasks,omitempty"`
PostDeploymentTasks []string `json:"postDeploymentTasks,omitempty"`
PreDeploymentEvaluation []string `json:"preDeploymentEvaluation,omitempty"`
PostDeploymentEvaluation []string `json:"postDeploymentEvaluation,omitempty"`
ResourceReference ResourceReference `json:"resourceReference"`
}

// KeptnWorkloadStatus defines the observed state of KeptnWorkload
Expand Down
9 changes: 9 additions & 0 deletions operator/api/v1alpha1/semconv/semconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ func AddAttributeFromTask(s trace.Span, t v1alpha1.KeptnTask) {
s.SetAttributes(common.TaskType.String(string(t.Spec.Type)))
}

func AddAttributeFromEvaluation(s trace.Span, t v1alpha1.KeptnEvaluation) {
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.WorkloadVersion))
s.SetAttributes(common.EvaluationName.String(t.Name))
s.SetAttributes(common.EvaluationType.String(string(t.Spec.Type)))
}

func AddAttributeFromAnnotations(s trace.Span, annotations map[string]string) {
s.SetAttributes(common.AppName.String(annotations[common.AppAnnotation]))
s.SetAttributes(common.WorkloadName.String(annotations[common.WorkloadAnnotation]))
Expand Down
Loading