operator: Reconcile owner reference for existing objects (#6923)

pull/6934/head
Robert Jacob 3 years ago committed by GitHub
parent 965650740c
commit 2911a74175
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      operator/CHANGELOG.md
  2. 2
      operator/bundle/manifests/loki-operator.clusterserviceversion.yaml
  3. 2
      operator/config/rbac/role.yaml
  4. 4
      operator/controllers/loki/lokistack_controller.go
  5. 4
      operator/internal/manifests/mutate.go
  6. 23
      operator/internal/manifests/mutate_test.go

@ -1,5 +1,6 @@
## Main
- [6923](https://github.com/grafana/loki/pull/6923) **xperimental**: Reconcile owner reference for existing objects
- [6907](https://github.com/grafana/loki/pull/6907) **Red-GV**: Adding valid subscription annotation to operator metadata
- [6479](https://github.com/grafana/loki/pull/6749) **periklis**: Update Loki operand to v2.6.1
- [6748](https://github.com/grafana/loki/pull/6748) **periklis**: Update go4.org/unsafe/assume-no-moving-gc to latest

@ -1096,6 +1096,7 @@ spec:
- servicemonitors
verbs:
- create
- delete
- get
- list
- update
@ -1131,6 +1132,7 @@ spec:
- routes
verbs:
- create
- delete
- get
- list
- update

@ -178,6 +178,7 @@ rules:
- servicemonitors
verbs:
- create
- delete
- get
- list
- update
@ -213,6 +214,7 @@ rules:
- routes
verbs:
- create
- delete
- get
- list
- update

@ -80,11 +80,11 @@ type LokiStackReconciler struct {
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
// +kubebuilder:rbac:groups=apps,resources=deployments;statefulsets,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=clusterrolebindings;clusterroles;roles;rolebindings,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=monitoring.coreos.com,resources=servicemonitors;prometheusrules,verbs=get;list;watch;create;update
// +kubebuilder:rbac:groups=monitoring.coreos.com,resources=servicemonitors;prometheusrules,verbs=get;list;watch;create;update;delete
// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;create;update
// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch;create;update
// +kubebuilder:rbac:groups=config.openshift.io,resources=dnses,verbs=get;list;watch
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=get;list;watch;create;update
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=get;list;watch;create;update;delete
// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.

@ -37,6 +37,10 @@ func MutateFuncFor(existing, desired client.Object) controllerutil.MutateFn {
}
existing.SetLabels(existingLabels)
if ownerRefs := desired.GetOwnerReferences(); len(ownerRefs) > 0 {
existing.SetOwnerReferences(ownerRefs)
}
switch existing.(type) {
case *corev1.ConfigMap:
cm := existing.(*corev1.ConfigMap)

@ -18,17 +18,6 @@ import (
)
func TestGetMutateFunc_MutateObjectMeta(t *testing.T) {
got := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"test": "test",
},
Annotations: map[string]string{
"test": "test",
},
},
}
want := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
@ -37,9 +26,20 @@ func TestGetMutateFunc_MutateObjectMeta(t *testing.T) {
Annotations: map[string]string{
"test": "test",
},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "loki.grafana.com/v1",
BlockOwnerDeletion: pointer.Bool(true),
Controller: pointer.Bool(true),
Kind: "LokiStack",
Name: "lokistack-testing",
UID: "6128aa83-de7f-47c0-abf2-4a380713b599",
},
},
},
}
got := &corev1.ConfigMap{}
f := manifests.MutateFuncFor(got, want)
err := f()
require.NoError(t, err)
@ -47,6 +47,7 @@ func TestGetMutateFunc_MutateObjectMeta(t *testing.T) {
// Partial mutation checks
require.Exactly(t, got.Labels, want.Labels)
require.Exactly(t, got.Annotations, want.Annotations)
require.Exactly(t, got.OwnerReferences, want.OwnerReferences)
}
func TestGetMutateFunc_ReturnErrOnNotSupportedType(t *testing.T) {

Loading…
Cancel
Save