diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index f7574d6a50..5359486120 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -163,6 +163,7 @@ envsubst envtest errorlint Etco +euo evaluatemetrics evaluationdefinition evaluationhandler diff --git a/.github/workflows/htmltest.yaml b/.github/workflows/htmltest.yaml index de0c76db61..f6abc51c0d 100644 --- a/.github/workflows/htmltest.yaml +++ b/.github/workflows/htmltest.yaml @@ -32,7 +32,7 @@ jobs: with: path: | tmp/.htmltest - key: htmltest-{{ hashFiles('tmp/.htmltest/refcache.json') }} + key: htmltest-${{ hashFiles('tmp/.htmltest/refcache.json') }} - name: Check HTML run: make htmltest diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 8d151a637e..38521ddbea 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -105,10 +105,10 @@ jobs: working-directory: . run: make chainsaw-integration-test-allowed-namespaces - # - name: (Chainsaw) Run Integration Tests - # if: inputs.allowed-namespaces == 'allowed_ns_off' - # working-directory: . - # run: make integration-test + - name: (Chainsaw) Run Integration Tests + if: inputs.allowed-namespaces == 'allowed_ns_off' + working-directory: . + run: make chainsaw-integration-test - name: Create reports if: failure() diff --git a/.release-please-manifest.json b/.release-please-manifest.json index fa6b9fbb4b..e96dd5899b 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,7 +1,7 @@ { ".": "0.9.0", "keptn-cert-manager": "1.2.0", - "runtimes/python-runtime": "1.0.1", + "runtimes/python-runtime": "1.0.2", "runtimes/deno-runtime": "2.0.0", "lifecycle-operator": "0.8.3", "scheduler": "0.8.3", diff --git a/.sonarcloud.properties b/.sonarcloud.properties index 28c412839f..2a64e4df32 100644 --- a/.sonarcloud.properties +++ b/.sonarcloud.properties @@ -1,6 +1,7 @@ sonar.projectKey=keptn_lifecycle-toolkit sonar.projectName=lifecycle-toolkit sonar.exclusions=test/kuttl/**/*.yaml,\ + test/chainsaw/**/*.yaml,\ docs/docs/**/*.yaml,\ test/prometheus/**/*.yaml,\ examples/**/*.yaml diff --git a/Makefile b/Makefile index 2181dd2b1a..0c85c0bee4 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,22 @@ integration-test-allowed-namespaces-local: install-prometheus # CHAINSAW # ############ +.PHONY: chainsaw-integration-test #these tests should run on a real cluster! +chainsaw-integration-test: + kubectl apply -f ./lifecycle-operator/config/crd/bases +# chainsaw test --test-dir ./test/chainsaw/integration/ + chainsaw test --test-dir ./test/chainsaw/testmetrics/ +# chainsaw test --test-dir ./test/chainsaw/testanalysis/ + chainsaw test --test-dir ./test/chainsaw/testcertificate/ + +.PHONY: chainsaw-integration-test-local #these tests should run on a real cluster! +chainsaw-integration-test-local: + kubectl apply -f ./lifecycle-operator/config/crd/bases +# chainsaw test --test-dir ./test/chainsaw/integration/ --config ./.chainsaw-local.yaml + chainsaw test --test-dir ./test/chainsaw/testmetrics/ --config ./.chainsaw-local.yaml +# chainsaw test --test-dir ./test/chainsaw/testanalysis/ --config ./.chainsaw-local.yaml + chainsaw test --test-dir ./test/chainsaw/testcertificate/ --config ./.chainsaw-local.yaml + .PHONY: chainsaw-integration-test-scheduling-gates #these tests should run on a real cluster! chainsaw-integration-test-scheduling-gates: chainsaw test --test-dir ./test/chainsaw/scheduling-gates/ diff --git a/docs/Makefile b/docs/Makefile index 9a0d418203..d8cd87f435 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,7 +1,7 @@ ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) # renovate: datasource=docker depName=squidfunk/mkdocs-material -MKDOCS_DOCKER_IMAGE_VERSION=9.5.5 +MKDOCS_DOCKER_IMAGE_VERSION=9.5.7 MKDOCS_DOCKER_IMAGE=squidfunk/mkdocs-material INTERACTIVE:=$(shell [ -t 0 ] && echo 1) diff --git a/docs/docs/reference/crd-reference/analysis.md b/docs/docs/reference/crd-reference/analysis.md index 2e7d15d535..5b3026763d 100644 --- a/docs/docs/reference/crd-reference/analysis.md +++ b/docs/docs/reference/crd-reference/analysis.md @@ -17,7 +17,7 @@ that are used in the `AnalysisDefinition` query. apiVersion: metrics.keptn.sh/v1beta1 kind: Analysis metadata: - name: analysis-sample + name: spec: timeframe: from: to: | `recent ` args: @@ -35,52 +35,55 @@ status: ``` ## Fields + * **apiVersion** -- API version being used * **kind** -- Resource type. Must be set to `Analysis` * **metadata** - * **name** -- Unique name of this analysis. - Names must comply with the - [Kubernetes Object Names and IDs](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names) - specification. + * **name** -- Unique name of this analysis. + Names must comply with the + [Kubernetes Object Names and IDs](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names) + specification. * **spec** - * **timeframe** (required) -- Specifies the range for the corresponding query - in the AnalysisValueTemplate. - This can be populated as one of the following: - - * A combination of ‘from’ and ’to’ - to specify the start and stop times for the analysis. - These fields follow the - [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) - timestamp format. - * Set the ‘recent’ property to a time span. - This causes the Analysis to use data going back that amount of time. - For example, if `recent: 10m` is set, - the Analysis studies data from the last ten minutes. - If neither is set, the Analysis can not be added to the cluster. - * **args** -- Map of key/value pairs that can be used - to substitute variables in the `AnalysisValueTemplate` query. - * **analysisDefinition** (required) -- Identify the `AnalysisDefinition` resource - that stores the `AnalysisValuesTemplate` associated with this `Analysis` - * **name** -- Name of the `AnalysisDefinition` resource - * **namespace** (optional) -- - Namespace of the `AnalysisDefinition` resource. - The `AnalysisDefinition` resource can be located in any namespace. - If the namespace is not specified, - the analysis controller looks for the `AnalysisDefinition` resource - in the same namespace as the `Analysis` resource. - * **status** -- results of this Analysis run, - added to the resource by Keptn, - based on criteria defined in the `AnalysisDefinition` resource. - - * **warning** -- Whether the analysis returned a warning. - * **raw** -- String-encoded JSON object that reports the results - of evaluating one or more objectives or metrics. - See - [Interpreting Analysis results](#interpreting-analysis-results) - for details. - * **state** -- Set to `Completed` or `Progressing` as appropriate. + * **timeframe** (required) -- Specifies the range for the corresponding query + in the AnalysisValueTemplate. + This can be populated as one of the following: + + * A combination of ‘from’ and ’to’ + to specify the start and stop times for the analysis. + These fields follow the + [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) + timestamp format. + * Set the ‘recent’ property to a time span. + This causes the Analysis to use data going back that amount of time. + For example, if `recent: 10m` is set, + the Analysis studies data from the last ten minutes. + + If neither is set, the Analysis can not be added to the cluster. + + * **args** -- Map of key/value pairs that can be used + to substitute variables in the `AnalysisValueTemplate` query. + * **analysisDefinition** (required) -- Identify the `AnalysisDefinition` resource + that stores the `AnalysisValuesTemplate` associated with this `Analysis` + * **name** -- Name of the `AnalysisDefinition` resource + * **namespace** (optional) -- + Namespace of the `AnalysisDefinition` resource. + The `AnalysisDefinition` resource can be located in any namespace. + If the namespace is not specified, + the analysis controller looks for the `AnalysisDefinition` resource + in the same namespace as the `Analysis` resource. + * **status** -- results of this Analysis run, + added to the resource by Keptn, + based on criteria defined in the `AnalysisDefinition` resource. + > **Warning** -- Whether the analysis returned a warning. + * **raw** -- String-encoded JSON object that reports the results + of evaluating one or more objectives or metrics. + See + [Interpreting Analysis results](#interpreting-analysis-results) + for details. + * **state** -- Set to `Completed` or `Progressing` as appropriate. + ## Interpreting Analysis results @@ -260,6 +263,7 @@ based on the objectives evaluated (totalScore: 2). **`warning`** -- Indicates whether any warnings have been issued during the evaluation (false in this case). + ## Usage @@ -332,25 +336,10 @@ API reference: [Analysis](../api-reference/metrics/v1beta1/index.md#analysis) ## Differences between versions -Keptn v0.8.3 and v0.9.0 include a preliminary release -of the Keptn Analysis feature -but it is hidden behind a feature flag. -To preview these features, do one of the following for your Keptn cluster: - -* Set the environment variable `ENABLE_ANALYSIS` to `true` - in the `metrics-operator` deployment -* Add the following to your `helm upgrade` command line: - - ```shell - --set metricsOperator.env.enableKeptnAnalysis=true - ``` -* Set `enableKeptnAnalysis: "true"` in the - [keptn-metrics-operator/values.yaml](https://github.com/keptn/lifecycle-toolkit-charts/blob/main/charts/keptn-metrics-operator/values.yaml) - file - -See -[Customizing the configuration of components](../../installation/index.md#customizing-the-configuration-of-components) -for more information. +The Keptn Analysis feature is an official part of Keptn v0.10.0 and later. +Keptn v0.8.3 included a preliminary release of this feature +but it was hidden behind a feature flag. +The behavior of this feature is unchanged since v0.8.3. ## See also diff --git a/docs/docs/reference/crd-reference/analysisdefinition.md b/docs/docs/reference/crd-reference/analysisdefinition.md index 3cc821d2cc..bf0dd46734 100644 --- a/docs/docs/reference/crd-reference/analysisdefinition.md +++ b/docs/docs/reference/crd-reference/analysisdefinition.md @@ -41,84 +41,89 @@ spec: ``` ## Fields + * **apiVersion** -- API version being used * **kind** -- Resource type. Must be set to `AnalysisDefinition`. -* **metadata** - * **name** -- Unique name of this analysis definition. - Names must comply with the - [Kubernetes Object Names and IDs](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names) - specification. - * **namespace** -- Namespace where this resource is located. - `Analysis` resources must specify this namespace - when referencing this definition, - unless it resides in the same namespace as the `Analysis` resource. + * **metadata** + * **name** -- Unique name of this analysis definition. + Names must comply with the + [Kubernetes Object Names and IDs](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names) + specification. + * **namespace** -- Namespace where this resource is located. + `Analysis` resources must specify this namespace + when referencing this definition, + unless it resides in the same namespace as the `Analysis` resource. * **spec** - * **objectives** - A list of objectives whose results are combined - to determine whether the analysis fails, passes, or passes with a warning. - * **analysisValueTemplateRef** (required) -- - This string marks the beginning of each objective - * **name** (required) -- The `metadata.name` value of the - [AnalysisValueTemplateRef](analysisvaluetemplate.md) - resource that defines the SLI used for this objective. - That resource defines the data provider and the query to use. - * **namespace** -- - Namespace of the `analysisValueTemplateRef` resource. - If the namespace is not specified, - the analysis controller looks for the `AnalysisValueTemplateRef` resource - in the same namespace as the `Analysis` resource. - * **target** -- defines failure or, optionally, warning criteria. - Values not specified for failure or warning result in a pass. - Keptn writes the results of the analysis to the `status` section - of the - [Analysis](analysis.md) - resource after the analysis runs. - - To use a value that includes a fraction, use a Kubernetes - [quantity](https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/quantity/) - value rather than a `float`. - For example, use the `3m` quantity - rather than the `0.003` float; - a `float` value here causes `Invalid value` errors. - A whole number (integer) is also a legal `quantity` value. - * **failure** -- criteria for failure, specified as - `operator: `. - This can be specified either as an absolute `quantity` value - or as a range of values. - - Valid operators for absolute values are: - * `lessThan` -- `<` operator - * `lessThanOrEqual` -- `<=` operator - * `greaterThan` -- `>` operator - * `greaterThanOrEqual` -- `>=` operator - * `equalTo` -- `==` operator - - Valid operators for specifying ranges are: - * `inRange` -- value is inclusively in the defined range - * `notInRange` -- value is exclusively out of the defined range - - Each of these operators require two arguments: - - * `lowBound` -- minimum `quantity` value - of the range included or excluded - * `highBound` -- maximum `quantity` value - of the range included or excluded - - * **warning** -- criteria for a warning, - specified in the same way as the `failure` field. - * **weight** -- used to emphasize the importance - of one `objective` over others - * **keyObjective** -- If set to `true`, - the entire analysis fails if this particular objective fails, - no matter what the actual `score` of the analysis is - * **totalScore** (required) -- - * **passPercentage** -- threshold to reach for the full analysis - (all objectives) to pass - - * **warningPercentage** -- threshold to reach - for the full analysis (all objectives) to pass with `warning` status + * **objectives** + A list of objectives whose results are combined + to determine whether the analysis fails, passes, or passes with a warning. + * **analysisValueTemplateRef** (required) -- + This string marks the beginning of each objective + * **name** (required) -- The `metadata.name` value of the + [AnalysisValueTemplateRef](analysisvaluetemplate.md) + resource that defines the SLI used for this objective. + That resource defines the data provider and the query to use. + * **namespace** -- + Namespace of the `analysisValueTemplateRef` resource. + If the namespace is not specified, + the analysis controller looks for the `AnalysisValueTemplateRef` resource + in the same namespace as the `Analysis` resource. + + * **target** -- defines failure or, optionally, warning criteria. + Values not specified for failure or warning result in a pass. + Keptn writes the results of the analysis to the `status` section + of the + [Analysis](analysis.md) + resource after the analysis runs. + + To use a value that includes a fraction, use a Kubernetes + [quantity](https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/quantity/) + value rather than a `float`. + For example, use the `3m` quantity + rather than the `0.003` float; + a `float` value here causes `Invalid value` errors. + A whole number (integer) is also a legal `quantity` value. + + * **failure** -- criteria for failure, specified as + `operator: `. + This can be specified either as an absolute `quantity` value + or as a range of values. + + Valid operators for absolute values are: + + * `lessThan` -- `<` operator + * `lessThanOrEqual` -- `<=` operator + * `greaterThan` -- `>` operator + * `greaterThanOrEqual` -- `>=` operator + * `equalTo` -- `==` operator + + Valid operators for specifying ranges are: + + * `inRange` -- value is inclusively in the defined range + * `notInRange` -- value is exclusively out of the defined range + + Each of these operators require two arguments: + + * `lowBound` -- minimum `quantity` value + of the range included or excluded + * `highBound` -- maximum `quantity` value + of the range included or excluded + > **Warning** -- criteria for a warning, + specified in the same way as the `failure` field. + + * **weight** -- used to emphasize the importance + of one `objective` over others + * **keyObjective** -- If set to `true`, + the entire analysis fails if this particular objective fails, + no matter what the actual `score` of the analysis is +* **totalScore** (required) -- + * **passPercentage** -- threshold to reach for the full analysis + (all objectives) to pass + > **Warning** Percentage + for the full analysis (all objectives) to pass with `warning` status + ## Usage @@ -150,11 +155,10 @@ API reference: ## Differences between versions -A preliminary release of the Keptn Analysis feature -is included in Keptn v0.8.3 and v0.9.0 but is hidden behind a feature flag. -See the -[Analysis](analysis.md/#differences-between-versions) -reference page for instructions to activate the preview of this feature. +The Keptn Analysis feature is an official part of Keptn v0.10.0 and later. +Keptn v0.8.3 included a preliminary release of this feature +but it was hidden behind a feature flag. +The behavior of this feature is unchanged since v0.8.3. ## See also diff --git a/docs/docs/reference/crd-reference/analysisvaluetemplate.md b/docs/docs/reference/crd-reference/analysisvaluetemplate.md index 1f1a09f46c..de129ca2a9 100644 --- a/docs/docs/reference/crd-reference/analysisvaluetemplate.md +++ b/docs/docs/reference/crd-reference/analysisvaluetemplate.md @@ -26,47 +26,40 @@ spec: ``` ## Fields + * **apiVersion** -- API version being used * **kind** -- Resource type. Must be set to `AnalysisValueTemplate` * **metadata** - * **labels** -- The Analysis feature uses the - `name` and `part-of` labels that are discussed in - [Basic annotations](../../guides/integrate.md#basic-annotations) - plus the following: - * **app.kubernetes.io/instance** analysis-sample - * **app.kubernetes.io/managed-by** -- Tool used to manage - the operation of the application. - Valid values are `helm` and `kustomize`. - * **app.kubernetes.io/created-by** metrics-operator - - TODO: Need to clarify how to use these annotations - * **name** -- Unique name of this template. - Names must comply with the - [Kubernetes Object Names and IDs](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names) - specification. - * **namespace** (optional) -- Namespace where this template lives. - `Analysis` resources must specify this namespace - when referencing this definition, - unless it resides in the same namespace as the `Analysis` resource. + + * **name** -- Unique name of this template. + Names must comply with the + [Kubernetes Object Names and IDs](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names) + specification. + * **namespace** (optional) -- Namespace where this template lives. + `Analysis` resources must specify this namespace + when referencing this definition, + unless it resides in the same namespace as the `Analysis` resource. + * **spec** - * **provider** (required) -- the KeptnMetricProvider - * **name** -- The `spec.name` value of the - [KeptnMetricsProvider](metricsprovider.md) resource to use. - Note that each `AnalysisValueTemplate` resource - can use only one data source. - However, an `Analysis` resource - can use multiple `AnalysisValueTemplate` resources, - each of which uses a different data source. - * **query** (required) -- query to be made. - This is done in the data provider's query language. - It can include variables that use the go templating syntax - to insert a placeholder in the query. - For example, the query might include `{{.nodename}}'}`; - the value to substitute for that variable for this Analysis - is defined in the `spec.args` section of the `AnalysisTemplate` resource, - which might be set to `nodename: test`. + * **provider** (required) -- the KeptnMetricProvider + * **name** -- The `spec.name` value of the + [KeptnMetricsProvider](metricsprovider.md) resource to use. + Note that each `AnalysisValueTemplate` resource + can use only one data source. + However, an `Analysis` resource + can use multiple `AnalysisValueTemplate` resources, + each of which uses a different data source. + * **query** (required) -- query to be made. + This is done in the data provider's query language. + It can include variables that use the go templating syntax + to insert a placeholder in the query. + For example, the query might include `{{.nodename}}'}`; + the value to substitute for that variable for this Analysis + is defined in the `spec.args` section of the `AnalysisTemplate` resource, + which might be set to `nodename: test`. + ## Usage @@ -100,11 +93,10 @@ API reference: ## Differences between versions -A preliminary release of the Keptn Analysis feature -is included in Keptn v0.8.3 and v0.9.0 but is hidden behind a feature flag. -See the -[Analysis](analysis.md#differences-between-versions) -reference page for instructions to activate the preview of this feature. +The Keptn Analysis feature is an official part of Keptn v0.10.0 and later. +Keptn v0.8.3 included a preliminary release of this feature +but it was hidden behind a feature flag. +The behavior of this feature is unchanged since v0.8.3. ## See also diff --git a/docs/docs/reference/crd-reference/config.md b/docs/docs/reference/crd-reference/config.md index c9b40ac806..8a7c33f5df 100644 --- a/docs/docs/reference/crd-reference/config.md +++ b/docs/docs/reference/crd-reference/config.md @@ -9,7 +9,7 @@ comments: true ## Yaml Synopsis ```yaml -apiVersion: options.keptn.sh/v?alpha? +apiVersion: options.keptn.sh/v1alpha1 kind: KeptnConfig metadata: name: @@ -20,27 +20,29 @@ spec: ``` ## Fields + * **apiVersion** -- API version being used. * **kind** -- Resource type. Must be set to `KeptnConfig`. * **metadata** - * **name** -- Unique name of this set of configurations. - Names must comply with the - [Kubernetes Object Names and IDs](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names) - specification. + * **name** -- Unique name of this set of configurations. + Names must comply with the + [Kubernetes Object Names and IDs](https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-subdomain-names) + specification. * **spec** - * **OTelCollectorUrl** -- The URL and port of the OpenTelemetry collector - This field must be populated - in order to export traces to the OpenTelemetry Collector. - * **keptnAppCreationRequestTimeoutSeconds** -- - Interval in which automatic app discovery searches for [workloads](https://kubernetes.io/docs/concepts/workloads/) - to put into the same auto-generated [KeptnApp](app.md). - The default value is 30 (seconds). - * **cloudEventsEndpoint** -- - Endpoint where the lifecycle operator posts Cloud Events. + * **OTelCollectorUrl** -- The URL and port of the OpenTelemetry collector + This field must be populated + in order to export traces to the OpenTelemetry Collector. + * **keptnAppCreationRequestTimeoutSeconds** -- + Interval in which automatic app discovery searches for [workloads](https://kubernetes.io/docs/concepts/workloads/) + to put into the same auto-generated [KeptnApp](app.md). + The default value is 30 (seconds). + * **cloudEventsEndpoint** -- + Endpoint where the lifecycle operator posts Cloud Events. + ## Usage diff --git a/docs/docs/reference/crd-reference/metricsprovider.md b/docs/docs/reference/crd-reference/metricsprovider.md index 953f20277b..682aced6fd 100644 --- a/docs/docs/reference/crd-reference/metricsprovider.md +++ b/docs/docs/reference/crd-reference/metricsprovider.md @@ -65,10 +65,11 @@ spec: * **type** (required) -- The type of data provider for this instance * **targetServer** (required) -- URL of the data provider, enclosed in double quotes - * **secretKeyRef** - * **name:** -- Name of the Secret used by the provider - * **key:** -- Key of the Secret from which to select - * **optional** -- Specify whether the Secret or its key are required + * **secretKeyRef** + * **name:** -- Name of the Secret used by the provider + * **key:** -- Key of the Secret from which to select + * **optional** -- Specify whether the Secret or its key must be defined + ## Usage diff --git a/requirements.txt b/requirements.txt index 44c5444a31..8359637f2b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ mkdocs==1.5.3 mkdocs-git-revision-date-localized-plugin==1.2.2 mkdocs-include-markdown-plugin==6.0.4 -mkdocs-material==9.5.5 +mkdocs-material==9.5.7 mkdocs-material-extensions==1.3.1 pymdown-extensions==10.7 -mkdocs-material[imaging]==9.5.5 +mkdocs-material[imaging]==9.5.7 diff --git a/runtimes/python-runtime/CHANGELOG.md b/runtimes/python-runtime/CHANGELOG.md index 611d05c7b6..9596c8f320 100644 --- a/runtimes/python-runtime/CHANGELOG.md +++ b/runtimes/python-runtime/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## [1.0.2](https://github.com/keptn/lifecycle-toolkit/compare/python-runtime-v1.0.1...python-runtime-v1.0.2) (2024-02-06) + + +### Other + +* rename Keptn default namespace to 'keptn-system' ([#2565](https://github.com/keptn/lifecycle-toolkit/issues/2565)) ([aec1148](https://github.com/keptn/lifecycle-toolkit/commit/aec11489451ab1b0bcd69a6b90b0d45f69c5df7c)) + + +### Docs + +* mention `KEPTN_CONTEXT` env var in runtime readmes files ([#2588](https://github.com/keptn/lifecycle-toolkit/issues/2588)) ([dfefc90](https://github.com/keptn/lifecycle-toolkit/commit/dfefc90e9e5075ef130e3962b1ded983b2b213f4)) +* remove Scarf transparent pixels ([#2590](https://github.com/keptn/lifecycle-toolkit/issues/2590)) ([95851fa](https://github.com/keptn/lifecycle-toolkit/commit/95851fa52cb3a6565a4b52ae0e8b00dcc9861a3b)) + + +### Dependency Updates + +* update python docker tag to v3.12.1 ([#2673](https://github.com/keptn/lifecycle-toolkit/issues/2673)) ([4dae93f](https://github.com/keptn/lifecycle-toolkit/commit/4dae93f48c0dfb391a7628c05bbe97404cc6a9da)) + ## [1.0.1](https://github.com/keptn/lifecycle-toolkit/compare/python-runtime-v1.0.0...python-runtime-v1.0.1) (2023-10-30) diff --git a/test/chainsaw/testcertificate/cert-recreates/00-assert.yaml b/test/chainsaw/testcertificate/cert-recreates/00-assert.yaml new file mode 100644 index 0000000000..05a31f9cd5 --- /dev/null +++ b/test/chainsaw/testcertificate/cert-recreates/00-assert.yaml @@ -0,0 +1,24 @@ +# certificate is recreated and there are operators instances available +apiVersion: v1 +kind: Secret +metadata: + name: keptn-certs + namespace: keptn-system +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: keptn-system + labels: + control-plane: metrics-operator +status: + readyReplicas: 1 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: keptn-system + labels: + control-plane: lifecycle-operator +status: + readyReplicas: 1 diff --git a/test/chainsaw/testcertificate/cert-recreates/01-assert.yaml b/test/chainsaw/testcertificate/cert-recreates/01-assert.yaml new file mode 100644 index 0000000000..05a31f9cd5 --- /dev/null +++ b/test/chainsaw/testcertificate/cert-recreates/01-assert.yaml @@ -0,0 +1,24 @@ +# certificate is recreated and there are operators instances available +apiVersion: v1 +kind: Secret +metadata: + name: keptn-certs + namespace: keptn-system +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: keptn-system + labels: + control-plane: metrics-operator +status: + readyReplicas: 1 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: keptn-system + labels: + control-plane: lifecycle-operator +status: + readyReplicas: 1 diff --git a/test/chainsaw/testcertificate/cert-recreates/01-delete.yaml b/test/chainsaw/testcertificate/cert-recreates/01-delete.yaml new file mode 100644 index 0000000000..e287393aa2 --- /dev/null +++ b/test/chainsaw/testcertificate/cert-recreates/01-delete.yaml @@ -0,0 +1,6 @@ +# second scenario: certificate is removed with no restart +apiVersion: v1 +kind: Secret +metadata: + name: keptn-certs + namespace: keptn-system diff --git a/test/chainsaw/testcertificate/cert-recreates/02-assert.yaml b/test/chainsaw/testcertificate/cert-recreates/02-assert.yaml new file mode 100644 index 0000000000..19f43f6912 --- /dev/null +++ b/test/chainsaw/testcertificate/cert-recreates/02-assert.yaml @@ -0,0 +1,26 @@ +# certificate is recreated and there are operators instances available +apiVersion: v1 +kind: Secret +metadata: + name: keptn-certs + namespace: keptn-system + annotations: + mycert: "true" # make sure this is the latest secret +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + control-plane: metrics-operator + namespace: keptn-system +status: + readyReplicas: 1 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + control-plane: lifecycle-operator + namespace: keptn-system +status: + readyReplicas: 1 diff --git a/test/chainsaw/testcertificate/cert-recreates/02-install.yaml b/test/chainsaw/testcertificate/cert-recreates/02-install.yaml new file mode 100644 index 0000000000..bd4821a4b0 --- /dev/null +++ b/test/chainsaw/testcertificate/cert-recreates/02-install.yaml @@ -0,0 +1,13 @@ +# third scenario: certificate is invalid/expired +apiVersion: v1 +kind: Secret +metadata: + name: keptn-certs + namespace: keptn-system + annotations: + mycert: "true" +data: + # yamllint disable rule:line-length + tls.crt: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNkekNDQWg2Z0F3SUJBZ0lRZUpBWkJMcmxCY2VqNzh3cm4wV1ZIekFLQmdncWhrak9QUVFEQWpDQmlURUwKa0ZGY1FpY29hdE8yRFJnPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t" + # yamllint disable rule:line-length + tls.key: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNkekNDQWg2Z0F3SUJBZ0lRZUpBWkJMcmxCY2VqNzh3cm4wV1ZIekFLQmdncWhrak9QUVFEQWpDQmlURUwKa0ZGY1FpY29hdE8yRFJnPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t" diff --git a/test/chainsaw/testcertificate/cert-recreates/chainsaw-test.yaml b/test/chainsaw/testcertificate/cert-recreates/chainsaw-test.yaml new file mode 100755 index 0000000000..ad67557087 --- /dev/null +++ b/test/chainsaw/testcertificate/cert-recreates/chainsaw-test.yaml @@ -0,0 +1,44 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: cert-recreates +spec: + steps: + - name: step-00 + try: + - delete: + ref: + apiVersion: v1 + kind: Secret + namespace: keptn-system + name: keptn-certs + - script: + content: | + set -e + kubectl rollout restart deployment -n keptn-system -l control-plane=lifecycle-operator + kubectl rollout restart deployment -n keptn-system -l control-plane=metrics-operator + - assert: + file: 00-assert.yaml + - name: step-01 + try: + - apply: + file: 01-delete.yaml + - assert: + file: 01-assert.yaml + - name: step-02 + try: + - apply: + file: 02-install.yaml + - script: + content: | + str1=$(kubectl get secret keptn-certs -n keptn-system -o=go-template='{{index .data "tls.crt"}}') + str2="LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUNkekNDQWg2Z0F3SUJBZ0lRZUpBWkJMcmxCY2VqNzh3cm4wV1ZIekFLQmdncWhrak9QUVFEQWpDQmlURUwKa0ZGY1FpY29hdE8yRFJnPQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t" + if [ "$str1" == "$str2" ]; then + echo "Strings are equal" $str1 + exit 1 + else + echo "Strings are not equal" $str1 "!=" $str2 + fi + - assert: + file: 02-assert.yaml diff --git a/test/chainsaw/testmetrics/metrics-hpa/00-install.yaml b/test/chainsaw/testmetrics/metrics-hpa/00-install.yaml new file mode 100644 index 0000000000..3fde10dabe --- /dev/null +++ b/test/chainsaw/testmetrics/metrics-hpa/00-install.yaml @@ -0,0 +1,49 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podtato-head-entry + labels: + app: podtato-head +spec: + selector: + matchLabels: + component: podtato-head-entry + replicas: 1 + template: + metadata: + labels: + component: podtato-head-entry + spec: + terminationGracePeriodSeconds: 5 + containers: + - name: server + image: ghcr.io/podtato-head/entry:0.2.8 + imagePullPolicy: Always + resources: + limits: + cpu: 10m + memory: 128Mi + requests: + cpu: 5m + memory: 64Mi + ports: + - containerPort: 9000 + env: + - name: PODTATO_PORT + value: "9000" +--- +apiVersion: v1 +kind: Service +metadata: + name: podtato-head-entry + labels: + app: podtato-head +spec: + selector: + component: podtato-head-entry + ports: + - name: http + port: 9000 + protocol: TCP + targetPort: 9000 + type: ClusterIP diff --git a/test/chainsaw/testmetrics/metrics-hpa/chainsaw-test.yaml b/test/chainsaw/testmetrics/metrics-hpa/chainsaw-test.yaml new file mode 100755 index 0000000000..44e2d8ce8a --- /dev/null +++ b/test/chainsaw/testmetrics/metrics-hpa/chainsaw-test.yaml @@ -0,0 +1,30 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + creationTimestamp: null + name: metrics-hpa +spec: + steps: + - name: step-00 + try: + - apply: + file: 00-install.yaml + - script: + content: | + kubectl apply -f mock-server.yaml -n $NAMESPACE + - script: + content: | + echo "registering the metric" + envsubst < metric.yaml | kubectl apply -f - -n $NAMESPACE + echo "configuring HPA" + kubectl apply -f hpa.yaml -n $NAMESPACE + catch: + - podLogs: + selector: app=podtato-head + - script: + content: | + kubectl logs -l app=metrics-operator -n keptn-system + kubectl describe keptnmetric podtatometric -n $NAMESPACE + kubectl describe keptnmetricsprovider dynatrace -n $NAMESPACE + kubectl describe pods -l app=podtato-head -n $NAMESPACE diff --git a/test/chainsaw/testmetrics/metrics-hpa/deployment.yaml b/test/chainsaw/testmetrics/metrics-hpa/deployment.yaml new file mode 100644 index 0000000000..c56170d909 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics-hpa/deployment.yaml @@ -0,0 +1,15 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podtato-head-entry + labels: + app: podtato-head +spec: + selector: + matchLabels: + component: podtato-head-entry + replicas: 3 + template: + metadata: + labels: + component: podtato-head-entry diff --git a/test/chainsaw/testmetrics/metrics-hpa/hpa.yaml b/test/chainsaw/testmetrics/metrics-hpa/hpa.yaml new file mode 100644 index 0000000000..a3107b7a4a --- /dev/null +++ b/test/chainsaw/testmetrics/metrics-hpa/hpa.yaml @@ -0,0 +1,23 @@ +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: podtato-metrics-hpa +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: podtato-head-entry + minReplicas: 1 + maxReplicas: 3 + metrics: + - type: Object + object: + metric: + name: cpu-throttling + describedObject: + apiVersion: metrics.keptn.sh/v1beta1 + kind: KeptnMetric + name: cpu-throttling + target: + type: Value + value: "0.05" diff --git a/test/chainsaw/testmetrics/metrics-hpa/metric.yaml b/test/chainsaw/testmetrics/metrics-hpa/metric.yaml new file mode 100644 index 0000000000..6c72b1c91c --- /dev/null +++ b/test/chainsaw/testmetrics/metrics-hpa/metric.yaml @@ -0,0 +1,19 @@ +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetricsProvider +metadata: + name: my-provider +spec: + type: prometheus + targetServer: "http://mockserver.$NAMESPACE.svc.cluster.local:1080" +--- +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: cpu-throttling +spec: + provider: + name: my-provider + query: 'avg(rate(container_cpu_cfs_throttled_seconds_total{container="server", namespace="podtato-metrics"}))' + fetchIntervalSeconds: 10 + range: + interval: "1m" diff --git a/test/chainsaw/testmetrics/metrics-hpa/mock-server.yaml b/test/chainsaw/testmetrics/metrics-hpa/mock-server.yaml new file mode 100644 index 0000000000..6ad8365e0a --- /dev/null +++ b/test/chainsaw/testmetrics/metrics-hpa/mock-server.yaml @@ -0,0 +1,140 @@ +apiVersion: v1 +kind: Service +metadata: + name: mockserver +spec: + ports: + - name: serviceport + port: 1080 + protocol: TCP + targetPort: serviceport + selector: + app: mockserver + sessionAffinity: None + type: ClusterIP +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: mockserver + name: mockserver +spec: + replicas: 1 + selector: + matchLabels: + app: mockserver + template: + metadata: + labels: + app: mockserver + name: mockserver + spec: + containers: + - env: + - name: MOCKSERVER_LOG_LEVEL + value: INFO + - name: SERVER_PORT + value: "1080" + image: mockserver/mockserver:mockserver-5.13.0 + imagePullPolicy: IfNotPresent + livenessProbe: + failureThreshold: 10 + initialDelaySeconds: 10 + periodSeconds: 5 + successThreshold: 1 + tcpSocket: + port: serviceport + timeoutSeconds: 1 + name: mockserver + ports: + - containerPort: 1080 + name: serviceport + protocol: TCP + readinessProbe: + failureThreshold: 10 + initialDelaySeconds: 2 + periodSeconds: 2 + successThreshold: 1 + tcpSocket: + port: serviceport + timeoutSeconds: 1 + volumeMounts: + - mountPath: /config + name: config-volume + - mountPath: /libs + name: libs-volume + terminationGracePeriodSeconds: 30 + volumes: + - configMap: + defaultMode: 420 + name: mockserver-config + optional: true + name: config-volume + - configMap: + defaultMode: 420 + name: mockserver-config + optional: true + name: libs-volume +--- +kind: ConfigMap +apiVersion: v1 +metadata: + name: mockserver-config +data: + initializerJson.json: |- + [ + { + "httpRequest": { + "path": "/api/v1/query_range", + "method": "POST" + }, + "httpResponse": { + "body": { + "status": "success", + "data": { + "resultType": "matrix", + "result": [ + { + "metric": { + "__name__": "cpu-throttling", + "job": "", + "instance": "" + }, + "values": [[1669714193.275, "4.0"]] + } + ] + } + }, + "statusCode": 200 + } + } + ] + mockserver.properties: |- + ############################### + # MockServer & Proxy Settings # + ############################### + # Socket & Port Settings + # socket timeout in milliseconds (default 120000) + mockserver.maxSocketTimeout=120000 + # Certificate Generation + # dynamically generated CA key pair (if they don't already exist in + specified directory) + mockserver.dynamicallyCreateCertificateAuthorityCertificate=true + # save dynamically generated CA key pair in working directory + mockserver.directoryToSaveDynamicSSLCertificate=. + # certificate domain name (default "localhost") + mockserver.sslCertificateDomainName=localhost + # comma separated list of ip addresses for Subject Alternative Name domain + names (default empty list) + mockserver.sslSubjectAlternativeNameDomains=www.example.com,www.another.com + # comma separated list of ip addresses for Subject Alternative Name ips + (default empty list) + mockserver.sslSubjectAlternativeNameIps=127.0.0.1 + # CORS + # enable CORS for MockServer REST API + mockserver.enableCORSForAPI=true + # enable CORS for all responses + mockserver.enableCORSForAllResponses=true + # Json Initialization + mockserver.initializationJsonPath=/config/initializerJson.json diff --git a/test/chainsaw/testmetrics/metrics-provider/00-install.yaml b/test/chainsaw/testmetrics/metrics-provider/00-install.yaml new file mode 100644 index 0000000000..0144dc52d4 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics-provider/00-install.yaml @@ -0,0 +1,32 @@ +apiVersion: v1 +kind: Secret +metadata: + name: dynatrace + namespace: keptn-system +type: Opaque +data: + DT_TOKEN: dG9rZW46IG15dG9rZW4= +--- +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: podtatometric + namespace: keptn-system +spec: + provider: + name: "dynatrace" + query: "query" + fetchIntervalSeconds: 5 + +--- +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetricsProvider +metadata: + name: dynatrace + namespace: keptn-system +spec: + secretKeyRef: + key: DT_TOKEN + name: dynatrace + type: dynatrace + targetServer: "http://localhost:8080" # string diff --git a/test/chainsaw/testmetrics/metrics-provider/chainsaw-test.yaml b/test/chainsaw/testmetrics/metrics-provider/chainsaw-test.yaml new file mode 100755 index 0000000000..88fedf6d08 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics-provider/chainsaw-test.yaml @@ -0,0 +1,16 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: metrics-provider +spec: + steps: + - name: step-00 + try: + - apply: + file: 00-install.yaml + - name: step-01 + try: + - script: + timeout: 5m + content: ./logs.sh diff --git a/test/chainsaw/testmetrics/metrics-provider/logs.sh b/test/chainsaw/testmetrics/metrics-provider/logs.sh new file mode 100755 index 0000000000..5674082879 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics-provider/logs.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +NAMESPACE="keptn-system" +RETRY_COUNT=3 +SLEEP_TIME=5 + +for i in $(seq 1 $RETRY_COUNT); do + VAR=$(kubectl logs -n $NAMESPACE deployments/lifecycle-operator | grep -c "Error while parsing response") + # shellcheck disable=SC1072 + if [ "$VAR" -ge 1 ]; then + echo "Controller could access secret" + exit 0 + fi + if [ "$i" -lt "$RETRY_COUNT" ]; then + echo "Sleeping for ${SLEEP_TIME} seconds before retrying..." + sleep ${SLEEP_TIME} + fi +done +echo "Retried ${RETRY_COUNT} times, but custom metric value did not meet the condition. Exiting..."exit 1 diff --git a/test/chainsaw/testmetrics/metrics/00-install.yaml b/test/chainsaw/testmetrics/metrics/00-install.yaml new file mode 100644 index 0000000000..6916e95967 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/00-install.yaml @@ -0,0 +1,23 @@ +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetricsProvider +metadata: + name: my-provider +spec: + type: prometheus + targetServer: "http://prometheus-k8s.monitoring.svc.cluster.local:9090" +--- +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetricsProvider +metadata: + name: my-provider2 +spec: + type: prometheus + targetServer: "http://prometheus-k8s.monitoring.svc.cluster.local:9090" +--- +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetricsProvider +metadata: + name: prometheus +spec: + type: prometheus + targetServer: "http://prometheus-k8s.monitoring.svc.cluster.local:9090" diff --git a/test/chainsaw/testmetrics/metrics/badmetric1.yaml b/test/chainsaw/testmetrics/metrics/badmetric1.yaml new file mode 100644 index 0000000000..96fef3d6c3 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/badmetric1.yaml @@ -0,0 +1,11 @@ +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: podtato-head1 +spec: + provider: + name: "my-provider" + query: "sum(kube_pod_container_resource_limits{resource='cpu'})" + fetchIntervalSeconds: 5 + range: + interval: "5mins" diff --git a/test/chainsaw/testmetrics/metrics/badmetric2.yaml b/test/chainsaw/testmetrics/metrics/badmetric2.yaml new file mode 100644 index 0000000000..c5fd1ccbe0 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/badmetric2.yaml @@ -0,0 +1,12 @@ +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: podtato-head1 +spec: + provider: + name: "my-provider" + query: "sum(kube_pod_container_resource_limits{resource='cpu'})" + fetchIntervalSeconds: 5 + range: + interval: "5m" + step: "1mins" diff --git a/test/chainsaw/testmetrics/metrics/badmetric3.yaml b/test/chainsaw/testmetrics/metrics/badmetric3.yaml new file mode 100644 index 0000000000..2dbbc08d6f --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/badmetric3.yaml @@ -0,0 +1,13 @@ +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: podtato-head1 +spec: + provider: + name: "my-provider" + query: "sum(kube_pod_container_resource_limits{resource='cpu'})" + fetchIntervalSeconds: 5 + range: + interval: "5m" + step: "1m" + aggregation: "p91" diff --git a/test/chainsaw/testmetrics/metrics/chainsaw-test.yaml b/test/chainsaw/testmetrics/metrics/chainsaw-test.yaml new file mode 100755 index 0000000000..a393e6f211 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/chainsaw-test.yaml @@ -0,0 +1,79 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + creationTimestamp: null + name: metrics +spec: + steps: + - name: step-00 + try: + - apply: + file: 00-install.yaml + - name: step-01 + try: + - apply: + file: badmetric1.yaml + expect: + - check: + ($error != null): true + - apply: + file: badmetric2.yaml + expect: + - check: + ($error != null): true + - apply: + file: badmetric3.yaml + expect: + - check: + ($error != null): true + - apply: + file: goodmetric1.yaml + - apply: + file: goodmetric2.yaml + - apply: + file: goodmetric3.yaml + - apply: + file: goodmetric4.yaml + - apply: + file: goodmetric5.yaml + - apply: + file: goodmetric6.yaml + - name: step-02 + try: + - assert: + file: goodmetric1.yaml + - assert: + file: goodmetric2.yaml + - assert: + file: goodmetric3.yaml + - assert: + file: goodmetric4.yaml + - assert: + file: goodmetric5.yaml + - assert: + file: goodmetric6.yaml + - error: + file: badmetric1.yaml + - error: + file: badmetric2.yaml + - error: + file: badmetric3.yaml + - name: step-03 + try: + - script: + content: ./retrieve-metrics.sh "podtato-head1" + - script: + content: ./retrieve-metrics.sh "podtato-head2" + - script: + content: ./retrieve-metrics.sh "podtato-head3" + - script: + content: ./retrieve-metrics.sh "podtato-head4" + - script: + content: ./retrieve-metrics.sh "podtato-head5" + - script: + content: ./retrieve-metrics.sh "podtato-head6" + - name: step-04 + try: + - script: + content: ./check-active-metrics.sh "keptn_lifecycle_active" diff --git a/test/chainsaw/testmetrics/metrics/check-active-metrics.sh b/test/chainsaw/testmetrics/metrics/check-active-metrics.sh new file mode 100755 index 0000000000..dacd571298 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/check-active-metrics.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Usage: ./retrieve-metrics.sh + +component_name=$1 + +metrics_url="http://lifecycle-operator-metrics-service.keptn-system.svc.cluster.local:2222/metrics" + +# Fetch keptn_lifecycle_active metrics +metrics=$(curl -s $metrics_url | grep "${component_name}") + +echo "$metrics" diff --git a/test/chainsaw/testmetrics/metrics/goodmetric1.yaml b/test/chainsaw/testmetrics/metrics/goodmetric1.yaml new file mode 100644 index 0000000000..9e0b73f3ab --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/goodmetric1.yaml @@ -0,0 +1,11 @@ +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: podtato-head1 +spec: + provider: + name: "my-provider" + query: "sum(kube_pod_container_resource_limits{resource='cpu'})" + fetchIntervalSeconds: 5 + range: + interval: "5m" diff --git a/test/chainsaw/testmetrics/metrics/goodmetric2.yaml b/test/chainsaw/testmetrics/metrics/goodmetric2.yaml new file mode 100644 index 0000000000..a03242714c --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/goodmetric2.yaml @@ -0,0 +1,11 @@ +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: podtato-head2 +spec: + provider: + name: "prometheus" + query: "sum(kube_pod_container_resource_limits{resource='cpu'})" + fetchIntervalSeconds: 5 + range: + interval: "5m" diff --git a/test/chainsaw/testmetrics/metrics/goodmetric3.yaml b/test/chainsaw/testmetrics/metrics/goodmetric3.yaml new file mode 100644 index 0000000000..b531508f3c --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/goodmetric3.yaml @@ -0,0 +1,11 @@ +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: podtato-head3 +spec: + provider: + name: "my-provider2" + query: "sum(kube_pod_container_resource_limits{resource='cpu'})" + fetchIntervalSeconds: 5 + range: + interval: "5m" diff --git a/test/chainsaw/testmetrics/metrics/goodmetric4.yaml b/test/chainsaw/testmetrics/metrics/goodmetric4.yaml new file mode 100644 index 0000000000..83375eebf7 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/goodmetric4.yaml @@ -0,0 +1,9 @@ +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: podtato-head4 +spec: + provider: + name: "prometheus" + query: "sum(kube_pod_container_resource_limits{resource='cpu'})" + fetchIntervalSeconds: 5 diff --git a/test/chainsaw/testmetrics/metrics/goodmetric5.yaml b/test/chainsaw/testmetrics/metrics/goodmetric5.yaml new file mode 100644 index 0000000000..72ade8cc6a --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/goodmetric5.yaml @@ -0,0 +1,13 @@ +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: podtato-head5 +spec: + provider: + name: "my-provider2" + query: "sum(kube_pod_container_resource_limits{resource='cpu'})" + fetchIntervalSeconds: 5 + range: + interval: "5m" + step: "1m" + aggregation: "p90" diff --git a/test/chainsaw/testmetrics/metrics/goodmetric6.yaml b/test/chainsaw/testmetrics/metrics/goodmetric6.yaml new file mode 100644 index 0000000000..3cfdce1104 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/goodmetric6.yaml @@ -0,0 +1,14 @@ +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: podtato-head6 +spec: + provider: + name: "my-provider2" + query: "sum(kube_pod_container_resource_limits{resource='cpu'})" + fetchIntervalSeconds: 5 + range: + interval: "5m" + step: "1m" + aggregation: "p90" + storedResults: 5 diff --git a/test/chainsaw/testmetrics/metrics/retrieve-metrics.sh b/test/chainsaw/testmetrics/metrics/retrieve-metrics.sh new file mode 100755 index 0000000000..777f096727 --- /dev/null +++ b/test/chainsaw/testmetrics/metrics/retrieve-metrics.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +METRIC_NAME=$1 +RETRY_COUNT=3 +SLEEP_TIME=5 + +for i in $(seq 1 $RETRY_COUNT); do + # Retrieve the custom metric value + METRIC_VALUE=$(kubectl get --raw "/apis/custom.metrics.k8s.io/v1beta1/namespaces/${NAMESPACE}/keptnmetrics.metrics.sh/${METRIC_NAME}/${METRIC_NAME}") + + LENGTH_ITEMS=$(echo $METRIC_VALUE | jq '.items | length') + + if [[ $LENGTH_ITEMS == 1 ]]; then + echo "Found the expected metric $METRIC_NAME" + exit 0 + else + echo "The length of the property .items of $METRIC_NAME is not 1, it is: $LENGTH_ITEMS" + fi + + if [ "$i" -lt "$RETRY_COUNT" ]; then + echo "Sleeping for ${SLEEP_TIME} seconds before retrying..." + sleep ${SLEEP_TIME} + fi +done + +echo "Retried ${RETRY_COUNT} times, but custom metric value did not meet the condition. Exiting..." +exit 1