Skip to content

Commit

Permalink
operator: k8s: Add update functionality to ClusterRole
Browse files Browse the repository at this point in the history
Almost all resources are reconciled with update functionality, so that
ClusterRole kubernetes resource will be corrected if changed outside of
operator reconcilied loop.
  • Loading branch information
Rafal Korepta committed Jun 4, 2022
1 parent 981878b commit d09b2c9
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/resources/cluster_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package resources

import (
"context"
"fmt"

"github.com/go-logr/logr"
redpandav1alpha1 "github.com/redpanda-data/redpanda/src/go/k8s/apis/redpanda/v1alpha1"
Expand Down Expand Up @@ -53,7 +54,19 @@ func (r *ClusterRoleResource) Ensure(ctx context.Context) error {
if r.pandaCluster.ExternalListener() == nil {
return nil
}
_, err := CreateIfNotExists(ctx, r, r.obj(), r.logger)

obj := r.obj()
created, err := CreateIfNotExists(ctx, r, obj, r.logger)
if err != nil || created {
return err
}
var cr v1.ClusterRole
err = r.Get(ctx, r.Key(), &cr)
if err != nil {
return fmt.Errorf("error while fetching ClusterRole resource: %w", err)
}

_, err = Update(ctx, &cr, obj, r.Client, r.logger)
return err
}

Expand Down

0 comments on commit d09b2c9

Please sign in to comment.