Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feat/cert-operator-…
Browse files Browse the repository at this point in the history
…config
  • Loading branch information
bacherfl committed May 3, 2023
2 parents 78ffedc + d5000da commit 2f63552
Show file tree
Hide file tree
Showing 27 changed files with 493 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{".":"0.7.0"}
{".":"0.7.1"}
161 changes: 161 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
KUSTOMIZE_VERSION?=v5.0.1
# renovate: datasource=github-tags depName=helm/helm
HELM_VERSION ?= v3.11.3
CHART_APPVERSION ?= v0.7.0 # x-release-please-version
CHART_APPVERSION ?= v0.7.1 # x-release-please-version

# renovate: datasource=docker depName=cytopia/yamllint
YAMLLINT_VERSION ?= alpine
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ For installing the Lifecycle Toolkit via manifests use:
<!---x-release-please-start-version-->

```shell
kubectl apply -f https://github.com/keptn/lifecycle-toolkit/releases/download/v0.7.0/manifest.yaml
kubectl apply -f https://github.com/keptn/lifecycle-toolkit/releases/download/v0.7.1/manifest.yaml
```

<!---x-release-please-end-->
Expand Down Expand Up @@ -322,6 +322,8 @@ a `PostDeploymentCheck` can be triggered.

A `KeptnTaskDefinition` is a CRD used to define tasks that can be run by the Keptn Lifecycle Toolkit
as part of pre- and post-deployment phases of a deployment.
`KeptnTaskDefinition` resource can be created in the namespace where the application is running, or
in the default KLT namespace, which will be the fallback option for the system to search.
The task definition is a [Deno](https://deno.land/) script
Please, refer to the [function runtime](./functions-runtime/) folder for more information about the runtime.
In the future, we also intend to support other runtimes, especially running a container image directly.
Expand Down Expand Up @@ -485,6 +487,9 @@ resource is specified and the `KeptnMetric` resource does not exist in this name

The `KeptnConfig` is a CRD defines configuration values for the Keptn Lifecycle Toolkit.
Currently, it can be used to configure the URL of the OpenTelemetry collector.
Additionally, it can be used to set the time interval in which automatic app discovery
searches for workloads to put into the same auto-generated `KeptnApp`.
When the parameter is not set, the default value is 30 seconds.

A `KeptnConfig` looks like the following:

Expand All @@ -495,6 +500,7 @@ metadata:
name: keptnconfig-sample
spec:
OTelCollectorUrl: 'otel-collector:4317'
keptnAppCreationRequestTimeoutSeconds: 30
```

## Install a dev build
Expand Down
36 changes: 13 additions & 23 deletions docs/content/en/docs/concepts/evaluations/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,24 @@ as part of pre- and post-analysis phases of a workload or application.
A Keptn evaluation definition looks like the following:

```yaml
apiVersion: lifecycle.keptn.sh/v1alpha2
apiVersion: lifecycle.keptn.sh/v1alpha3
kind: KeptnEvaluationDefinition
metadata:
name: my-prometheus-evaluation
namespace: example
spec:
source: prometheus
objectives:
- name: query-1
query: "xxxx"
evaluationTarget: <20
- name: query-2
query: "yyyy"
evaluationTarget: >4
- keptnMetricRef:
name: available-cpus
namespace: example
evaluationTarget: ">1"
- keptnMetricRef:
name: cpus-throttling
namespace: example
evaluationTarget: "<0.01"
```

### Keptn Evaluation Provider

A `KeptnEvaluationProvider` is a CRD used to define evaluation provider, which will provide data for the
pre- and post-analysis phases of a workload or application.

A Keptn evaluation provider looks like the following:

```yaml
apiVersion: lifecycle.keptn.sh/v1alpha2
kind: KeptnEvaluationProvider
metadata:
name: prometheus
spec:
targetServer: "http://prometheus-k8s.monitoring.svc.cluster.local:9090"
secretName: prometheusLoginCredentials
```
A `KeptnEvaluationDefinition` references one or more [`KeptnMetric`s](../metrics/).
If multiple `KeptnMetric`s are used, the Keptn Lifecycle Toolkit will consider the
evaluation successful if **all** metrics are respecting their `evaluationTarget`.
4 changes: 4 additions & 0 deletions docs/content/en/docs/concepts/keptnConfig/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ hidechildren: true # this flag hides all sub-pages in the sidebar-multicard.html

A `KeptnConfig` CRD defines configuration values for the Keptn Lifecycle Toolkit.
Currently, it can be used to configure the URL of the OpenTelemetry collector.
Additionally, it can be used to set the time interval in which automatic app discovery
searches for workloads to put into the same auto-generated `KeptnApp`.
When the parameter is not set, the default value is 30 seconds.

A `KeptnConfig` looks like the following:

Expand All @@ -22,4 +25,5 @@ metadata:
name: keptnconfig-sample
spec:
OTelCollectorUrl: 'otel-collector:4317'
keptnAppCreationRequestTimeoutSeconds: 30
```
2 changes: 2 additions & 0 deletions docs/content/en/docs/concepts/tasks/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ hidechildren: true # this flag hides all sub-pages in the sidebar-multicard.html

A `KeptnTaskDefinition` is a CRD used to define tasks that can be run by the Keptn Lifecycle Toolkit
as part of pre- and post-deployment phases of a deployment.
`KeptnTaskDefinition` resource can be created in the namespace where the application is running, or
in the default KLT namespace, which will be the fallback option for the system to search.
The task definition is a [Deno](https://deno.land/) script
Please, refer to the [function runtime](https://github.com/keptn/lifecycle-toolkit/tree/main/functions-runtime) for more
information about the runtime.
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/docs/getting-started/orchestrate/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Getting started with the Lifecycle Toolkit
title: Orchestrate deployment checks
description: Learn how the Keptn Lifecycle Toolkit can orchestrate deployment checks.
weight: 55
---
Expand Down
2 changes: 1 addition & 1 deletion docs/content/en/docs/snippets/tasks/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ with a command like the following:
<!---x-release-please-start-version-->

```shell
kubectl apply -f https://github.com/keptn/lifecycle-toolkit/releases/download/v0.7.0/manifest.yaml
kubectl apply -f https://github.com/keptn/lifecycle-toolkit/releases/download/v0.7.1/manifest.yaml
kubectl wait --for=condition=Available deployment/lifecycle-operator -n keptn-lifecycle-toolkit-system --timeout=120s
```

Expand Down
1 change: 1 addition & 0 deletions examples/support/keptn/keptnconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ metadata:
name: keptnconfig-sample
spec:
OTelCollectorUrl: 'otel-collector:4317'
keptnAppCreationRequestTimeoutSeconds: 30
2 changes: 1 addition & 1 deletion helm/chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ version: 0.2.1
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v0.7.0" # x-release-please-version
appVersion: "v0.7.1" # x-release-please-version
10 changes: 5 additions & 5 deletions helm/chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ checks
| `scheduler.scheduler.containerSecurityContext` | Sets security context | |
| `scheduler.scheduler.env.otelCollectorUrl` | sets url for open telemetry collector | `otel-collector:4317` |
| `scheduler.scheduler.image.repository` | set image repository for scheduler | `ghcr.keptn.sh/keptn/scheduler` |
| `scheduler.scheduler.image.tag` | set image tag for scheduler <!---x-release-please-version--> | `v0.7.0` |
| `scheduler.scheduler.image.tag` | set image tag for scheduler <!---x-release-please-version--> | `v0.7.1` |
| `scheduler.scheduler.imagePullPolicy` | set image pull policy for scheduler | `Always` |
| `scheduler.scheduler.livenessProbe` | customizable liveness probe for the scheduler | |
| `scheduler.scheduler.readinessProbe` | customizable readiness probe for the scheduler | |
Expand Down Expand Up @@ -46,7 +46,7 @@ checks
| ------------------------------------------------------ | ------------------------------------------------------------------------- | ------------------------------------------ |
| `certificateOperator.manager.containerSecurityContext` | Sets security context for the cert manager | |
| `certificateOperator.manager.image.repository` | specify repo for manager image | `ghcr.keptn.sh/keptn/certificate-operator` |
| `certificateOperator.manager.image.tag` | select tag for manager container <!---x-release-please-version--> | `v0.7.0` |
| `certificateOperator.manager.image.tag` | select tag for manager container <!---x-release-please-version--> | `v0.7.1` |
| `certificateOperator.manager.imagePullPolicy` | select image pull policy for manager container | `Always` |
| `certificateOperator.manager.env.labelSelectorKey` | specify the label selector to find resources to generate certificates for | `keptn.sh/inject-cert` |
| `certificateOperator.manager.env.labelSelectorValue` | specify the value for the label selector | `true` |
Expand Down Expand Up @@ -91,9 +91,9 @@ checks
| `lifecycleOperator.manager.env.keptnWorkloadInstanceControllerLogLevel` | sets the log level of Keptn WorkloadInstance Controller | `0` |
| `lifecycleOperator.manager.env.optionsControllerLogLevel` | sets the log level of Keptn Options Controller | `0` |
| `lifecycleOperator.manager.env.otelCollectorUrl` | Sets the URL for the open telemetry collector | `otel-collector:4317` |
| `lifecycleOperator.manager.env.functionRunnerImage` | specify image for task runtime <!---x-release-please-version--> | `ghcr.keptn.sh/keptn/functions-runtime:v0.7.0` |
| `lifecycleOperator.manager.env.functionRunnerImage` | specify image for task runtime <!---x-release-please-version--> | `ghcr.keptn.sh/keptn/functions-runtime:v0.7.1` |
| `lifecycleOperator.manager.image.repository` | specify registry for manager image | `ghcr.keptn.sh/keptn/lifecycle-operator` |
| `lifecycleOperator.manager.image.tag` | select tag for manager image <!---x-release-please-version--> | `v0.7.0` |
| `lifecycleOperator.manager.image.tag` | select tag for manager image <!---x-release-please-version--> | `v0.7.1` |
| `lifecycleOperator.manager.imagePullPolicy` | specify pull policy for manager image | `Always` |
| `lifecycleOperator.manager.livenessProbe` | custom livenessprobe for manager container | |
| `lifecycleOperator.manager.readinessProbe` | custom readinessprobe for manager container | |
Expand Down Expand Up @@ -146,7 +146,7 @@ checks
| `metricsOperator.manager.containerSecurityContext.runAsUser` | | `65532` |
| `metricsOperator.manager.containerSecurityContext.seccompProfile.type` | | `RuntimeDefault` |
| `metricsOperator.manager.image.repository` | specify registry for manager image | `ghcr.keptn.sh/keptn/metrics-operator` |
| `metricsOperator.manager.image.tag` | select tag for manager image <!---x-release-please-version--> | `v0.7.0` |
| `metricsOperator.manager.image.tag` | select tag for manager image <!---x-release-please-version--> | `v0.7.1` |
| `metricsOperator.manager.env.exposeKeptnMetrics` | enable metrics exporter | `true` |
| `metricsOperator.manager.env.metricsControllerLogLevel` | sets the log level of Metrics Controller | `0` |
| `metricsOperator.manager.livenessProbe` | custom livenessprobe for manager container | |
Expand Down
2 changes: 1 addition & 1 deletion klt-cert-manager/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RELEASE_REGISTRY?=ghcr.io/keptn
RELEASE_TIME=$(shell date +%Y%m%d%s)
BUILD_TIME=$(shell date -u "+%F_%T")
RELEASE_VERSION?=$(RELEASE_TIME)-v0.24.3#$(shell git describe --tags --match "v*")
TAG?="v0.7.0" # x-release-please-version
TAG?="v0.7.1" # x-release-please-version
RELEASE_IMAGE:=certificate-operator:$(TAG)
CHART_APPVERSION?=""

Expand Down
2 changes: 1 addition & 1 deletion metrics-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RELEASE_REGISTRY?=ghcr.io/keptn
RELEASE_TIME=$(shell date +%Y%m%d%s)
BUILD_TIME=$(shell date -u "+%F_%T")
RELEASE_VERSION?=$(RELEASE_TIME)-v0.24.3#$(shell git describe --tags --match "v*")
TAG?="v0.7.0" # x-release-please-version
TAG?="v0.7.1" # x-release-please-version
RELEASE_IMAGE:=metrics-operator:$(TAG)
CHART_APPVERSION?=""

Expand Down
2 changes: 1 addition & 1 deletion operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RELEASE_REGISTRY?=ghcr.io/keptn
RELEASE_TIME=$(shell date +%Y%m%d%s)
BUILD_TIME=$(shell date -u "+%F_%T")
RELEASE_VERSION?=$(RELEASE_TIME)-v0.24.3#$(shell git describe --tags --match "v*")
TAG?="v0.7.0" # x-release-please-version
TAG?="v0.7.1" # x-release-please-version
RELEASE_IMAGE:=lifecycle-operator:$(TAG)
CHART_APPVERSION?=""

Expand Down
2 changes: 1 addition & 1 deletion operator/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ spec:
fieldRef:
fieldPath: metadata.name
- name: FUNCTION_RUNNER_IMAGE
value: ghcr.keptn.sh/keptn/functions-runtime:v0.7.0 # x-release-please-version
value: ghcr.keptn.sh/keptn/functions-runtime:v0.7.1 # x-release-please-version
- name: OTEL_COLLECTOR_URL
value: otel-collector:4317
- name: KEPTN_APP_CONTROLLER_LOG_LEVEL
Expand Down
22 changes: 22 additions & 0 deletions operator/controllers/common/helperfunctions.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package common

import (
"context"
"fmt"

"github.com/go-logr/logr"
klcv1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3"
apicommon "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3/common"
"github.com/keptn/lifecycle-toolkit/operator/controllers/lifecycle/interfaces"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const KLTNamespace = "keptn-lifecycle-toolkit-system"

// GetItemStatus retrieves the state of the task/evaluation, if it does not exists, it creates a default one
func GetItemStatus(name string, instanceStatus []klcv1alpha3.ItemStatus) klcv1alpha3.ItemStatus {
for _, status := range instanceStatus {
Expand Down Expand Up @@ -81,3 +86,20 @@ func copyMap[M1 ~map[K]V, M2 ~map[K]V, K comparable, V any](dst M1, src M2) {
dst[k] = v
}
}

func GetTaskDefinition(k8sclient client.Client, log logr.Logger, ctx context.Context, definitionName string, namespace string) (*klcv1alpha3.KeptnTaskDefinition, error) {
definition := &klcv1alpha3.KeptnTaskDefinition{}
err := k8sclient.Get(ctx, types.NamespacedName{Name: definitionName, Namespace: namespace}, definition)
if err != nil {
log.Error(err, "Failed to get KeptnTaskDefinition from application namespace")
if k8serrors.IsNotFound(err) {
if err := k8sclient.Get(ctx, types.NamespacedName{Name: definitionName, Namespace: KLTNamespace}, definition); err != nil {
log.Error(err, "Failed to get KeptnTaskDefinition from default KLT namespace")
return nil, err
}
return definition, nil
}
return nil, err
}
return definition, nil
}
85 changes: 85 additions & 0 deletions operator/controllers/common/helperfunctions_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package common

import (
"context"
"testing"

klcv1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3"
apicommon "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3/common"
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func Test_GetItemStatus(t *testing.T) {
Expand Down Expand Up @@ -402,3 +406,84 @@ func Test_setAnnotations(t *testing.T) {
})
}
}

func Test_GetTaskDefinition(t *testing.T) {
tests := []struct {
name string
taskDef *klcv1alpha3.KeptnTaskDefinition
taskDefName string
taskDefNamespace string
out *klcv1alpha3.KeptnTaskDefinition
wantError bool
}{
{
name: "taskDef not found",
taskDef: &klcv1alpha3.KeptnTaskDefinition{
ObjectMeta: v1.ObjectMeta{
Name: "taskDef",
Namespace: "some-other-namespace",
},
},
taskDefName: "taskDef",
taskDefNamespace: "some-namespace",
out: nil,
wantError: true,
},
{
name: "taskDef found",
taskDef: &klcv1alpha3.KeptnTaskDefinition{
ObjectMeta: v1.ObjectMeta{
Name: "taskDef",
Namespace: "some-namespace",
},
},
taskDefName: "taskDef",
taskDefNamespace: "some-namespace",
out: &klcv1alpha3.KeptnTaskDefinition{
ObjectMeta: v1.ObjectMeta{
Name: "taskDef",
Namespace: "some-namespace",
},
},
wantError: false,
},
{
name: "taskDef found in default KLT namespace",
taskDef: &klcv1alpha3.KeptnTaskDefinition{
ObjectMeta: v1.ObjectMeta{
Name: "taskDef",
Namespace: KLTNamespace,
},
},
taskDefName: "taskDef",
taskDefNamespace: "some-namespace",
out: &klcv1alpha3.KeptnTaskDefinition{
ObjectMeta: v1.ObjectMeta{
Name: "taskDef",
Namespace: KLTNamespace,
},
},
wantError: false,
},
}

err := klcv1alpha3.AddToScheme(scheme.Scheme)
require.Nil(t, err)

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := fake.NewClientBuilder().WithObjects(tt.taskDef).Build()
d, err := GetTaskDefinition(client, ctrl.Log.WithName("testytest"), context.TODO(), tt.taskDefName, tt.taskDefNamespace)
if tt.out != nil && d != nil {
require.Equal(t, tt.out.Name, d.Name)
require.Equal(t, tt.out.Namespace, d.Namespace)
} else if tt.out != d {
t.Errorf("want: %v, got: %v", tt.out, d)
}
if tt.wantError != (err != nil) {
t.Errorf("want error: %t, got: %v", tt.wantError, err)
}

})
}
}
Loading

0 comments on commit 2f63552

Please sign in to comment.