From d95dc1037ce22296aff65d6ad6fa420e96172d5d Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Wed, 11 Oct 2023 08:00:47 +0200 Subject: [PATCH] feat(lifecycle-operator): introduce v1alpha4 API version for KeptnWorkloadInstance (#2250) Signed-off-by: odubajDT Signed-off-by: odubajDT <93584209+odubajDT@users.noreply.github.com> Co-authored-by: Florian Bacher Co-authored-by: RealAnna <89971034+RealAnna@users.noreply.github.com> --- .../scripts/.helm-tests/default/result.yaml | 354 +++++++++++++ .../.helm-tests/lifecycle-only/result.yaml | 354 +++++++++++++ .../lifecycle-with-certs/result.yaml | 354 +++++++++++++ .../generate-crd-docs/generate-crd-docs.sh | 7 + .../docs/crd-ref/lifecycle/v1alpha3/_index.md | 2 +- .../docs/crd-ref/lifecycle/v1alpha4/_index.md | 122 +++++ lifecycle-operator/PROJECT | 8 + .../lifecycle/v1alpha3/keptnworkload_types.go | 1 + .../lifecycle/v1alpha4/groupversion_info.go | 36 ++ .../v1alpha4/keptnworkloadversion_types.go | 470 ++++++++++++++++++ .../keptnworkloadversion_types_test.go | 448 +++++++++++++++++ .../v1alpha4/zz_generated.deepcopy.go | 189 +++++++ .../templates/keptnworkloadversion-crd.yaml | 322 ++++++++++++ .../templates/lifecycle-operator-rbac.yaml | 26 + ...ecycle.keptn.sh_keptnworkloadversions.yaml | 317 ++++++++++++ .../config/crd/kustomization.yaml | 1 + ...ok_in_lifecycle_keptnworkloadversions.yaml | 16 + .../keptnworkloadversion_editor_role.yaml | 24 + .../keptnworkloadversion_viewer_role.yaml | 20 + ...ycle_keptnworkloadversion_editor_role.yaml | 24 + ...ycle_keptnworkloadversion_viewer_role.yaml | 20 + ...fecycle_v1alpha4_keptnworkloadversion.yaml | 24 + lifecycle-operator/main.go | 2 + .../workloadversion/00-assert.yaml | 24 + .../workloadversion/00-install.yaml | 24 + 25 files changed, 3188 insertions(+), 1 deletion(-) create mode 100644 docs/content/en/docs/crd-ref/lifecycle/v1alpha4/_index.md create mode 100644 lifecycle-operator/apis/lifecycle/v1alpha4/groupversion_info.go create mode 100644 lifecycle-operator/apis/lifecycle/v1alpha4/keptnworkloadversion_types.go create mode 100644 lifecycle-operator/apis/lifecycle/v1alpha4/keptnworkloadversion_types_test.go create mode 100644 lifecycle-operator/apis/lifecycle/v1alpha4/zz_generated.deepcopy.go create mode 100644 lifecycle-operator/chart/templates/keptnworkloadversion-crd.yaml create mode 100644 lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnworkloadversions.yaml create mode 100644 lifecycle-operator/config/crd/patches/webhook_in_lifecycle_keptnworkloadversions.yaml create mode 100644 lifecycle-operator/config/rbac/keptnworkloadversion_editor_role.yaml create mode 100644 lifecycle-operator/config/rbac/keptnworkloadversion_viewer_role.yaml create mode 100644 lifecycle-operator/config/rbac/lifecycle_keptnworkloadversion_editor_role.yaml create mode 100644 lifecycle-operator/config/rbac/lifecycle_keptnworkloadversion_viewer_role.yaml create mode 100644 lifecycle-operator/config/samples/lifecycle_v1alpha4_keptnworkloadversion.yaml create mode 100644 test/integration/workloadversion/00-assert.yaml create mode 100644 test/integration/workloadversion/00-install.yaml diff --git a/.github/scripts/.helm-tests/default/result.yaml b/.github/scripts/.helm-tests/default/result.yaml index 5471265584..22ada330e0 100644 --- a/.github/scripts/.helm-tests/default/result.yaml +++ b/.github/scripts/.helm-tests/default/result.yaml @@ -5321,6 +5321,334 @@ spec: subresources: status: {} --- +# Source: keptn/charts/lifecycleOperator/templates/keptnworkloadversion-crd.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: keptnworkloadversions.lifecycle.keptn.sh + annotations: + controller-gen.kubebuilder.io/version: v0.13.0 + cert-manager.io/inject-ca-from: 'helmtests/keptn-certs' + labels: + app.kubernetes.io/part-of: keptn-lifecycle-toolkit + crdGroup: lifecycle.keptn.sh + keptn.sh/inject-cert: "true" + helm.sh/chart: lifecycle-operator-0.1.0 + app.kubernetes.io/name: lifecycle-operator + app.kubernetes.io/instance: keptn-test + app.kubernetes.io/version: "v0.8.2" + app.kubernetes.io/managed-by: Helm +spec: + group: lifecycle.keptn.sh + names: + kind: KeptnWorkloadVersion + listKind: KeptnWorkloadVersionList + plural: keptnworkloadversions + shortNames: + - kwv + singular: keptnworkloadversion + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.app + name: AppName + type: string + - jsonPath: .spec.workloadName + name: WorkloadName + type: string + - jsonPath: .spec.version + name: WorkloadVersion + type: string + - jsonPath: .status.currentPhase + name: Phase + type: string + - jsonPath: .status.preDeploymentStatus + name: PreDeploymentStatus + priority: 1 + type: string + - jsonPath: .status.preDeploymentEvaluationStatus + name: PreDeploymentEvaluationStatus + priority: 1 + type: string + - jsonPath: .status.deploymentStatus + name: DeploymentStatus + priority: 1 + type: string + - jsonPath: .status.postDeploymentStatus + name: PostDeploymentStatus + priority: 1 + type: string + - jsonPath: .status.postDeploymentEvaluationStatus + name: PostDeploymentEvaluationStatus + priority: 1 + type: string + name: v1alpha4 + schema: + openAPIV3Schema: + description: KeptnWorkloadVersion is the Schema for the keptnworkloadversions + 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 + 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 KeptnWorkloadVersion. + properties: + app: + description: AppName is the name of the KeptnApp containing the KeptnWorkload. + type: string + postDeploymentEvaluations: + description: PostDeploymentEvaluations is a list of all evaluations + to be performed during the post-deployment phase of the KeptnWorkload. + The items of this list refer to the names of KeptnEvaluationDefinitions + located in the same namespace as the KeptnWorkload, or in the Keptn + namespace. + items: + type: string + type: array + postDeploymentTasks: + description: PostDeploymentTasks is a list of all tasks to be performed + during the post-deployment phase of the KeptnWorkload. The items + of this list refer to the names of KeptnTaskDefinitions located + in the same namespace as the KeptnWorkload, or in the Keptn namespace. + items: + type: string + type: array + preDeploymentEvaluations: + description: PreDeploymentEvaluations is a list of all evaluations + to be performed during the pre-deployment phase of the KeptnWorkload. + The items of this list refer to the names of KeptnEvaluationDefinitions + located in the same namespace as the KeptnWorkload, or in the Keptn + namespace. + items: + type: string + type: array + preDeploymentTasks: + description: PreDeploymentTasks is a list of all tasks to be performed + during the pre-deployment phase of the KeptnWorkload. The items + of this list refer to the names of KeptnTaskDefinitions located + in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array + previousVersion: + description: PreviousVersion is the version of the KeptnWorkload that + has been deployed prior to this version. + type: string + resourceReference: + description: ResourceReference is a reference to the Kubernetes resource + (Deployment, DaemonSet, StatefulSet or ReplicaSet) the KeptnWorkload + is representing. + properties: + kind: + type: string + name: + type: string + uid: + description: UID is a type that holds unique ID values, including + UUIDs. Because we don't ONLY use UUIDs, this is an alias to + string. Being a type captures intent and helps make sure that + UIDs and names do not get conflated. + type: string + required: + - kind + - name + - uid + type: object + traceId: + additionalProperties: + type: string + description: TraceId contains the OpenTelemetry trace ID. + type: object + version: + description: Version defines the version of the KeptnWorkload. + type: string + workloadName: + description: WorkloadName is the name of the KeptnWorkload. + type: string + required: + - app + - resourceReference + - version + - workloadName + type: object + status: + description: Status describes the current state of the KeptnWorkloadVersion. + properties: + currentPhase: + description: 'CurrentPhase indicates the current phase of the KeptnWorkloadVersion. + This can be: - PreDeploymentTasks - PreDeploymentEvaluations - Deployment + - PostDeploymentTasks - PostDeploymentEvaluations' + type: string + deploymentStatus: + default: Pending + description: DeploymentStatus indicates the current status of the + KeptnWorkloadVersion's Deployment phase. + type: string + endTime: + description: EndTime represents the time at which the deployment of + the KeptnWorkloadVersion finished. + format: date-time + type: string + phaseTraceIDs: + additionalProperties: + additionalProperties: + type: string + description: MapCarrier is a TextMapCarrier that uses a map held + in memory as a storage medium for propagated key-value pairs. + type: object + description: PhaseTraceIDs contains the trace IDs of the OpenTelemetry + spans of each phase of the KeptnWorkloadVersion + type: object + postDeploymentEvaluationStatus: + default: Pending + description: PostDeploymentEvaluationStatus indicates the current + status of the KeptnWorkloadVersion's PostDeploymentEvaluation phase. + type: string + postDeploymentEvaluationTaskStatus: + description: PostDeploymentEvaluationTaskStatus indicates the current + state of each postDeploymentEvaluation of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + postDeploymentStatus: + default: Pending + description: PostDeploymentStatus indicates the current status of + the KeptnWorkloadVersion's PostDeployment phase. + type: string + postDeploymentTaskStatus: + description: PostDeploymentTaskStatus indicates the current state + of each postDeploymentTask of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + preDeploymentEvaluationStatus: + default: Pending + description: PreDeploymentEvaluationStatus indicates the current status + of the KeptnWorkloadVersion's PreDeploymentEvaluation phase. + type: string + preDeploymentEvaluationTaskStatus: + description: PreDeploymentEvaluationTaskStatus indicates the current + state of each preDeploymentEvaluation of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + preDeploymentStatus: + default: Pending + description: PreDeploymentStatus indicates the current status of the + KeptnWorkloadVersion's PreDeployment phase. + type: string + preDeploymentTaskStatus: + description: PreDeploymentTaskStatus indicates the current state of + each preDeploymentTask of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + startTime: + description: StartTime represents the time at which the deployment + of the KeptnWorkloadVersion started. + format: date-time + type: string + status: + default: Pending + description: Status represents the overall status of the KeptnWorkloadVersion. + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- # Source: keptn/charts/metricsOperator/templates/analysis-crd.yaml apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition @@ -7012,6 +7340,32 @@ rules: - get - patch - update +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/finalizers + verbs: + - update +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/status + verbs: + - get + - patch + - update - apiGroups: - lifecycle.keptn.sh resources: diff --git a/.github/scripts/.helm-tests/lifecycle-only/result.yaml b/.github/scripts/.helm-tests/lifecycle-only/result.yaml index d72f1e7ad2..fa2758ff80 100644 --- a/.github/scripts/.helm-tests/lifecycle-only/result.yaml +++ b/.github/scripts/.helm-tests/lifecycle-only/result.yaml @@ -5267,6 +5267,334 @@ spec: subresources: status: {} --- +# Source: keptn/charts/lifecycleOperator/templates/keptnworkloadversion-crd.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: keptnworkloadversions.lifecycle.keptn.sh + annotations: + controller-gen.kubebuilder.io/version: v0.13.0 + cert-manager.io/inject-ca-from: 'helmtests/keptn-certs' + labels: + app.kubernetes.io/part-of: keptn-lifecycle-toolkit + crdGroup: lifecycle.keptn.sh + keptn.sh/inject-cert: "true" + helm.sh/chart: lifecycle-operator-0.1.0 + app.kubernetes.io/name: lifecycle-operator + app.kubernetes.io/instance: keptn-test + app.kubernetes.io/version: "v0.8.2" + app.kubernetes.io/managed-by: Helm +spec: + group: lifecycle.keptn.sh + names: + kind: KeptnWorkloadVersion + listKind: KeptnWorkloadVersionList + plural: keptnworkloadversions + shortNames: + - kwv + singular: keptnworkloadversion + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.app + name: AppName + type: string + - jsonPath: .spec.workloadName + name: WorkloadName + type: string + - jsonPath: .spec.version + name: WorkloadVersion + type: string + - jsonPath: .status.currentPhase + name: Phase + type: string + - jsonPath: .status.preDeploymentStatus + name: PreDeploymentStatus + priority: 1 + type: string + - jsonPath: .status.preDeploymentEvaluationStatus + name: PreDeploymentEvaluationStatus + priority: 1 + type: string + - jsonPath: .status.deploymentStatus + name: DeploymentStatus + priority: 1 + type: string + - jsonPath: .status.postDeploymentStatus + name: PostDeploymentStatus + priority: 1 + type: string + - jsonPath: .status.postDeploymentEvaluationStatus + name: PostDeploymentEvaluationStatus + priority: 1 + type: string + name: v1alpha4 + schema: + openAPIV3Schema: + description: KeptnWorkloadVersion is the Schema for the keptnworkloadversions + 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 + 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 KeptnWorkloadVersion. + properties: + app: + description: AppName is the name of the KeptnApp containing the KeptnWorkload. + type: string + postDeploymentEvaluations: + description: PostDeploymentEvaluations is a list of all evaluations + to be performed during the post-deployment phase of the KeptnWorkload. + The items of this list refer to the names of KeptnEvaluationDefinitions + located in the same namespace as the KeptnWorkload, or in the Keptn + namespace. + items: + type: string + type: array + postDeploymentTasks: + description: PostDeploymentTasks is a list of all tasks to be performed + during the post-deployment phase of the KeptnWorkload. The items + of this list refer to the names of KeptnTaskDefinitions located + in the same namespace as the KeptnWorkload, or in the Keptn namespace. + items: + type: string + type: array + preDeploymentEvaluations: + description: PreDeploymentEvaluations is a list of all evaluations + to be performed during the pre-deployment phase of the KeptnWorkload. + The items of this list refer to the names of KeptnEvaluationDefinitions + located in the same namespace as the KeptnWorkload, or in the Keptn + namespace. + items: + type: string + type: array + preDeploymentTasks: + description: PreDeploymentTasks is a list of all tasks to be performed + during the pre-deployment phase of the KeptnWorkload. The items + of this list refer to the names of KeptnTaskDefinitions located + in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array + previousVersion: + description: PreviousVersion is the version of the KeptnWorkload that + has been deployed prior to this version. + type: string + resourceReference: + description: ResourceReference is a reference to the Kubernetes resource + (Deployment, DaemonSet, StatefulSet or ReplicaSet) the KeptnWorkload + is representing. + properties: + kind: + type: string + name: + type: string + uid: + description: UID is a type that holds unique ID values, including + UUIDs. Because we don't ONLY use UUIDs, this is an alias to + string. Being a type captures intent and helps make sure that + UIDs and names do not get conflated. + type: string + required: + - kind + - name + - uid + type: object + traceId: + additionalProperties: + type: string + description: TraceId contains the OpenTelemetry trace ID. + type: object + version: + description: Version defines the version of the KeptnWorkload. + type: string + workloadName: + description: WorkloadName is the name of the KeptnWorkload. + type: string + required: + - app + - resourceReference + - version + - workloadName + type: object + status: + description: Status describes the current state of the KeptnWorkloadVersion. + properties: + currentPhase: + description: 'CurrentPhase indicates the current phase of the KeptnWorkloadVersion. + This can be: - PreDeploymentTasks - PreDeploymentEvaluations - Deployment + - PostDeploymentTasks - PostDeploymentEvaluations' + type: string + deploymentStatus: + default: Pending + description: DeploymentStatus indicates the current status of the + KeptnWorkloadVersion's Deployment phase. + type: string + endTime: + description: EndTime represents the time at which the deployment of + the KeptnWorkloadVersion finished. + format: date-time + type: string + phaseTraceIDs: + additionalProperties: + additionalProperties: + type: string + description: MapCarrier is a TextMapCarrier that uses a map held + in memory as a storage medium for propagated key-value pairs. + type: object + description: PhaseTraceIDs contains the trace IDs of the OpenTelemetry + spans of each phase of the KeptnWorkloadVersion + type: object + postDeploymentEvaluationStatus: + default: Pending + description: PostDeploymentEvaluationStatus indicates the current + status of the KeptnWorkloadVersion's PostDeploymentEvaluation phase. + type: string + postDeploymentEvaluationTaskStatus: + description: PostDeploymentEvaluationTaskStatus indicates the current + state of each postDeploymentEvaluation of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + postDeploymentStatus: + default: Pending + description: PostDeploymentStatus indicates the current status of + the KeptnWorkloadVersion's PostDeployment phase. + type: string + postDeploymentTaskStatus: + description: PostDeploymentTaskStatus indicates the current state + of each postDeploymentTask of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + preDeploymentEvaluationStatus: + default: Pending + description: PreDeploymentEvaluationStatus indicates the current status + of the KeptnWorkloadVersion's PreDeploymentEvaluation phase. + type: string + preDeploymentEvaluationTaskStatus: + description: PreDeploymentEvaluationTaskStatus indicates the current + state of each preDeploymentEvaluation of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + preDeploymentStatus: + default: Pending + description: PreDeploymentStatus indicates the current status of the + KeptnWorkloadVersion's PreDeployment phase. + type: string + preDeploymentTaskStatus: + description: PreDeploymentTaskStatus indicates the current state of + each preDeploymentTask of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + startTime: + description: StartTime represents the time at which the deployment + of the KeptnWorkloadVersion started. + format: date-time + type: string + status: + default: Pending + description: Status represents the overall status of the KeptnWorkloadVersion. + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- # Source: keptn/charts/lifecycleOperator/templates/keptn-scheduler-rbac.yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole @@ -5784,6 +6112,32 @@ rules: - get - patch - update +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/finalizers + verbs: + - update +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/status + verbs: + - get + - patch + - update - apiGroups: - lifecycle.keptn.sh resources: diff --git a/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml b/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml index 8f27701e53..59ebbc290c 100644 --- a/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml +++ b/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml @@ -5282,6 +5282,334 @@ spec: subresources: status: {} --- +# Source: keptn/charts/lifecycleOperator/templates/keptnworkloadversion-crd.yaml +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: keptnworkloadversions.lifecycle.keptn.sh + annotations: + controller-gen.kubebuilder.io/version: v0.13.0 + cert-manager.io/inject-ca-from: 'helmtests/keptn-certs' + labels: + app.kubernetes.io/part-of: keptn-lifecycle-toolkit + crdGroup: lifecycle.keptn.sh + keptn.sh/inject-cert: "true" + helm.sh/chart: lifecycle-operator-0.1.0 + app.kubernetes.io/name: lifecycle-operator + app.kubernetes.io/instance: keptn-test + app.kubernetes.io/version: "v0.8.2" + app.kubernetes.io/managed-by: Helm +spec: + group: lifecycle.keptn.sh + names: + kind: KeptnWorkloadVersion + listKind: KeptnWorkloadVersionList + plural: keptnworkloadversions + shortNames: + - kwv + singular: keptnworkloadversion + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.app + name: AppName + type: string + - jsonPath: .spec.workloadName + name: WorkloadName + type: string + - jsonPath: .spec.version + name: WorkloadVersion + type: string + - jsonPath: .status.currentPhase + name: Phase + type: string + - jsonPath: .status.preDeploymentStatus + name: PreDeploymentStatus + priority: 1 + type: string + - jsonPath: .status.preDeploymentEvaluationStatus + name: PreDeploymentEvaluationStatus + priority: 1 + type: string + - jsonPath: .status.deploymentStatus + name: DeploymentStatus + priority: 1 + type: string + - jsonPath: .status.postDeploymentStatus + name: PostDeploymentStatus + priority: 1 + type: string + - jsonPath: .status.postDeploymentEvaluationStatus + name: PostDeploymentEvaluationStatus + priority: 1 + type: string + name: v1alpha4 + schema: + openAPIV3Schema: + description: KeptnWorkloadVersion is the Schema for the keptnworkloadversions + 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 + 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 KeptnWorkloadVersion. + properties: + app: + description: AppName is the name of the KeptnApp containing the KeptnWorkload. + type: string + postDeploymentEvaluations: + description: PostDeploymentEvaluations is a list of all evaluations + to be performed during the post-deployment phase of the KeptnWorkload. + The items of this list refer to the names of KeptnEvaluationDefinitions + located in the same namespace as the KeptnWorkload, or in the Keptn + namespace. + items: + type: string + type: array + postDeploymentTasks: + description: PostDeploymentTasks is a list of all tasks to be performed + during the post-deployment phase of the KeptnWorkload. The items + of this list refer to the names of KeptnTaskDefinitions located + in the same namespace as the KeptnWorkload, or in the Keptn namespace. + items: + type: string + type: array + preDeploymentEvaluations: + description: PreDeploymentEvaluations is a list of all evaluations + to be performed during the pre-deployment phase of the KeptnWorkload. + The items of this list refer to the names of KeptnEvaluationDefinitions + located in the same namespace as the KeptnWorkload, or in the Keptn + namespace. + items: + type: string + type: array + preDeploymentTasks: + description: PreDeploymentTasks is a list of all tasks to be performed + during the pre-deployment phase of the KeptnWorkload. The items + of this list refer to the names of KeptnTaskDefinitions located + in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array + previousVersion: + description: PreviousVersion is the version of the KeptnWorkload that + has been deployed prior to this version. + type: string + resourceReference: + description: ResourceReference is a reference to the Kubernetes resource + (Deployment, DaemonSet, StatefulSet or ReplicaSet) the KeptnWorkload + is representing. + properties: + kind: + type: string + name: + type: string + uid: + description: UID is a type that holds unique ID values, including + UUIDs. Because we don't ONLY use UUIDs, this is an alias to + string. Being a type captures intent and helps make sure that + UIDs and names do not get conflated. + type: string + required: + - kind + - name + - uid + type: object + traceId: + additionalProperties: + type: string + description: TraceId contains the OpenTelemetry trace ID. + type: object + version: + description: Version defines the version of the KeptnWorkload. + type: string + workloadName: + description: WorkloadName is the name of the KeptnWorkload. + type: string + required: + - app + - resourceReference + - version + - workloadName + type: object + status: + description: Status describes the current state of the KeptnWorkloadVersion. + properties: + currentPhase: + description: 'CurrentPhase indicates the current phase of the KeptnWorkloadVersion. + This can be: - PreDeploymentTasks - PreDeploymentEvaluations - Deployment + - PostDeploymentTasks - PostDeploymentEvaluations' + type: string + deploymentStatus: + default: Pending + description: DeploymentStatus indicates the current status of the + KeptnWorkloadVersion's Deployment phase. + type: string + endTime: + description: EndTime represents the time at which the deployment of + the KeptnWorkloadVersion finished. + format: date-time + type: string + phaseTraceIDs: + additionalProperties: + additionalProperties: + type: string + description: MapCarrier is a TextMapCarrier that uses a map held + in memory as a storage medium for propagated key-value pairs. + type: object + description: PhaseTraceIDs contains the trace IDs of the OpenTelemetry + spans of each phase of the KeptnWorkloadVersion + type: object + postDeploymentEvaluationStatus: + default: Pending + description: PostDeploymentEvaluationStatus indicates the current + status of the KeptnWorkloadVersion's PostDeploymentEvaluation phase. + type: string + postDeploymentEvaluationTaskStatus: + description: PostDeploymentEvaluationTaskStatus indicates the current + state of each postDeploymentEvaluation of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + postDeploymentStatus: + default: Pending + description: PostDeploymentStatus indicates the current status of + the KeptnWorkloadVersion's PostDeployment phase. + type: string + postDeploymentTaskStatus: + description: PostDeploymentTaskStatus indicates the current state + of each postDeploymentTask of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + preDeploymentEvaluationStatus: + default: Pending + description: PreDeploymentEvaluationStatus indicates the current status + of the KeptnWorkloadVersion's PreDeploymentEvaluation phase. + type: string + preDeploymentEvaluationTaskStatus: + description: PreDeploymentEvaluationTaskStatus indicates the current + state of each preDeploymentEvaluation of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + preDeploymentStatus: + default: Pending + description: PreDeploymentStatus indicates the current status of the + KeptnWorkloadVersion's PreDeployment phase. + type: string + preDeploymentTaskStatus: + description: PreDeploymentTaskStatus indicates the current state of + each preDeploymentTask of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + startTime: + description: StartTime represents the time at which the deployment + of the KeptnWorkloadVersion started. + format: date-time + type: string + status: + default: Pending + description: Status represents the overall status of the KeptnWorkloadVersion. + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} +--- # Source: keptn/charts/certManager/templates/certificate-operator-rbac.yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole @@ -5851,6 +6179,32 @@ rules: - get - patch - update +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/finalizers + verbs: + - update +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/status + verbs: + - get + - patch + - update - apiGroups: - lifecycle.keptn.sh resources: diff --git a/.github/scripts/generate-crd-docs/generate-crd-docs.sh b/.github/scripts/generate-crd-docs/generate-crd-docs.sh index a582a23c0e..579a639ae1 100755 --- a/.github/scripts/generate-crd-docs/generate-crd-docs.sh +++ b/.github/scripts/generate-crd-docs/generate-crd-docs.sh @@ -70,6 +70,13 @@ for api_group in "$OPERATOR_API_ROOT"*; do done done +## Hack: sorry :( +## Due to not adding KeptnWorkload resource into v1alpha4, there is a problem to generate CRD docs +## in KeptnWorkloadVersion we are using KeptnWorkloadSpec from v1alpha3, which leads to using +## ResourceReference struct from v1alpha3 -> CRD docs generator generates the docs, but it +## refers to ResourceReference from v1alpha3, as if it is present in v1alpha4 +sed -i 's|#resourcereference|../v1alpha3/#resourcereference|' docs/content/en/docs/crd-ref/lifecycle/v1alpha4/_index.md + # Metrics API 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 4268195454..db4326caf1 100644 --- a/docs/content/en/docs/crd-ref/lifecycle/v1alpha3/_index.md +++ b/docs/content/en/docs/crd-ref/lifecycle/v1alpha3/_index.md @@ -846,7 +846,7 @@ _Appears in:_ - +ResourceReference represents the parent resource of Workload _Appears in:_ - [KeptnWorkloadInstanceSpec](#keptnworkloadinstancespec) diff --git a/docs/content/en/docs/crd-ref/lifecycle/v1alpha4/_index.md b/docs/content/en/docs/crd-ref/lifecycle/v1alpha4/_index.md new file mode 100644 index 0000000000..3a113c4f3a --- /dev/null +++ b/docs/content/en/docs/crd-ref/lifecycle/v1alpha4/_index.md @@ -0,0 +1,122 @@ +--- +title: v1alpha4 +description: Reference information for lifecycle.keptn.sh/v1alpha4 +--- + + +## Packages +- [lifecycle.keptn.sh/v1alpha4](#lifecyclekeptnshv1alpha4) + + +## lifecycle.keptn.sh/v1alpha4 + +Package v1alpha4 contains API Schema definitions for the lifecycle v1alpha4 API group + +### Resource Types +- [KeptnWorkloadVersion](#keptnworkloadversion) +- [KeptnWorkloadVersionList](#keptnworkloadversionlist) + + + +#### ItemStatus + + + + + +_Appears in:_ +- [KeptnWorkloadVersionStatus](#keptnworkloadversionstatus) + +| Field | Description | +| --- | --- | +| `definitionName` _string_ | DefinitionName is the name of the EvaluationDefinition/TaskDefinition | +| `status` _KeptnState_ | | +| `name` _string_ | Name is the name of the Evaluation/Task | +| `startTime` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#time-v1-meta)_ | StartTime represents the time at which the Item (Evaluation/Task) started. | +| `endTime` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#time-v1-meta)_ | EndTime represents the time at which the Item (Evaluation/Task) started. | + + +#### KeptnWorkloadVersion + + + +KeptnWorkloadVersion is the Schema for the keptnworkloadversions API + +_Appears in:_ +- [KeptnWorkloadVersionList](#keptnworkloadversionlist) + +| Field | Description | +| --- | --- | +| `apiVersion` _string_ | `lifecycle.keptn.sh/v1alpha4` +| `kind` _string_ | `KeptnWorkloadVersion` +| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | +| `spec` _[KeptnWorkloadVersionSpec](#keptnworkloadversionspec)_ | Spec describes the desired state of the KeptnWorkloadVersion. | +| `status` _[KeptnWorkloadVersionStatus](#keptnworkloadversionstatus)_ | Status describes the current state of the KeptnWorkloadVersion. | + + +#### KeptnWorkloadVersionList + + + +KeptnWorkloadVersionList contains a list of KeptnWorkloadVersion + + + +| Field | Description | +| --- | --- | +| `apiVersion` _string_ | `lifecycle.keptn.sh/v1alpha4` +| `kind` _string_ | `KeptnWorkloadVersionList` +| `metadata` _[ListMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#listmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | +| `items` _[KeptnWorkloadVersion](#keptnworkloadversion) array_ | | + + +#### KeptnWorkloadVersionSpec + + + +KeptnWorkloadVersionSpec defines the desired state of KeptnWorkloadVersion + +_Appears in:_ +- [KeptnWorkloadVersion](#keptnworkloadversion) + +| Field | Description | +| --- | --- | +| `app` _string_ | AppName is the name of the KeptnApp containing the KeptnWorkload. | +| `version` _string_ | Version defines the version of the KeptnWorkload. | +| `preDeploymentTasks` _string array_ | PreDeploymentTasks is a list of all tasks to be performed during the pre-deployment phase of the KeptnWorkload. The items of this list refer to the names of KeptnTaskDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. | +| `postDeploymentTasks` _string array_ | PostDeploymentTasks is a list of all tasks to be performed during the post-deployment phase of the KeptnWorkload. The items of this list refer to the names of KeptnTaskDefinitions located in the same namespace as the KeptnWorkload, or in the Keptn namespace. | +| `preDeploymentEvaluations` _string array_ | PreDeploymentEvaluations is a list of all evaluations to be performed during the pre-deployment phase of the KeptnWorkload. The items of this list refer to the names of KeptnEvaluationDefinitions located in the same namespace as the KeptnWorkload, or in the Keptn namespace. | +| `postDeploymentEvaluations` _string array_ | PostDeploymentEvaluations is a list of all evaluations to be performed during the post-deployment phase of the KeptnWorkload. The items of this list refer to the names of KeptnEvaluationDefinitions located in the same namespace as the KeptnWorkload, or in the Keptn namespace. | +| `resourceReference` _[ResourceReference](../v1alpha3/#resourcereference)_ | ResourceReference is a reference to the Kubernetes resource (Deployment, DaemonSet, StatefulSet or ReplicaSet) the KeptnWorkload is representing. | +| `workloadName` _string_ | WorkloadName is the name of the KeptnWorkload. | +| `previousVersion` _string_ | PreviousVersion is the version of the KeptnWorkload that has been deployed prior to this version. | +| `traceId` _object (keys:string, values:string)_ | TraceId contains the OpenTelemetry trace ID. | + + +#### KeptnWorkloadVersionStatus + + + +KeptnWorkloadVersionStatus defines the observed state of KeptnWorkloadVersion + +_Appears in:_ +- [KeptnWorkloadVersion](#keptnworkloadversion) + +| Field | Description | +| --- | --- | +| `preDeploymentStatus` _KeptnState_ | PreDeploymentStatus indicates the current status of the KeptnWorkloadVersion's PreDeployment phase. | +| `deploymentStatus` _KeptnState_ | DeploymentStatus indicates the current status of the KeptnWorkloadVersion's Deployment phase. | +| `preDeploymentEvaluationStatus` _KeptnState_ | PreDeploymentEvaluationStatus indicates the current status of the KeptnWorkloadVersion's PreDeploymentEvaluation phase. | +| `postDeploymentEvaluationStatus` _KeptnState_ | PostDeploymentEvaluationStatus indicates the current status of the KeptnWorkloadVersion's PostDeploymentEvaluation phase. | +| `postDeploymentStatus` _KeptnState_ | PostDeploymentStatus indicates the current status of the KeptnWorkloadVersion's PostDeployment phase. | +| `preDeploymentTaskStatus` _[ItemStatus](#itemstatus) array_ | PreDeploymentTaskStatus indicates the current state of each preDeploymentTask of the KeptnWorkloadVersion. | +| `postDeploymentTaskStatus` _[ItemStatus](#itemstatus) array_ | PostDeploymentTaskStatus indicates the current state of each postDeploymentTask of the KeptnWorkloadVersion. | +| `preDeploymentEvaluationTaskStatus` _[ItemStatus](#itemstatus) array_ | PreDeploymentEvaluationTaskStatus indicates the current state of each preDeploymentEvaluation of the KeptnWorkloadVersion. | +| `postDeploymentEvaluationTaskStatus` _[ItemStatus](#itemstatus) array_ | PostDeploymentEvaluationTaskStatus indicates the current state of each postDeploymentEvaluation of the KeptnWorkloadVersion. | +| `startTime` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#time-v1-meta)_ | StartTime represents the time at which the deployment of the KeptnWorkloadVersion started. | +| `endTime` _[Time](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#time-v1-meta)_ | EndTime represents the time at which the deployment of the KeptnWorkloadVersion finished. | +| `currentPhase` _string_ | CurrentPhase indicates the current phase of the KeptnWorkloadVersion. This can be: - PreDeploymentTasks - PreDeploymentEvaluations - Deployment - PostDeploymentTasks - PostDeploymentEvaluations | +| `phaseTraceIDs` _object (keys:string, values:object)_ | PhaseTraceIDs contains the trace IDs of the OpenTelemetry spans of each phase of the KeptnWorkloadVersion | +| `status` _KeptnState_ | Status represents the overall status of the KeptnWorkloadVersion. | + + diff --git a/lifecycle-operator/PROJECT b/lifecycle-operator/PROJECT index 4eff914800..874d841800 100644 --- a/lifecycle-operator/PROJECT +++ b/lifecycle-operator/PROJECT @@ -270,4 +270,12 @@ resources: kind: KeptnAppCreationRequest path: github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3 version: v1alpha3 +- api: + crdVersion: v1 + namespaced: true + domain: keptn.sh + group: lifecycle + kind: KeptnWorkloadVersion + path: github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha4 + version: v1alpha4 version: "3" diff --git a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkload_types.go b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkload_types.go index 956debd855..e0c7fbb8c6 100644 --- a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkload_types.go +++ b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnworkload_types.go @@ -92,6 +92,7 @@ type KeptnWorkloadList struct { Items []KeptnWorkload `json:"items"` } +// ResourceReference represents the parent resource of Workload type ResourceReference struct { UID types.UID `json:"uid"` Kind string `json:"kind"` diff --git a/lifecycle-operator/apis/lifecycle/v1alpha4/groupversion_info.go b/lifecycle-operator/apis/lifecycle/v1alpha4/groupversion_info.go new file mode 100644 index 0000000000..11a8fa1feb --- /dev/null +++ b/lifecycle-operator/apis/lifecycle/v1alpha4/groupversion_info.go @@ -0,0 +1,36 @@ +/* +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 v1alpha4 contains API Schema definitions for the lifecycle v1alpha4 API group +// +kubebuilder:object:generate=true +// +groupName=lifecycle.keptn.sh +package v1alpha4 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "lifecycle.keptn.sh", Version: "v1alpha4"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/lifecycle-operator/apis/lifecycle/v1alpha4/keptnworkloadversion_types.go b/lifecycle-operator/apis/lifecycle/v1alpha4/keptnworkloadversion_types.go new file mode 100644 index 0000000000..c81d082b8f --- /dev/null +++ b/lifecycle-operator/apis/lifecycle/v1alpha4/keptnworkloadversion_types.go @@ -0,0 +1,470 @@ +/* +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 v1alpha4 + +import ( + "fmt" + "time" + + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/propagation" + "go.opentelemetry.io/otel/trace" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +// KeptnWorkloadVersionSpec defines the desired state of KeptnWorkloadVersion +type KeptnWorkloadVersionSpec struct { + v1alpha3.KeptnWorkloadSpec `json:",inline"` + // WorkloadName is the name of the KeptnWorkload. + WorkloadName string `json:"workloadName"` + // PreviousVersion is the version of the KeptnWorkload that has been deployed prior to this version. + PreviousVersion string `json:"previousVersion,omitempty"` + // TraceId contains the OpenTelemetry trace ID. + TraceId map[string]string `json:"traceId,omitempty"` +} + +// KeptnWorkloadVersionStatus defines the observed state of KeptnWorkloadVersion +type KeptnWorkloadVersionStatus struct { + // PreDeploymentStatus indicates the current status of the KeptnWorkloadVersion's PreDeployment phase. + // +kubebuilder:default:=Pending + PreDeploymentStatus common.KeptnState `json:"preDeploymentStatus,omitempty"` + // DeploymentStatus indicates the current status of the KeptnWorkloadVersion's Deployment phase. + // +kubebuilder:default:=Pending + DeploymentStatus common.KeptnState `json:"deploymentStatus,omitempty"` + // PreDeploymentEvaluationStatus indicates the current status of the KeptnWorkloadVersion's PreDeploymentEvaluation phase. + // +kubebuilder:default:=Pending + PreDeploymentEvaluationStatus common.KeptnState `json:"preDeploymentEvaluationStatus,omitempty"` + // PostDeploymentEvaluationStatus indicates the current status of the KeptnWorkloadVersion's PostDeploymentEvaluation phase. + // +kubebuilder:default:=Pending + PostDeploymentEvaluationStatus common.KeptnState `json:"postDeploymentEvaluationStatus,omitempty"` + // PostDeploymentStatus indicates the current status of the KeptnWorkloadVersion's PostDeployment phase. + // +kubebuilder:default:=Pending + PostDeploymentStatus common.KeptnState `json:"postDeploymentStatus,omitempty"` + // PreDeploymentTaskStatus indicates the current state of each preDeploymentTask of the KeptnWorkloadVersion. + PreDeploymentTaskStatus []ItemStatus `json:"preDeploymentTaskStatus,omitempty"` + // PostDeploymentTaskStatus indicates the current state of each postDeploymentTask of the KeptnWorkloadVersion. + PostDeploymentTaskStatus []ItemStatus `json:"postDeploymentTaskStatus,omitempty"` + // PreDeploymentEvaluationTaskStatus indicates the current state of each preDeploymentEvaluation of the KeptnWorkloadVersion. + PreDeploymentEvaluationTaskStatus []ItemStatus `json:"preDeploymentEvaluationTaskStatus,omitempty"` + // PostDeploymentEvaluationTaskStatus indicates the current state of each postDeploymentEvaluation of the KeptnWorkloadVersion. + PostDeploymentEvaluationTaskStatus []ItemStatus `json:"postDeploymentEvaluationTaskStatus,omitempty"` + // StartTime represents the time at which the deployment of the KeptnWorkloadVersion started. + StartTime metav1.Time `json:"startTime,omitempty"` + // EndTime represents the time at which the deployment of the KeptnWorkloadVersion finished. + EndTime metav1.Time `json:"endTime,omitempty"` + // CurrentPhase indicates the current phase of the KeptnWorkloadVersion. This can be: + // - PreDeploymentTasks + // - PreDeploymentEvaluations + // - Deployment + // - PostDeploymentTasks + // - PostDeploymentEvaluations + CurrentPhase string `json:"currentPhase,omitempty"` + // PhaseTraceIDs contains the trace IDs of the OpenTelemetry spans of each phase of the KeptnWorkloadVersion + PhaseTraceIDs common.PhaseTraceID `json:"phaseTraceIDs,omitempty"` + // Status represents the overall status of the KeptnWorkloadVersion. + // +kubebuilder:default:=Pending + Status common.KeptnState `json:"status,omitempty"` +} + +type ItemStatus struct { + // DefinitionName is the name of the EvaluationDefinition/TaskDefinition + DefinitionName string `json:"definitionName,omitempty"` + // +kubebuilder:default:=Pending + Status common.KeptnState `json:"status,omitempty"` + // Name is the name of the Evaluation/Task + Name string `json:"name,omitempty"` + // StartTime represents the time at which the Item (Evaluation/Task) started. + StartTime metav1.Time `json:"startTime,omitempty"` + // EndTime represents the time at which the Item (Evaluation/Task) started. + EndTime metav1.Time `json:"endTime,omitempty"` +} + +// +kubebuilder:object:root=true +// +kubebuilder:resource:path=keptnworkloadversions,shortName=kwv +// +kubebuilder:subresource:status +// +kubebuilder:storageversion +// +kubebuilder:printcolumn:name="AppName",type=string,JSONPath=`.spec.app` +// +kubebuilder:printcolumn:name="WorkloadName",type=string,JSONPath=`.spec.workloadName` +// +kubebuilder:printcolumn:name="WorkloadVersion",type=string,JSONPath=`.spec.version` +// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.currentPhase` +// +kubebuilder:printcolumn:name="PreDeploymentStatus",priority=1,type=string,JSONPath=`.status.preDeploymentStatus` +// +kubebuilder:printcolumn:name="PreDeploymentEvaluationStatus",priority=1,type=string,JSONPath=`.status.preDeploymentEvaluationStatus` +// +kubebuilder:printcolumn:name="DeploymentStatus",type=string,priority=1,JSONPath=`.status.deploymentStatus` +// +kubebuilder:printcolumn:name="PostDeploymentStatus",type=string,priority=1,JSONPath=`.status.postDeploymentStatus` +// +kubebuilder:printcolumn:name="PostDeploymentEvaluationStatus",priority=1,type=string,JSONPath=`.status.postDeploymentEvaluationStatus` + +// KeptnWorkloadVersion is the Schema for the keptnworkloadversions API +type KeptnWorkloadVersion struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec describes the desired state of the KeptnWorkloadVersion. + Spec KeptnWorkloadVersionSpec `json:"spec,omitempty"` + // Status describes the current state of the KeptnWorkloadVersion. + Status KeptnWorkloadVersionStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// KeptnWorkloadVersionList contains a list of KeptnWorkloadVersion +type KeptnWorkloadVersionList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []KeptnWorkloadVersion `json:"items"` +} + +func init() { + SchemeBuilder.Register(&KeptnWorkloadVersion{}, &KeptnWorkloadVersionList{}) +} + +func (w KeptnWorkloadVersionList) GetItems() []client.Object { + var b []client.Object + for i := 0; i < len(w.Items); i++ { + b = append(b, &w.Items[i]) + } + return b +} + +func (w KeptnWorkloadVersion) IsPreDeploymentCompleted() bool { + return w.Status.PreDeploymentStatus.IsCompleted() +} + +func (w KeptnWorkloadVersion) IsPreDeploymentEvaluationCompleted() bool { + return w.Status.PreDeploymentEvaluationStatus.IsCompleted() +} + +func (w KeptnWorkloadVersion) IsPreDeploymentSucceeded() bool { + return w.Status.PreDeploymentStatus.IsSucceeded() +} + +func (w KeptnWorkloadVersion) IsPreDeploymentFailed() bool { + return w.Status.PreDeploymentStatus.IsFailed() +} + +func (w KeptnWorkloadVersion) IsPreDeploymentEvaluationSucceeded() bool { + return w.Status.PreDeploymentEvaluationStatus.IsSucceeded() +} + +func (w KeptnWorkloadVersion) IsPreDeploymentEvaluationFailed() bool { + return w.Status.PreDeploymentEvaluationStatus.IsFailed() +} + +func (w KeptnWorkloadVersion) IsPostDeploymentCompleted() bool { + return w.Status.PostDeploymentStatus.IsCompleted() +} + +func (w KeptnWorkloadVersion) IsPostDeploymentEvaluationCompleted() bool { + return w.Status.PostDeploymentEvaluationStatus.IsCompleted() +} + +func (w KeptnWorkloadVersion) IsPostDeploymentSucceeded() bool { + return w.Status.PostDeploymentStatus.IsSucceeded() +} + +func (w KeptnWorkloadVersion) IsPostDeploymentFailed() bool { + return w.Status.PostDeploymentStatus.IsFailed() +} + +func (w KeptnWorkloadVersion) IsPostDeploymentEvaluationSucceeded() bool { + return w.Status.PostDeploymentEvaluationStatus.IsSucceeded() +} + +func (w KeptnWorkloadVersion) IsPostDeploymentEvaluationFailed() bool { + return w.Status.PostDeploymentEvaluationStatus.IsFailed() +} + +func (w KeptnWorkloadVersion) IsDeploymentCompleted() bool { + return w.Status.DeploymentStatus.IsCompleted() +} + +func (w KeptnWorkloadVersion) IsDeploymentSucceeded() bool { + return w.Status.DeploymentStatus.IsSucceeded() +} + +func (w KeptnWorkloadVersion) IsDeploymentFailed() bool { + return w.Status.DeploymentStatus.IsFailed() +} + +func (w *KeptnWorkloadVersion) SetStartTime() { + if w.Status.StartTime.IsZero() { + w.Status.StartTime = metav1.NewTime(time.Now().UTC()) + } +} + +func (w *KeptnWorkloadVersion) SetEndTime() { + if w.Status.EndTime.IsZero() { + w.Status.EndTime = metav1.NewTime(time.Now().UTC()) + } +} + +func (w *KeptnWorkloadVersion) IsStartTimeSet() bool { + return !w.Status.StartTime.IsZero() +} + +func (w *KeptnWorkloadVersion) IsEndTimeSet() bool { + return !w.Status.EndTime.IsZero() +} + +func (w KeptnWorkloadVersion) GetStartTime() time.Time { + return w.Status.StartTime.Time +} + +func (w KeptnWorkloadVersion) GetEndTime() time.Time { + return w.Status.EndTime.Time +} + +func (w *KeptnWorkloadVersion) Complete() { + w.SetEndTime() +} + +func (e *ItemStatus) SetStartTime() { + if e.StartTime.IsZero() { + e.StartTime = metav1.NewTime(time.Now().UTC()) + } +} + +func (e *ItemStatus) SetEndTime() { + if e.EndTime.IsZero() { + e.EndTime = metav1.NewTime(time.Now().UTC()) + } +} + +func (w KeptnWorkloadVersion) GetActiveMetricsAttributes() []attribute.KeyValue { + return []attribute.KeyValue{ + common.AppName.String(w.Spec.AppName), + common.WorkloadName.String(w.Spec.WorkloadName), + common.WorkloadVersion.String(w.Spec.Version), + common.WorkloadNamespace.String(w.Namespace), + } +} + +func (w KeptnWorkloadVersion) GetMetricsAttributes() []attribute.KeyValue { + return []attribute.KeyValue{ + common.AppName.String(w.Spec.AppName), + common.WorkloadName.String(w.Spec.WorkloadName), + common.WorkloadVersion.String(w.Spec.Version), + common.WorkloadNamespace.String(w.Namespace), + common.WorkloadStatus.String(string(w.Status.Status)), + } +} + +func (w KeptnWorkloadVersion) GetDurationMetricsAttributes() []attribute.KeyValue { + return []attribute.KeyValue{ + common.AppName.String(w.Spec.AppName), + common.WorkloadName.String(w.Spec.WorkloadName), + common.WorkloadVersion.String(w.Spec.Version), + common.WorkloadPreviousVersion.String(w.Spec.PreviousVersion), + } +} + +func (w KeptnWorkloadVersion) GetState() common.KeptnState { + return w.Status.Status +} + +func (w KeptnWorkloadVersion) GetPreDeploymentTasks() []string { + return w.Spec.PreDeploymentTasks +} + +func (w KeptnWorkloadVersion) GetPostDeploymentTasks() []string { + return w.Spec.PostDeploymentTasks +} + +func (w KeptnWorkloadVersion) GetPreDeploymentTaskStatus() []ItemStatus { + return w.Status.PreDeploymentTaskStatus +} + +func (w KeptnWorkloadVersion) GetPostDeploymentTaskStatus() []ItemStatus { + return w.Status.PostDeploymentTaskStatus +} + +func (w KeptnWorkloadVersion) GetPreDeploymentEvaluations() []string { + return w.Spec.PreDeploymentEvaluations +} + +func (w KeptnWorkloadVersion) GetPostDeploymentEvaluations() []string { + return w.Spec.PostDeploymentEvaluations +} + +func (w KeptnWorkloadVersion) GetPreDeploymentEvaluationTaskStatus() []ItemStatus { + return w.Status.PreDeploymentEvaluationTaskStatus +} + +func (w KeptnWorkloadVersion) GetPostDeploymentEvaluationTaskStatus() []ItemStatus { + return w.Status.PostDeploymentEvaluationTaskStatus +} + +func (w KeptnWorkloadVersion) GetAppName() string { + return w.Spec.AppName +} + +func (w KeptnWorkloadVersion) GetPreviousVersion() string { + return w.Spec.PreviousVersion +} + +func (w KeptnWorkloadVersion) GetParentName() string { + return w.Spec.WorkloadName +} + +func (w KeptnWorkloadVersion) GetNamespace() string { + return w.Namespace +} + +func (w *KeptnWorkloadVersion) SetState(state common.KeptnState) { + w.Status.Status = state +} + +func (w KeptnWorkloadVersion) GetCurrentPhase() string { + return w.Status.CurrentPhase +} + +func (w *KeptnWorkloadVersion) SetCurrentPhase(phase string) { + w.Status.CurrentPhase = phase +} + +func (w KeptnWorkloadVersion) GetVersion() string { + return w.Spec.Version +} + +func (w KeptnWorkloadVersion) GenerateTask(taskDefinition v1alpha3.KeptnTaskDefinition, checkType common.CheckType) v1alpha3.KeptnTask { + return v1alpha3.KeptnTask{ + ObjectMeta: metav1.ObjectMeta{ + Name: common.GenerateTaskName(checkType, taskDefinition.Name), + Namespace: w.Namespace, + Labels: taskDefinition.Labels, + Annotations: taskDefinition.Annotations, + }, + Spec: v1alpha3.KeptnTaskSpec{ + Context: v1alpha3.TaskContext{ + WorkloadName: w.GetParentName(), + AppName: w.GetAppName(), + WorkloadVersion: w.GetVersion(), + TaskType: string(checkType), + ObjectType: "Workload", + }, + TaskDefinition: taskDefinition.Name, + Parameters: v1alpha3.TaskParameters{}, + SecureParameters: v1alpha3.SecureParameters{}, + Type: checkType, + Retries: taskDefinition.Spec.Retries, + Timeout: taskDefinition.Spec.Timeout, + }, + } +} + +func (w KeptnWorkloadVersion) GenerateEvaluation(evaluationDefinition v1alpha3.KeptnEvaluationDefinition, checkType common.CheckType) v1alpha3.KeptnEvaluation { + return v1alpha3.KeptnEvaluation{ + ObjectMeta: metav1.ObjectMeta{ + Name: common.GenerateEvaluationName(checkType, evaluationDefinition.Name), + Namespace: w.Namespace, + }, + Spec: v1alpha3.KeptnEvaluationSpec{ + AppName: w.GetAppName(), + WorkloadVersion: w.GetVersion(), + Workload: w.GetParentName(), + EvaluationDefinition: evaluationDefinition.Name, + Type: checkType, + RetryInterval: metav1.Duration{ + Duration: 5 * time.Second, + }, + }, + } +} + +func (w KeptnWorkloadVersion) GetSpanAttributes() []attribute.KeyValue { + return []attribute.KeyValue{ + common.AppName.String(w.Spec.AppName), + common.WorkloadName.String(w.Spec.WorkloadName), + common.WorkloadVersion.String(w.Spec.Version), + common.WorkloadNamespace.String(w.Namespace), + } +} + +func (w KeptnWorkloadVersion) GetSpanKey(phase string) string { + return fmt.Sprintf("%s.%s.%s.%s", w.Spec.TraceId["traceparent"], w.Spec.WorkloadName, w.Spec.Version, phase) +} + +func (w KeptnWorkloadVersion) GetSpanName(phase string) string { + if phase == "" { + return w.Name + } + return fmt.Sprintf("%s/%s", w.Spec.WorkloadName, phase) +} + +func (w KeptnWorkloadVersion) SetSpanAttributes(span trace.Span) { + span.SetAttributes(w.GetSpanAttributes()...) +} + +//nolint:dupl +func (w *KeptnWorkloadVersion) DeprecateRemainingPhases(phase common.KeptnPhaseType) { + // no need to deprecate anything when post-eval tasks fail + if phase == common.PhaseWorkloadPostEvaluation { + return + } + // deprecate post evaluation when post tasks failed + if phase == common.PhaseWorkloadPostDeployment { + w.Status.PostDeploymentEvaluationStatus = common.StateDeprecated + } + // deprecate post evaluation and tasks when app deployment failed + if phase == common.PhaseWorkloadDeployment { + w.Status.PostDeploymentStatus = common.StateDeprecated + w.Status.PostDeploymentEvaluationStatus = common.StateDeprecated + } + // deprecate app deployment, post tasks and evaluations if app pre-eval failed + if phase == common.PhaseWorkloadPreEvaluation { + w.Status.PostDeploymentStatus = common.StateDeprecated + w.Status.PostDeploymentEvaluationStatus = common.StateDeprecated + w.Status.DeploymentStatus = common.StateDeprecated + } + // deprecate pre evaluations, app deployment and post tasks and evaluations when pre-tasks failed + if phase == common.PhaseWorkloadPreDeployment { + w.Status.PostDeploymentStatus = common.StateDeprecated + w.Status.PostDeploymentEvaluationStatus = common.StateDeprecated + w.Status.DeploymentStatus = common.StateDeprecated + w.Status.PreDeploymentEvaluationStatus = common.StateDeprecated + } + // deprecate completely everything + if phase == common.PhaseDeprecated { + w.Status.PostDeploymentStatus = common.StateDeprecated + w.Status.PostDeploymentEvaluationStatus = common.StateDeprecated + w.Status.DeploymentStatus = common.StateDeprecated + w.Status.PreDeploymentEvaluationStatus = common.StateDeprecated + w.Status.PreDeploymentStatus = common.StateDeprecated + w.Status.Status = common.StateDeprecated + return + } + + w.Status.Status = common.StateFailed +} + +func (w *KeptnWorkloadVersion) SetPhaseTraceID(phase string, carrier propagation.MapCarrier) { + if w.Status.PhaseTraceIDs == nil { + w.Status.PhaseTraceIDs = common.PhaseTraceID{} + } + w.Status.PhaseTraceIDs[common.GetShortPhaseName(phase)] = carrier +} + +func (w KeptnWorkloadVersion) GetEventAnnotations() map[string]string { + return map[string]string{ + "appName": w.Spec.AppName, + "workloadName": w.Spec.WorkloadName, + "workloadVersion": w.Spec.Version, + "workloadVersionName": w.Name, + } +} diff --git a/lifecycle-operator/apis/lifecycle/v1alpha4/keptnworkloadversion_types_test.go b/lifecycle-operator/apis/lifecycle/v1alpha4/keptnworkloadversion_types_test.go new file mode 100644 index 0000000000..4caa543675 --- /dev/null +++ b/lifecycle-operator/apis/lifecycle/v1alpha4/keptnworkloadversion_types_test.go @@ -0,0 +1,448 @@ +package v1alpha4 + +import ( + "testing" + "time" + + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" + "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/propagation" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestKeptnWorkloadVersion(t *testing.T) { + workload := &KeptnWorkloadVersion{ + ObjectMeta: metav1.ObjectMeta{ + Name: "workload", + Namespace: "namespace", + }, + Status: KeptnWorkloadVersionStatus{ + PreDeploymentStatus: common.StateFailed, + PreDeploymentEvaluationStatus: common.StateFailed, + PostDeploymentStatus: common.StateFailed, + PostDeploymentEvaluationStatus: common.StateFailed, + DeploymentStatus: common.StateFailed, + Status: common.StateFailed, + PreDeploymentTaskStatus: []ItemStatus{ + { + DefinitionName: "defname", + Status: common.StateFailed, + Name: "taskname", + }, + }, + PostDeploymentTaskStatus: []ItemStatus{ + { + DefinitionName: "defname2", + Status: common.StateFailed, + Name: "taskname2", + }, + }, + PreDeploymentEvaluationTaskStatus: []ItemStatus{ + { + DefinitionName: "defname3", + Status: common.StateFailed, + Name: "taskname3", + }, + }, + PostDeploymentEvaluationTaskStatus: []ItemStatus{ + { + DefinitionName: "defname4", + Status: common.StateFailed, + Name: "taskname4", + }, + }, + CurrentPhase: common.PhaseAppDeployment.ShortName, + }, + Spec: KeptnWorkloadVersionSpec{ + KeptnWorkloadSpec: v1alpha3.KeptnWorkloadSpec{ + PreDeploymentTasks: []string{"task1", "task2"}, + PostDeploymentTasks: []string{"task3", "task4"}, + PreDeploymentEvaluations: []string{"task5", "task6"}, + PostDeploymentEvaluations: []string{"task7", "task8"}, + Version: "version", + AppName: "appname", + }, + PreviousVersion: "prev", + WorkloadName: "workloadname", + TraceId: map[string]string{"traceparent": "trace1"}, + }, + } + + require.True(t, workload.IsPreDeploymentCompleted()) + require.False(t, workload.IsPreDeploymentSucceeded()) + require.True(t, workload.IsPreDeploymentFailed()) + + require.True(t, workload.IsPreDeploymentEvaluationCompleted()) + require.False(t, workload.IsPreDeploymentEvaluationSucceeded()) + require.True(t, workload.IsPreDeploymentEvaluationFailed()) + + require.True(t, workload.IsPostDeploymentCompleted()) + require.False(t, workload.IsPostDeploymentSucceeded()) + require.True(t, workload.IsPostDeploymentFailed()) + + require.True(t, workload.IsPostDeploymentEvaluationCompleted()) + require.False(t, workload.IsPostDeploymentEvaluationSucceeded()) + require.True(t, workload.IsPostDeploymentEvaluationFailed()) + + require.True(t, workload.IsDeploymentCompleted()) + require.False(t, workload.IsDeploymentSucceeded()) + require.True(t, workload.IsDeploymentFailed()) + + require.False(t, workload.IsEndTimeSet()) + require.False(t, workload.IsStartTimeSet()) + + workload.SetStartTime() + workload.SetEndTime() + + require.True(t, workload.IsEndTimeSet()) + require.True(t, workload.IsStartTimeSet()) + + require.Equal(t, []attribute.KeyValue{ + common.AppName.String("appname"), + common.WorkloadName.String("workloadname"), + common.WorkloadVersion.String("version"), + common.WorkloadNamespace.String("namespace"), + }, workload.GetActiveMetricsAttributes()) + + require.Equal(t, []attribute.KeyValue{ + common.AppName.String("appname"), + common.WorkloadName.String("workloadname"), + common.WorkloadVersion.String("version"), + common.WorkloadNamespace.String("namespace"), + common.WorkloadStatus.String(string(common.StateFailed)), + }, workload.GetMetricsAttributes()) + + require.Equal(t, []attribute.KeyValue{ + common.AppName.String("appname"), + common.WorkloadName.String("workloadname"), + common.WorkloadVersion.String("version"), + common.WorkloadPreviousVersion.String("prev"), + }, workload.GetDurationMetricsAttributes()) + + require.Equal(t, common.StateFailed, workload.GetState()) + + require.Equal(t, []string{"task1", "task2"}, workload.GetPreDeploymentTasks()) + require.Equal(t, []string{"task3", "task4"}, workload.GetPostDeploymentTasks()) + require.Equal(t, []string{"task5", "task6"}, workload.GetPreDeploymentEvaluations()) + require.Equal(t, []string{"task7", "task8"}, workload.GetPostDeploymentEvaluations()) + + require.Equal(t, []ItemStatus{ + { + DefinitionName: "defname", + Status: common.StateFailed, + Name: "taskname", + }, + }, workload.GetPreDeploymentTaskStatus()) + + require.Equal(t, []ItemStatus{ + { + DefinitionName: "defname2", + Status: common.StateFailed, + Name: "taskname2", + }, + }, workload.GetPostDeploymentTaskStatus()) + + require.Equal(t, []ItemStatus{ + { + DefinitionName: "defname3", + Status: common.StateFailed, + Name: "taskname3", + }, + }, workload.GetPreDeploymentEvaluationTaskStatus()) + + require.Equal(t, []ItemStatus{ + { + DefinitionName: "defname4", + Status: common.StateFailed, + Name: "taskname4", + }, + }, workload.GetPostDeploymentEvaluationTaskStatus()) + + require.Equal(t, "appname", workload.GetAppName()) + require.Equal(t, "prev", workload.GetPreviousVersion()) + require.Equal(t, "workloadname", workload.GetParentName()) + require.Equal(t, "namespace", workload.GetNamespace()) + + workload.SetState(common.StatePending) + require.Equal(t, common.StatePending, workload.GetState()) + + require.True(t, !workload.GetStartTime().IsZero()) + require.True(t, !workload.GetEndTime().IsZero()) + + workload.SetCurrentPhase(common.PhaseAppDeployment.LongName) + require.Equal(t, common.PhaseAppDeployment.LongName, workload.GetCurrentPhase()) + + workload.Status.EndTime = v1.Time{Time: time.Time{}} + workload.Complete() + require.True(t, !workload.GetEndTime().IsZero()) + + require.Equal(t, "version", workload.GetVersion()) + + require.Equal(t, "trace1.workloadname.version.phase", workload.GetSpanKey("phase")) + + retries := int32(5) + task := workload.GenerateTask(v1alpha3.KeptnTaskDefinition{ + ObjectMeta: v1.ObjectMeta{ + Name: "task-def", + Labels: map[string]string{ + "label1": "label2", + }, + Annotations: map[string]string{ + "annotation1": "annotation2", + }, + }, + Spec: v1alpha3.KeptnTaskDefinitionSpec{ + Timeout: v1.Duration{ + Duration: 5 * time.Second, + }, + Retries: &retries, + }, + }, common.PostDeploymentCheckType) + require.Equal(t, v1alpha3.KeptnTaskSpec{ + Context: v1alpha3.TaskContext{ + AppName: workload.GetAppName(), + WorkloadVersion: workload.GetVersion(), + WorkloadName: workload.GetParentName(), + TaskType: string(common.PostDeploymentCheckType), + ObjectType: "Workload", + }, + TaskDefinition: "task-def", + Parameters: v1alpha3.TaskParameters{}, + SecureParameters: v1alpha3.SecureParameters{}, + Type: common.PostDeploymentCheckType, + Timeout: v1.Duration{ + Duration: 5 * time.Second, + }, + Retries: &retries, + }, task.Spec) + + require.Equal(t, map[string]string{ + "label1": "label2", + }, task.Labels) + + require.Equal(t, map[string]string{ + "annotation1": "annotation2", + }, task.Annotations) + + evaluation := workload.GenerateEvaluation(v1alpha3.KeptnEvaluationDefinition{ + ObjectMeta: v1.ObjectMeta{ + Name: "eval-def", + }, + }, common.PostDeploymentCheckType) + require.Equal(t, v1alpha3.KeptnEvaluationSpec{ + AppName: workload.GetAppName(), + WorkloadVersion: workload.GetVersion(), + Workload: workload.GetParentName(), + EvaluationDefinition: "eval-def", + Type: common.PostDeploymentCheckType, + RetryInterval: metav1.Duration{ + Duration: 5 * time.Second, + }, + }, evaluation.Spec) + + require.Equal(t, "workload", workload.GetSpanName("")) + + require.Equal(t, "workloadname/phase", workload.GetSpanName("phase")) + + require.Equal(t, []attribute.KeyValue{ + common.AppName.String("appname"), + common.WorkloadName.String("workloadname"), + common.WorkloadVersion.String("version"), + common.WorkloadNamespace.String("namespace"), + }, workload.GetSpanAttributes()) + + require.Equal(t, map[string]string{ + "appName": "appname", + "workloadName": "workloadname", + "workloadVersion": "version", + "workloadVersionName": "workload", + }, workload.GetEventAnnotations()) +} + +//nolint:dupl +func TestKeptnWorkloadVersion_DeprecateRemainingPhases(t *testing.T) { + workloadVersion := KeptnWorkloadVersion{ + Status: KeptnWorkloadVersionStatus{ + PreDeploymentStatus: common.StatePending, + PreDeploymentEvaluationStatus: common.StatePending, + PostDeploymentStatus: common.StatePending, + PostDeploymentEvaluationStatus: common.StatePending, + DeploymentStatus: common.StatePending, + Status: common.StatePending, + }, + } + + tests := []struct { + workloadVersion KeptnWorkloadVersion + phase common.KeptnPhaseType + want KeptnWorkloadVersion + }{ + { + workloadVersion: workloadVersion, + phase: common.PhaseWorkloadPostEvaluation, + want: KeptnWorkloadVersion{ + Status: KeptnWorkloadVersionStatus{ + PreDeploymentStatus: common.StatePending, + PreDeploymentEvaluationStatus: common.StatePending, + PostDeploymentStatus: common.StatePending, + PostDeploymentEvaluationStatus: common.StatePending, + DeploymentStatus: common.StatePending, + Status: common.StatePending, + }, + }, + }, + { + workloadVersion: workloadVersion, + phase: common.PhaseWorkloadPostDeployment, + want: KeptnWorkloadVersion{ + Status: KeptnWorkloadVersionStatus{ + PreDeploymentStatus: common.StatePending, + PreDeploymentEvaluationStatus: common.StatePending, + PostDeploymentStatus: common.StatePending, + PostDeploymentEvaluationStatus: common.StateDeprecated, + DeploymentStatus: common.StatePending, + Status: common.StateFailed, + }, + }, + }, + { + workloadVersion: workloadVersion, + phase: common.PhaseWorkloadDeployment, + want: KeptnWorkloadVersion{ + Status: KeptnWorkloadVersionStatus{ + PreDeploymentStatus: common.StatePending, + PreDeploymentEvaluationStatus: common.StatePending, + PostDeploymentStatus: common.StateDeprecated, + PostDeploymentEvaluationStatus: common.StateDeprecated, + DeploymentStatus: common.StatePending, + Status: common.StateFailed, + }, + }, + }, + { + workloadVersion: workloadVersion, + phase: common.PhaseWorkloadPreEvaluation, + want: KeptnWorkloadVersion{ + Status: KeptnWorkloadVersionStatus{ + PreDeploymentStatus: common.StatePending, + PreDeploymentEvaluationStatus: common.StatePending, + PostDeploymentStatus: common.StateDeprecated, + PostDeploymentEvaluationStatus: common.StateDeprecated, + DeploymentStatus: common.StateDeprecated, + Status: common.StateFailed, + }, + }, + }, + { + workloadVersion: workloadVersion, + phase: common.PhaseWorkloadPreDeployment, + want: KeptnWorkloadVersion{ + Status: KeptnWorkloadVersionStatus{ + PreDeploymentStatus: common.StatePending, + PreDeploymentEvaluationStatus: common.StateDeprecated, + PostDeploymentStatus: common.StateDeprecated, + PostDeploymentEvaluationStatus: common.StateDeprecated, + DeploymentStatus: common.StateDeprecated, + Status: common.StateFailed, + }, + }, + }, + { + workloadVersion: workloadVersion, + phase: common.PhaseDeprecated, + want: KeptnWorkloadVersion{ + Status: KeptnWorkloadVersionStatus{ + PreDeploymentStatus: common.StateDeprecated, + PreDeploymentEvaluationStatus: common.StateDeprecated, + PostDeploymentStatus: common.StateDeprecated, + PostDeploymentEvaluationStatus: common.StateDeprecated, + DeploymentStatus: common.StateDeprecated, + Status: common.StateDeprecated, + }, + }, + }, + { + workloadVersion: workloadVersion, + phase: common.PhaseAppPreDeployment, + want: KeptnWorkloadVersion{ + Status: KeptnWorkloadVersionStatus{ + PreDeploymentStatus: common.StatePending, + PreDeploymentEvaluationStatus: common.StatePending, + PostDeploymentStatus: common.StatePending, + PostDeploymentEvaluationStatus: common.StatePending, + DeploymentStatus: common.StatePending, + Status: common.StateFailed, + }, + }, + }, + } + + for _, tt := range tests { + t.Run("", func(t *testing.T) { + tt.workloadVersion.DeprecateRemainingPhases(tt.phase) + require.Equal(t, tt.want, tt.workloadVersion) + }) + } +} + +func TestKeptnWorkloadVersion_SetPhaseTraceID(t *testing.T) { + app := KeptnWorkloadVersion{ + Status: KeptnWorkloadVersionStatus{}, + } + + app.SetPhaseTraceID(common.PhaseAppDeployment.ShortName, propagation.MapCarrier{ + "name3": "trace3", + }) + + require.Equal(t, KeptnWorkloadVersion{ + Status: KeptnWorkloadVersionStatus{ + PhaseTraceIDs: common.PhaseTraceID{ + common.PhaseAppDeployment.ShortName: propagation.MapCarrier{ + "name3": "trace3", + }, + }, + }, + }, app) + + app.SetPhaseTraceID(common.PhaseWorkloadDeployment.LongName, propagation.MapCarrier{ + "name2": "trace2", + }) + + require.Equal(t, KeptnWorkloadVersion{ + Status: KeptnWorkloadVersionStatus{ + PhaseTraceIDs: common.PhaseTraceID{ + common.PhaseAppDeployment.ShortName: propagation.MapCarrier{ + "name3": "trace3", + }, + common.PhaseWorkloadDeployment.ShortName: propagation.MapCarrier{ + "name2": "trace2", + }, + }, + }, + }, app) +} + +func TestKeptnWorkloadVersionList(t *testing.T) { + list := KeptnWorkloadVersionList{ + Items: []KeptnWorkloadVersion{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "obj1", + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "obj2", + }, + }, + }, + } + + got := list.GetItems() + require.Len(t, got, 2) + require.Equal(t, "obj1", got[0].GetName()) + require.Equal(t, "obj2", got[1].GetName()) +} diff --git a/lifecycle-operator/apis/lifecycle/v1alpha4/zz_generated.deepcopy.go b/lifecycle-operator/apis/lifecycle/v1alpha4/zz_generated.deepcopy.go new file mode 100644 index 0000000000..da223c672b --- /dev/null +++ b/lifecycle-operator/apis/lifecycle/v1alpha4/zz_generated.deepcopy.go @@ -0,0 +1,189 @@ +//go:build !ignore_autogenerated + +/* +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. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha4 + +import ( + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common" + "go.opentelemetry.io/otel/propagation" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ItemStatus) DeepCopyInto(out *ItemStatus) { + *out = *in + in.StartTime.DeepCopyInto(&out.StartTime) + in.EndTime.DeepCopyInto(&out.EndTime) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ItemStatus. +func (in *ItemStatus) DeepCopy() *ItemStatus { + if in == nil { + return nil + } + out := new(ItemStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KeptnWorkloadVersion) DeepCopyInto(out *KeptnWorkloadVersion) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeptnWorkloadVersion. +func (in *KeptnWorkloadVersion) DeepCopy() *KeptnWorkloadVersion { + if in == nil { + return nil + } + out := new(KeptnWorkloadVersion) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KeptnWorkloadVersion) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KeptnWorkloadVersionList) DeepCopyInto(out *KeptnWorkloadVersionList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]KeptnWorkloadVersion, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeptnWorkloadVersionList. +func (in *KeptnWorkloadVersionList) DeepCopy() *KeptnWorkloadVersionList { + if in == nil { + return nil + } + out := new(KeptnWorkloadVersionList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *KeptnWorkloadVersionList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KeptnWorkloadVersionSpec) DeepCopyInto(out *KeptnWorkloadVersionSpec) { + *out = *in + in.KeptnWorkloadSpec.DeepCopyInto(&out.KeptnWorkloadSpec) + if in.TraceId != nil { + in, out := &in.TraceId, &out.TraceId + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeptnWorkloadVersionSpec. +func (in *KeptnWorkloadVersionSpec) DeepCopy() *KeptnWorkloadVersionSpec { + if in == nil { + return nil + } + out := new(KeptnWorkloadVersionSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KeptnWorkloadVersionStatus) DeepCopyInto(out *KeptnWorkloadVersionStatus) { + *out = *in + if in.PreDeploymentTaskStatus != nil { + in, out := &in.PreDeploymentTaskStatus, &out.PreDeploymentTaskStatus + *out = make([]ItemStatus, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.PostDeploymentTaskStatus != nil { + in, out := &in.PostDeploymentTaskStatus, &out.PostDeploymentTaskStatus + *out = make([]ItemStatus, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.PreDeploymentEvaluationTaskStatus != nil { + in, out := &in.PreDeploymentEvaluationTaskStatus, &out.PreDeploymentEvaluationTaskStatus + *out = make([]ItemStatus, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.PostDeploymentEvaluationTaskStatus != nil { + in, out := &in.PostDeploymentEvaluationTaskStatus, &out.PostDeploymentEvaluationTaskStatus + *out = make([]ItemStatus, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + in.StartTime.DeepCopyInto(&out.StartTime) + in.EndTime.DeepCopyInto(&out.EndTime) + if in.PhaseTraceIDs != nil { + in, out := &in.PhaseTraceIDs, &out.PhaseTraceIDs + *out = make(common.PhaseTraceID, len(*in)) + for key, val := range *in { + var outVal map[string]string + if val == nil { + (*out)[key] = nil + } else { + inVal := (*in)[key] + in, out := &inVal, &outVal + *out = make(propagation.MapCarrier, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } + (*out)[key] = outVal + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeptnWorkloadVersionStatus. +func (in *KeptnWorkloadVersionStatus) DeepCopy() *KeptnWorkloadVersionStatus { + if in == nil { + return nil + } + out := new(KeptnWorkloadVersionStatus) + in.DeepCopyInto(out) + return out +} diff --git a/lifecycle-operator/chart/templates/keptnworkloadversion-crd.yaml b/lifecycle-operator/chart/templates/keptnworkloadversion-crd.yaml new file mode 100644 index 0000000000..86c5bd398e --- /dev/null +++ b/lifecycle-operator/chart/templates/keptnworkloadversion-crd.yaml @@ -0,0 +1,322 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: keptnworkloadversions.lifecycle.keptn.sh + annotations: + controller-gen.kubebuilder.io/version: v0.13.0 + cert-manager.io/inject-ca-from: '{{ .Release.Namespace }}/keptn-certs' + labels: + app.kubernetes.io/part-of: keptn-lifecycle-toolkit + crdGroup: lifecycle.keptn.sh + keptn.sh/inject-cert: "true" + {{- include "chart.labels" . | nindent 4 }} +spec: + group: lifecycle.keptn.sh + names: + kind: KeptnWorkloadVersion + listKind: KeptnWorkloadVersionList + plural: keptnworkloadversions + shortNames: + - kwv + singular: keptnworkloadversion + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.app + name: AppName + type: string + - jsonPath: .spec.workloadName + name: WorkloadName + type: string + - jsonPath: .spec.version + name: WorkloadVersion + type: string + - jsonPath: .status.currentPhase + name: Phase + type: string + - jsonPath: .status.preDeploymentStatus + name: PreDeploymentStatus + priority: 1 + type: string + - jsonPath: .status.preDeploymentEvaluationStatus + name: PreDeploymentEvaluationStatus + priority: 1 + type: string + - jsonPath: .status.deploymentStatus + name: DeploymentStatus + priority: 1 + type: string + - jsonPath: .status.postDeploymentStatus + name: PostDeploymentStatus + priority: 1 + type: string + - jsonPath: .status.postDeploymentEvaluationStatus + name: PostDeploymentEvaluationStatus + priority: 1 + type: string + name: v1alpha4 + schema: + openAPIV3Schema: + description: KeptnWorkloadVersion is the Schema for the keptnworkloadversions + 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 + 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 KeptnWorkloadVersion. + properties: + app: + description: AppName is the name of the KeptnApp containing the KeptnWorkload. + type: string + postDeploymentEvaluations: + description: PostDeploymentEvaluations is a list of all evaluations + to be performed during the post-deployment phase of the KeptnWorkload. + The items of this list refer to the names of KeptnEvaluationDefinitions + located in the same namespace as the KeptnWorkload, or in the Keptn + namespace. + items: + type: string + type: array + postDeploymentTasks: + description: PostDeploymentTasks is a list of all tasks to be performed + during the post-deployment phase of the KeptnWorkload. The items + of this list refer to the names of KeptnTaskDefinitions located + in the same namespace as the KeptnWorkload, or in the Keptn namespace. + items: + type: string + type: array + preDeploymentEvaluations: + description: PreDeploymentEvaluations is a list of all evaluations + to be performed during the pre-deployment phase of the KeptnWorkload. + The items of this list refer to the names of KeptnEvaluationDefinitions + located in the same namespace as the KeptnWorkload, or in the Keptn + namespace. + items: + type: string + type: array + preDeploymentTasks: + description: PreDeploymentTasks is a list of all tasks to be performed + during the pre-deployment phase of the KeptnWorkload. The items + of this list refer to the names of KeptnTaskDefinitions located + in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array + previousVersion: + description: PreviousVersion is the version of the KeptnWorkload that + has been deployed prior to this version. + type: string + resourceReference: + description: ResourceReference is a reference to the Kubernetes resource + (Deployment, DaemonSet, StatefulSet or ReplicaSet) the KeptnWorkload + is representing. + properties: + kind: + type: string + name: + type: string + uid: + description: UID is a type that holds unique ID values, including + UUIDs. Because we don't ONLY use UUIDs, this is an alias to + string. Being a type captures intent and helps make sure that + UIDs and names do not get conflated. + type: string + required: + - kind + - name + - uid + type: object + traceId: + additionalProperties: + type: string + description: TraceId contains the OpenTelemetry trace ID. + type: object + version: + description: Version defines the version of the KeptnWorkload. + type: string + workloadName: + description: WorkloadName is the name of the KeptnWorkload. + type: string + required: + - app + - resourceReference + - version + - workloadName + type: object + status: + description: Status describes the current state of the KeptnWorkloadVersion. + properties: + currentPhase: + description: 'CurrentPhase indicates the current phase of the KeptnWorkloadVersion. + This can be: - PreDeploymentTasks - PreDeploymentEvaluations - Deployment + - PostDeploymentTasks - PostDeploymentEvaluations' + type: string + deploymentStatus: + default: Pending + description: DeploymentStatus indicates the current status of the + KeptnWorkloadVersion's Deployment phase. + type: string + endTime: + description: EndTime represents the time at which the deployment of + the KeptnWorkloadVersion finished. + format: date-time + type: string + phaseTraceIDs: + additionalProperties: + additionalProperties: + type: string + description: MapCarrier is a TextMapCarrier that uses a map held + in memory as a storage medium for propagated key-value pairs. + type: object + description: PhaseTraceIDs contains the trace IDs of the OpenTelemetry + spans of each phase of the KeptnWorkloadVersion + type: object + postDeploymentEvaluationStatus: + default: Pending + description: PostDeploymentEvaluationStatus indicates the current + status of the KeptnWorkloadVersion's PostDeploymentEvaluation phase. + type: string + postDeploymentEvaluationTaskStatus: + description: PostDeploymentEvaluationTaskStatus indicates the current + state of each postDeploymentEvaluation of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + postDeploymentStatus: + default: Pending + description: PostDeploymentStatus indicates the current status of + the KeptnWorkloadVersion's PostDeployment phase. + type: string + postDeploymentTaskStatus: + description: PostDeploymentTaskStatus indicates the current state + of each postDeploymentTask of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + preDeploymentEvaluationStatus: + default: Pending + description: PreDeploymentEvaluationStatus indicates the current status + of the KeptnWorkloadVersion's PreDeploymentEvaluation phase. + type: string + preDeploymentEvaluationTaskStatus: + description: PreDeploymentEvaluationTaskStatus indicates the current + state of each preDeploymentEvaluation of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + preDeploymentStatus: + default: Pending + description: PreDeploymentStatus indicates the current status of the + KeptnWorkloadVersion's PreDeployment phase. + type: string + preDeploymentTaskStatus: + description: PreDeploymentTaskStatus indicates the current state of + each preDeploymentTask of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + startTime: + description: StartTime represents the time at which the deployment + of the KeptnWorkloadVersion started. + format: date-time + type: string + status: + default: Pending + description: Status represents the overall status of the KeptnWorkloadVersion. + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/lifecycle-operator/chart/templates/lifecycle-operator-rbac.yaml b/lifecycle-operator/chart/templates/lifecycle-operator-rbac.yaml index 6a4317ad58..5bef4b0255 100644 --- a/lifecycle-operator/chart/templates/lifecycle-operator-rbac.yaml +++ b/lifecycle-operator/chart/templates/lifecycle-operator-rbac.yaml @@ -319,6 +319,32 @@ rules: - get - patch - update +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions + verbs: + - create + - delete + - get + - list + - patch + - update + - watch +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/finalizers + verbs: + - update +- apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/status + verbs: + - get + - patch + - update - apiGroups: - lifecycle.keptn.sh resources: diff --git a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnworkloadversions.yaml b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnworkloadversions.yaml new file mode 100644 index 0000000000..c4eb990cad --- /dev/null +++ b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnworkloadversions.yaml @@ -0,0 +1,317 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.13.0 + name: keptnworkloadversions.lifecycle.keptn.sh +spec: + group: lifecycle.keptn.sh + names: + kind: KeptnWorkloadVersion + listKind: KeptnWorkloadVersionList + plural: keptnworkloadversions + shortNames: + - kwv + singular: keptnworkloadversion + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .spec.app + name: AppName + type: string + - jsonPath: .spec.workloadName + name: WorkloadName + type: string + - jsonPath: .spec.version + name: WorkloadVersion + type: string + - jsonPath: .status.currentPhase + name: Phase + type: string + - jsonPath: .status.preDeploymentStatus + name: PreDeploymentStatus + priority: 1 + type: string + - jsonPath: .status.preDeploymentEvaluationStatus + name: PreDeploymentEvaluationStatus + priority: 1 + type: string + - jsonPath: .status.deploymentStatus + name: DeploymentStatus + priority: 1 + type: string + - jsonPath: .status.postDeploymentStatus + name: PostDeploymentStatus + priority: 1 + type: string + - jsonPath: .status.postDeploymentEvaluationStatus + name: PostDeploymentEvaluationStatus + priority: 1 + type: string + name: v1alpha4 + schema: + openAPIV3Schema: + description: KeptnWorkloadVersion is the Schema for the keptnworkloadversions + 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 + 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 KeptnWorkloadVersion. + properties: + app: + description: AppName is the name of the KeptnApp containing the KeptnWorkload. + type: string + postDeploymentEvaluations: + description: PostDeploymentEvaluations is a list of all evaluations + to be performed during the post-deployment phase of the KeptnWorkload. + The items of this list refer to the names of KeptnEvaluationDefinitions + located in the same namespace as the KeptnWorkload, or in the Keptn + namespace. + items: + type: string + type: array + postDeploymentTasks: + description: PostDeploymentTasks is a list of all tasks to be performed + during the post-deployment phase of the KeptnWorkload. The items + of this list refer to the names of KeptnTaskDefinitions located + in the same namespace as the KeptnWorkload, or in the Keptn namespace. + items: + type: string + type: array + preDeploymentEvaluations: + description: PreDeploymentEvaluations is a list of all evaluations + to be performed during the pre-deployment phase of the KeptnWorkload. + The items of this list refer to the names of KeptnEvaluationDefinitions + located in the same namespace as the KeptnWorkload, or in the Keptn + namespace. + items: + type: string + type: array + preDeploymentTasks: + description: PreDeploymentTasks is a list of all tasks to be performed + during the pre-deployment phase of the KeptnWorkload. The items + of this list refer to the names of KeptnTaskDefinitions located + in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array + previousVersion: + description: PreviousVersion is the version of the KeptnWorkload that + has been deployed prior to this version. + type: string + resourceReference: + description: ResourceReference is a reference to the Kubernetes resource + (Deployment, DaemonSet, StatefulSet or ReplicaSet) the KeptnWorkload + is representing. + properties: + kind: + type: string + name: + type: string + uid: + description: UID is a type that holds unique ID values, including + UUIDs. Because we don't ONLY use UUIDs, this is an alias to + string. Being a type captures intent and helps make sure that + UIDs and names do not get conflated. + type: string + required: + - kind + - name + - uid + type: object + traceId: + additionalProperties: + type: string + description: TraceId contains the OpenTelemetry trace ID. + type: object + version: + description: Version defines the version of the KeptnWorkload. + type: string + workloadName: + description: WorkloadName is the name of the KeptnWorkload. + type: string + required: + - app + - resourceReference + - version + - workloadName + type: object + status: + description: Status describes the current state of the KeptnWorkloadVersion. + properties: + currentPhase: + description: 'CurrentPhase indicates the current phase of the KeptnWorkloadVersion. + This can be: - PreDeploymentTasks - PreDeploymentEvaluations - Deployment + - PostDeploymentTasks - PostDeploymentEvaluations' + type: string + deploymentStatus: + default: Pending + description: DeploymentStatus indicates the current status of the + KeptnWorkloadVersion's Deployment phase. + type: string + endTime: + description: EndTime represents the time at which the deployment of + the KeptnWorkloadVersion finished. + format: date-time + type: string + phaseTraceIDs: + additionalProperties: + additionalProperties: + type: string + description: MapCarrier is a TextMapCarrier that uses a map held + in memory as a storage medium for propagated key-value pairs. + type: object + description: PhaseTraceIDs contains the trace IDs of the OpenTelemetry + spans of each phase of the KeptnWorkloadVersion + type: object + postDeploymentEvaluationStatus: + default: Pending + description: PostDeploymentEvaluationStatus indicates the current + status of the KeptnWorkloadVersion's PostDeploymentEvaluation phase. + type: string + postDeploymentEvaluationTaskStatus: + description: PostDeploymentEvaluationTaskStatus indicates the current + state of each postDeploymentEvaluation of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + postDeploymentStatus: + default: Pending + description: PostDeploymentStatus indicates the current status of + the KeptnWorkloadVersion's PostDeployment phase. + type: string + postDeploymentTaskStatus: + description: PostDeploymentTaskStatus indicates the current state + of each postDeploymentTask of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + preDeploymentEvaluationStatus: + default: Pending + description: PreDeploymentEvaluationStatus indicates the current status + of the KeptnWorkloadVersion's PreDeploymentEvaluation phase. + type: string + preDeploymentEvaluationTaskStatus: + description: PreDeploymentEvaluationTaskStatus indicates the current + state of each preDeploymentEvaluation of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + preDeploymentStatus: + default: Pending + description: PreDeploymentStatus indicates the current status of the + KeptnWorkloadVersion's PreDeployment phase. + type: string + preDeploymentTaskStatus: + description: PreDeploymentTaskStatus indicates the current state of + each preDeploymentTask of the KeptnWorkloadVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + type: string + type: object + type: array + startTime: + description: StartTime represents the time at which the deployment + of the KeptnWorkloadVersion started. + format: date-time + type: string + status: + default: Pending + description: Status represents the overall status of the KeptnWorkloadVersion. + type: string + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/lifecycle-operator/config/crd/kustomization.yaml b/lifecycle-operator/config/crd/kustomization.yaml index 4deef5a372..27ef1924fc 100644 --- a/lifecycle-operator/config/crd/kustomization.yaml +++ b/lifecycle-operator/config/crd/kustomization.yaml @@ -13,6 +13,7 @@ resources: - bases/lifecycle.keptn.sh_keptnevaluations.yaml - bases/options.keptn.sh_keptnconfigs.yaml - bases/lifecycle.keptn.sh_keptnappcreationrequests.yaml + - bases/lifecycle.keptn.sh_keptnworkloadversions.yaml # +kubebuilder:scaffold:crdkustomizeresource # the following config is for teaching kustomize how to do kustomization for CRDs. configurations: diff --git a/lifecycle-operator/config/crd/patches/webhook_in_lifecycle_keptnworkloadversions.yaml b/lifecycle-operator/config/crd/patches/webhook_in_lifecycle_keptnworkloadversions.yaml new file mode 100644 index 0000000000..ebbd784cf4 --- /dev/null +++ b/lifecycle-operator/config/crd/patches/webhook_in_lifecycle_keptnworkloadversions.yaml @@ -0,0 +1,16 @@ +# The following patch enables a conversion webhook for the CRD +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + name: keptnworkloadversions.lifecycle.keptn.sh +spec: + conversion: + strategy: Webhook + webhook: + clientConfig: + service: + namespace: system + name: webhook-service + path: /convert + conversionReviewVersions: + - v1 diff --git a/lifecycle-operator/config/rbac/keptnworkloadversion_editor_role.yaml b/lifecycle-operator/config/rbac/keptnworkloadversion_editor_role.yaml new file mode 100644 index 0000000000..616fcc5c54 --- /dev/null +++ b/lifecycle-operator/config/rbac/keptnworkloadversion_editor_role.yaml @@ -0,0 +1,24 @@ +# permissions for end users to edit keptnworkloadversions. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: keptnworkloadversion-editor-role +rules: + - apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/status + verbs: + - get diff --git a/lifecycle-operator/config/rbac/keptnworkloadversion_viewer_role.yaml b/lifecycle-operator/config/rbac/keptnworkloadversion_viewer_role.yaml new file mode 100644 index 0000000000..66372499a6 --- /dev/null +++ b/lifecycle-operator/config/rbac/keptnworkloadversion_viewer_role.yaml @@ -0,0 +1,20 @@ +# permissions for end users to view keptnworkloadversions. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: keptnworkloadversion-viewer-role +rules: + - apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions + verbs: + - get + - list + - watch + - apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/status + verbs: + - get diff --git a/lifecycle-operator/config/rbac/lifecycle_keptnworkloadversion_editor_role.yaml b/lifecycle-operator/config/rbac/lifecycle_keptnworkloadversion_editor_role.yaml new file mode 100644 index 0000000000..616fcc5c54 --- /dev/null +++ b/lifecycle-operator/config/rbac/lifecycle_keptnworkloadversion_editor_role.yaml @@ -0,0 +1,24 @@ +# permissions for end users to edit keptnworkloadversions. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: keptnworkloadversion-editor-role +rules: + - apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions + verbs: + - create + - delete + - get + - list + - patch + - update + - watch + - apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/status + verbs: + - get diff --git a/lifecycle-operator/config/rbac/lifecycle_keptnworkloadversion_viewer_role.yaml b/lifecycle-operator/config/rbac/lifecycle_keptnworkloadversion_viewer_role.yaml new file mode 100644 index 0000000000..66372499a6 --- /dev/null +++ b/lifecycle-operator/config/rbac/lifecycle_keptnworkloadversion_viewer_role.yaml @@ -0,0 +1,20 @@ +# permissions for end users to view keptnworkloadversions. +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: keptnworkloadversion-viewer-role +rules: + - apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions + verbs: + - get + - list + - watch + - apiGroups: + - lifecycle.keptn.sh + resources: + - keptnworkloadversions/status + verbs: + - get diff --git a/lifecycle-operator/config/samples/lifecycle_v1alpha4_keptnworkloadversion.yaml b/lifecycle-operator/config/samples/lifecycle_v1alpha4_keptnworkloadversion.yaml new file mode 100644 index 0000000000..d37a262852 --- /dev/null +++ b/lifecycle-operator/config/samples/lifecycle_v1alpha4_keptnworkloadversion.yaml @@ -0,0 +1,24 @@ +apiVersion: lifecycle.keptn.sh/v1alpha4 +kind: KeptnWorkloadVersion +metadata: + annotations: + traceparent: my-trace-parent + name: some-keptn-workload-version +spec: + app: podtato-head + resourceReference: + kind: ReplicaSet + name: my-replica-set + uid: 957f825e-4025-4ea8-ad22-9292877ff7eb + traceId: + traceparent: my-trace-parent + version: 0.2.7 + preDeploymentTasks: + - pre-deployment-task + preDeploymentEvaluations: + - pre-deployment-evaluation + postDeploymentTasks: + - post-deployment-task + postDeploymentEvaluations: + - post-deployment-evaluation + workloadName: some-keptn-workload-instance-2 diff --git a/lifecycle-operator/main.go b/lifecycle-operator/main.go index 42961ab3db..b9bdcd11ca 100644 --- a/lifecycle-operator/main.go +++ b/lifecycle-operator/main.go @@ -33,6 +33,7 @@ import ( lifecyclev1alpha1 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha1" lifecyclev1alpha2 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha2" lifecyclev1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3" + lifecyclev1alpha4 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha4" optionsv1alpha1 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/options/v1alpha1" controllercommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/config" @@ -77,6 +78,7 @@ func init() { utilruntime.Must(optionsv1alpha1.AddToScheme(scheme)) utilruntime.Must(lifecyclev1alpha3.AddToScheme(scheme)) utilruntime.Must(argov1alpha1.AddToScheme(scheme)) + utilruntime.Must(lifecyclev1alpha4.AddToScheme(scheme)) // +kubebuilder:scaffold:scheme } diff --git a/test/integration/workloadversion/00-assert.yaml b/test/integration/workloadversion/00-assert.yaml new file mode 100644 index 0000000000..844b6885c2 --- /dev/null +++ b/test/integration/workloadversion/00-assert.yaml @@ -0,0 +1,24 @@ +apiVersion: lifecycle.keptn.sh/v1alpha4 +kind: KeptnWorkloadVersion +metadata: + annotations: + traceparent: my-trace-parent + name: some-keptn-workload-version-1 +spec: + app: podtato-head + resourceReference: + kind: ReplicaSet + name: my-replica-set + uid: 957f825e-4025-4ea8-ad22-9292877ff7eb + traceId: + traceparent: my-trace-parent + version: 0.2.7 + preDeploymentTasks: + - pre-deployment-task + preDeploymentEvaluations: + - pre-deployment-evaluation + postDeploymentTasks: + - post-deployment-task + postDeploymentEvaluations: + - post-deployment-evaluation + workloadName: some-keptn-workload-version-1 diff --git a/test/integration/workloadversion/00-install.yaml b/test/integration/workloadversion/00-install.yaml new file mode 100644 index 0000000000..844b6885c2 --- /dev/null +++ b/test/integration/workloadversion/00-install.yaml @@ -0,0 +1,24 @@ +apiVersion: lifecycle.keptn.sh/v1alpha4 +kind: KeptnWorkloadVersion +metadata: + annotations: + traceparent: my-trace-parent + name: some-keptn-workload-version-1 +spec: + app: podtato-head + resourceReference: + kind: ReplicaSet + name: my-replica-set + uid: 957f825e-4025-4ea8-ad22-9292877ff7eb + traceId: + traceparent: my-trace-parent + version: 0.2.7 + preDeploymentTasks: + - pre-deployment-task + preDeploymentEvaluations: + - pre-deployment-evaluation + postDeploymentTasks: + - post-deployment-task + postDeploymentEvaluations: + - post-deployment-evaluation + workloadName: some-keptn-workload-version-1