Skip to content

Commit

Permalink
Switch test cases to not use flux controllers
Browse files Browse the repository at this point in the history
The operator will have new boolean `force-defluxed-mode` flag that needs to be combined with
`--enable-helm-controllers=false` flag to not use flux controllers.
  • Loading branch information
RafalKorepta committed Nov 25, 2024
1 parent b015110 commit 06312d2
Show file tree
Hide file tree
Showing 25 changed files with 46 additions and 144 deletions.
2 changes: 1 addition & 1 deletion acceptance/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestMain(m *testing.M) {
"createAdditionalControllerCRs": true,
"createRPKBundleCRs": true,
},
"additionalCmdFlags": []string{"--additional-controllers=all"},
"additionalCmdFlags": []string{"--additional-controllers=all", "--enable-helm-controllers=false", "--force-defluxed-mode"},
},
})
t.Log("Successfully installed Redpanda operator chart")
Expand Down
13 changes: 9 additions & 4 deletions operator/cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func Command() *cobra.Command {
ghostbuster bool
unbindPVCsAfter time.Duration
autoDeletePVCs bool
forceDefluxedMode bool
)

cmd := &cobra.Command{
Expand Down Expand Up @@ -136,6 +137,7 @@ func Command() *cobra.Command {
ghostbuster,
unbindPVCsAfter,
autoDeletePVCs,
forceDefluxedMode,
)
},
}
Expand Down Expand Up @@ -166,6 +168,7 @@ func Command() *cobra.Command {
cmd.Flags().BoolVar(&enableHelmControllers, "enable-helm-controllers", true, "if a namespace is defined and operator mode is true, this enables the use of helm controllers to manage fluxcd helm resources.")
cmd.Flags().DurationVar(&unbindPVCsAfter, "unbind-pvcs-after", 0, "if not zero, runs the PVCUnbinder controller which attempts to 'unbind' the PVCs' of Pods that are Pending for longer than the given duration")
cmd.Flags().BoolVar(&autoDeletePVCs, "auto-delete-pvcs", false, "Use StatefulSet PersistentVolumeClaimRetentionPolicy to auto delete PVCs on scale down and Cluster resource delete.")
cmd.Flags().BoolVar(&forceDefluxedMode, "force-defluxed-mode", false, "specifies the default value for useFlux of Redpanda CRs if not specified. May be used in conjunction with enable-helm-controllers=false")

// 3rd party flags.
clientOptions.BindFlags(cmd.Flags())
Expand Down Expand Up @@ -199,6 +202,7 @@ func Run(
ghostbuster bool,
unbindPVCsAfter time.Duration,
autoDeletePVCs bool,
forceDefluxedMode bool,
) error {
setupLog := ctrl.LoggerFrom(ctx).WithName("setup")

Expand Down Expand Up @@ -360,10 +364,11 @@ func Run(

// Redpanda Reconciler
if err = (&redpandacontrollers.RedpandaReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
EventRecorder: mgr.GetEventRecorderFor("RedpandaReconciler"),
ClientFactory: internalclient.NewFactory(mgr.GetConfig(), mgr.GetClient()),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
EventRecorder: mgr.GetEventRecorderFor("RedpandaReconciler"),
ClientFactory: internalclient.NewFactory(mgr.GetConfig(), mgr.GetClient()),
DefaultDisableFlux: forceDefluxedMode,
}).SetupWithManager(ctx, mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Redpanda")
return err
Expand Down
21 changes: 13 additions & 8 deletions operator/internal/controller/redpanda/redpanda_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ type gvkKey struct {

// RedpandaReconciler reconciles a Redpanda object
type RedpandaReconciler struct {
Client client.Client
Scheme *runtime.Scheme
EventRecorder kuberecorder.EventRecorder
ClientFactory internalclient.ClientFactory
Client client.Client
Scheme *runtime.Scheme
EventRecorder kuberecorder.EventRecorder
ClientFactory internalclient.ClientFactory
DefaultDisableFlux bool
}

// flux resources main resources
Expand Down Expand Up @@ -321,7 +322,7 @@ func (r *RedpandaReconciler) reconcileStatus(ctx context.Context, rp *v1alpha2.R
func (r *RedpandaReconciler) reconcileDefluxed(ctx context.Context, rp *v1alpha2.Redpanda) error {
log := ctrl.LoggerFrom(ctx)

if ptr.Deref(rp.Spec.ChartRef.UseFlux, true) {
if r.IsFluxEnabled(rp.Spec.ChartRef.UseFlux) {
log.V(logger.TraceLevel).Info("useFlux is true; skipping non-flux reconciliation...")
return nil
}
Expand Down Expand Up @@ -518,7 +519,7 @@ func (r *RedpandaReconciler) reconcileLicense(ctx context.Context, rp *v1alpha2.
}

func (r *RedpandaReconciler) reconcileClusterConfig(ctx context.Context, rp *v1alpha2.Redpanda) error {
if ptr.Deref(rp.Spec.ChartRef.UseFlux, true) {
if r.IsFluxEnabled(rp.Spec.ChartRef.UseFlux) {
apimeta.SetStatusCondition(rp.GetConditions(), metav1.Condition{
Type: v1alpha2.ClusterConfigSynced,
Status: metav1.ConditionUnknown,
Expand Down Expand Up @@ -861,7 +862,7 @@ func (r *RedpandaReconciler) createHelmReleaseFromTemplate(ctx context.Context,
OwnerReferences: []metav1.OwnerReference{rp.OwnerShipRefObj()},
},
Spec: helmv2beta2.HelmReleaseSpec{
Suspend: !ptr.Deref(rp.Spec.ChartRef.UseFlux, true),
Suspend: !r.IsFluxEnabled(rp.Spec.ChartRef.UseFlux),
Chart: helmv2beta2.HelmChartTemplate{
Spec: helmv2beta2.HelmChartTemplateSpec{
Chart: "redpanda",
Expand Down Expand Up @@ -890,7 +891,7 @@ func (r *RedpandaReconciler) helmRepositoryFromTemplate(rp *v1alpha2.Redpanda) *
OwnerReferences: []metav1.OwnerReference{rp.OwnerShipRefObj()},
},
Spec: sourcev1.HelmRepositorySpec{
Suspend: !ptr.Deref(rp.Spec.ChartRef.UseFlux, true),
Suspend: !r.IsFluxEnabled(rp.Spec.ChartRef.UseFlux),
Interval: metav1.Duration{Duration: 30 * time.Second},
URL: v1alpha2.RedpandaChartRepository,
},
Expand Down Expand Up @@ -982,3 +983,7 @@ func allListTypes(c client.Client) ([]client.ObjectList, error) {
}
return types, nil
}

func (r *RedpandaReconciler) IsFluxEnabled(useFlux *bool) bool {
return ptr.Deref(useFlux, !r.DefaultDisableFlux)
}
21 changes: 21 additions & 0 deletions operator/internal/controller/redpanda/redpanda_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,27 @@ func TestPostInstallUpgradeJobIndex(t *testing.T) {
require.Equal(t, "bootstrap-yaml-envsubst", job.Spec.Template.Spec.InitContainers[0].Name)
}

func TestIsFluxEnabled(t *testing.T) {
for _, tc := range []struct {
expected bool
expectedSuspended bool
useFluxCRD *bool
forceDefluxed bool
}{
{true, false, ptr.To(true), false},
{false, true, ptr.To(false), false},
{true, false, nil, false},
{true, false, ptr.To(true), true},
{false, true, ptr.To(false), true},
{false, true, nil, true},
} {
r := redpanda.RedpandaReconciler{DefaultDisableFlux: tc.forceDefluxed}
assert.Equal(t, tc.expected, r.IsFluxEnabled(tc.useFluxCRD))
// When it comes for helmrepository and helmrelease they should be suspended
assert.Equal(t, tc.expectedSuspended, !r.IsFluxEnabled(tc.useFluxCRD))
}
}

// TestControllerRBAC asserts that the declared Roles and ClusterRoles of the
// RedpandaReconciler line up with all the resource types it needs to manage.
func TestControllerRBAC(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion operator/kuttl-v2-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ commands:
- command: helm repo update
- command: helm install --set logLevel=trace --set image.tag=dev
--set image.repository=localhost/redpanda-operator --namespace redpanda --create-namespace redpanda-operator
redpanda/operator --set rbac.createAdditionalControllerCRs=true --set additionalCmdFlags="{--additional-controllers=all}"
redpanda/operator --set rbac.createAdditionalControllerCRs=true --set additionalCmdFlags="{--additional-controllers=all,--force-defluxed-mode,--enable-helm-controllers=false}"
--set rbac.createRPKBundleCRs=true --wait
artifactsDir: tests/_e2e_artifacts_v2
timeout: 720
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ metadata:
- operator.redpanda.com/finalizer
name: rp-connectors
spec:
chartRef:
chartVersion: "5.7.4"
clusterSpec:
statefulset:
replicas: 1
Expand Down
2 changes: 0 additions & 2 deletions operator/tests/e2e-v2/connectors/00-create-redpanda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ kind: Redpanda
metadata:
name: rp-connectors
spec:
chartRef:
chartVersion: "5.7.4"
clusterSpec:
statefulset:
replicas: 1
Expand Down
17 changes: 0 additions & 17 deletions operator/tests/e2e-v2/decommission/00-assert-create-redpanda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,6 @@ status:
replicas: 5
updatedReplicas: 5
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: decommission
status:
conditions:

- reason: InstallSucceeded
status: "True"
type: Ready
- reason: InstallSucceeded
status: "True"
type: Released
helmChart: redpanda/redpanda-decommission
lastAppliedRevision: 5.7.9
lastAttemptedRevision: 5.7.9
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
Expand Down
2 changes: 0 additions & 2 deletions operator/tests/e2e-v2/decommission/00-create-redpanda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ kind: Redpanda
metadata:
name: decommission
spec:
chartRef:
chartVersion: "5.7.9"
clusterSpec:
statefulset:
replicas: 5
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@ status:
replicas: 4
updatedReplicas: 4
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: decommission
status:
conditions:
- reason: UpgradeSucceeded
status: "True"
type: Ready
- reason: UpgradeSucceeded
status: "True"
type: Released
helmChart: redpanda/redpanda-decommission
lastAppliedRevision: 5.7.9
lastAttemptedRevision: 5.7.9
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ kind: Redpanda
metadata:
name: decommission
spec:
chartRef:
chartVersion: "5.7.9"
clusterSpec:
statefulset:
replicas: 4
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,6 @@ status:
replicas: 3
updatedReplicas: 3
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: decommission
status:
conditions:
- reason: UpgradeSucceeded
status: "True"
type: Ready
- reason: UpgradeSucceeded
status: "True"
type: Released
helmChart: redpanda/redpanda-decommission
lastAppliedRevision: 5.7.9
lastAttemptedRevision: 5.7.9
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ kind: Redpanda
metadata:
name: decommission
spec:
chartRef:
chartVersion: "5.7.9"
clusterSpec:
statefulset:
replicas: 3
16 changes: 0 additions & 16 deletions operator/tests/e2e-v2/node-deleted/00-assert-create-redpanda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,6 @@ status:
replicas: 3
updatedReplicas: 3
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: redpanda-node-deleted
status:
conditions:
- reason: InstallSucceeded
status: "True"
type: Ready
- reason: InstallSucceeded
status: "True"
type: Released
helmChart: redpanda/redpanda-redpanda-node-deleted
lastAppliedRevision: 5.3.2
lastAttemptedRevision: 5.3.2
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
Expand Down
2 changes: 0 additions & 2 deletions operator/tests/e2e-v2/node-deleted/00-create-redpanda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ kind: Redpanda
metadata:
name: redpanda-node-deleted
spec:
chartRef:
chartVersion: "5.3.2"
clusterSpec:
statefulset:
replicas: 3
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ metadata:
- operator.redpanda.com/finalizer
name: redpanda
spec:
chartRef:
chartVersion: "5.3.2"
clusterSpec:
statefulset:
replicas: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ kind: Redpanda
metadata:
name: redpanda
spec:
chartRef:
chartVersion: "5.3.2"
clusterSpec:
statefulset:
replicas: 1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ metadata:
- operator.redpanda.com/finalizer
name: redpanda
spec:
chartRef:
chartVersion: "5.5.1"
clusterSpec:
statefulset:
replicas: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ metadata:
name: redpanda
spec:
chartRef:
chartVersion: "5.5.1"
useFlux: false
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ metadata:
- operator.redpanda.com/finalizer
name: redpanda
spec:
chartRef:
chartVersion: "5.5.1"
clusterSpec:
statefulset:
replicas: 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ metadata:
- operator.redpanda.com/finalizer
name: redpanda
spec:
chartRef:
chartVersion: "5.5.1"
clusterSpec:
statefulset:
replicas: 3
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ kind: Redpanda
metadata:
name: redpanda-topic
spec:
chartRef:
chartVersion: "5.3.3"
clusterSpec:
statefulset:
replicas: 3
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,6 @@ status:
replicas: 1
updatedReplicas: 1
---
apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
metadata:
name: redpanda-values-check
status:
conditions:
- reason: InstallSucceeded
status: "True"
type: Ready
- reason: InstallSucceeded
status: "True"
type: Released
helmChart: redpanda/redpanda-redpanda-values-check
lastAppliedRevision: 5.3.2
lastAttemptedRevision: 5.3.2
lastAttemptedConfigDigest: sha256:bd42835737f3bc042176268bda36420d9edab32547c60c778cb6835c13e117d6
lastAttemptedGeneration: 1
observedGeneration: 1
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ kind: Redpanda
metadata:
name: redpanda-values-check
spec:
chartRef:
chartVersion: "5.3.2"
clusterSpec:
statefulset:
replicas: 1
Expand Down
Loading

0 comments on commit 06312d2

Please sign in to comment.