Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create telemetry resource by default for applications #529

Merged
merged 14 commits into from
Sep 13, 2024
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
.vscode/
.idea/
dist/
istio*
!**/istio/
istio-*
!**/istio/
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ spec:
- name: smtp
protocol: TCP
port: 587
# podSettings are used to apply specific settings to the Pod Template used by Skiperator to create Deployments.
podSettings:
annotations:
some-annotation: some-value
terminationGracePeriodSeconds: 30
disablePodSpreadTopologyConstraints: false
# istioSettings are used to configure istio specific resources. Currently, adjusting sampling interval for tracing is
# the only supported option.
istioSettings:
telemetry:
tracing:
- randomSamplingPercentage: 10


```

## SKIPJob reference
Expand Down
14 changes: 12 additions & 2 deletions api/v1alpha1/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"github.com/kartverket/skiperator/api/v1alpha1/digdirator"
"github.com/kartverket/skiperator/api/v1alpha1/istiotypes"
"github.com/kartverket/skiperator/api/v1alpha1/podtypes"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand Down Expand Up @@ -242,6 +243,14 @@ type ApplicationSpec struct {
//
//+kubebuilder:validation:Optional
PodSettings *podtypes.PodSettings `json:"podSettings,omitempty"`

// IstioSettings are used to configure istio specific resources such as telemetry. Currently, adjusting sampling
// interval for tracing is the only supported option.
// By default, tracing is enabled with a random sampling percentage of 10%.
//
//+kubebuilder:validation:Optional
//+kubebuilder:default:={telemetry: {tracing: {{randomSamplingPercentage: 10}}}}
IstioSettings *istiotypes.IstioSettings `json:"istioSettings,omitempty"`
}

// AuthorizationSettings Settings for overriding the default deny of all actuator endpoints. AllowAll will allow any
Expand Down Expand Up @@ -427,8 +436,9 @@ func (a *Application) GetDefaultLabels() map[string]string {

func (a *Application) GetCommonSpec() *CommonSpec {
return &CommonSpec{
GCP: a.Spec.GCP,
AccessPolicy: a.Spec.AccessPolicy,
GCP: a.Spec.GCP,
AccessPolicy: a.Spec.AccessPolicy,
IstioSettings: a.Spec.IstioSettings,
}
}

Expand Down
38 changes: 38 additions & 0 deletions api/v1alpha1/istiotypes/istio_settings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This package reimplements specific parts of the Telemetry struct from "istio.io/api/telemetry/v1" in order to be
// forward compatible if we choose to incorporate the struct directly in the future.

package istiotypes

// Tracing contains relevant settings for tracing in the telemetry configuration
omaen marked this conversation as resolved.
Show resolved Hide resolved
// +kubebuilder:object:generate=true
type Tracing struct {
// NB: RandomSamplingPercentage uses a wrapped type of *wrappers.DoubleValue in the original struct, but due
// to incompatibalities with the kubebuilder code generator, we have chosen to use a simple int instead. This only allows
// for whole numbers, but this is sufficient for our use case.

// RandomSamplingPercentage is the percentage of requests that should be sampled for tracing, specified by a whole number between 0-100.
// Setting RandomSamplingPercentage to 0 will disable tracing.
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=100
// +kubebuilder:default:=10
RandomSamplingPercentage int `json:"randomSamplingPercentage,omitempty"`
omaen marked this conversation as resolved.
Show resolved Hide resolved
}

// Telemetry is a placeholder for all relevant telemetry types, and may be extended in the future to configure additional telemetry settings.
//
// +kubebuilder:object:generate=true
type Telemetry struct {
// Tracing is a list of tracing configurations for the telemetry resource. Normally only one tracing configuration is needed.
// +kubebuilder:validation:Optional
// +kubebuilder:default:={{randomSamplingPercentage: 10}}
Tracing []*Tracing `json:"tracing,omitempty"`
}

// IstioSettings contains configuration settings for istio resources. Currently only telemetry configuration is supported.
//
// +kubebuilder:object:generate=true
type IstioSettings struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default:={tracing: {{randomSamplingPercentage: 10}}}
Telemetry Telemetry `json:"telemetry,omitempty"`
}
64 changes: 64 additions & 0 deletions api/v1alpha1/istiotypes/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions api/v1alpha1/skipjob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1alpha1
import (
"dario.cat/mergo"
"fmt"
"github.com/kartverket/skiperator/api/v1alpha1/istiotypes"
"github.com/kartverket/skiperator/api/v1alpha1/podtypes"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -81,6 +82,14 @@ type SKIPJobSpec struct {
// +kubebuilder:validation:Required
Container ContainerSettings `json:"container"`

// IstioSettings are used to configure istio specific resources such as telemetry. Currently, adjusting sampling
// interval for tracing is the only supported option.
// By default, tracing is enabled with a random sampling percentage of 10%.
//
//+kubebuilder:validation:Optional
//+kubebuilder:default:={telemetry: {tracing: {{randomSamplingPercentage: 10}}}}
IstioSettings *istiotypes.IstioSettings `json:"istioSettings,omitempty"`

// Prometheus settings for pod running in job. Fields are identical to Application and if set,
// a podmonitoring object is created.
Prometheus *PrometheusConfig `json:"prometheus,omitempty"`
Expand Down Expand Up @@ -279,7 +288,8 @@ func (skipJob *SKIPJob) GetDefaultLabels() map[string]string {

func (skipJob *SKIPJob) GetCommonSpec() *CommonSpec {
return &CommonSpec{
GCP: skipJob.Spec.Container.GCP,
AccessPolicy: skipJob.Spec.Container.AccessPolicy,
GCP: skipJob.Spec.Container.GCP,
AccessPolicy: skipJob.Spec.Container.AccessPolicy,
IstioSettings: skipJob.Spec.IstioSettings,
}
}
4 changes: 3 additions & 1 deletion api/v1alpha1/skipns_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v1alpha1

import corev1 "k8s.io/api/core/v1"
import (
corev1 "k8s.io/api/core/v1"
)

/*
* SKIPNamespace is a wrapper for the kubernetes namespace resource, so we can utilize the SKIPObject interface
Expand Down
6 changes: 4 additions & 2 deletions api/v1alpha1/skipobj_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha1

import (
"fmt"
"github.com/kartverket/skiperator/api/v1alpha1/istiotypes"
"github.com/kartverket/skiperator/api/v1alpha1/podtypes"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -18,6 +19,7 @@ var ErrNoGVK = fmt.Errorf("no GroupVersionKind found in the resources, cannot pr

// CommonSpec TODO: This needs some more thought. We should probably try to expand on it. v1Alpha2?
type CommonSpec struct {
AccessPolicy *podtypes.AccessPolicy
GCP *podtypes.GCP
AccessPolicy *podtypes.AccessPolicy
GCP *podtypes.GCP
IstioSettings *istiotypes.IstioSettings
}
11 changes: 11 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions config/crd/skiperator.kartverket.no_applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,46 @@ spec:
items:
type: string
type: array
istioSettings:
default:
telemetry:
tracing:
- randomSamplingPercentage: 10
description: |-
IstioSettings are used to configure istio specific resources such as telemetry. Currently, adjusting sampling
interval for tracing is the only supported option.
By default, tracing is enabled with a random sampling percentage of 10%.
properties:
telemetry:
default:
tracing:
- randomSamplingPercentage: 10
description: Telemetry is a placeholder for all relevant telemetry
types, and may be extended in the future to configure additional
telemetry settings.
properties:
tracing:
default:
- randomSamplingPercentage: 10
description: Tracing is a list of tracing configurations for
the telemetry resource. Normally only one tracing configuration
is needed.
items:
description: Tracing contains relevant settings for tracing
in the telemetry configuration
properties:
randomSamplingPercentage:
default: 10
description: |-
RandomSamplingPercentage is the percentage of requests that should be sampled for tracing, specified by a whole number between 0-100.
Setting RandomSamplingPercentage to 0 will disable tracing.
maximum: 100
minimum: 0
type: integer
type: object
type: array
type: object
type: object
labels:
additionalProperties:
type: string
Expand Down
40 changes: 40 additions & 0 deletions config/crd/skiperator.kartverket.no_skipjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,46 @@ spec:
required:
- schedule
type: object
istioSettings:
default:
telemetry:
tracing:
- randomSamplingPercentage: 10
description: |-
IstioSettings are used to configure istio specific resources such as telemetry. Currently, adjusting sampling
interval for tracing is the only supported option.
By default, tracing is enabled with a random sampling percentage of 10%.
properties:
telemetry:
default:
tracing:
- randomSamplingPercentage: 10
description: Telemetry is a placeholder for all relevant telemetry
types, and may be extended in the future to configure additional
telemetry settings.
properties:
tracing:
default:
- randomSamplingPercentage: 10
description: Tracing is a list of tracing configurations for
the telemetry resource. Normally only one tracing configuration
is needed.
items:
description: Tracing contains relevant settings for tracing
in the telemetry configuration
properties:
randomSamplingPercentage:
default: 10
description: |-
RandomSamplingPercentage is the percentage of requests that should be sampled for tracing, specified by a whole number between 0-100.
Setting RandomSamplingPercentage to 0 will disable tracing.
maximum: 100
minimum: 0
type: integer
type: object
type: array
type: object
type: object
job:
description: Settings for the actual Job. If you use a scheduled job,
the settings in here will also specify the template of the job.
Expand Down
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,15 @@ rules:
- list
- update
- watch
- apiGroups:
- telemetry.istio.io
resources:
- telemetries
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
Loading
Loading