Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jotak committed Dec 5, 2023
1 parent 4998658 commit e323417
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 17 deletions.
4 changes: 2 additions & 2 deletions bundle/manifests/flows.netobserv.io_flowcollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8033,8 +8033,8 @@ spec:
type: object
type: array
namespace:
description: Namespace where console plugin and flowlogs-pipeline
have been deployed.
description: 'Namespace where console plugin and flowlogs-pipeline
have been deployed. Deprecated: annotations are used instead'
type: string
required:
- conditions
Expand Down
4 changes: 2 additions & 2 deletions config/crd/bases/flows.netobserv.io_flowcollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8019,8 +8019,8 @@ spec:
type: object
type: array
namespace:
description: Namespace where console plugin and flowlogs-pipeline
have been deployed.
description: 'Namespace where console plugin and flowlogs-pipeline
have been deployed. Deprecated: annotations are used instead'
type: string
required:
- conditions
Expand Down
4 changes: 4 additions & 0 deletions controllers/flp/flp_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ type subReconciler interface {
getStatus() *status.Instance
}

// Reconcile is the controller entry point for reconciling current state with desired state.
// It manages the controller status at a high level. Business logic is delegated into `reconcile`.
func (r *Reconciler) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error) {
l := log.Log.WithName("flp") // clear context (too noisy)
ctx = log.IntoContext(ctx, l)
Expand Down Expand Up @@ -114,6 +116,8 @@ func (r *Reconciler) reconcile(ctx context.Context) error {
}

// Create sub-reconcilers
// TODO: refactor to move these subReconciler allocations in `Start`. It will involve some decoupling work, as currently
// `reconcilers.Common` is dependent on the FlowCollector object, which isn't known at start time.
reconcilers := []subReconciler{
newMonolithReconciler(cmn.NewInstance(r.mgr.Config.FlowlogsPipelineImage, r.mgr.Status.ForComponent(status.FLPMonolith))),
newTransformerReconciler(cmn.NewInstance(r.mgr.Config.FlowlogsPipelineImage, r.mgr.Status.ForComponent(status.FLPTransformOnly))),
Expand Down
6 changes: 3 additions & 3 deletions controllers/flp/flp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func TestDeploymentNoChange(t *testing.T) {
second := b.deployment(annotate(digest))

report := helper.NewChangeReport("")
assert.False(helper.DeploymentChanged(first, second, constants.FLPName, helper.HPADisabled(&cfg.Processor.KafkaConsumerAutoscaler), *cfg.Processor.KafkaConsumerReplicas, &report))
assert.False(helper.DeploymentChanged(first, second, constants.FLPName, !helper.HPAEnabled(&cfg.Processor.KafkaConsumerAutoscaler), *cfg.Processor.KafkaConsumerReplicas, &report))
assert.Contains(report.String(), "no change")
}

Expand All @@ -394,7 +394,7 @@ func TestDeploymentChanged(t *testing.T) {

report := helper.NewChangeReport("")
checkChanged := func(old, new *appsv1.Deployment, spec flowslatest.FlowCollectorSpec) bool {
return helper.DeploymentChanged(old, new, constants.FLPName, helper.HPADisabled(&spec.Processor.KafkaConsumerAutoscaler), *spec.Processor.KafkaConsumerReplicas, &report)
return helper.DeploymentChanged(old, new, constants.FLPName, !helper.HPAEnabled(&spec.Processor.KafkaConsumerAutoscaler), *spec.Processor.KafkaConsumerReplicas, &report)
}

assert.True(checkChanged(first, second, cfg))
Expand Down Expand Up @@ -475,7 +475,7 @@ func TestDeploymentChangedReplicasNoHPA(t *testing.T) {
second := b.deployment(annotate(digest))

report := helper.NewChangeReport("")
assert.True(helper.DeploymentChanged(first, second, constants.FLPName, helper.HPADisabled(&cfg2.Processor.KafkaConsumerAutoscaler), *cfg2.Processor.KafkaConsumerReplicas, &report))
assert.True(helper.DeploymentChanged(first, second, constants.FLPName, !helper.HPAEnabled(&cfg2.Processor.KafkaConsumerAutoscaler), *cfg2.Processor.KafkaConsumerReplicas, &report))
assert.Contains(report.String(), "Replicas changed")
}

Expand Down
2 changes: 2 additions & 0 deletions controllers/monitoring/monitoring_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func Start(ctx context.Context, mgr *manager.Manager) error {
Complete(&r)
}

// Reconcile is the controller entry point for reconciling current state with desired state.
// It manages the controller status at a high level. Business logic is delegated into `reconcile`.
func (r *Reconciler) Reconcile(ctx context.Context, _ ctrl.Request) (ctrl.Result, error) {
l := log.Log.WithName("monitoring") // clear context (too noisy)
ctx = log.IntoContext(ctx, l)
Expand Down
7 changes: 3 additions & 4 deletions controllers/reconcilers/reconcilers.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,22 @@ func ReconcileDeployment(ctx context.Context, ci *Instance, old, new *appsv1.Dep
return ci.CreateOwned(ctx, new)
}
ci.Status.CheckDeploymentProgress(old)
if helper.DeploymentChanged(old, new, containerName, helper.HPADisabled(hpa), replicas, report) {
if helper.DeploymentChanged(old, new, containerName, !helper.HPAEnabled(hpa), replicas, report) {
return ci.UpdateIfOwned(ctx, old, new)
}
return nil
}

func ReconcileHPA(ctx context.Context, ci *Instance, old, new *ascv2.HorizontalPodAutoscaler, desired *flowslatest.FlowCollectorHPA, report *helper.ChangeReport) error {
// Delete or Create / Update Autoscaler according to HPA option
if helper.HPADisabled(desired) {
ci.Managed.TryDelete(ctx, old)
} else {
if helper.HPAEnabled(desired) {
if !ci.Managed.Exists(old) {
return ci.CreateOwned(ctx, new)
} else if helper.AutoScalerChanged(old, *desired, report) {
return ci.UpdateIfOwned(ctx, old, new)
}
}
ci.Managed.TryDelete(ctx, old)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion docs/FlowCollector.md
Original file line number Diff line number Diff line change
Expand Up @@ -14049,7 +14049,7 @@ ResourceClaim references one entry in PodSpec.ResourceClaims.
<td><b>namespace</b></td>
<td>string</td>
<td>
Namespace where console plugin and flowlogs-pipeline have been deployed.<br/>
Namespace where console plugin and flowlogs-pipeline have been deployed. Deprecated: annotations are used instead<br/>
</td>
<td>false</td>
</tr></tbody>
Expand Down
2 changes: 1 addition & 1 deletion hack/cloned.flows.netobserv.io_flowcollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5567,7 +5567,7 @@ spec:
type: object
type: array
namespace:
description: Namespace where console plugin and flowlogs-pipeline have been deployed.
description: 'Namespace where console plugin and flowlogs-pipeline have been deployed. Deprecated: annotations are used instead'
type: string
required:
- conditions
Expand Down
4 changes: 0 additions & 4 deletions pkg/helper/flowcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ func HasKafkaExporter(spec *flowslatest.FlowCollectorSpec) bool {
return false
}

func HPADisabled(spec *flowslatest.FlowCollectorHPA) bool {
return spec == nil || spec.Status == flowslatest.HPAStatusDisabled
}

func HPAEnabled(spec *flowslatest.FlowCollectorHPA) bool {
return spec != nil && spec.Status == flowslatest.HPAStatusEnabled
}
Expand Down

0 comments on commit e323417

Please sign in to comment.