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

Keep multiple versions of Collector Config #2946

Merged
merged 20 commits into from
May 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into matth.versioned_config
matthagenbuch authored May 21, 2024
commit bef63e532fd9a6e38868f0fb15f136ef6ecb47e4
31 changes: 28 additions & 3 deletions controllers/opentelemetrycollector_controller.go
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@
ownedObjects[pdbList.Items[i].GetUID()] = &pdbList.Items[i]
}
if params.Config.CreateRBACPermissions() == rbac.Available {
clusterObjects, err := r.findClusterRoleObjects(ctx, params)

Check failure on line 133 in controllers/opentelemetrycollector_controller.go

GitHub Actions / Code standards (linting)

shadow: declaration of "err" shadows declaration at line 79 (govet)
if err != nil {
return nil, err
}
@@ -138,9 +138,7 @@
ownedObjects[k] = v
}
}
return ownedObjects, nil
}


configMapList := &corev1.ConfigMapList{}
err = r.List(ctx, configMapList, listOps)
if err != nil {
@@ -154,6 +152,33 @@
return ownedObjects, nil
}

// The cluster scope objects do not have owner reference.
func (r *OpenTelemetryCollectorReconciler) findClusterRoleObjects(ctx context.Context, params manifests.Params) (map[types.UID]client.Object, error) {
ownedObjects := map[types.UID]client.Object{}
// Remove cluster roles and bindings.
// Users might switch off the RBAC creation feature on the operator which should remove existing RBAC.
listOpsCluster := &client.ListOptions{
LabelSelector: labels.SelectorFromSet(manifestutils.SelectorLabels(params.OtelCol.ObjectMeta, collector.ComponentOpenTelemetryCollector)),
}
clusterroleList := &rbacv1.ClusterRoleList{}
err := r.List(ctx, clusterroleList, listOpsCluster)
if err != nil {
return nil, fmt.Errorf("error listing ClusterRoles: %w", err)
}
for i := range clusterroleList.Items {
ownedObjects[clusterroleList.Items[i].GetUID()] = &clusterroleList.Items[i]
}
clusterrolebindingList := &rbacv1.ClusterRoleBindingList{}
err = r.List(ctx, clusterrolebindingList, listOpsCluster)
if err != nil {
return nil, fmt.Errorf("error listing ClusterRoleBIndings: %w", err)
}
for i := range clusterrolebindingList.Items {
ownedObjects[clusterrolebindingList.Items[i].GetUID()] = &clusterrolebindingList.Items[i]
}
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 {

Unchanged files with check annotations Beta

package naming
// ConfigMap builds the name for the config map used in the OpenTelemetryCollector containers.
// The configHash should be calculated using manifestutils.GetConfigMapSHA

Check failure on line 19 in internal/naming/main.go

GitHub Actions / Code standards (linting)

Comment should end in a period (godot)
func ConfigMap(otelcol, configHash string) string {
return DNSName(Truncate("%s-collector-%s", 63, otelcol, configHash[:8]))
}
You are viewing a condensed version of this merge commit. You can view the full changes here.