-
Notifications
You must be signed in to change notification settings - Fork 15
Implement alternative sidecar broker and pvc decommissioner #342
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
23fc48e
Implement alternative sidecar broker and pvc decommissioner
andrewstucki ca31f20
run linter fix
andrewstucki 5ab6828
Add ghost broker portion of test
andrewstucki 835735e
check error in tests
andrewstucki 1f6658d
Add delayed cache
andrewstucki 0574e70
fix linter
andrewstucki 7d073a8
Fix early return conditions
andrewstucki def31f5
Add alternative fetcher implementations
andrewstucki 774ea6d
Don't initialize new FS every fetch call
andrewstucki f785107
Add memoized profile so we don't read it every time
andrewstucki 7544a80
Address review comments
andrewstucki 71d7f15
re-run task generate and update flags
andrewstucki 90ffa2b
fix group for leader election
andrewstucki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| // Copyright 2024 Redpanda Data, Inc. | ||
| // | ||
| // Use of this software is governed by the Business Source License | ||
| // included in the file licenses/BSL.md | ||
| // | ||
| // As of the Change Date specified in that file, in accordance with | ||
| // the Business Source License, use of this software will be governed | ||
| // by the Apache License, Version 2.0 | ||
|
|
||
| package sidecar | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "time" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" | ||
|
|
||
| "github.com/redpanda-data/redpanda-operator/operator/internal/decommissioning" | ||
| ) | ||
|
|
||
| var schemes = []func(s *runtime.Scheme) error{ | ||
| clientgoscheme.AddToScheme, | ||
| } | ||
|
|
||
| func Command() *cobra.Command { | ||
| var ( | ||
| metricsAddr string | ||
| probeAddr string | ||
| pprofAddr string | ||
| clusterNamespace string | ||
| clusterName string | ||
| decommissionRequeueTimeout time.Duration | ||
| decommissionVoteInterval time.Duration | ||
| decommissionMaxVoteCount int | ||
| redpandaYAMLPath string | ||
| ) | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "run", | ||
| Short: "Run the redpanda sidecar", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx := cmd.Context() | ||
|
|
||
| return Run( | ||
| ctx, | ||
| metricsAddr, | ||
| probeAddr, | ||
| pprofAddr, | ||
| clusterNamespace, | ||
| clusterName, | ||
| decommissionRequeueTimeout, | ||
| decommissionVoteInterval, | ||
| decommissionMaxVoteCount, | ||
| redpandaYAMLPath, | ||
| ) | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") | ||
| cmd.Flags().StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") | ||
| cmd.Flags().StringVar(&pprofAddr, "pprof-bind-address", ":8082", "The address the metric endpoint binds to.") | ||
| cmd.Flags().StringVar(&clusterNamespace, "redpanda-cluster-namespace", "", "The namespace of the cluster that this sidecar manages.") | ||
| cmd.Flags().StringVar(&clusterName, "redpanda-cluster-name", "", "The name of the cluster that this sidecar manages.") | ||
| cmd.Flags().DurationVar(&decommissionRequeueTimeout, "decommission-requeue-timeout", 10*time.Second, "The time period to wait before rechecking a broker that is being decommissioned.") | ||
| cmd.Flags().DurationVar(&decommissionVoteInterval, "decommission-vote-interval", 30*time.Second, "The time period between incrementing decommission vote counts since the last decommission conditions were met.") | ||
| cmd.Flags().IntVar(&decommissionMaxVoteCount, "decommission-vote-count", 2, "The number of times that a vote must be tallied when a resource meets decommission conditions for it to actually be decommissioned.") | ||
| cmd.Flags().StringVar(&redpandaYAMLPath, "redpanda-yaml", "/etc/redpanda/redpanda.yaml", "Path to redpanda.yaml whose rpk stanza will be used for connecting to a Redpanda cluster.") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func Run( | ||
| ctx context.Context, | ||
| metricsAddr string, | ||
| probeAddr string, | ||
| pprofAddr string, | ||
| clusterNamespace string, | ||
| clusterName string, | ||
| decommissionRequeueTimeout time.Duration, | ||
| decommissionVoteInterval time.Duration, | ||
| decommissionMaxVoteCount int, | ||
| redpandaYAMLPath string, | ||
| ) error { | ||
| setupLog := ctrl.LoggerFrom(ctx).WithName("setup") | ||
|
|
||
| if clusterNamespace == "" { | ||
| err := errors.New("must specify a cluster-namespace parameter") | ||
| setupLog.Error(err, "no cluster namespace provided") | ||
| return err | ||
| } | ||
|
|
||
| if clusterName == "" { | ||
| err := errors.New("must specify a cluster-name parameter") | ||
| setupLog.Error(err, "no cluster name provided") | ||
| return err | ||
| } | ||
|
|
||
| scheme := runtime.NewScheme() | ||
|
|
||
| for _, fn := range schemes { | ||
| utilruntime.Must(fn(scheme)) | ||
| } | ||
|
|
||
| mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ | ||
andrewstucki marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Metrics: metricsserver.Options{BindAddress: metricsAddr}, | ||
| HealthProbeBindAddress: probeAddr, | ||
| PprofBindAddress: pprofAddr, | ||
| LeaderElection: true, | ||
| LeaderElectionID: clusterName + "." + clusterNamespace + ".redpanda", | ||
| Scheme: scheme, | ||
| LeaderElectionNamespace: clusterNamespace, | ||
| }) | ||
| if err != nil { | ||
| setupLog.Error(err, "unable to initialize manager") | ||
| return err | ||
| } | ||
|
|
||
| fetcher := decommissioning.NewChainedFetcher( | ||
| // prefer RPK profile first and then move on to fetch from helm values | ||
| decommissioning.NewRPKProfileFetcher(redpandaYAMLPath), | ||
| decommissioning.NewHelmFetcher(mgr), | ||
| ) | ||
|
|
||
| if err := decommissioning.NewStatefulSetDecommissioner(mgr, fetcher, []decommissioning.Option{ | ||
| decommissioning.WithFilter(decommissioning.FilterStatefulSetOwner(clusterNamespace, clusterName)), | ||
| decommissioning.WithRequeueTimeout(decommissionRequeueTimeout), | ||
| decommissioning.WithDelayedCacheInterval(decommissionVoteInterval), | ||
| decommissioning.WithDelayedCacheMaxCount(decommissionMaxVoteCount), | ||
| }...).SetupWithManager(mgr); err != nil { | ||
| setupLog.Error(err, "unable to create controller", "controller", "StatefulSetDecommissioner") | ||
| return err | ||
| } | ||
|
|
||
| if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { | ||
| setupLog.Error(err, "problem running manager") | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: decommissioner-role | ||
| rules: | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - events | ||
| verbs: | ||
| - create | ||
| - patch | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - persistentvolumeclaims | ||
| verbs: | ||
| - delete | ||
| - get | ||
| - list | ||
| - watch | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - persistentvolumes | ||
| verbs: | ||
| - patch | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - pods | ||
| - secrets | ||
| verbs: | ||
| - get | ||
| - list | ||
| - watch | ||
| - apiGroups: | ||
| - apps | ||
| resources: | ||
| - statefulsets | ||
| verbs: | ||
| - get | ||
| - list | ||
| - watch | ||
| - apiGroups: | ||
| - coordination.k8s.io | ||
| resources: | ||
| - leases | ||
| verbs: | ||
| - create | ||
| - delete | ||
| - get | ||
| - list | ||
| - patch | ||
| - update | ||
| - watch | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: Role | ||
| metadata: | ||
| name: decommissioner-role | ||
| namespace: default | ||
| rules: | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - events | ||
| verbs: | ||
| - create | ||
| - patch | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - persistentvolumeclaims | ||
| verbs: | ||
| - delete | ||
| - get | ||
| - list | ||
| - watch | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - pods | ||
| - secrets | ||
| verbs: | ||
| - get | ||
| - list | ||
| - watch | ||
| - apiGroups: | ||
| - apps | ||
| resources: | ||
| - statefulsets | ||
| verbs: | ||
| - get | ||
| - list | ||
| - watch | ||
| - apiGroups: | ||
| - coordination.k8s.io | ||
| resources: | ||
| - leases | ||
| verbs: | ||
| - create | ||
| - delete | ||
| - get | ||
| - list | ||
| - patch | ||
| - update | ||
| - watch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: port 8082 in default Redpanda helm chart deployment is used by HTTP listener. Could you add test to deploy Redpanda helm chart with this sidecar?
https://github.com/redpanda-data/helm-charts/blob/b0a8f611127d405d0811eae052fe75d56a70799d/charts/redpanda/ci/16-controller-sidecar-values.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add the test once I get the rest of the sidecar command finished off with the configwatcher port and pvcunbinder. Will leave this comment open so I don't forget!