Skip to content

Commit

Permalink
append hash to configmap name
Browse files Browse the repository at this point in the history
  • Loading branch information
matthagenbuch committed May 1, 2024
1 parent fbbca3d commit fd492fc
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 7 deletions.
4 changes: 4 additions & 0 deletions apis/v1beta1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ 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
ConfigVersions *int32 `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.
Expand Down
5 changes: 5 additions & 0 deletions apis/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -5555,6 +5555,9 @@ spec:
- service
type: object
x-kubernetes-preserve-unknown-fields: true
configVersions:
format: int32
type: integer
configmaps:
items:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5541,6 +5541,9 @@ spec:
- service
type: object
x-kubernetes-preserve-unknown-fields: true
configVersions:
format: int32
type: integer
configmaps:
items:
properties:
Expand Down
6 changes: 6 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: localhost:5001/opentelemetry-operator
newTag: matth-dev-1714578767
6 changes: 5 additions & 1 deletion internal/manifests/collector/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import (
)

func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
name := naming.ConfigMap(params.OtelCol.Name)
hash, err := manifestutils.GetConfigMapSHA(params.OtelCol.Spec.Config)
if err != nil {
return nil, err
}
name := naming.ConfigMap(params.OtelCol.Name, hash)
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{})

replacedConf, err := ReplaceConfig(params.OtelCol)
Expand Down
5 changes: 4 additions & 1 deletion internal/manifests/collector/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions internal/manifests/manifestutils/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions internal/naming/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fd492fc

Please sign in to comment.