Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split up controllers by resource group #260

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions operator/cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import (
redpandav1alpha1 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha1"
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
vectorizedv1alpha1 "github.com/redpanda-data/redpanda-operator/operator/api/vectorized/v1alpha1"
"github.com/redpanda-data/redpanda-operator/operator/internal/controller/pvcunbinder"
redpandacontrollers "github.com/redpanda-data/redpanda-operator/operator/internal/controller/redpanda"
vectorizedcontrollers "github.com/redpanda-data/redpanda-operator/operator/internal/controller/vectorized"
adminutils "github.com/redpanda-data/redpanda-operator/operator/pkg/admin"
internalclient "github.com/redpanda-data/redpanda-operator/operator/pkg/client"
consolepkg "github.com/redpanda-data/redpanda-operator/operator/pkg/console"
Expand Down Expand Up @@ -312,7 +312,7 @@ func Run(

adminAPIClientFactory := adminutils.CachedAdminAPIClientFactory(adminutils.NewInternalAdminAPI)

if err = (&redpandacontrollers.ClusterReconciler{
if err = (&vectorizedcontrollers.ClusterReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("redpanda").WithName("Cluster"),
Scheme: mgr.GetScheme(),
Expand All @@ -327,7 +327,7 @@ func Run(
os.Exit(1)
}

if err = (&redpandacontrollers.ClusterConfigurationDriftReconciler{
if err = (&vectorizedcontrollers.ClusterConfigurationDriftReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("redpanda").WithName("ClusterConfigurationDrift"),
Scheme: mgr.GetScheme(),
Expand All @@ -338,13 +338,13 @@ func Run(
os.Exit(1)
}

if err = redpandacontrollers.NewClusterMetricsController(mgr.GetClient()).
if err = vectorizedcontrollers.NewClusterMetricsController(mgr.GetClient()).
SetupWithManager(mgr); err != nil {
setupLog.Error(err, "Unable to create controller", "controller", "ClustersMetrics")
os.Exit(1)
}

if err = (&redpandacontrollers.ConsoleReconciler{
if err = (&vectorizedcontrollers.ConsoleReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("controllers").WithName("redpanda").WithName("Console"),
Expand Down Expand Up @@ -378,7 +378,7 @@ func Run(
} else {
setupLog.Info("starting PVCUnbinder controller", "flag", unbindPVCsAfter)

if err := (&pvcunbinder.Reconciler{
if err := (&vectorizedcontrollers.PVCUnbinderReconciler{
Client: mgr.GetClient(),
Timeout: unbindPVCsAfter,
}).SetupWithManager(mgr); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

// Package redpanda contains reconciliation logic for cluster.redpanda.com CRDs
package redpanda

import (
Expand Down Expand Up @@ -49,6 +50,10 @@ import (
)

const (
FinalizerKey = "operator.redpanda.com/finalizer"

NotManaged = "false"

resourceReadyStrFmt = "%s '%s/%s' is ready"
resourceNotReadyStrFmt = "%s '%s/%s' is not ready"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

// Package redpanda contains reconciliation logic for redpanda.vectorized.io CRD
package redpanda
// Package vectorized contains reconciliation logic for redpanda.vectorized.io CRDs
package vectorized

import (
"context"
Expand Down Expand Up @@ -56,6 +56,8 @@ const (
SecretAnnotationExternalCAKey = "operator.redpanda.com/external-ca"

NotManaged = "false"

managedPath = "/managed"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

package redpanda
package vectorized

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

package redpanda
package vectorized

import (
"context"
Expand Down Expand Up @@ -72,13 +72,6 @@ func (r *ClusterReconciler) reconcileConfiguration(
if err != nil {
return errorWithContext(err, "error creating the admin API client")
}
if err != nil {
log.Info("Waiting for admin API to be available before syncing the configuration")
return &resources.RequeueAfterError{
RequeueAfter: resources.RequeueDuration,
Msg: "admin API is not available yet",
}
}

// Checking if the feature is active because in the initial stages of cluster creation, it takes time for the feature to be activated
// and the API returns the same error (400) that is returned in case of malformed input, which causes a stop of the reconciliation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

package redpanda
package vectorized

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

package redpanda
package vectorized

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

package redpanda
package vectorized

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

package redpanda
package vectorized

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

// Package pvcunbinder implements a reconciler that allows StatefulSet Pods to
// reschedule in the event of a lost HostPath PersistentVolume.
package pvcunbinder
package vectorized

import (
"context"
Expand All @@ -33,7 +31,7 @@ import (

var schedulingFailureRE = regexp.MustCompile(`(^0/[1-9]\d* nodes are available)|(volume node affinity)`)

// Reconciler is a Kubernetes Reconciler that watches for Pods stuck in a
// PVCUnbinderReconciler is a Kubernetes Reconciler that watches for Pods stuck in a
// Pending state due to volume affinities and attempts a remediation.
//
// It watches for Pod events rather than Node events because:
Expand All @@ -52,7 +50,7 @@ var schedulingFailureRE = regexp.MustCompile(`(^0/[1-9]\d* nodes are available)|
// NodeAffinity. By "recycling" we permit Flakey Nodes to rejoin the cluster
// which _might_ reclaim the now freed volume.
// 5. Deleting the Pod to re-trigger PVC creation and rebinding.
type Reconciler struct {
type PVCUnbinderReconciler struct {
Client client.Client
// Timeout is the duration a Pod must be stuck in Pending before
// remediation is attempted.
Expand All @@ -62,7 +60,7 @@ type Reconciler struct {
Selector labels.Selector
}

func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *PVCUnbinderReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).For(&corev1.Pod{}, builder.WithPredicates(predicate.NewPredicateFuncs(pvcUnbinderPredicate))).Complete(r)
}

Expand All @@ -74,7 +72,7 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
// ResourceVersions to inform us about changes from external actors, in which
// case we'll re-queue.
// TODO use an in memory timeout to prevent complete unbinding of Pods.
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
func (r *PVCUnbinderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
logger := ctrl.LoggerFrom(ctx).WithName("PVCUnbinder")
ctx = log.IntoContext(ctx, logger)

Expand Down Expand Up @@ -215,7 +213,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return ctrl.Result{}, nil
}

func (r *Reconciler) ensureRetainPolicy(ctx context.Context, pv *corev1.PersistentVolume) error {
func (r *PVCUnbinderReconciler) ensureRetainPolicy(ctx context.Context, pv *corev1.PersistentVolume) error {
if pv.Spec.PersistentVolumeReclaimPolicy == corev1.PersistentVolumeReclaimRetain {
return nil
}
Expand All @@ -233,7 +231,7 @@ func (r *Reconciler) ensureRetainPolicy(ctx context.Context, pv *corev1.Persiste
// recyclePersistentVolume "recycles" a released PV by clearing it's .ClaimRef
// which makes it available for binding once again.
// This strategy is only valid for volumes that utilize .HostPath.
func (r *Reconciler) recyclePersistentVolume(ctx context.Context, pv *corev1.PersistentVolume) error {
func (r *PVCUnbinderReconciler) recyclePersistentVolume(ctx context.Context, pv *corev1.PersistentVolume) error {
if pv.Spec.HostPath == nil && pv.Spec.Local == nil {
return fmt.Errorf("%T must specify .Spec.HostPath or .Spec.Local for recycling: %q", pv, pv.Name)
}
Expand All @@ -256,7 +254,7 @@ func (r *Reconciler) recyclePersistentVolume(ctx context.Context, pv *corev1.Per
return nil
}

func (r *Reconciler) shouldRemediate(ctx context.Context, pod *corev1.Pod) (bool, time.Duration) {
func (r *PVCUnbinderReconciler) shouldRemediate(ctx context.Context, pod *corev1.Pod) (bool, time.Duration) {
if r.Selector != nil && !r.Selector.Matches(labels.Set(pod.Labels)) {
log.FromContext(ctx).Info("selector not satisfied; skipping", "name", pod.Name, "labels", pod.Labels, "selector", r.Selector.String())
return false, 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

package pvcunbinder
package vectorized

import (
"context"
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestPVCUnbinderShouldRemediate(t *testing.T) {
},
}

r := &Reconciler{
r := &PVCUnbinderReconciler{
Timeout: 30 * time.Second,
Selector: labels.SelectorFromSet(labels.Set{
"key": "value",
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestPVCUnbinder(t *testing.T) {
})
require.NoError(t, err)

r := Reconciler{Client: c}
r := PVCUnbinderReconciler{Client: c}
require.NoError(t, r.SetupWithManager(mgr))

tgo(t, ctx, func(ctx context.Context) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0

package redpanda
package vectorized

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
types2 "github.com/onsi/gomega/types"
"github.com/redpanda-data/redpanda-operator/operator/internal/controller/redpanda"
"github.com/redpanda-data/redpanda-operator/operator/internal/controller/vectorized"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/rbac/v1"
Expand Down Expand Up @@ -812,7 +812,7 @@ var _ = Describe("RedPandaCluster controller", func() {
// so neither redpanda Cluster object or CRB or any other object
// exists. This verifies that these situations are handled
// gracefully and without error
r := &redpanda.ClusterReconciler{
r := &vectorized.ClusterReconciler{
Client: fake.NewClientBuilder().Build(),
Log: ctrl.Log,
Scheme: scheme.Scheme,
Expand All @@ -833,7 +833,7 @@ var _ = Describe("RedPandaCluster controller", func() {
restrictedVersion := "v23.1.2"
key, redpandaCluster := getVersionedRedpanda("restricted-redpanda-negative", restrictedVersion)
fc := fake.NewClientBuilder().WithObjects(redpandaCluster).WithStatusSubresource(redpandaCluster).Build()
r := &redpanda.ClusterReconciler{
r := &vectorized.ClusterReconciler{
Client: fc,
Log: ctrl.Log,
Scheme: scheme.Scheme,
Expand Down Expand Up @@ -862,7 +862,7 @@ var _ = Describe("RedPandaCluster controller", func() {
objects = append(objects, pods[i])
}
fc := fake.NewClientBuilder().WithObjects(objects...).WithStatusSubresource(objects...).Build()
r := &redpanda.ClusterReconciler{
r := &vectorized.ClusterReconciler{
Client: fc,
Log: ctrl.Log,
Scheme: scheme.Scheme,
Expand Down Expand Up @@ -890,7 +890,7 @@ var _ = Describe("RedPandaCluster controller", func() {
})
Expect(err).NotTo(HaveOccurred())

r := &redpanda.ClusterReconciler{
r := &vectorized.ClusterReconciler{
Client: fake.NewClientBuilder().Build(),
Log: ctrl.Log,
Scheme: scheme.Scheme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
redpandav1alpha2 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha2"
vectorizedv1alpha1 "github.com/redpanda-data/redpanda-operator/operator/api/vectorized/v1alpha1"
"github.com/redpanda-data/redpanda-operator/operator/internal/controller/redpanda"
"github.com/redpanda-data/redpanda-operator/operator/internal/controller/vectorized"
"github.com/redpanda-data/redpanda-operator/operator/internal/testutils"
adminutils "github.com/redpanda-data/redpanda-operator/operator/pkg/admin"
consolepkg "github.com/redpanda-data/redpanda-operator/operator/pkg/console"
Expand Down Expand Up @@ -237,7 +238,7 @@ var _ = BeforeSuite(func(suiteCtx SpecContext) {
return testKafkaAdmin, nil
}

err = (&redpanda.ClusterReconciler{
err = (&vectorized.ClusterReconciler{
Client: k8sManager.GetClient(),
Log: l.WithName("controllers").WithName("core").WithName("RedpandaCluster"),
Scheme: k8sManager.GetScheme(),
Expand All @@ -251,7 +252,7 @@ var _ = BeforeSuite(func(suiteCtx SpecContext) {
Expect(err).ToNot(HaveOccurred())

driftCheckPeriod := 500 * time.Millisecond
err = (&redpanda.ClusterConfigurationDriftReconciler{
err = (&vectorized.ClusterConfigurationDriftReconciler{
Client: k8sManager.GetClient(),
Log: l.WithName("controllers").WithName("core").WithName("RedpandaCluster"),
Scheme: k8sManager.GetScheme(),
Expand All @@ -260,7 +261,7 @@ var _ = BeforeSuite(func(suiteCtx SpecContext) {
}).WithClusterDomain("cluster.local").SetupWithManager(k8sManager)
Expect(err).ToNot(HaveOccurred())

err = (&redpanda.ConsoleReconciler{
err = (&vectorized.ConsoleReconciler{
Client: k8sManager.GetClient(),
Scheme: k8sManager.GetScheme(),
Log: l.WithName("controllers").WithName("redpanda").WithName("Console"),
Expand Down
4 changes: 2 additions & 2 deletions operator/webhooks/redpanda/validate_enterprise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (

redpandav1alpha1 "github.com/redpanda-data/redpanda-operator/operator/api/redpanda/v1alpha1"
vectorizedv1alpha1 "github.com/redpanda-data/redpanda-operator/operator/api/vectorized/v1alpha1"
redpandacontrollers "github.com/redpanda-data/redpanda-operator/operator/internal/controller/redpanda"
vectorizedcontrollers "github.com/redpanda-data/redpanda-operator/operator/internal/controller/vectorized"
"github.com/redpanda-data/redpanda-operator/operator/internal/testutils"
adminutils "github.com/redpanda-data/redpanda-operator/operator/pkg/admin"
consolepkg "github.com/redpanda-data/redpanda-operator/operator/pkg/console"
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestDoNotValidateWhenDeleted(t *testing.T) {
require.NoError(t, err)
hookServer := mgr.GetWebhookServer()

err = (&redpandacontrollers.ConsoleReconciler{
err = (&vectorizedcontrollers.ConsoleReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Log: ctrl.Log.WithName("controllers").WithName("redpanda").WithName("Console"),
Expand Down