From 257b220a6171ccc82d1b471002b6cf773ec9bd09 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Tue, 5 Sep 2023 08:52:07 +0200 Subject: [PATCH] feat(lifecycle-operator): clean up KeptnTask API by removing duplicated attributes (#1965) Signed-off-by: Florian Bacher --- .../scripts/.helm-tests/default/result.yaml | 766 +++++++++-------- .../docs/crd-ref/lifecycle/v1alpha3/_index.md | 4 - helm/chart/templates/keptntask-crd.yaml | 767 +++++++++--------- .../v1alpha3/keptnappversion_test.go | 8 +- .../v1alpha3/keptnappversion_types.go | 8 +- .../v1alpha3/keptntask_conversion.go | 6 + .../apis/lifecycle/v1alpha3/keptntask_test.go | 16 +- .../lifecycle/v1alpha3/keptntask_types.go | 59 +- .../v1alpha3/keptnworkloadinstance_test.go | 10 +- .../v1alpha3/keptnworkloadinstance_types.go | 10 +- .../bases/lifecycle.keptn.sh_keptntasks.yaml | 28 - .../function_execution/task_schedule.yaml | 7 +- .../function_execution/task_slack.yaml | 14 +- .../common/helperfunctions_test.go | 12 +- .../lifecycle/keptntask/job_utils.go | 18 - .../lifecycle/keptntask/job_utils_test.go | 10 +- .../lifecycle/keptntask/runtime_builder.go | 2 +- .../keptntask/runtime_builder_test.go | 3 + .../test/component/task/task_test.go | 8 +- .../integration/api-conversion/01-assert.yaml | 16 + .../api-conversion/01-install.yaml | 20 + .../app-failing-pre-task-retry/00-assert.yaml | 7 +- .../00-assert.yaml | 7 +- .../00-assert.yaml | 7 +- 24 files changed, 894 insertions(+), 919 deletions(-) create mode 100644 lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_conversion.go diff --git a/.github/scripts/.helm-tests/default/result.yaml b/.github/scripts/.helm-tests/default/result.yaml index a46a56153b..5d84bab439 100644 --- a/.github/scripts/.helm-tests/default/result.yaml +++ b/.github/scripts/.helm-tests/default/result.yaml @@ -3215,421 +3215,391 @@ spec: singular: keptntask scope: Namespaced versions: - - additionalPrinterColumns: - - jsonPath: .spec.app - name: AppName - type: string - - jsonPath: .spec.appVersion - name: AppVersion - type: string - - jsonPath: .spec.workload - name: WorkloadName - type: string - - jsonPath: .spec.workloadVersion - name: WorkloadVersion - type: string - - jsonPath: .status.jobName - name: Job Name - type: string - - jsonPath: .status.status - name: Status - type: string - name: v1alpha1 - schema: - openAPIV3Schema: - description: KeptnTask is the Schema for the keptntasks API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation + - additionalPrinterColumns: + - jsonPath: .spec.app + name: AppName + type: string + - jsonPath: .spec.appVersion + name: AppVersion + type: string + - jsonPath: .spec.workload + name: WorkloadName + type: string + - jsonPath: .spec.workloadVersion + name: WorkloadVersion + type: string + - jsonPath: .status.jobName + name: Job Name + type: string + - jsonPath: .status.status + name: Status + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: KeptnTask is the Schema for the keptntasks API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: KeptnTaskSpec defines the desired state of KeptnTask - properties: - app: - type: string - appVersion: - type: string - checkType: - type: string - context: - properties: - appName: - type: string - appVersion: - type: string - objectType: - type: string - taskType: - type: string - workloadName: - type: string - workloadVersion: - type: string - required: - - appName + type: string + metadata: + type: object + spec: + description: KeptnTaskSpec defines the desired state of KeptnTask + properties: + app: + type: string + appVersion: + type: string + checkType: + type: string + context: + properties: + appName: + type: string + appVersion: + type: string + objectType: + type: string + taskType: + type: string + workloadName: + type: string + workloadVersion: + type: string + required: + - appName + - appVersion + - objectType + - taskType + - workloadName + - workloadVersion + type: object + parameters: + properties: + map: + additionalProperties: + type: string + type: object + type: object + secureParameters: + properties: + secret: + type: string + type: object + taskDefinition: + type: string + workload: + type: string + workloadVersion: + type: string + required: + - app - appVersion - - objectType - - taskType - - workloadName + - context + - taskDefinition + - workload - workloadVersion - type: object - parameters: - properties: - map: - additionalProperties: - type: string - type: object - type: object - secureParameters: - properties: - secret: - type: string - type: object - taskDefinition: - type: string - workload: - type: string - workloadVersion: - type: string - required: - - app - - appVersion - - context - - taskDefinition - - workload - - workloadVersion - type: object - status: - description: KeptnTaskStatus defines the observed state of KeptnTask - properties: - endTime: - format: date-time - type: string - jobName: - type: string - message: - type: string - startTime: - format: date-time - type: string - status: - default: Pending - type: string - type: object - type: object - served: true - storage: false - subresources: - status: {} - - additionalPrinterColumns: - - jsonPath: .spec.app - name: AppName - type: string - - jsonPath: .spec.appVersion - name: AppVersion - type: string - - jsonPath: .spec.workload - name: WorkloadName - type: string - - jsonPath: .spec.workloadVersion - name: WorkloadVersion - type: string - - jsonPath: .status.jobName - name: Job Name - type: string - - jsonPath: .status.status - name: Status - type: string - name: v1alpha2 - schema: - openAPIV3Schema: - description: KeptnTask is the Schema for the keptntasks API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation + type: object + status: + description: KeptnTaskStatus defines the observed state of KeptnTask + properties: + endTime: + format: date-time + type: string + jobName: + type: string + message: + type: string + startTime: + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: object + served: true + storage: false + subresources: + status: {} + - additionalPrinterColumns: + - jsonPath: .spec.app + name: AppName + type: string + - jsonPath: .spec.appVersion + name: AppVersion + type: string + - jsonPath: .spec.workload + name: WorkloadName + type: string + - jsonPath: .spec.workloadVersion + name: WorkloadVersion + type: string + - jsonPath: .status.jobName + name: Job Name + type: string + - jsonPath: .status.status + name: Status + type: string + name: v1alpha2 + schema: + openAPIV3Schema: + description: KeptnTask is the Schema for the keptntasks API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: KeptnTaskSpec defines the desired state of KeptnTask - properties: - app: - type: string - appVersion: - type: string - checkType: - type: string - context: - properties: - appName: - type: string - appVersion: - type: string - objectType: - type: string - taskType: - type: string - workloadName: - type: string - workloadVersion: - type: string - required: - - appName + type: string + metadata: + type: object + spec: + description: KeptnTaskSpec defines the desired state of KeptnTask + properties: + app: + type: string + appVersion: + type: string + checkType: + type: string + context: + properties: + appName: + type: string + appVersion: + type: string + objectType: + type: string + taskType: + type: string + workloadName: + type: string + workloadVersion: + type: string + required: + - appName + - appVersion + - objectType + - taskType + - workloadName + - workloadVersion + type: object + parameters: + properties: + map: + additionalProperties: + type: string + type: object + type: object + secureParameters: + properties: + secret: + type: string + type: object + taskDefinition: + type: string + workload: + type: string + workloadVersion: + type: string + required: + - app - appVersion - - objectType - - taskType - - workloadName + - context + - taskDefinition + - workload - workloadVersion - type: object - parameters: - properties: - map: - additionalProperties: - type: string - type: object - type: object - secureParameters: - properties: - secret: - type: string - type: object - taskDefinition: - type: string - workload: - type: string - workloadVersion: - type: string - required: - - app - - appVersion - - context - - taskDefinition - - workload - - workloadVersion - type: object - status: - description: KeptnTaskStatus defines the observed state of KeptnTask - properties: - endTime: - format: date-time - type: string - jobName: - type: string - message: - type: string - startTime: - format: date-time - type: string - status: - default: Pending - type: string - type: object - type: object - served: true - storage: false - subresources: - status: {} - - additionalPrinterColumns: - - jsonPath: .spec.app - name: AppName - type: string - - jsonPath: .spec.appVersion - name: AppVersion - type: string - - jsonPath: .spec.workload - name: WorkloadName - type: string - - jsonPath: .spec.workloadVersion - name: WorkloadVersion - type: string - - jsonPath: .status.jobName - name: Job Name - type: string - - jsonPath: .status.status - name: Status - type: string - name: v1alpha3 - schema: - openAPIV3Schema: - description: KeptnTask is the Schema for the keptntasks API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation + type: object + status: + description: KeptnTaskStatus defines the observed state of KeptnTask + properties: + endTime: + format: date-time + type: string + jobName: + type: string + message: + type: string + startTime: + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: object + served: true + storage: false + subresources: + status: {} + - additionalPrinterColumns: + - jsonPath: .spec.app + name: AppName + type: string + - jsonPath: .spec.appVersion + name: AppVersion + type: string + - jsonPath: .spec.workload + name: WorkloadName + type: string + - jsonPath: .spec.workloadVersion + name: WorkloadVersion + type: string + - jsonPath: .status.jobName + name: Job Name + type: string + - jsonPath: .status.status + name: Status + type: string + name: v1alpha3 + schema: + openAPIV3Schema: + description: KeptnTask is the Schema for the keptntasks API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: Spec describes the desired state of the KeptnTask. - properties: - app: - description: AppName defines the KeptnApp for which the KeptnTask is - executed. - type: string - appVersion: - description: AppVersion defines the version of the KeptnApp for which - the KeptnTask is executed. - type: string - checkType: - description: Type indicates whether the KeptnTask is part of the pre- - or postDeployment phase. - type: string - context: - description: Context contains contextual information about the task - execution. - properties: - appName: - description: AppName the name of the KeptnApp the KeptnTask is being - executed for. - type: string - appVersion: - description: AppVersion the version of the KeptnApp the KeptnTask - is being executed for. - type: string - objectType: - description: ObjectType indicates whether the KeptnTask is being - executed for a KeptnApp or KeptnWorkload. - type: string - taskType: - description: TaskType indicates whether the KeptnTask is part of - the pre- or postDeployment phase. - type: string - workloadName: - description: WorkloadName the name of the KeptnWorkload the KeptnTask - is being executed for. - type: string - workloadVersion: - description: WorkloadVersion the version of the KeptnWorkload the - KeptnTask is being executed for. - type: string - required: - - appName - - appVersion - - objectType - - taskType - - workloadName - - workloadVersion - type: object - parameters: - description: Parameters contains parameters that will be passed to the - job that executes the task. - properties: - map: - additionalProperties: + type: string + metadata: + type: object + spec: + description: Spec describes the desired state of the KeptnTask. + properties: + checkType: + description: Type indicates whether the KeptnTask is part of the pre- + or postDeployment phase. + type: string + context: + description: Context contains contextual information about the task + execution. + properties: + appName: + description: AppName the name of the KeptnApp the KeptnTask is + being executed for. type: string - description: Inline contains the parameters that will be made available - to the job executing the KeptnTask via the 'DATA' environment - variable. The 'DATA' environment variable's content will be a - json encoded string containing all properties of the map provided. - type: object - type: object - retries: - default: 10 - description: Retries indicates how many times the KeptnTask can be attempted - in the case of an error before considering the KeptnTask to be failed. - format: int32 - type: integer - secureParameters: - description: SecureParameters contains secure parameters that will be - passed to the job that executes the task. These will be stored and - accessed as secrets in the cluster. - properties: - secret: - description: Secret contains the parameters that will be made available - to the job executing the KeptnTask via the 'SECRET_DATA' environment - variable. The 'SECRET_DATA' environment variable's content will - the same as value of the 'SECRET_DATA' key of the referenced secret. - type: string - type: object - taskDefinition: - description: TaskDefinition refers to the name of the KeptnTaskDefinition - which includes the specification for the task to be performed. The - KeptnTaskDefinition can be located in the same namespace as the KeptnTask, - or in the KLT namespace. - type: string - timeout: - default: 5m - description: Timeout specifies the maximum time to wait for the task - to be completed successfully. If the task does not complete successfully - within this time frame, it will be considered to be failed. - pattern: ^0|([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$ - type: string - workload: - description: Workload defines the KeptnWorkload for which the KeptnTask - is executed. - type: string - workloadVersion: - description: WorkloadVersion defines the version of the KeptnWorkload - for which the KeptnTask is executed. - type: string - required: - - app - - appVersion - - context - - taskDefinition - - workload - - workloadVersion - type: object - status: - description: Status describes the current state of the KeptnTask. - properties: - endTime: - description: EndTime represents the time at which the KeptnTask finished. - format: date-time - type: string - jobName: - description: JobName is the name of the Job executing the Task. - type: string - message: - description: Message contains information about unexpected errors encountered - during the execution of the KeptnTask. - type: string - reason: - description: Reason contains more information about the reason for the - last transition of the Job executing the KeptnTask. - type: string - startTime: - description: StartTime represents the time at which the KeptnTask started. - format: date-time - type: string - status: - default: Pending - description: Status represents the overall state of the KeptnTask. - type: string - type: object - type: object - served: true - storage: true - subresources: - status: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] + appVersion: + description: AppVersion the version of the KeptnApp the KeptnTask + is being executed for. + type: string + objectType: + description: ObjectType indicates whether the KeptnTask is being + executed for a KeptnApp or KeptnWorkload. + type: string + taskType: + description: TaskType indicates whether the KeptnTask is part + of the pre- or postDeployment phase. + type: string + workloadName: + description: WorkloadName the name of the KeptnWorkload the KeptnTask + is being executed for. + type: string + workloadVersion: + description: WorkloadVersion the version of the KeptnWorkload + the KeptnTask is being executed for. + type: string + type: object + parameters: + description: Parameters contains parameters that will be passed to + the job that executes the task. + properties: + map: + additionalProperties: + type: string + description: Inline contains the parameters that will be made + available to the job executing the KeptnTask via the 'DATA' + environment variable. The 'DATA' environment variable's content + will be a json encoded string containing all properties of the + map provided. + type: object + type: object + retries: + default: 10 + description: Retries indicates how many times the KeptnTask can be + attempted in the case of an error before considering the KeptnTask + to be failed. + format: int32 + type: integer + secureParameters: + description: SecureParameters contains secure parameters that will + be passed to the job that executes the task. These will be stored + and accessed as secrets in the cluster. + properties: + secret: + description: Secret contains the parameters that will be made + available to the job executing the KeptnTask via the 'SECRET_DATA' + environment variable. The 'SECRET_DATA' environment variable's + content will the same as value of the 'SECRET_DATA' key of the + referenced secret. + type: string + type: object + taskDefinition: + description: TaskDefinition refers to the name of the KeptnTaskDefinition + which includes the specification for the task to be performed. The + KeptnTaskDefinition can be located in the same namespace as the + KeptnTask, or in the KLT namespace. + type: string + timeout: + default: 5m + description: Timeout specifies the maximum time to wait for the task + to be completed successfully. If the task does not complete successfully + within this time frame, it will be considered to be failed. + pattern: ^0|([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$ + type: string + required: + - taskDefinition + type: object + status: + description: Status describes the current state of the KeptnTask. + properties: + endTime: + description: EndTime represents the time at which the KeptnTask finished. + format: date-time + type: string + jobName: + description: JobName is the name of the Job executing the Task. + type: string + message: + description: Message contains information about unexpected errors + encountered during the execution of the KeptnTask. + type: string + reason: + description: Reason contains more information about the reason for + the last transition of the Job executing the KeptnTask. + type: string + startTime: + description: StartTime represents the time at which the KeptnTask + started. + format: date-time + type: string + status: + default: Pending + description: Status represents the overall state of the KeptnTask. + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} --- # Source: klt/templates/keptntaskdefinition-crd.yaml apiVersion: apiextensions.k8s.io/v1 diff --git a/docs/content/en/docs/crd-ref/lifecycle/v1alpha3/_index.md b/docs/content/en/docs/crd-ref/lifecycle/v1alpha3/_index.md index 905e43fe6e..7587d7c60c 100644 --- a/docs/content/en/docs/crd-ref/lifecycle/v1alpha3/_index.md +++ b/docs/content/en/docs/crd-ref/lifecycle/v1alpha3/_index.md @@ -676,10 +676,6 @@ _Appears in:_ | Field | Description | | --- | --- | -| `workload` _string_ | Workload defines the KeptnWorkload for which the KeptnTask is executed. | -| `workloadVersion` _string_ | WorkloadVersion defines the version of the KeptnWorkload for which the KeptnTask is executed. | -| `app` _string_ | AppName defines the KeptnApp for which the KeptnTask is executed. | -| `appVersion` _string_ | AppVersion defines the version of the KeptnApp for which the KeptnTask is executed. | | `taskDefinition` _string_ | TaskDefinition refers to the name of the KeptnTaskDefinition which includes the specification for the task to be performed. The KeptnTaskDefinition can be located in the same namespace as the KeptnTask, or in the KLT namespace. | | `context` _[TaskContext](#taskcontext)_ | Context contains contextual information about the task execution. | | `parameters` _[TaskParameters](#taskparameters)_ | Parameters contains parameters that will be passed to the job that executes the task. | diff --git a/helm/chart/templates/keptntask-crd.yaml b/helm/chart/templates/keptntask-crd.yaml index 3ecd20679e..469d519d8d 100644 --- a/helm/chart/templates/keptntask-crd.yaml +++ b/helm/chart/templates/keptntask-crd.yaml @@ -1,3 +1,4 @@ +--- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: @@ -19,418 +20,388 @@ spec: singular: keptntask scope: Namespaced versions: - - additionalPrinterColumns: - - jsonPath: .spec.app - name: AppName - type: string - - jsonPath: .spec.appVersion - name: AppVersion - type: string - - jsonPath: .spec.workload - name: WorkloadName - type: string - - jsonPath: .spec.workloadVersion - name: WorkloadVersion - type: string - - jsonPath: .status.jobName - name: Job Name - type: string - - jsonPath: .status.status - name: Status - type: string - name: v1alpha1 - schema: - openAPIV3Schema: - description: KeptnTask is the Schema for the keptntasks API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation + - additionalPrinterColumns: + - jsonPath: .spec.app + name: AppName + type: string + - jsonPath: .spec.appVersion + name: AppVersion + type: string + - jsonPath: .spec.workload + name: WorkloadName + type: string + - jsonPath: .spec.workloadVersion + name: WorkloadVersion + type: string + - jsonPath: .status.jobName + name: Job Name + type: string + - jsonPath: .status.status + name: Status + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: KeptnTask is the Schema for the keptntasks API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: KeptnTaskSpec defines the desired state of KeptnTask - properties: - app: - type: string - appVersion: - type: string - checkType: - type: string - context: - properties: - appName: - type: string - appVersion: - type: string - objectType: - type: string - taskType: - type: string - workloadName: - type: string - workloadVersion: - type: string - required: - - appName + type: string + metadata: + type: object + spec: + description: KeptnTaskSpec defines the desired state of KeptnTask + properties: + app: + type: string + appVersion: + type: string + checkType: + type: string + context: + properties: + appName: + type: string + appVersion: + type: string + objectType: + type: string + taskType: + type: string + workloadName: + type: string + workloadVersion: + type: string + required: + - appName + - appVersion + - objectType + - taskType + - workloadName + - workloadVersion + type: object + parameters: + properties: + map: + additionalProperties: + type: string + type: object + type: object + secureParameters: + properties: + secret: + type: string + type: object + taskDefinition: + type: string + workload: + type: string + workloadVersion: + type: string + required: + - app - appVersion - - objectType - - taskType - - workloadName + - context + - taskDefinition + - workload - workloadVersion - type: object - parameters: - properties: - map: - additionalProperties: - type: string - type: object - type: object - secureParameters: - properties: - secret: - type: string - type: object - taskDefinition: - type: string - workload: - type: string - workloadVersion: - type: string - required: - - app - - appVersion - - context - - taskDefinition - - workload - - workloadVersion - type: object - status: - description: KeptnTaskStatus defines the observed state of KeptnTask - properties: - endTime: - format: date-time - type: string - jobName: - type: string - message: - type: string - startTime: - format: date-time - type: string - status: - default: Pending - type: string - type: object - type: object - served: true - storage: false - subresources: - status: {} - - additionalPrinterColumns: - - jsonPath: .spec.app - name: AppName - type: string - - jsonPath: .spec.appVersion - name: AppVersion - type: string - - jsonPath: .spec.workload - name: WorkloadName - type: string - - jsonPath: .spec.workloadVersion - name: WorkloadVersion - type: string - - jsonPath: .status.jobName - name: Job Name - type: string - - jsonPath: .status.status - name: Status - type: string - name: v1alpha2 - schema: - openAPIV3Schema: - description: KeptnTask is the Schema for the keptntasks API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation + type: object + status: + description: KeptnTaskStatus defines the observed state of KeptnTask + properties: + endTime: + format: date-time + type: string + jobName: + type: string + message: + type: string + startTime: + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: object + served: true + storage: false + subresources: + status: {} + - additionalPrinterColumns: + - jsonPath: .spec.app + name: AppName + type: string + - jsonPath: .spec.appVersion + name: AppVersion + type: string + - jsonPath: .spec.workload + name: WorkloadName + type: string + - jsonPath: .spec.workloadVersion + name: WorkloadVersion + type: string + - jsonPath: .status.jobName + name: Job Name + type: string + - jsonPath: .status.status + name: Status + type: string + name: v1alpha2 + schema: + openAPIV3Schema: + description: KeptnTask is the Schema for the keptntasks API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: KeptnTaskSpec defines the desired state of KeptnTask - properties: - app: - type: string - appVersion: - type: string - checkType: - type: string - context: - properties: - appName: - type: string - appVersion: - type: string - objectType: - type: string - taskType: - type: string - workloadName: - type: string - workloadVersion: - type: string - required: - - appName + type: string + metadata: + type: object + spec: + description: KeptnTaskSpec defines the desired state of KeptnTask + properties: + app: + type: string + appVersion: + type: string + checkType: + type: string + context: + properties: + appName: + type: string + appVersion: + type: string + objectType: + type: string + taskType: + type: string + workloadName: + type: string + workloadVersion: + type: string + required: + - appName + - appVersion + - objectType + - taskType + - workloadName + - workloadVersion + type: object + parameters: + properties: + map: + additionalProperties: + type: string + type: object + type: object + secureParameters: + properties: + secret: + type: string + type: object + taskDefinition: + type: string + workload: + type: string + workloadVersion: + type: string + required: + - app - appVersion - - objectType - - taskType - - workloadName + - context + - taskDefinition + - workload - workloadVersion - type: object - parameters: - properties: - map: - additionalProperties: - type: string - type: object - type: object - secureParameters: - properties: - secret: - type: string - type: object - taskDefinition: - type: string - workload: - type: string - workloadVersion: - type: string - required: - - app - - appVersion - - context - - taskDefinition - - workload - - workloadVersion - type: object - status: - description: KeptnTaskStatus defines the observed state of KeptnTask - properties: - endTime: - format: date-time - type: string - jobName: - type: string - message: - type: string - startTime: - format: date-time - type: string - status: - default: Pending - type: string - type: object - type: object - served: true - storage: false - subresources: - status: {} - - additionalPrinterColumns: - - jsonPath: .spec.app - name: AppName - type: string - - jsonPath: .spec.appVersion - name: AppVersion - type: string - - jsonPath: .spec.workload - name: WorkloadName - type: string - - jsonPath: .spec.workloadVersion - name: WorkloadVersion - type: string - - jsonPath: .status.jobName - name: Job Name - type: string - - jsonPath: .status.status - name: Status - type: string - name: v1alpha3 - schema: - openAPIV3Schema: - description: KeptnTask is the Schema for the keptntasks API - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation + type: object + status: + description: KeptnTaskStatus defines the observed state of KeptnTask + properties: + endTime: + format: date-time + type: string + jobName: + type: string + message: + type: string + startTime: + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: object + served: true + storage: false + subresources: + status: {} + - additionalPrinterColumns: + - jsonPath: .spec.app + name: AppName + type: string + - jsonPath: .spec.appVersion + name: AppVersion + type: string + - jsonPath: .spec.workload + name: WorkloadName + type: string + - jsonPath: .spec.workloadVersion + name: WorkloadVersion + type: string + - jsonPath: .status.jobName + name: Job Name + type: string + - jsonPath: .status.status + name: Status + type: string + name: v1alpha3 + schema: + openAPIV3Schema: + description: KeptnTask is the Schema for the keptntasks API + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this + type: string + kind: + description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: Spec describes the desired state of the KeptnTask. - properties: - app: - description: AppName defines the KeptnApp for which the KeptnTask is - executed. - type: string - appVersion: - description: AppVersion defines the version of the KeptnApp for which - the KeptnTask is executed. - type: string - checkType: - description: Type indicates whether the KeptnTask is part of the pre- - or postDeployment phase. - type: string - context: - description: Context contains contextual information about the task - execution. - properties: - appName: - description: AppName the name of the KeptnApp the KeptnTask is being - executed for. - type: string - appVersion: - description: AppVersion the version of the KeptnApp the KeptnTask - is being executed for. - type: string - objectType: - description: ObjectType indicates whether the KeptnTask is being - executed for a KeptnApp or KeptnWorkload. - type: string - taskType: - description: TaskType indicates whether the KeptnTask is part of - the pre- or postDeployment phase. - type: string - workloadName: - description: WorkloadName the name of the KeptnWorkload the KeptnTask - is being executed for. - type: string - workloadVersion: - description: WorkloadVersion the version of the KeptnWorkload the - KeptnTask is being executed for. - type: string - required: - - appName - - appVersion - - objectType - - taskType - - workloadName - - workloadVersion - type: object - parameters: - description: Parameters contains parameters that will be passed to the - job that executes the task. - properties: - map: - additionalProperties: + type: string + metadata: + type: object + spec: + description: Spec describes the desired state of the KeptnTask. + properties: + checkType: + description: Type indicates whether the KeptnTask is part of the pre- + or postDeployment phase. + type: string + context: + description: Context contains contextual information about the task + execution. + properties: + appName: + description: AppName the name of the KeptnApp the KeptnTask is + being executed for. + type: string + appVersion: + description: AppVersion the version of the KeptnApp the KeptnTask + is being executed for. + type: string + objectType: + description: ObjectType indicates whether the KeptnTask is being + executed for a KeptnApp or KeptnWorkload. + type: string + taskType: + description: TaskType indicates whether the KeptnTask is part + of the pre- or postDeployment phase. + type: string + workloadName: + description: WorkloadName the name of the KeptnWorkload the KeptnTask + is being executed for. + type: string + workloadVersion: + description: WorkloadVersion the version of the KeptnWorkload + the KeptnTask is being executed for. + type: string + type: object + parameters: + description: Parameters contains parameters that will be passed to + the job that executes the task. + properties: + map: + additionalProperties: + type: string + description: Inline contains the parameters that will be made + available to the job executing the KeptnTask via the 'DATA' + environment variable. The 'DATA' environment variable's content + will be a json encoded string containing all properties of the + map provided. + type: object + type: object + retries: + default: 10 + description: Retries indicates how many times the KeptnTask can be + attempted in the case of an error before considering the KeptnTask + to be failed. + format: int32 + type: integer + secureParameters: + description: SecureParameters contains secure parameters that will + be passed to the job that executes the task. These will be stored + and accessed as secrets in the cluster. + properties: + secret: + description: Secret contains the parameters that will be made + available to the job executing the KeptnTask via the 'SECRET_DATA' + environment variable. The 'SECRET_DATA' environment variable's + content will the same as value of the 'SECRET_DATA' key of the + referenced secret. type: string - description: Inline contains the parameters that will be made available - to the job executing the KeptnTask via the 'DATA' environment - variable. The 'DATA' environment variable's content will be a - json encoded string containing all properties of the map provided. - type: object - type: object - retries: - default: 10 - description: Retries indicates how many times the KeptnTask can be attempted - in the case of an error before considering the KeptnTask to be failed. - format: int32 - type: integer - secureParameters: - description: SecureParameters contains secure parameters that will be - passed to the job that executes the task. These will be stored and - accessed as secrets in the cluster. - properties: - secret: - description: Secret contains the parameters that will be made available - to the job executing the KeptnTask via the 'SECRET_DATA' environment - variable. The 'SECRET_DATA' environment variable's content will - the same as value of the 'SECRET_DATA' key of the referenced secret. - type: string - type: object - taskDefinition: - description: TaskDefinition refers to the name of the KeptnTaskDefinition - which includes the specification for the task to be performed. The - KeptnTaskDefinition can be located in the same namespace as the KeptnTask, - or in the KLT namespace. - type: string - timeout: - default: 5m - description: Timeout specifies the maximum time to wait for the task - to be completed successfully. If the task does not complete successfully - within this time frame, it will be considered to be failed. - pattern: ^0|([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$ - type: string - workload: - description: Workload defines the KeptnWorkload for which the KeptnTask - is executed. - type: string - workloadVersion: - description: WorkloadVersion defines the version of the KeptnWorkload - for which the KeptnTask is executed. - type: string - required: - - app - - appVersion - - context - - taskDefinition - - workload - - workloadVersion - type: object - status: - description: Status describes the current state of the KeptnTask. - properties: - endTime: - description: EndTime represents the time at which the KeptnTask finished. - format: date-time - type: string - jobName: - description: JobName is the name of the Job executing the Task. - type: string - message: - description: Message contains information about unexpected errors encountered - during the execution of the KeptnTask. - type: string - reason: - description: Reason contains more information about the reason for the - last transition of the Job executing the KeptnTask. - type: string - startTime: - description: StartTime represents the time at which the KeptnTask started. - format: date-time - type: string - status: - default: Pending - description: Status represents the overall state of the KeptnTask. - type: string - type: object - type: object - served: true - storage: true - subresources: - status: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] \ No newline at end of file + type: object + taskDefinition: + description: TaskDefinition refers to the name of the KeptnTaskDefinition + which includes the specification for the task to be performed. The + KeptnTaskDefinition can be located in the same namespace as the + KeptnTask, or in the KLT namespace. + type: string + timeout: + default: 5m + description: Timeout specifies the maximum time to wait for the task + to be completed successfully. If the task does not complete successfully + within this time frame, it will be considered to be failed. + pattern: ^0|([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$ + type: string + required: + - taskDefinition + type: object + status: + description: Status describes the current state of the KeptnTask. + properties: + endTime: + description: EndTime represents the time at which the KeptnTask finished. + format: date-time + type: string + jobName: + description: JobName is the name of the Job executing the Task. + type: string + message: + description: Message contains information about unexpected errors + encountered during the execution of the KeptnTask. + type: string + reason: + description: Reason contains more information about the reason for + the last transition of the Job executing the KeptnTask. + type: string + startTime: + description: StartTime represents the time at which the KeptnTask + started. + format: date-time + type: string + status: + default: Pending + description: Status represents the overall state of the KeptnTask. + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} \ No newline at end of file diff --git a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_test.go b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_test.go index c7a5e40bb3..1f51ba625f 100644 --- a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_test.go +++ b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_test.go @@ -197,8 +197,12 @@ func TestKeptnAppVersion(t *testing.T) { }, }, common.PostDeploymentCheckType) require.Equal(t, KeptnTaskSpec{ - AppVersion: app.GetVersion(), - AppName: app.GetParentName(), + Context: TaskContext{ + AppName: app.GetParentName(), + AppVersion: app.GetVersion(), + TaskType: string(common.PostDeploymentCheckType), + ObjectType: "App", + }, TaskDefinition: "task-def", Parameters: TaskParameters{}, SecureParameters: SecureParameters{}, diff --git a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_types.go b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_types.go index 1b5c6ffcf1..1bdc3563c4 100644 --- a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_types.go +++ b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_types.go @@ -340,8 +340,12 @@ func (a KeptnAppVersion) GenerateTask(taskDefinition KeptnTaskDefinition, checkT Annotations: taskDefinition.Annotations, }, Spec: KeptnTaskSpec{ - AppVersion: a.GetVersion(), - AppName: a.GetParentName(), + Context: TaskContext{ + AppName: a.GetParentName(), + AppVersion: a.GetVersion(), + TaskType: string(checkType), + ObjectType: "App", + }, TaskDefinition: taskDefinition.Name, Parameters: TaskParameters{}, SecureParameters: SecureParameters{}, diff --git a/lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_conversion.go b/lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_conversion.go new file mode 100644 index 0000000000..9f3ce38f4d --- /dev/null +++ b/lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_conversion.go @@ -0,0 +1,6 @@ +package v1alpha3 + +// Hub is the stub function to make the API conversion pattern with hub and spokes complete +func (kt *KeptnTask) Hub() { + // Hub() needed to implement interface +} diff --git a/lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_test.go b/lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_test.go index 55c4bf1c91..23e17c9d7b 100644 --- a/lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_test.go +++ b/lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_test.go @@ -22,8 +22,10 @@ func TestKeptnTask(t *testing.T) { }, }, Spec: KeptnTaskSpec{ - AppName: "app", - AppVersion: "appversion", + Context: TaskContext{ + AppName: "app", + AppVersion: "appversion", + }, Type: common.PostDeploymentCheckType, TaskDefinition: "def", Timeout: metav1.Duration{ @@ -47,8 +49,10 @@ func TestKeptnTask(t *testing.T) { }, }, Spec: KeptnTaskSpec{ - AppName: "app", - AppVersion: "appversion", + Context: TaskContext{ + AppName: "app", + AppVersion: "appversion", + }, Type: common.PostDeploymentCheckType, TaskDefinition: "def", Timeout: metav1.Duration{ @@ -98,8 +102,8 @@ func TestKeptnTask(t *testing.T) { "annotation1": "annotation2", }, task.CreateKeptnAnnotations()) - task.Spec.Workload = "workload" - task.Spec.WorkloadVersion = "workloadversion" + task.Spec.Context.WorkloadName = "workload" + task.Spec.Context.WorkloadVersion = "workloadversion" require.Equal(t, map[string]string{ "keptn.sh/app": "app", diff --git a/lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_types.go b/lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_types.go index d1929d892d..ff91d9d1ea 100644 --- a/lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_types.go +++ b/lifecycle-operator/apis/lifecycle/v1alpha3/keptntask_types.go @@ -32,20 +32,13 @@ import ( // KeptnTaskSpec defines the desired state of KeptnTask type KeptnTaskSpec struct { - // Workload defines the KeptnWorkload for which the KeptnTask is executed. - Workload string `json:"workload"` - // WorkloadVersion defines the version of the KeptnWorkload for which the KeptnTask is executed. - WorkloadVersion string `json:"workloadVersion"` - // AppName defines the KeptnApp for which the KeptnTask is executed. - AppName string `json:"app"` - // AppVersion defines the version of the KeptnApp for which the KeptnTask is executed. - AppVersion string `json:"appVersion"` // TaskDefinition refers to the name of the KeptnTaskDefinition // which includes the specification for the task to be performed. // The KeptnTaskDefinition can be // located in the same namespace as the KeptnTask, or in the KLT namespace. TaskDefinition string `json:"taskDefinition"` // Context contains contextual information about the task execution. + // +optional Context TaskContext `json:"context"` // Parameters contains parameters that will be passed to the job that executes the task. Parameters TaskParameters `json:"parameters,omitempty"` @@ -71,16 +64,22 @@ type KeptnTaskSpec struct { type TaskContext struct { // WorkloadName the name of the KeptnWorkload the KeptnTask is being executed for. + // +optional WorkloadName string `json:"workloadName"` // AppName the name of the KeptnApp the KeptnTask is being executed for. + // +optional AppName string `json:"appName"` // AppVersion the version of the KeptnApp the KeptnTask is being executed for. + // +optional AppVersion string `json:"appVersion"` // WorkloadVersion the version of the KeptnWorkload the KeptnTask is being executed for. + // +optional WorkloadVersion string `json:"workloadVersion"` // TaskType indicates whether the KeptnTask is part of the pre- or postDeployment phase. + // +optional TaskType string `json:"taskType"` // ObjectType indicates whether the KeptnTask is being executed for a KeptnApp or KeptnWorkload. + // +optional ObjectType string `json:"objectType"` } @@ -181,10 +180,10 @@ func (t *KeptnTask) IsEndTimeSet() bool { func (t KeptnTask) GetActiveMetricsAttributes() []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.AppName.String(t.Spec.Context.AppName), + common.AppVersion.String(t.Spec.Context.AppVersion), + common.WorkloadName.String(t.Spec.Context.WorkloadName), + common.WorkloadVersion.String(t.Spec.Context.WorkloadVersion), common.TaskName.String(t.Name), common.TaskType.String(string(t.Spec.Type)), } @@ -192,10 +191,10 @@ func (t KeptnTask) GetActiveMetricsAttributes() []attribute.KeyValue { func (t KeptnTask) GetMetricsAttributes() []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.AppName.String(t.Spec.Context.AppName), + common.AppVersion.String(t.Spec.Context.AppVersion), + common.WorkloadName.String(t.Spec.Context.WorkloadName), + common.WorkloadVersion.String(t.Spec.Context.WorkloadVersion), common.TaskName.String(t.Name), common.TaskType.String(string(t.Spec.Type)), common.TaskStatus.String(string(t.Status.Status)), @@ -207,27 +206,27 @@ func (t KeptnTask) SetSpanAttributes(span trace.Span) { } func (t KeptnTask) CreateKeptnAnnotations() map[string]string { - if t.Spec.Workload != "" { + if t.Spec.Context.WorkloadName != "" { return common.MergeMaps(t.Annotations, map[string]string{ - common.AppAnnotation: t.Spec.AppName, - common.WorkloadAnnotation: t.Spec.Workload, - common.VersionAnnotation: t.Spec.WorkloadVersion, + common.AppAnnotation: t.Spec.Context.AppName, + common.WorkloadAnnotation: t.Spec.Context.WorkloadName, + common.VersionAnnotation: t.Spec.Context.WorkloadVersion, common.TaskNameAnnotation: t.Name, }) } return common.MergeMaps(t.Annotations, map[string]string{ - common.AppAnnotation: t.Spec.AppName, - common.VersionAnnotation: t.Spec.AppVersion, + common.AppAnnotation: t.Spec.Context.AppName, + common.VersionAnnotation: t.Spec.Context.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.AppName.String(t.Spec.Context.AppName), + common.AppVersion.String(t.Spec.Context.AppVersion), + common.WorkloadName.String(t.Spec.Context.WorkloadName), + common.WorkloadVersion.String(t.Spec.Context.WorkloadVersion), common.TaskName.String(t.Name), common.TaskType.String(string(t.Spec.Type)), } @@ -247,10 +246,10 @@ func (t KeptnTask) GetSpanName(phase string) string { func (t KeptnTask) GetEventAnnotations() map[string]string { return map[string]string{ - "appName": t.Spec.AppName, - "appVersion": t.Spec.AppVersion, - "workloadName": t.Spec.Workload, - "workloadVersion": t.Spec.WorkloadVersion, + "appName": t.Spec.Context.AppName, + "appVersion": t.Spec.Context.AppVersion, + "workloadName": t.Spec.Context.WorkloadName, + "workloadVersion": t.Spec.Context.WorkloadVersion, "taskName": t.Name, "taskDefinitionName": t.Spec.TaskDefinition, } diff --git a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkloadinstance_test.go b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkloadinstance_test.go index 0227a51048..8781e7da26 100644 --- a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkloadinstance_test.go +++ b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkloadinstance_test.go @@ -201,9 +201,13 @@ func TestKeptnWorkloadInstance(t *testing.T) { }, }, common.PostDeploymentCheckType) require.Equal(t, KeptnTaskSpec{ - AppName: workload.GetAppName(), - WorkloadVersion: workload.GetVersion(), - Workload: workload.GetParentName(), + Context: TaskContext{ + AppName: workload.GetAppName(), + WorkloadVersion: workload.GetVersion(), + WorkloadName: workload.GetParentName(), + TaskType: string(common.PostDeploymentCheckType), + ObjectType: "Workload", + }, TaskDefinition: "task-def", Parameters: TaskParameters{}, SecureParameters: SecureParameters{}, diff --git a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkloadinstance_types.go b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkloadinstance_types.go index 0a5b721da3..dd86346368 100644 --- a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkloadinstance_types.go +++ b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkloadinstance_types.go @@ -353,9 +353,13 @@ func (w KeptnWorkloadInstance) GenerateTask(taskDefinition KeptnTaskDefinition, Annotations: taskDefinition.Annotations, }, Spec: KeptnTaskSpec{ - AppName: w.GetAppName(), - WorkloadVersion: w.GetVersion(), - Workload: w.GetParentName(), + Context: TaskContext{ + WorkloadName: w.GetParentName(), + AppName: w.GetAppName(), + WorkloadVersion: w.GetVersion(), + TaskType: string(checkType), + ObjectType: "Workload", + }, TaskDefinition: taskDefinition.Name, Parameters: TaskParameters{}, SecureParameters: SecureParameters{}, diff --git a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptntasks.yaml b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptntasks.yaml index 622f5ab9b5..f376487590 100644 --- a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptntasks.yaml +++ b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptntasks.yaml @@ -283,14 +283,6 @@ spec: spec: description: Spec describes the desired state of the KeptnTask. properties: - app: - description: AppName defines the KeptnApp for which the KeptnTask - is executed. - type: string - appVersion: - description: AppVersion defines the version of the KeptnApp for which - the KeptnTask is executed. - type: string checkType: description: Type indicates whether the KeptnTask is part of the pre- or postDeployment phase. @@ -323,13 +315,6 @@ spec: description: WorkloadVersion the version of the KeptnWorkload the KeptnTask is being executed for. type: string - required: - - appName - - appVersion - - objectType - - taskType - - workloadName - - workloadVersion type: object parameters: description: Parameters contains parameters that will be passed to @@ -378,21 +363,8 @@ spec: within this time frame, it will be considered to be failed. pattern: ^0|([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$ type: string - workload: - description: Workload defines the KeptnWorkload for which the KeptnTask - is executed. - type: string - workloadVersion: - description: WorkloadVersion defines the version of the KeptnWorkload - for which the KeptnTask is executed. - type: string required: - - app - - appVersion - - context - taskDefinition - - workload - - workloadVersion type: object status: description: Status describes the current state of the KeptnTask. diff --git a/lifecycle-operator/config/samples/function_execution/task_schedule.yaml b/lifecycle-operator/config/samples/function_execution/task_schedule.yaml index fb8c92ffcd..efe401c173 100644 --- a/lifecycle-operator/config/samples/function_execution/task_schedule.yaml +++ b/lifecycle-operator/config/samples/function_execution/task_schedule.yaml @@ -1,11 +1,12 @@ -apiVersion: lifecycle.keptn.sh/v1alpha2 +apiVersion: lifecycle.keptn.sh/v1alpha3 kind: KeptnTask metadata: name: scheduled-deployment spec: taskDefinition: schedule-upstream-deployment - workload: my-workload - version: "1.0" + context: + workloadName: my-workload + workloadVersion: "1.0" app: my-app parameters: map: diff --git a/lifecycle-operator/config/samples/function_execution/task_slack.yaml b/lifecycle-operator/config/samples/function_execution/task_slack.yaml index f255779fc6..514d2e4bec 100644 --- a/lifecycle-operator/config/samples/function_execution/task_slack.yaml +++ b/lifecycle-operator/config/samples/function_execution/task_slack.yaml @@ -4,8 +4,16 @@ metadata: name: slack-deployment-notification spec: taskDefinition: slack-notification-inline - workload: my-workload - version: "1.0" - app: my-app + appVersion: "1.0" + workload: "w" + workloadVersion: "2.0" + app: "app" + context: + workloadName: my-workload + workloadVersion: "1.0" + taskType: "pre" + appName: "my-app" + objectType: "App" + appVersion: "1.0" secureParameters: secret: slack-notification diff --git a/lifecycle-operator/controllers/common/helperfunctions_test.go b/lifecycle-operator/controllers/common/helperfunctions_test.go index 3393c9c49d..0d34aeea82 100644 --- a/lifecycle-operator/controllers/common/helperfunctions_test.go +++ b/lifecycle-operator/controllers/common/helperfunctions_test.go @@ -297,11 +297,13 @@ func Test_setAnnotations(t *testing.T) { Namespace: "namespace", }, Spec: klcv1alpha3.KeptnTaskSpec{ - AppName: "app", - AppVersion: "1.0.0", - Workload: "workload", - WorkloadVersion: "2.0.0", - TaskDefinition: "def", + TaskDefinition: "def", + Context: klcv1alpha3.TaskContext{ + WorkloadName: "workload", + AppName: "app", + AppVersion: "1.0.0", + WorkloadVersion: "2.0.0", + }, }, }, want: map[string]string{ diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go index d336171c91..85d7173df8 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go @@ -75,24 +75,6 @@ func (r *KeptnTaskReconciler) getJob(ctx context.Context, jobName string, namesp return job, nil } -func setupTaskContext(task *klcv1alpha3.KeptnTask) klcv1alpha3.TaskContext { - taskContext := klcv1alpha3.TaskContext{} - - if task.Spec.Workload != "" { - taskContext.WorkloadName = task.Spec.Workload - taskContext.WorkloadVersion = task.Spec.WorkloadVersion - taskContext.ObjectType = "Workload" - - } else { - taskContext.ObjectType = "Application" - taskContext.AppVersion = task.Spec.AppVersion - } - taskContext.TaskType = string(task.Spec.Type) - taskContext.AppName = task.Spec.AppName - - return taskContext -} - func (r *KeptnTaskReconciler) generateJob(ctx context.Context, task *klcv1alpha3.KeptnTask, definition *klcv1alpha3.KeptnTaskDefinition, request ctrl.Request) (*batchv1.Job, error) { job := &batchv1.Job{ ObjectMeta: metav1.ObjectMeta{ diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils_test.go b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils_test.go index b7929137ad..f991e7dfff 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils_test.go @@ -238,9 +238,13 @@ func makeTask(name, namespace string, taskDefinitionName string) *klcv1alpha3.Ke }, }, Spec: klcv1alpha3.KeptnTaskSpec{ - Workload: "my-workload", - AppName: "my-app", - AppVersion: "0.1.0", + Context: klcv1alpha3.TaskContext{ + WorkloadName: "my-workload", + AppName: "my-app", + AppVersion: "0.1.0", + ObjectType: "Workload", + TaskType: string(apicommon.PostDeploymentCheckType), + }, TaskDefinition: taskDefinitionName, Type: apicommon.PostDeploymentCheckType, }, diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go b/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go index 670b46eca2..30b13eaf84 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder.go @@ -152,7 +152,7 @@ func (fb *RuntimeBuilder) getParams(ctx context.Context) (*RuntimeExecutionParam } } - params.Context = setupTaskContext(fb.options.task) + params.Context = fb.options.task.Spec.Context if len(fb.options.task.Spec.Parameters.Inline) > 0 { err = mergo.Merge(¶ms.Parameters, fb.options.task.Spec.Parameters.Inline) diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder_test.go b/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder_test.go index 3a07d6834a..168fd971ab 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/runtime_builder_test.go @@ -226,6 +226,7 @@ func TestJSBuilder_getParams(t *testing.T) { Context: klcv1alpha3.TaskContext{ WorkloadName: "my-workload", AppName: "my-app", + AppVersion: "0.1.0", ObjectType: "Workload", TaskType: string(apicommon.PostDeploymentCheckType), }, @@ -258,6 +259,7 @@ func TestJSBuilder_getParams(t *testing.T) { Context: klcv1alpha3.TaskContext{ WorkloadName: "my-workload", AppName: "my-app", + AppVersion: "0.1.0", ObjectType: "Workload", TaskType: string(apicommon.PostDeploymentCheckType), }, @@ -285,6 +287,7 @@ func TestJSBuilder_getParams(t *testing.T) { Context: klcv1alpha3.TaskContext{ WorkloadName: "my-workload", AppName: "my-app", + AppVersion: "0.1.0", ObjectType: "Workload", TaskType: string(apicommon.PostDeploymentCheckType), }, diff --git a/lifecycle-operator/test/component/task/task_test.go b/lifecycle-operator/test/component/task/task_test.go index 26586a6490..20ced4ae92 100644 --- a/lifecycle-operator/test/component/task/task_test.go +++ b/lifecycle-operator/test/component/task/task_test.go @@ -256,9 +256,11 @@ func makeTask(name string, namespace, taskDefinitionName string) *klcv1alpha3.Ke }, }, Spec: klcv1alpha3.KeptnTaskSpec{ - Workload: "my-workload", - AppName: "my-app", - AppVersion: "0.1.0", + Context: klcv1alpha3.TaskContext{ + WorkloadName: "my-workload", + AppName: "my-app", + AppVersion: "0.1.0", + }, TaskDefinition: taskDefinitionName, }, } diff --git a/test/integration/api-conversion/01-assert.yaml b/test/integration/api-conversion/01-assert.yaml index b6fd57dd37..2adfb32dd3 100644 --- a/test/integration/api-conversion/01-assert.yaml +++ b/test/integration/api-conversion/01-assert.yaml @@ -72,3 +72,19 @@ spec: provider: name: prometheus query: "sum(kube_pod_container_resource_limits{resource='cpu'})" +--- +apiVersion: lifecycle.keptn.sh/v1alpha3 +kind: KeptnTask +metadata: + name: slack-deployment-notification +spec: + taskDefinition: slack-notification-inline + context: + workloadName: my-workload + workloadVersion: "1.0" + taskType: "pre" + appName: "my-app" + objectType: "App" + appVersion: "1.0" + secureParameters: + secret: slack-notification diff --git a/test/integration/api-conversion/01-install.yaml b/test/integration/api-conversion/01-install.yaml index 30030abe6c..1561c3e10a 100644 --- a/test/integration/api-conversion/01-install.yaml +++ b/test/integration/api-conversion/01-install.yaml @@ -68,3 +68,23 @@ spec: provider: name: prometheus query: "sum(kube_pod_container_resource_limits{resource='cpu'})" +--- +apiVersion: lifecycle.keptn.sh/v1alpha2 +kind: KeptnTask +metadata: + name: slack-deployment-notification +spec: + taskDefinition: slack-notification-inline + appVersion: "1.0" + workload: "w" + workloadVersion: "2.0" + app: "app" + context: + workloadName: my-workload + workloadVersion: "1.0" + taskType: "pre" + appName: "my-app" + objectType: "App" + appVersion: "1.0" + secureParameters: + secret: slack-notification diff --git a/test/integration/app-failing-pre-task-retry/00-assert.yaml b/test/integration/app-failing-pre-task-retry/00-assert.yaml index f3801bba36..0e97da75ca 100644 --- a/test/integration/app-failing-pre-task-retry/00-assert.yaml +++ b/test/integration/app-failing-pre-task-retry/00-assert.yaml @@ -14,9 +14,10 @@ status: apiVersion: lifecycle.keptn.sh/v1alpha3 kind: KeptnTask spec: - app: podtato-head - appVersion: '1.3' - checkType: pre + context: + appName: podtato-head + appVersion: '1.3' + taskType: pre retries: 2 taskDefinition: pre-task-retries timeout: 5m0s diff --git a/test/integration/app-failing-pre-task-timeout/00-assert.yaml b/test/integration/app-failing-pre-task-timeout/00-assert.yaml index bd8cb2c1dd..cef4d70d07 100644 --- a/test/integration/app-failing-pre-task-timeout/00-assert.yaml +++ b/test/integration/app-failing-pre-task-timeout/00-assert.yaml @@ -14,9 +14,10 @@ status: apiVersion: lifecycle.keptn.sh/v1alpha3 kind: KeptnTask spec: - app: podtato-head - appVersion: '1.3' - checkType: pre + context: + appName: podtato-head + appVersion: '1.3' + taskType: pre retries: 10 taskDefinition: pre-task-timeout timeout: 30s diff --git a/test/integration/app-one-taskdefinition-not-found/00-assert.yaml b/test/integration/app-one-taskdefinition-not-found/00-assert.yaml index 7b6da25d83..f9521c017d 100644 --- a/test/integration/app-one-taskdefinition-not-found/00-assert.yaml +++ b/test/integration/app-one-taskdefinition-not-found/00-assert.yaml @@ -14,9 +14,10 @@ status: apiVersion: lifecycle.keptn.sh/v1alpha3 kind: KeptnTask spec: - app: podtato-head - appVersion: '1.3' - checkType: pre + context: + appName: podtato-head + appVersion: '1.3' + taskType: pre retries: 10 taskDefinition: pre-task-timeout timeout: 30s