diff --git a/.chloggen/matth.versioned_config.yaml b/.chloggen/matth.versioned_config.yaml new file mode 100755 index 0000000000..b49551e923 --- /dev/null +++ b/.chloggen/matth.versioned_config.yaml @@ -0,0 +1,17 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action) +component: collector + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Keep multiple previous versions of the Collector ConfigMap, configurable via the ConfigVersions field. + +# One or more tracking issues related to the change +issues: [2871] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: | + This change introduces a new field in the Collector ConfigMap, `ConfigVersions`, which allows users to specify the number of previous versions of the Collector ConfigMap to keep. The default value is 1, which means that the current and one previous version of the Collector ConfigMap are kept. By keeping historical versions of the configuration, we ensure that during a config upgrade the previous configuration is still available for running (non-upgraded) pods as well as for rollbacks. If we overwrite the original ConfigMap with the new configuration, any pod which restarts for any reason will get the new configuration, which makes rollouts impossible to control. \ No newline at end of file diff --git a/apis/v1beta1/opentelemetrycollector_types.go b/apis/v1beta1/opentelemetrycollector_types.go index 141178895f..28e91ded22 100644 --- a/apis/v1beta1/opentelemetrycollector_types.go +++ b/apis/v1beta1/opentelemetrycollector_types.go @@ -94,6 +94,12 @@ type OpenTelemetryCollectorSpec struct { // +required // +kubebuilder:pruning:PreserveUnknownFields Config Config `json:"config"` + // ConfigVersions defines the number versions to keep for the collector config. Each config version is stored in a separate ConfigMap. + // Defaults to 3. The minimum value is 1. + // +optional + // +kubebuilder:default:=3 + // +kubebuilder:validation:Minimum:=1 + ConfigVersions int `json:"configVersions,omitempty"` // Ingress is used to specify how OpenTelemetry Collector is exposed. This // functionality is only available if one of the valid modes is set. // Valid modes are: deployment, daemonset and statefulset. diff --git a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml index 092ca2428e..c7b60afc4f 100644 --- a/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml +++ b/bundle/manifests/opentelemetry.io_opentelemetrycollectors.yaml @@ -5555,6 +5555,10 @@ spec: - service type: object x-kubernetes-preserve-unknown-fields: true + configVersions: + default: 3 + minimum: 1 + type: integer configmaps: items: properties: diff --git a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml index ad8c35a81b..e1121c60af 100644 --- a/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml +++ b/config/crd/bases/opentelemetry.io_opentelemetrycollectors.yaml @@ -5541,6 +5541,10 @@ spec: - service type: object x-kubernetes-preserve-unknown-fields: true + configVersions: + default: 3 + minimum: 1 + type: integer configmaps: items: properties: diff --git a/controllers/builder_test.go b/controllers/builder_test.go index 32fd6db2fd..63de426fb4 100644 --- a/controllers/builder_test.go +++ b/controllers/builder_test.go @@ -37,6 +37,7 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/pkg/featuregate" ) @@ -86,6 +87,10 @@ service: goodConfig := v1beta1.Config{} err := go_yaml.Unmarshal([]byte(goodConfigYaml), &goodConfig) require.NoError(t, err) + + goodConfigHash, _ := manifestutils.GetConfigMapSHA(goodConfig) + goodConfigHash = goodConfigHash[:8] + one := int32(1) type args struct { instance v1beta1.OpenTelemetryCollector @@ -164,7 +169,7 @@ service: VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ LocalObjectReference: corev1.LocalObjectReference{ - Name: "test-collector", + Name: "test-collector-" + goodConfigHash, }, Items: []corev1.KeyToPath{ { @@ -223,7 +228,7 @@ service: }, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: "test-collector", + Name: "test-collector-" + goodConfigHash, Namespace: "test", Labels: map[string]string{ "app.kubernetes.io/component": "opentelemetry-collector", @@ -414,7 +419,7 @@ service: VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ LocalObjectReference: corev1.LocalObjectReference{ - Name: "test-collector", + Name: "test-collector-" + goodConfigHash, }, Items: []corev1.KeyToPath{ { @@ -473,7 +478,7 @@ service: }, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: "test-collector", + Name: "test-collector-" + goodConfigHash, Namespace: "test", Labels: map[string]string{ "app.kubernetes.io/component": "opentelemetry-collector", @@ -700,7 +705,7 @@ service: VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ LocalObjectReference: corev1.LocalObjectReference{ - Name: "test-collector", + Name: "test-collector-" + goodConfigHash, }, Items: []corev1.KeyToPath{ { @@ -759,7 +764,7 @@ service: }, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: "test-collector", + Name: "test-collector-" + goodConfigHash, Namespace: "test", Labels: map[string]string{ "app.kubernetes.io/component": "opentelemetry-collector", @@ -1138,6 +1143,10 @@ service: goodConfig := v1beta1.Config{} err := go_yaml.Unmarshal([]byte(goodConfigYaml), &goodConfig) require.NoError(t, err) + + goodConfigHash, _ := manifestutils.GetConfigMapSHA(goodConfig) + goodConfigHash = goodConfigHash[:8] + one := int32(1) type args struct { instance v1beta1.OpenTelemetryCollector @@ -1225,7 +1234,7 @@ service: VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ LocalObjectReference: corev1.LocalObjectReference{ - Name: "test-collector", + Name: "test-collector-" + goodConfigHash, }, Items: []corev1.KeyToPath{ { @@ -1284,7 +1293,7 @@ service: }, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: "test-collector", + Name: "test-collector-" + goodConfigHash, Namespace: "test", Labels: map[string]string{ "app.kubernetes.io/component": "opentelemetry-collector", @@ -1620,7 +1629,7 @@ prometheus_cr: VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ LocalObjectReference: corev1.LocalObjectReference{ - Name: "test-collector", + Name: "test-collector-" + goodConfigHash, }, Items: []corev1.KeyToPath{ { @@ -1679,7 +1688,7 @@ prometheus_cr: }, &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: "test-collector", + Name: "test-collector-" + goodConfigHash, Namespace: "test", Labels: map[string]string{ "app.kubernetes.io/component": "opentelemetry-collector", diff --git a/controllers/opentelemetrycollector_controller.go b/controllers/opentelemetrycollector_controller.go index e4f64429d3..b005728199 100644 --- a/controllers/opentelemetrycollector_controller.go +++ b/controllers/opentelemetrycollector_controller.go @@ -17,6 +17,8 @@ package controllers import ( "context" + "fmt" + "sort" "github.com/go-logr/logr" routev1 "github.com/openshift/api/route/v1" @@ -111,6 +113,17 @@ func (r *OpenTelemetryCollectorReconciler) findOtelOwnedObjects(ctx context.Cont ownedObjects[uid] = object } } + + configMapList := &corev1.ConfigMapList{} + err := r.List(ctx, configMapList, listOps) + if err != nil { + return nil, fmt.Errorf("error listing ConfigMaps: %w", err) + } + ownedConfigMaps := r.getConfigMapsToRemove(params.OtelCol.Spec.ConfigVersions, configMapList) + for i := range ownedConfigMaps { + ownedObjects[ownedConfigMaps[i].GetUID()] = &ownedConfigMaps[i] + } + return ownedObjects, nil } @@ -134,6 +147,27 @@ func (r *OpenTelemetryCollectorReconciler) findClusterRoleObjects(ctx context.Co return ownedObjects, nil } +// getConfigMapsToRemove returns a list of ConfigMaps to remove based on the number of ConfigMaps to keep. +// It keeps the newest ConfigMap, the `configVersionsToKeep` next newest ConfigMaps, and returns the remainder. +func (r *OpenTelemetryCollectorReconciler) getConfigMapsToRemove(configVersionsToKeep int, configMapList *corev1.ConfigMapList) []corev1.ConfigMap { + configVersionsToKeep = max(1, configVersionsToKeep) + ownedConfigMaps := []corev1.ConfigMap{} + sort.Slice(configMapList.Items, func(i, j int) bool { + iTime := configMapList.Items[i].GetCreationTimestamp().Time + jTime := configMapList.Items[j].GetCreationTimestamp().Time + // sort the ConfigMaps newest to oldest + return iTime.After(jTime) + }) + + for i := range configMapList.Items { + if i > configVersionsToKeep { + ownedConfigMaps = append(ownedConfigMaps, configMapList.Items[i]) + } + } + + return ownedConfigMaps +} + func (r *OpenTelemetryCollectorReconciler) getParams(instance v1beta1.OpenTelemetryCollector) (manifests.Params, error) { p := manifests.Params{ Config: r.config, diff --git a/controllers/reconcile_test.go b/controllers/reconcile_test.go index db6cfb267b..2a48e28ed9 100644 --- a/controllers/reconcile_test.go +++ b/controllers/reconcile_test.go @@ -430,7 +430,9 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { result: controllerruntime.Result{}, checks: []check[v1alpha1.OpenTelemetryCollector]{ func(t *testing.T, params v1alpha1.OpenTelemetryCollector) { - exists, err := populateObjectIfExists(t, &v1.ConfigMap{}, namespacedObjectName(naming.Collector(params.Name), params.Namespace)) + configHash, _ := getConfigMapSHAFromString(params.Spec.Config) + configHash = configHash[:8] + exists, err := populateObjectIfExists(t, &v1.ConfigMap{}, namespacedObjectName(naming.ConfigMap(params.Name, configHash), params.Namespace)) assert.NoError(t, err) assert.True(t, exists) exists, err = populateObjectIfExists(t, &appsv1.StatefulSet{}, namespacedObjectName(naming.Collector(params.Name), params.Namespace)) @@ -452,7 +454,9 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { result: controllerruntime.Result{}, checks: []check[v1alpha1.OpenTelemetryCollector]{ func(t *testing.T, params v1alpha1.OpenTelemetryCollector) { - exists, err := populateObjectIfExists(t, &v1.ConfigMap{}, namespacedObjectName(naming.Collector(params.Name), params.Namespace)) + configHash, _ := getConfigMapSHAFromString(params.Spec.Config) + configHash = configHash[:8] + exists, err := populateObjectIfExists(t, &v1.ConfigMap{}, namespacedObjectName(naming.ConfigMap(params.Name, configHash), params.Namespace)) assert.NoError(t, err) assert.True(t, exists) actual := v1.ConfigMap{} @@ -497,7 +501,9 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) { result: controllerruntime.Result{}, checks: []check[v1alpha1.OpenTelemetryCollector]{ func(t *testing.T, params v1alpha1.OpenTelemetryCollector) { - exists, err := populateObjectIfExists(t, &v1.ConfigMap{}, namespacedObjectName(naming.Collector(params.Name), params.Namespace)) + configHash, _ := getConfigMapSHAFromString(params.Spec.Config) + configHash = configHash[:8] + exists, err := populateObjectIfExists(t, &v1.ConfigMap{}, namespacedObjectName(naming.ConfigMap(params.Name, configHash), params.Namespace)) assert.NoError(t, err) assert.True(t, exists) actual := v1.ConfigMap{} diff --git a/controllers/suite_test.go b/controllers/suite_test.go index b9c2aebfce..b17379dd8b 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -50,6 +50,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" + "sigs.k8s.io/yaml" "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" @@ -60,6 +61,7 @@ import ( "github.com/open-telemetry/opentelemetry-operator/internal/config" "github.com/open-telemetry/opentelemetry-operator/internal/manifests" "github.com/open-telemetry/opentelemetry-operator/internal/manifests/collector/testdata" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/rbac" // +kubebuilder:scaffold:imports ) @@ -480,3 +482,12 @@ func populateObjectIfExists(t testing.TB, object client.Object, namespacedName t } return true, nil } + +func getConfigMapSHAFromString(configStr string) (string, error) { + var config v1beta1.Config + err := yaml.Unmarshal([]byte(configStr), &config) + if err != nil { + return "", err + } + return manifestutils.GetConfigMapSHA(config) +} diff --git a/docs/api.md b/docs/api.md index c374b1d622..43815b9add 100644 --- a/docs/api.md +++ b/docs/api.md @@ -29872,6 +29872,17 @@ doing so, you wil accept the risk of it breaking things.
for the workload.
false + + configVersions + integer + + ConfigVersions defines the number versions to keep for the collector config. Each config version is stored in a separate ConfigMap. +Defaults to 3. The minimum value is 1.
+
+ Default: 3
+ Minimum: 1
+ + false configmaps []object diff --git a/internal/manifests/collector/configmap.go b/internal/manifests/collector/configmap.go index 58ee4c1312..74f90f28d5 100644 --- a/internal/manifests/collector/configmap.go +++ b/internal/manifests/collector/configmap.go @@ -24,8 +24,13 @@ import ( ) func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) { - name := naming.ConfigMap(params.OtelCol.Name) - labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{}) + hash, err := manifestutils.GetConfigMapSHA(params.OtelCol.Spec.Config) + if err != nil { + return nil, err + } + name := naming.ConfigMap(params.OtelCol.Name, hash) + collectorName := naming.Collector(params.OtelCol.Name) + labels := manifestutils.Labels(params.OtelCol.ObjectMeta, collectorName, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{}) replacedConf, err := ReplaceConfig(params.OtelCol) if err != nil { diff --git a/internal/manifests/collector/configmap_test.go b/internal/manifests/collector/configmap_test.go index b850084c53..d7614c8648 100644 --- a/internal/manifests/collector/configmap_test.go +++ b/internal/manifests/collector/configmap_test.go @@ -18,6 +18,9 @@ import ( "testing" "github.com/stretchr/testify/assert" + + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" + "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) func TestDesiredConfigMap(t *testing.T) { @@ -29,9 +32,6 @@ func TestDesiredConfigMap(t *testing.T) { } t.Run("should return expected collector config map", func(t *testing.T) { - expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector" - expectedLables["app.kubernetes.io/name"] = "test-collector" - expectedLables["app.kubernetes.io/version"] = "0.47.0" expectedData := map[string]string{ "collector.yaml": `receivers: @@ -58,10 +58,17 @@ service: } param := deploymentParams() + hash, _ := manifestutils.GetConfigMapSHA(param.OtelCol.Spec.Config) + expectedName := naming.ConfigMap("test", hash) + + expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector" + expectedLables["app.kubernetes.io/name"] = "test-collector" + expectedLables["app.kubernetes.io/version"] = "0.47.0" + actual, err := ConfigMap(param) assert.NoError(t, err) - assert.Equal(t, "test-collector", actual.Name) + assert.Equal(t, expectedName, actual.Name) assert.Equal(t, expectedLables, actual.Labels) assert.Equal(t, len(expectedData), len(actual.Data)) for k, expected := range expectedData { @@ -70,10 +77,6 @@ service: }) t.Run("should return expected escaped collector config map with target_allocator config block", func(t *testing.T) { - expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector" - expectedLables["app.kubernetes.io/name"] = "test-collector" - expectedLables["app.kubernetes.io/version"] = "latest" - expectedData := map[string]string{ "collector.yaml": `exporters: debug: @@ -97,11 +100,19 @@ service: param, err := newParams("test/test-img", "testdata/http_sd_config_servicemonitor_test.yaml") assert.NoError(t, err) + + hash, _ := manifestutils.GetConfigMapSHA(param.OtelCol.Spec.Config) + expectedName := naming.ConfigMap("test", hash) + + expectedLables["app.kubernetes.io/component"] = "opentelemetry-collector" + expectedLables["app.kubernetes.io/name"] = "test-collector" + expectedLables["app.kubernetes.io/version"] = "latest" + param.OtelCol.Spec.TargetAllocator.Enabled = true actual, err := ConfigMap(param) assert.NoError(t, err) - assert.Equal(t, "test-collector", actual.Name) + assert.Equal(t, expectedName, actual.Name) assert.Equal(t, expectedLables, actual.Labels) assert.Equal(t, len(expectedData), len(actual.Data)) for k, expected := range expectedData { diff --git a/internal/manifests/collector/volume.go b/internal/manifests/collector/volume.go index 5cf82fde7a..ea033b3a4a 100644 --- a/internal/manifests/collector/volume.go +++ b/internal/manifests/collector/volume.go @@ -20,16 +20,19 @@ import ( "github.com/open-telemetry/opentelemetry-operator/apis/v1beta1" "github.com/open-telemetry/opentelemetry-operator/internal/config" + "github.com/open-telemetry/opentelemetry-operator/internal/manifests/manifestutils" "github.com/open-telemetry/opentelemetry-operator/internal/naming" ) // Volumes builds the volumes for the given instance, including the config map volume. func Volumes(cfg config.Config, otelcol v1beta1.OpenTelemetryCollector) []corev1.Volume { + hash, _ := manifestutils.GetConfigMapSHA(otelcol.Spec.Config) + configMapName := naming.ConfigMap(otelcol.Name, hash) volumes := []corev1.Volume{{ Name: naming.ConfigMapVolume(), VolumeSource: corev1.VolumeSource{ ConfigMap: &corev1.ConfigMapVolumeSource{ - LocalObjectReference: corev1.LocalObjectReference{Name: naming.ConfigMap(otelcol.Name)}, + LocalObjectReference: corev1.LocalObjectReference{Name: configMapName}, Items: []corev1.KeyToPath{{ Key: cfg.CollectorConfigMapEntry(), Path: cfg.CollectorConfigMapEntry(), diff --git a/internal/manifests/manifestutils/annotations.go b/internal/manifests/manifestutils/annotations.go index 06f1baed81..c4243e350d 100644 --- a/internal/manifests/manifestutils/annotations.go +++ b/internal/manifests/manifestutils/annotations.go @@ -44,7 +44,7 @@ func Annotations(instance v1beta1.OpenTelemetryCollector, filterAnnotations []st } } - hash, err := getConfigMapSHA(instance.Spec.Config) + hash, err := GetConfigMapSHA(instance.Spec.Config) if err != nil { return nil, err } @@ -78,7 +78,7 @@ func PodAnnotations(instance v1beta1.OpenTelemetryCollector, filterAnnotations [ } } - hash, err := getConfigMapSHA(instance.Spec.Config) + hash, err := GetConfigMapSHA(instance.Spec.Config) if err != nil { return nil, err } @@ -88,7 +88,7 @@ func PodAnnotations(instance v1beta1.OpenTelemetryCollector, filterAnnotations [ return podAnnotations, nil } -func getConfigMapSHA(config v1beta1.Config) (string, error) { +func GetConfigMapSHA(config v1beta1.Config) (string, error) { b, err := json.Marshal(&config) if err != nil { return "", err diff --git a/internal/naming/main.go b/internal/naming/main.go index def5adbf2a..7ebd21d9ba 100644 --- a/internal/naming/main.go +++ b/internal/naming/main.go @@ -16,8 +16,9 @@ package naming // ConfigMap builds the name for the config map used in the OpenTelemetryCollector containers. -func ConfigMap(otelcol string) string { - return DNSName(Truncate("%s-collector", 63, otelcol)) +// The configHash should be calculated using manifestutils.GetConfigMapSHA. +func ConfigMap(otelcol, configHash string) string { + return DNSName(Truncate("%s-collector-%s", 63, otelcol, configHash[:8])) } // TAConfigMap returns the name for the config map used in the TargetAllocator. diff --git a/tests/e2e-targetallocator/targetallocator-features/00-assert.yaml b/tests/e2e-targetallocator/targetallocator-features/00-assert.yaml index 823f435484..7175937de8 100644 --- a/tests/e2e-targetallocator/targetallocator-features/00-assert.yaml +++ b/tests/e2e-targetallocator/targetallocator-features/00-assert.yaml @@ -20,7 +20,7 @@ spec: items: - key: collector.yaml path: collector.yaml - name: stateful-collector + name: stateful-collector-31b1d381 name: otc-internal - emptyDir: {} name: testvolume diff --git a/tests/e2e-targetallocator/targetallocator-kubernetessd/00-assert.yaml b/tests/e2e-targetallocator/targetallocator-kubernetessd/00-assert.yaml index 88d16ed604..300d2668b4 100644 --- a/tests/e2e-targetallocator/targetallocator-kubernetessd/00-assert.yaml +++ b/tests/e2e-targetallocator/targetallocator-kubernetessd/00-assert.yaml @@ -15,7 +15,7 @@ metadata: apiVersion: v1 kind: ConfigMap metadata: - name: prometheus-kubernetessd-collector + name: prometheus-kubernetessd-collector-8236b782 data: collector.yaml: | exporters: diff --git a/tests/e2e-targetallocator/targetallocator-prometheuscr/00-assert.yaml b/tests/e2e-targetallocator/targetallocator-prometheuscr/00-assert.yaml index 66a10f2f1d..4afae1a5ee 100644 --- a/tests/e2e-targetallocator/targetallocator-prometheuscr/00-assert.yaml +++ b/tests/e2e-targetallocator/targetallocator-prometheuscr/00-assert.yaml @@ -43,4 +43,4 @@ data: - prometheus kind: ConfigMap metadata: - name: prometheus-cr-collector + name: prometheus-cr-collector-b88fa6e7 diff --git a/tests/e2e/managed-reconcile/02-assert.yaml b/tests/e2e/managed-reconcile/02-assert.yaml index 0a6a83b1a3..0847c94ed8 100644 --- a/tests/e2e/managed-reconcile/02-assert.yaml +++ b/tests/e2e/managed-reconcile/02-assert.yaml @@ -52,7 +52,7 @@ spec: apiVersion: v1 kind: ConfigMap metadata: - name: simplest-collector + name: simplest-collector-17ca6c13 data: collector.yaml: | receivers: diff --git a/tests/e2e/multiple-configmaps/00-assert.yaml b/tests/e2e/multiple-configmaps/00-assert.yaml index 14c929470a..b040f87074 100644 --- a/tests/e2e/multiple-configmaps/00-assert.yaml +++ b/tests/e2e/multiple-configmaps/00-assert.yaml @@ -25,7 +25,7 @@ spec: volumes: - name: otc-internal configMap: - name: simplest-with-configmaps-collector + name: simplest-with-configmaps-collector-17ca6c13 items: - key: collector.yaml path: collector.yaml diff --git a/tests/e2e/smoke-targetallocator/00-assert.yaml b/tests/e2e/smoke-targetallocator/00-assert.yaml index 35a1d6356f..53d8bc5a89 100644 --- a/tests/e2e/smoke-targetallocator/00-assert.yaml +++ b/tests/e2e/smoke-targetallocator/00-assert.yaml @@ -45,4 +45,4 @@ data: - jaeger kind: ConfigMap metadata: - name: stateful-collector + name: stateful-collector-fb278632 diff --git a/tests/e2e/statefulset-features/00-assert.yaml b/tests/e2e/statefulset-features/00-assert.yaml index 744ba76e26..5363d785b9 100644 --- a/tests/e2e/statefulset-features/00-assert.yaml +++ b/tests/e2e/statefulset-features/00-assert.yaml @@ -20,7 +20,7 @@ spec: items: - key: collector.yaml path: collector.yaml - name: stateful-collector + name: stateful-collector-f0fa6faa name: otc-internal - emptyDir: {} name: testvolume diff --git a/tests/e2e/statefulset-features/01-assert.yaml b/tests/e2e/statefulset-features/01-assert.yaml index fdccb0fadd..c68dc9aa80 100644 --- a/tests/e2e/statefulset-features/01-assert.yaml +++ b/tests/e2e/statefulset-features/01-assert.yaml @@ -20,7 +20,7 @@ spec: items: - key: collector.yaml path: collector.yaml - name: stateful-collector + name: stateful-collector-f0fa6faa name: otc-internal - emptyDir: {} name: testvolume diff --git a/tests/e2e/versioned-configmaps/00-assert.yaml b/tests/e2e/versioned-configmaps/00-assert.yaml new file mode 100644 index 0000000000..09b5d13d9e --- /dev/null +++ b/tests/e2e/versioned-configmaps/00-assert.yaml @@ -0,0 +1,19 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: simple-collector +spec: + template: + spec: + volumes: + - name: otc-internal + configMap: + name: simple-collector-d6f40475 +status: + readyReplicas: 1 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: simple-collector-d6f40475 diff --git a/tests/e2e/versioned-configmaps/00-install.yaml b/tests/e2e/versioned-configmaps/00-install.yaml new file mode 100644 index 0000000000..a34135e7f0 --- /dev/null +++ b/tests/e2e/versioned-configmaps/00-install.yaml @@ -0,0 +1,27 @@ +--- +apiVersion: opentelemetry.io/v1beta1 +kind: OpenTelemetryCollector +metadata: + name: simple +spec: + mode: "deployment" + configVersions: 1 + config: + receivers: + otlp: + protocols: + grpc: {} + http: {} + processors: + batch: + send_batch_size: 10000 + timeout: 10s + exporters: + debug: {} + + service: + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [debug] diff --git a/tests/e2e/versioned-configmaps/01-assert.yaml b/tests/e2e/versioned-configmaps/01-assert.yaml new file mode 100644 index 0000000000..b9cb6d35d9 --- /dev/null +++ b/tests/e2e/versioned-configmaps/01-assert.yaml @@ -0,0 +1,24 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: simple-collector +spec: + template: + spec: + volumes: + - name: otc-internal + configMap: + name: simple-collector-8cd615bf +status: + readyReplicas: 1 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: simple-collector-d6f40475 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: simple-collector-8cd615bf diff --git a/tests/e2e/versioned-configmaps/01-update.yaml b/tests/e2e/versioned-configmaps/01-update.yaml new file mode 100644 index 0000000000..8004c4ef55 --- /dev/null +++ b/tests/e2e/versioned-configmaps/01-update.yaml @@ -0,0 +1,27 @@ +--- +apiVersion: opentelemetry.io/v1beta1 +kind: OpenTelemetryCollector +metadata: + name: simple +spec: + mode: "deployment" + configVersions: 1 + config: + receivers: + otlp: + protocols: + grpc: {} + http: {} + processors: + batch: + send_batch_size: 10000 + timeout: 20s + exporters: + debug: {} + + service: + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [debug] diff --git a/tests/e2e/versioned-configmaps/02-error.yaml b/tests/e2e/versioned-configmaps/02-error.yaml new file mode 100644 index 0000000000..2b63829a6c --- /dev/null +++ b/tests/e2e/versioned-configmaps/02-error.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: simple-collector-d6f40475 diff --git a/tests/e2e/versioned-configmaps/02-update.yaml b/tests/e2e/versioned-configmaps/02-update.yaml new file mode 100644 index 0000000000..7cb8f19060 --- /dev/null +++ b/tests/e2e/versioned-configmaps/02-update.yaml @@ -0,0 +1,27 @@ +--- +apiVersion: opentelemetry.io/v1beta1 +kind: OpenTelemetryCollector +metadata: + name: simple +spec: + mode: "deployment" + configVersions: 1 + config: + receivers: + otlp: + protocols: + grpc: {} + http: {} + processors: + batch: + send_batch_size: 10000 + timeout: 30s + exporters: + debug: {} + + service: + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [debug] \ No newline at end of file diff --git a/tests/e2e/versioned-configmaps/chainsaw-test.yaml b/tests/e2e/versioned-configmaps/chainsaw-test.yaml new file mode 100755 index 0000000000..f837498100 --- /dev/null +++ b/tests/e2e/versioned-configmaps/chainsaw-test.yaml @@ -0,0 +1,28 @@ +# 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: versioned-configmaps +spec: + steps: + - name: step-00 + try: + - apply: + file: 00-install.yaml + - assert: + file: 00-assert.yaml + # Update the collector config and ensure both the new and old confmaps are present + - name: step-01 + try: + - apply: + file: 01-update.yaml + - assert: + file: 01-assert.yaml + # Update the collector config again and ensure the oldest confmap is deleted + - name: step-02 + try: + - apply: + file: 02-update.yaml + - error: + file: 02-error.yaml \ No newline at end of file