Skip to content

Commit

Permalink
k8s: generate the console configmap after the cluster spec is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
paulzhang97 committed Jun 8, 2023
1 parent 35a0949 commit 85cb12f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/go/k8s/apis/vectorized/v1alpha1/console_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ type ConsoleStatus struct {
// The generation observed by the controller
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// The generation of the Repanda cluster
ClusterGeneration int64 `json:"clusterGeneration,omitempty"`

Connectivity *Connectivity `json:"connectivity,omitempty"`

// Total number of non-terminated pods targeted by this deployment (their labels match the selector).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,10 @@ spec:
targeted by this deployment.
format: int32
type: integer
clusterGeneration:
description: The generation of the Repanda cluster
format: int64
type: integer
configMapRef:
description: The ConfigMap used by Console This is used to pass the
ConfigMap used to mount in the Deployment Resource since Ensure()
Expand Down
15 changes: 7 additions & 8 deletions src/go/k8s/controllers/redpanda/console_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,17 @@ func (r *Reconciling) Do(
if err != nil {
return ctrl.Result{}, fmt.Errorf("reporting console status: %w", err)
}
if err := r.Status().Update(ctx, console); err != nil {
return ctrl.Result{}, err
}

if !console.GenerationMatchesObserved() {
r.Log.Info("observed generation updating", "observed generation", console.Status.ObservedGeneration, "generation", console.GetGeneration())
if !console.GenerationMatchesObserved() || cluster.GetGeneration() != console.Status.ClusterGeneration {
r.Log.Info("observed generation updating", "observed generation", console.Status.ObservedGeneration, "generation", console.GetGeneration(),
"observed cluster generation", console.Status.ClusterGeneration, "cluster generation", cluster.GetGeneration())
console.Status.ObservedGeneration = console.GetGeneration()
if err := r.Status().Update(ctx, console); err != nil {
return ctrl.Result{}, err
}
console.Status.ClusterGeneration = cluster.GetGeneration()
}

if err := r.Status().Update(ctx, console); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}

Expand Down
8 changes: 7 additions & 1 deletion src/go/k8s/pkg/console/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ func (cm *ConfigMap) Ensure(ctx context.Context) error {
}
return &resources.RequeueError{Msg: err.Error()}
}
return err

if cm.clusterobj.GetGeneration() == cm.consoleobj.Status.ClusterGeneration || err != nil {
return err
}

log.V(logger.InfoLevel).Info("cluster spec changed; will generate new configmap", "cluster generation", cm.clusterobj.GetGeneration(),
"observed cluster generation", cm.consoleobj.Status.ClusterGeneration)
}

// If old ConfigMaps can't be deleted for any reason, it will not continue reconciliation
Expand Down

0 comments on commit 85cb12f

Please sign in to comment.