-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
k8s: reconciliation changes, now using patch instead of update
- Loading branch information
1 parent
ed61b1c
commit 866ef6e
Showing
7 changed files
with
406 additions
and
173 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,166 @@ | ||
// Copyright 2021 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 main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"net/http/pprof" | ||
"os" | ||
"time" | ||
|
||
cmapiv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1" | ||
helmControllerAPIV2 "github.com/fluxcd/helm-controller/api/v2beta1" | ||
"github.com/fluxcd/pkg/runtime/client" | ||
"github.com/fluxcd/pkg/runtime/logger" | ||
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2" | ||
redpandav1alpha1 "github.com/redpanda-data/redpanda/src/go/k8s/apis/redpanda/v1alpha1" | ||
vectorizedv1alpha1 "github.com/redpanda-data/redpanda/src/go/k8s/apis/vectorized/v1alpha1" | ||
redpandacontrollers "github.com/redpanda-data/redpanda/src/go/k8s/controllers/redpanda" | ||
flag "github.com/spf13/pflag" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
_ "k8s.io/client-go/plugin/pkg/client/auth" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/healthz" | ||
) | ||
|
||
var ( | ||
scheme = runtime.NewScheme() | ||
setupLog = ctrl.Log.WithName("setup") | ||
|
||
clientOptions client.Options | ||
kubeConfigOpts client.KubeConfigOptions | ||
logOptions logger.Options | ||
) | ||
|
||
//nolint:wsl // the init was generated by kubebuilder | ||
func init() { | ||
utilruntime.Must(clientgoscheme.AddToScheme(scheme)) | ||
utilruntime.Must(redpandav1alpha1.AddToScheme(scheme)) | ||
utilruntime.Must(vectorizedv1alpha1.AddToScheme(scheme)) | ||
utilruntime.Must(cmapiv1.AddToScheme(scheme)) | ||
utilruntime.Must(helmControllerAPIV2.AddToScheme(scheme)) | ||
utilruntime.Must(sourcev1.AddToScheme(scheme)) | ||
//+kubebuilder:scaffold:scheme | ||
} | ||
|
||
// +kubebuilder:rbac:groups=coordination.k8s.io,namespace=default,resources=leases,verbs=get;list;watch;create;update;patch;delete | ||
// +kubebuilder:rbac:groups=core,namespace=default,resources=configmaps,verbs=get;list;watch;create;update;patch;delete | ||
// +kubebuilder:rbac:groups=core,namespace=default,resources=events,verbs=create;patch | ||
|
||
//nolint:funlen // length looks good | ||
func main() { | ||
var ( | ||
clusterDomain string | ||
metricsAddr string | ||
probeAddr string | ||
pprofAddr string | ||
enableLeaderElection bool | ||
decommissionWaitInterval time.Duration | ||
metricsTimeout time.Duration | ||
namespace string | ||
eventsAddr string | ||
|
||
debug bool | ||
) | ||
|
||
flag.StringVar(&eventsAddr, "events-addr", "", "The address of the events receiver.") | ||
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") | ||
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") | ||
flag.StringVar(&pprofAddr, "pprof-bind-address", ":8082", "The address the metric endpoint binds to.") | ||
flag.StringVar(&clusterDomain, "cluster-domain", "cluster.local", "Set the Kubernetes local domain (Kubelet's --cluster-domain)") | ||
flag.BoolVar(&enableLeaderElection, "leader-elect", false, | ||
"Enable leader election for controller manager. "+ | ||
"Enabling this will ensure there is only one active controller manager.") | ||
flag.DurationVar(&decommissionWaitInterval, "decommission-wait-interval", 8*time.Second, "Set the time to wait for a node decommission to happen in the cluster") | ||
flag.DurationVar(&metricsTimeout, "metrics-timeout", 8*time.Second, "Set the timeout for a checking metrics Admin API endpoint. If set to 0, then the 2 seconds default will be used") | ||
flag.BoolVar(&vectorizedv1alpha1.AllowDownscalingInWebhook, "allow-downscaling", true, "Allow to reduce the number of replicas in existing clusters") | ||
flag.BoolVar(&vectorizedv1alpha1.AllowConsoleAnyNamespace, "allow-console-any-ns", false, "Allow to create Console in any namespace. Allowing this copies Redpanda SchemaRegistry TLS Secret to namespace (alpha feature)") | ||
flag.StringVar(&vectorizedv1alpha1.SuperUsersPrefix, "superusers-prefix", "", "Prefix to add in username of superusers managed by operator. This will only affect new clusters, enabling this will not add prefix to existing clusters (alpha feature)") | ||
flag.BoolVar(&debug, "debug", false, "Set to enable debugging") | ||
flag.StringVar(&namespace, "namespace", corev1.NamespaceDefault, "If namespace is set to not empty value, it changes scope of Redpanda operator to work in single namespace") | ||
|
||
logOptions.BindFlags(flag.CommandLine) | ||
clientOptions.BindFlags(flag.CommandLine) | ||
kubeConfigOpts.BindFlags(flag.CommandLine) | ||
|
||
flag.Parse() | ||
|
||
ctrl.SetLogger(logger.NewLogger(logOptions)) | ||
|
||
if debug { | ||
go func() { | ||
pprofMux := http.NewServeMux() | ||
pprofMux.HandleFunc("/debug/pprof/", pprof.Index) | ||
pprofMux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) | ||
pprofMux.HandleFunc("/debug/pprof/profile", pprof.Profile) | ||
pprofMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) | ||
pprofMux.HandleFunc("/debug/pprof/trace", pprof.Trace) | ||
pprofServer := &http.Server{ | ||
Addr: pprofAddr, | ||
Handler: pprofMux, | ||
ReadHeaderTimeout: 3 * time.Second, | ||
} | ||
log.Fatal(pprofServer.ListenAndServe()) | ||
}() | ||
} | ||
|
||
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ | ||
Scheme: scheme, | ||
MetricsBindAddress: metricsAddr, | ||
Port: 9443, | ||
HealthProbeBindAddress: probeAddr, | ||
LeaderElection: enableLeaderElection, | ||
LeaderElectionID: "aa9gre693.redpanda.io", | ||
Namespace: namespace, | ||
LeaderElectionNamespace: namespace, | ||
}) | ||
if err != nil { | ||
setupLog.Error(err, "Unable to start manager") | ||
os.Exit(1) | ||
} | ||
|
||
if err = (&redpandacontrollers.RedpandaNodePVCReconciler{ | ||
Client: mgr.GetClient(), | ||
Namespace: namespace, | ||
}).SetupWithManager(mgr); err != nil { | ||
setupLog.Error(err, "unable to create controller", "controller", "RedpandaNodePVCReconciler") | ||
os.Exit(1) | ||
} | ||
|
||
if err = (&redpandacontrollers.DecommissionReconciler{ | ||
Client: mgr.GetClient(), | ||
Namespace: namespace, | ||
}).SetupWithManager(mgr); err != nil { | ||
setupLog.Error(err, "unable to create controller", "controller", "DecommissionReconciler") | ||
os.Exit(1) | ||
} | ||
|
||
//+kubebuilder:scaffold:builder | ||
|
||
if err := mgr.AddHealthzCheck("health", healthz.Ping); err != nil { | ||
setupLog.Error(err, "Unable to set up health check") | ||
os.Exit(1) | ||
} | ||
|
||
if err := mgr.AddReadyzCheck("check", healthz.Ping); err != nil { | ||
setupLog.Error(err, "Unable to set up ready check") | ||
os.Exit(1) | ||
} | ||
|
||
setupLog.Info("Starting manager") | ||
|
||
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { | ||
setupLog.Error(err, "Problem running manager") | ||
os.Exit(1) | ||
} | ||
} |
This file contains 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 @@ | ||
package redpanda |
Oops, something went wrong.