Skip to content

Commit f6c6af6

Browse files
authored
Create telemetry resource by default for applications (#529)
* Create telemetry resource by default for applications * Fix gitignore * Update CRDs * Add telemetry to skipjob * Set validation to optional * Add Telemetry to jobSchemas * Add missing CRD update * Update docs * Specify type in telemetry name * Update tests * Remove obsolete code * Clean up
1 parent 7965d30 commit f6c6af6

28 files changed

+470
-11
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
.vscode/
88
.idea/
99
dist/
10-
istio*
11-
!**/istio/
10+
istio-*
11+
!**/istio/

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,20 @@ spec:
163163
- name: smtp
164164
protocol: TCP
165165
port: 587
166+
# podSettings are used to apply specific settings to the Pod Template used by Skiperator to create Deployments.
167+
podSettings:
168+
annotations:
169+
some-annotation: some-value
170+
terminationGracePeriodSeconds: 30
171+
disablePodSpreadTopologyConstraints: false
172+
# istioSettings are used to configure istio specific resources. Currently, adjusting sampling interval for tracing is
173+
# the only supported option.
174+
istioSettings:
175+
telemetry:
176+
tracing:
177+
- randomSamplingPercentage: 10
178+
179+
166180
```
167181

168182
## SKIPJob reference

api/v1alpha1/application_types.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"errors"
66
"github.com/kartverket/skiperator/api/v1alpha1/digdirator"
7+
"github.com/kartverket/skiperator/api/v1alpha1/istiotypes"
78
"github.com/kartverket/skiperator/api/v1alpha1/podtypes"
89
corev1 "k8s.io/api/core/v1"
910
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -242,6 +243,14 @@ type ApplicationSpec struct {
242243
//
243244
//+kubebuilder:validation:Optional
244245
PodSettings *podtypes.PodSettings `json:"podSettings,omitempty"`
246+
247+
// IstioSettings are used to configure istio specific resources such as telemetry. Currently, adjusting sampling
248+
// interval for tracing is the only supported option.
249+
// By default, tracing is enabled with a random sampling percentage of 10%.
250+
//
251+
//+kubebuilder:validation:Optional
252+
//+kubebuilder:default:={telemetry: {tracing: {{randomSamplingPercentage: 10}}}}
253+
IstioSettings *istiotypes.IstioSettings `json:"istioSettings,omitempty"`
245254
}
246255

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

428437
func (a *Application) GetCommonSpec() *CommonSpec {
429438
return &CommonSpec{
430-
GCP: a.Spec.GCP,
431-
AccessPolicy: a.Spec.AccessPolicy,
439+
GCP: a.Spec.GCP,
440+
AccessPolicy: a.Spec.AccessPolicy,
441+
IstioSettings: a.Spec.IstioSettings,
432442
}
433443
}
434444

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This package reimplements specific parts of the Telemetry struct from "istio.io/api/telemetry/v1" in order to be
2+
// forward compatible if we choose to incorporate the struct directly in the future.
3+
4+
package istiotypes
5+
6+
// Tracing contains relevant settings for tracing in the telemetry configuration
7+
// +kubebuilder:object:generate=true
8+
type Tracing struct {
9+
// NB: RandomSamplingPercentage uses a wrapped type of *wrappers.DoubleValue in the original struct, but due
10+
// to incompatibalities with the kubebuilder code generator, we have chosen to use a simple int instead. This only allows
11+
// for whole numbers, but this is sufficient for our use case.
12+
13+
// RandomSamplingPercentage is the percentage of requests that should be sampled for tracing, specified by a whole number between 0-100.
14+
// Setting RandomSamplingPercentage to 0 will disable tracing.
15+
// +kubebuilder:validation:Minimum=0
16+
// +kubebuilder:validation:Maximum=100
17+
// +kubebuilder:default:=10
18+
RandomSamplingPercentage int `json:"randomSamplingPercentage,omitempty"`
19+
}
20+
21+
// Telemetry is a placeholder for all relevant telemetry types, and may be extended in the future to configure additional telemetry settings.
22+
//
23+
// +kubebuilder:object:generate=true
24+
type Telemetry struct {
25+
// Tracing is a list of tracing configurations for the telemetry resource. Normally only one tracing configuration is needed.
26+
// +kubebuilder:validation:Optional
27+
// +kubebuilder:default:={{randomSamplingPercentage: 10}}
28+
Tracing []*Tracing `json:"tracing,omitempty"`
29+
}
30+
31+
// IstioSettings contains configuration settings for istio resources. Currently only telemetry configuration is supported.
32+
//
33+
// +kubebuilder:object:generate=true
34+
type IstioSettings struct {
35+
// +kubebuilder:validation:Optional
36+
// +kubebuilder:default:={tracing: {{randomSamplingPercentage: 10}}}
37+
Telemetry Telemetry `json:"telemetry,omitempty"`
38+
}

api/v1alpha1/istiotypes/zz_generated.deepcopy.go

+64
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/skipjob_types.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package v1alpha1
33
import (
44
"dario.cat/mergo"
55
"fmt"
6+
"github.com/kartverket/skiperator/api/v1alpha1/istiotypes"
67
"github.com/kartverket/skiperator/api/v1alpha1/podtypes"
78
batchv1 "k8s.io/api/batch/v1"
89
corev1 "k8s.io/api/core/v1"
@@ -81,6 +82,14 @@ type SKIPJobSpec struct {
8182
// +kubebuilder:validation:Required
8283
Container ContainerSettings `json:"container"`
8384

85+
// IstioSettings are used to configure istio specific resources such as telemetry. Currently, adjusting sampling
86+
// interval for tracing is the only supported option.
87+
// By default, tracing is enabled with a random sampling percentage of 10%.
88+
//
89+
//+kubebuilder:validation:Optional
90+
//+kubebuilder:default:={telemetry: {tracing: {{randomSamplingPercentage: 10}}}}
91+
IstioSettings *istiotypes.IstioSettings `json:"istioSettings,omitempty"`
92+
8493
// Prometheus settings for pod running in job. Fields are identical to Application and if set,
8594
// a podmonitoring object is created.
8695
Prometheus *PrometheusConfig `json:"prometheus,omitempty"`
@@ -287,7 +296,8 @@ func (skipJob *SKIPJob) GetDefaultLabels() map[string]string {
287296

288297
func (skipJob *SKIPJob) GetCommonSpec() *CommonSpec {
289298
return &CommonSpec{
290-
GCP: skipJob.Spec.Container.GCP,
291-
AccessPolicy: skipJob.Spec.Container.AccessPolicy,
299+
GCP: skipJob.Spec.Container.GCP,
300+
AccessPolicy: skipJob.Spec.Container.AccessPolicy,
301+
IstioSettings: skipJob.Spec.IstioSettings,
292302
}
293303
}

api/v1alpha1/skipns_types.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package v1alpha1
22

3-
import corev1 "k8s.io/api/core/v1"
3+
import (
4+
corev1 "k8s.io/api/core/v1"
5+
)
46

57
/*
68
* SKIPNamespace is a wrapper for the kubernetes namespace resource, so we can utilize the SKIPObject interface

api/v1alpha1/skipobj_interfaces.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1alpha1
22

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

1920
// CommonSpec TODO: This needs some more thought. We should probably try to expand on it. v1Alpha2?
2021
type CommonSpec struct {
21-
AccessPolicy *podtypes.AccessPolicy
22-
GCP *podtypes.GCP
22+
AccessPolicy *podtypes.AccessPolicy
23+
GCP *podtypes.GCP
24+
IstioSettings *istiotypes.IstioSettings
2325
}

api/v1alpha1/zz_generated.deepcopy.go

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/skiperator.kartverket.no_applications.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,46 @@ spec:
649649
items:
650650
type: string
651651
type: array
652+
istioSettings:
653+
default:
654+
telemetry:
655+
tracing:
656+
- randomSamplingPercentage: 10
657+
description: |-
658+
IstioSettings are used to configure istio specific resources such as telemetry. Currently, adjusting sampling
659+
interval for tracing is the only supported option.
660+
By default, tracing is enabled with a random sampling percentage of 10%.
661+
properties:
662+
telemetry:
663+
default:
664+
tracing:
665+
- randomSamplingPercentage: 10
666+
description: Telemetry is a placeholder for all relevant telemetry
667+
types, and may be extended in the future to configure additional
668+
telemetry settings.
669+
properties:
670+
tracing:
671+
default:
672+
- randomSamplingPercentage: 10
673+
description: Tracing is a list of tracing configurations for
674+
the telemetry resource. Normally only one tracing configuration
675+
is needed.
676+
items:
677+
description: Tracing contains relevant settings for tracing
678+
in the telemetry configuration
679+
properties:
680+
randomSamplingPercentage:
681+
default: 10
682+
description: |-
683+
RandomSamplingPercentage is the percentage of requests that should be sampled for tracing, specified by a whole number between 0-100.
684+
Setting RandomSamplingPercentage to 0 will disable tracing.
685+
maximum: 100
686+
minimum: 0
687+
type: integer
688+
type: object
689+
type: array
690+
type: object
691+
type: object
652692
labels:
653693
additionalProperties:
654694
type: string

config/crd/skiperator.kartverket.no_skipjobs.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,46 @@ spec:
790790
required:
791791
- schedule
792792
type: object
793+
istioSettings:
794+
default:
795+
telemetry:
796+
tracing:
797+
- randomSamplingPercentage: 10
798+
description: |-
799+
IstioSettings are used to configure istio specific resources such as telemetry. Currently, adjusting sampling
800+
interval for tracing is the only supported option.
801+
By default, tracing is enabled with a random sampling percentage of 10%.
802+
properties:
803+
telemetry:
804+
default:
805+
tracing:
806+
- randomSamplingPercentage: 10
807+
description: Telemetry is a placeholder for all relevant telemetry
808+
types, and may be extended in the future to configure additional
809+
telemetry settings.
810+
properties:
811+
tracing:
812+
default:
813+
- randomSamplingPercentage: 10
814+
description: Tracing is a list of tracing configurations for
815+
the telemetry resource. Normally only one tracing configuration
816+
is needed.
817+
items:
818+
description: Tracing contains relevant settings for tracing
819+
in the telemetry configuration
820+
properties:
821+
randomSamplingPercentage:
822+
default: 10
823+
description: |-
824+
RandomSamplingPercentage is the percentage of requests that should be sampled for tracing, specified by a whole number between 0-100.
825+
Setting RandomSamplingPercentage to 0 will disable tracing.
826+
maximum: 100
827+
minimum: 0
828+
type: integer
829+
type: object
830+
type: array
831+
type: object
832+
type: object
793833
job:
794834
description: Settings for the actual Job. If you use a scheduled job,
795835
the settings in here will also specify the template of the job.

config/rbac/role.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,15 @@ rules:
191191
- list
192192
- update
193193
- watch
194+
- apiGroups:
195+
- telemetry.istio.io
196+
resources:
197+
- telemetries
198+
verbs:
199+
- create
200+
- delete
201+
- get
202+
- list
203+
- patch
204+
- update
205+
- watch

0 commit comments

Comments
 (0)