Skip to content

Commit

Permalink
Merge pull request #11 from redpanda-data/rk/gh-6076/add-migration-lo…
Browse files Browse the repository at this point in the history
…gic-from-cluster-to-redpanda

Add migration logic from cluster to redpanda
  • Loading branch information
alejandroEsc authored Nov 20, 2023
2 parents 30d04db + 0bc4e9f commit 5c1f696
Show file tree
Hide file tree
Showing 21 changed files with 554 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ steps:
steps:
- key: k8s-operator-v2
label: K8s Operator v2
timeout: 30
timeout: 37
notify:
- github_commit_status:
context: k8s-operator-v2
Expand Down
15 changes: 9 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ bin
_e2e_artifacts/
_e2e_unstable_artifacts/
_helm_e2e_artifacts/
/src/go/k8s/testbin/*
/src/go/k8s/cm-verifier
/src/go/k8s/*.tar.gz
/src/go/k8s/*-exit-code
/src/go/k8s/kubeconfig
/src/go/k8s/tests/_e2e_artifacts_v2/
src/go/k8s/testbin/*
src/go/k8s/cm-verifier
src/go/k8s/*.tar.gz
src/go/k8s/*-exit-code
src/go/k8s/kubeconfig
src/go/k8s/tests/_e2e_artifacts_v2/
src/go/k8s/test-generator-chart/files/
src/go/k8s/tests/_e2e_helm_artifacts_v2/
src/go/k8s/tests/e2e-v2-helm/
*.idea

.DS_Store
Expand Down
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
3 changes: 3 additions & 0 deletions src/go/k8s/hack/v2-helm-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ helm template redpanda test-generator-chart -s templates/assertions.yaml | yq -s
# create the next step files
helm template redpanda test-generator-chart -s templates/run-helm-tests.yaml | yq -s '"temp_tests/" + .metadata.name + "/01-helm-test.yaml"'

# create the deletion
helm template redpanda test-generator-chart -s templates/cleanup.yaml | yq -s '"temp_tests/" + .delete[0].name + "/02-cleanup.yaml"'

# remove the #--- from comments, this is on purpose
OS=$(uname -s)
if [ "$OS" == "Darwin" ]; then
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

0 comments on commit 5c1f696

Please sign in to comment.