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

Add migration logic from cluster to redpanda #7

Closed
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
2 changes: 1 addition & 1 deletion src/go/k8s/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM public.ecr.aws/docker/library/golang:1.21.2 as builder
FROM --platform=$BUILDPLATFORM public.ecr.aws/docker/library/golang:1.21.3 as builder

ARG TARGETARCH
ARG TARGETOS
Expand Down
20 changes: 19 additions & 1 deletion src/go/k8s/api/redpanda/v1alpha1/redpanda_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
"fmt"

helmv2beta1 "github.com/fluxcd/helm-controller/api/v2beta1"

"github.com/fluxcd/pkg/apis/meta"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/redpanda-data/redpanda-operator/src/go/k8s/api/vectorized/v1alpha1"
)

var RedpandaChartRepository = "https://charts.redpanda.com/"
Expand Down Expand Up @@ -46,6 +47,23 @@ type RedpandaSpec struct {
ChartRef ChartRef `json:"chartRef,omitempty"`
// ClusterSpec defines the values to use in the cluster
ClusterSpec *RedpandaClusterSpec `json:"clusterSpec,omitempty"`
// Migration flag that adjust Kubernetes core resources with annotation and labels, so
// flux controller can import resources.
// Doc: https://docs.redpanda.com/current/upgrade/migrate/kubernetes/operator/
Migration *Migration `json:"migration,omitempty"`
}

// Migration can configure old Cluster and Console custom resource that will be disabled.
// With Migration the ChartRef and ClusterSpec still need to be correctly configured.
type Migration struct {
Enabled bool `json:"enabled"`
// ClusterRef by default will not be able to reach different namespaces, but it can be
// overwritten by adding ClusterRole and ClusterRoleBinding to operator ServiceAccount.
ClusterRef v1alpha1.NamespaceNameRef `json:"clusterRef"`

// ConsoleRef by default will not be able to reach different namespaces, but it can be
// overwritten by adding ClusterRole and ClusterRoleBinding to operator ServiceAccount.
ConsoleRef v1alpha1.NamespaceNameRef `json:"consoleRef"`
}

// RedpandaStatus defines the observed state of Redpanda
Expand Down
22 changes: 22 additions & 0 deletions src/go/k8s/api/redpanda/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions src/go/k8s/config/crd/bases/cluster.redpanda.com_redpandas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3009,6 +3009,48 @@ spec:
type: string
type: object
type: object
migration:
description: 'Migration flag that adjust Kubernetes core resources
with annotation and labels, so flux controller can import resources.
Doc: https://docs.redpanda.com/current/upgrade/migrate/kubernetes/operator/'
properties:
clusterRef:
description: ClusterRef by default will not be able to reach different
namespaces, but it can be overwritten by adding ClusterRole
and ClusterRoleBinding to operator ServiceAccount.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
required:
- name
- namespace
type: object
consoleRef:
description: ConsoleRef by default will not be able to reach different
namespaces, but it can be overwritten by adding ClusterRole
and ClusterRoleBinding to operator ServiceAccount.
properties:
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
required:
- name
- namespace
type: object
enabled:
type: boolean
required:
- clusterRef
- consoleRef
- enabled
type: object
type: object
status:
description: RedpandaStatus defines the observed state of Redpanda
Expand Down
4 changes: 4 additions & 0 deletions src/go/k8s/config/rbac/bases/operator/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,10 @@ rules:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
Expand Down Expand Up @@ -556,8 +558,10 @@ rules:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- rbac.authorization.k8s.io
resources:
Expand Down
18 changes: 18 additions & 0 deletions src/go/k8s/internal/controller/redpanda/console_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func (r *ConsoleReconciler) Reconcile(
}

r.Log.V(logger.DebugLevel).Info("console", "observed generation", console.Status.ObservedGeneration, "generation", console.GetGeneration())

if !isConsoleManaged(r.Log, console) {
return ctrl.Result{}, nil
}

var s state
switch {
case !console.GetDeletionTimestamp().IsZero():
Expand Down Expand Up @@ -369,3 +374,16 @@ func (r *ConsoleReconciler) reconcileConsoleForCluster(pctx context.Context, c c

return res
}

func isConsoleManaged(
l logr.Logger, console *vectorizedv1alpha1.Console,
) bool {
log := l.WithName("isConsoleManaged")
managedAnnotationKey := vectorizedv1alpha1.GroupVersion.Group + managedPath
if managed, exists := console.Annotations[managedAnnotationKey]; exists && managed == NotManaged {
log.Info(fmt.Sprintf("management is disabled; to enable it, change the '%s' annotation to true or remove it",
managedAnnotationKey))
return false
}
return true
}
Loading
Loading