Skip to content

Commit cbe369b

Browse files
Allow override arbitrary tempo config (#718)
* Allow override arbitrary tempo config Signed-off-by: Ruben Vargas <[email protected]> * Replace custom config type with apiextensionsv1.JSONN Signed-off-by: Ruben Vargas <[email protected]> * Update apis/tempo/v1alpha1/tempostack_types.go Co-authored-by: Andreas Gerstmayr <[email protected]> * Some simplificiations, and warning webhook added Signed-off-by: Ruben Vargas <[email protected]> * Fix tests Signed-off-by: Ruben Vargas <[email protected]> * Update docs Signed-off-by: Ruben Vargas <[email protected]> * Convert from pointer to normal object Signed-off-by: Ruben Vargas <[email protected]> * Fix wrong override Signed-off-by: Ruben Vargas <[email protected]> * Update apis/tempo/v1alpha1/tempostack_webhook.go Co-authored-by: Andreas Gerstmayr <[email protected]> --------- Signed-off-by: Ruben Vargas <[email protected]> Co-authored-by: Andreas Gerstmayr <[email protected]>
1 parent 105a022 commit cbe369b

16 files changed

+465
-7
lines changed

.chloggen/free_form_config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. operator, github action)
5+
component: operator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Allow override arbitrary tempo configurations
9+
10+
# One or more tracking issues related to the change
11+
issues: [629]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

apis/tempo/v1alpha1/tempostack_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1alpha1
22

33
import (
44
corev1 "k8s.io/api/core/v1"
5+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
56
"k8s.io/apimachinery/pkg/api/resource"
67
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
78

@@ -122,6 +123,18 @@ type TempoStackSpec struct {
122123
// +kubebuilder:validation:Optional
123124
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Observability"
124125
Observability ObservabilitySpec `json:"observability,omitempty"`
126+
127+
// +optional
128+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Extra Configurations"
129+
ExtraConfig *ExtraConfigSpec `json:"extraConfig,omitempty"`
130+
}
131+
132+
// ExtraConfigSpec defines extra configurations for tempo that will be merged with the operator generated, configurations defined here
133+
// has precedence and could override generated config.
134+
type ExtraConfigSpec struct {
135+
// +optional
136+
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Tempo Extra Configurations"
137+
Tempo apiextensionsv1.JSON `json:"tempo,omitempty"`
125138
}
126139

127140
// ObservabilitySpec defines how telemetry data gets handled.

apis/tempo/v1alpha1/tempostack_webhook.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,13 @@ func (v *validator) validate(ctx context.Context, obj runtime.Object) (admission
450450
allErrors = append(allErrors, errors...)
451451
}
452452

453+
if tempo.Spec.ExtraConfig != nil && len(tempo.Spec.ExtraConfig.Tempo.Raw) > 0 {
454+
allWarnings = append(allWarnings, admission.Warnings{
455+
"override tempo configuration could potentially break the stack, use it carefully",
456+
}...)
457+
458+
}
459+
453460
allErrors = append(allErrors, v.validateReplicationFactor(*tempo)...)
454461
allErrors = append(allErrors, v.validateQueryFrontend(*tempo)...)
455462
allErrors = append(allErrors, v.validateGateway(*tempo)...)

apis/tempo/v1alpha1/tempostack_webhook_test.go

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import (
88

99
"github.com/stretchr/testify/assert"
1010
corev1 "k8s.io/api/core/v1"
11+
v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1112
apierrors "k8s.io/apimachinery/pkg/api/errors"
1213
"k8s.io/apimachinery/pkg/api/resource"
1314
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1415
"k8s.io/apimachinery/pkg/runtime"
1516
"k8s.io/apimachinery/pkg/util/validation/field"
1617
"k8s.io/utils/ptr"
1718
"sigs.k8s.io/controller-runtime/pkg/client"
19+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1820

1921
"github.com/grafana/tempo-operator/apis/config/v1alpha1"
2022
"github.com/grafana/tempo-operator/internal/manifests/naming"
@@ -1578,10 +1580,125 @@ func TestValidateReceiverTLSAndGateway(t *testing.T) {
15781580
}
15791581
}
15801582

1583+
func TestWarning(t *testing.T) {
1584+
gvType := metav1.TypeMeta{
1585+
APIVersion: "testv1",
1586+
Kind: "something",
1587+
}
1588+
1589+
tests := []struct {
1590+
name string
1591+
input runtime.Object
1592+
expected admission.Warnings
1593+
client client.Client
1594+
}{
1595+
{
1596+
name: "no secret exists",
1597+
input: &TempoStack{
1598+
ObjectMeta: metav1.ObjectMeta{
1599+
Name: "test-obj",
1600+
Namespace: "abc",
1601+
},
1602+
TypeMeta: gvType,
1603+
Spec: TempoStackSpec{
1604+
ServiceAccount: naming.DefaultServiceAccountName("test-obj"),
1605+
Storage: ObjectStorageSpec{
1606+
Secret: ObjectStorageSecretSpec{
1607+
Name: "not-found",
1608+
},
1609+
},
1610+
Template: TempoTemplateSpec{
1611+
Ingester: TempoComponentSpec{
1612+
Replicas: func(i int32) *int32 { return &i }(1),
1613+
},
1614+
},
1615+
},
1616+
},
1617+
client: &k8sFake{},
1618+
expected: admission.Warnings{"Secret 'not-found' does not exist"},
1619+
},
1620+
{
1621+
name: "warning for use extra config",
1622+
input: &TempoStack{
1623+
ObjectMeta: metav1.ObjectMeta{
1624+
Name: "test-obj",
1625+
Namespace: "abc",
1626+
},
1627+
TypeMeta: gvType,
1628+
Spec: TempoStackSpec{
1629+
ServiceAccount: naming.DefaultServiceAccountName("test-obj"),
1630+
Storage: ObjectStorageSpec{
1631+
Secret: ObjectStorageSecretSpec{
1632+
Name: "not-found",
1633+
},
1634+
},
1635+
Template: TempoTemplateSpec{
1636+
Ingester: TempoComponentSpec{
1637+
Replicas: func(i int32) *int32 { return &i }(1),
1638+
},
1639+
},
1640+
ExtraConfig: &ExtraConfigSpec{
1641+
Tempo: v1.JSON{Raw: []byte("{}")},
1642+
},
1643+
},
1644+
},
1645+
client: &k8sFake{
1646+
secret: &corev1.Secret{},
1647+
},
1648+
expected: admission.Warnings{
1649+
"override tempo configuration could potentially break the stack, use it carefully",
1650+
},
1651+
},
1652+
{
1653+
name: "no extra config used",
1654+
input: &TempoStack{
1655+
ObjectMeta: metav1.ObjectMeta{
1656+
Name: "test-obj",
1657+
Namespace: "abc",
1658+
},
1659+
TypeMeta: gvType,
1660+
Spec: TempoStackSpec{
1661+
ServiceAccount: naming.DefaultServiceAccountName("test-obj"),
1662+
Storage: ObjectStorageSpec{
1663+
Secret: ObjectStorageSecretSpec{
1664+
Name: "not-found",
1665+
},
1666+
},
1667+
Template: TempoTemplateSpec{
1668+
Ingester: TempoComponentSpec{
1669+
Replicas: func(i int32) *int32 { return &i }(1),
1670+
},
1671+
},
1672+
},
1673+
},
1674+
client: &k8sFake{
1675+
secret: &corev1.Secret{},
1676+
},
1677+
expected: admission.Warnings{},
1678+
},
1679+
}
1680+
1681+
for _, test := range tests {
1682+
t.Run(test.name, func(t *testing.T) {
1683+
v := &validator{ctrlConfig: v1alpha1.ProjectConfig{}, client: test.client}
1684+
wrgs, _ := v.validate(context.Background(), test.input)
1685+
assert.Equal(t, test.expected, wrgs)
1686+
})
1687+
}
1688+
}
1689+
15811690
type k8sFake struct {
1691+
secret *corev1.Secret
15821692
client.Client
15831693
}
15841694

1585-
func (*k8sFake) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
1695+
func (k *k8sFake) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
1696+
if k.secret != nil {
1697+
if obj.GetObjectKind().GroupVersionKind().Kind == k.secret.Kind {
1698+
obj = k.secret
1699+
return nil
1700+
}
1701+
}
1702+
15861703
return fmt.Errorf("mock: fails always")
15871704
}

apis/tempo/v1alpha1/zz_generated.deepcopy.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bundle/community/manifests/tempo-operator.clusterserviceversion.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ metadata:
4242
capabilities: Deep Insights
4343
categories: Logging & Tracing,Monitoring
4444
containerImage: ghcr.io/grafana/tempo-operator/tempo-operator
45-
createdAt: "2023-12-13T18:24:45Z"
45+
createdAt: "2023-12-31T18:14:24Z"
4646
description: Create and manage deployments of Tempo, a high-scale distributed
4747
tracing backend.
4848
operatorframework.io/cluster-monitoring: "true"
@@ -87,6 +87,10 @@ spec:
8787
name: ""
8888
version: v1
8989
specDescriptors:
90+
- displayName: Extra Configurations
91+
path: extraConfig
92+
- displayName: Tempo Extra Configurations
93+
path: extraConfig.tempo
9094
- description: HashRing defines the spec for the distributed hash ring configuration.
9195
displayName: Hash Ring
9296
path: hashRing

bundle/community/manifests/tempo.grafana.com_tempostacks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ spec:
5353
spec:
5454
description: TempoStackSpec defines the desired state of TempoStack.
5555
properties:
56+
extraConfig:
57+
description: ExtraConfigSpec defines extra configurations for tempo
58+
that will be merged with the operator generated, configurations
59+
defined here has precedence and could override generated config.
60+
properties:
61+
tempo:
62+
x-kubernetes-preserve-unknown-fields: true
63+
type: object
5664
hashRing:
5765
description: HashRing defines the spec for the distributed hash ring
5866
configuration.

bundle/openshift/manifests/tempo-operator.clusterserviceversion.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ metadata:
4242
capabilities: Deep Insights
4343
categories: Logging & Tracing,Monitoring
4444
containerImage: ghcr.io/grafana/tempo-operator/tempo-operator
45-
createdAt: "2023-12-13T18:24:44Z"
45+
createdAt: "2023-12-31T18:14:22Z"
4646
description: Create and manage deployments of Tempo, a high-scale distributed
4747
tracing backend.
4848
operatorframework.io/cluster-monitoring: "true"
@@ -87,6 +87,10 @@ spec:
8787
name: ""
8888
version: v1
8989
specDescriptors:
90+
- displayName: Extra Configurations
91+
path: extraConfig
92+
- displayName: Tempo Extra Configurations
93+
path: extraConfig.tempo
9094
- description: HashRing defines the spec for the distributed hash ring configuration.
9195
displayName: Hash Ring
9296
path: hashRing

bundle/openshift/manifests/tempo.grafana.com_tempostacks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ spec:
5353
spec:
5454
description: TempoStackSpec defines the desired state of TempoStack.
5555
properties:
56+
extraConfig:
57+
description: ExtraConfigSpec defines extra configurations for tempo
58+
that will be merged with the operator generated, configurations
59+
defined here has precedence and could override generated config.
60+
properties:
61+
tempo:
62+
x-kubernetes-preserve-unknown-fields: true
63+
type: object
5664
hashRing:
5765
description: HashRing defines the spec for the distributed hash ring
5866
configuration.

config/crd/bases/tempo.grafana.com_tempostacks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ spec:
5050
spec:
5151
description: TempoStackSpec defines the desired state of TempoStack.
5252
properties:
53+
extraConfig:
54+
description: ExtraConfigSpec defines extra configurations for tempo
55+
that will be merged with the operator generated, configurations
56+
defined here has precedence and could override generated config.
57+
properties:
58+
tempo:
59+
x-kubernetes-preserve-unknown-fields: true
60+
type: object
5361
hashRing:
5462
description: HashRing defines the spec for the distributed hash ring
5563
configuration.

0 commit comments

Comments
 (0)