snapshots #5

Merged
jandre merged 37 commits from snapshots into master 2023-04-24 07:00:47 +00:00
3 changed files with 103 additions and 0 deletions
Showing only changes of commit bfc1bdec2a - Show all commits

View File

@ -0,0 +1,31 @@
package server
import (
"context"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
formolv1alpha1 "github.com/desmo999r/formol/api/v1alpha1"
)
type BackupSessionReconciler struct {
client.Client
Log logr.Logger
Scheme *runtime.Scheme
}
func (r *BackupSessionReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
r.Log = log.FromContext(ctx)
r.Log.V(0).Info("Enter Reconcile with req", "req", req)
return ctrl.Result{}, nil
}
// SetupWithManager sets up the controller with the Manager.
func (r *BackupSessionReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&formolv1alpha1.BackupSession{}).
Complete(r)
}

View File

@ -0,0 +1,61 @@
package server
import (
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"os"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
formolv1alpha1 "github.com/desmo999r/formol/api/v1alpha1"
)
var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("StartServer")
)
func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(formolv1alpha1.AddToScheme(scheme))
}
func StartServer() {
opts := zap.Options{
Development: true,
}
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
MetricsBindAddress: "0", // disabling prometheus metrics
Scheme: scheme,
Namespace: os.Getenv("POD_NAMESPACE"),
})
if err != nil {
setupLog.Error(err, "unable to create manager")
os.Exit(1)
}
if err = (&BackupSessionReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "BackupSession")
os.Exit(1)
}
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
os.Exit(1)
}
if err := mgr.AddReadyzCheck("readyz", 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 starting manager")
os.Exit(1)
}
}

View File

@ -6,6 +6,7 @@ package cmd
import ( import (
"fmt" "fmt"
"github.com/desmo999r/formolcli/backupsession" "github.com/desmo999r/formolcli/backupsession"
"github.com/desmo999r/formolcli/backupsession/server"
"github.com/spf13/cobra" "github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
) )
@ -24,6 +25,15 @@ var createBackupSessionCmd = &cobra.Command{
}, },
} }
var startServerCmd = &cobra.Command{
Use: "server",
Short: "Start a BackupSession controller",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("starts backupsession controller")
server.StartServer()
},
}
// backupsessionCmd represents the backupsession command // backupsessionCmd represents the backupsession command
var backupSessionCmd = &cobra.Command{ var backupSessionCmd = &cobra.Command{
Use: "backupsession", Use: "backupsession",
@ -33,6 +43,7 @@ var backupSessionCmd = &cobra.Command{
func init() { func init() {
rootCmd.AddCommand(backupSessionCmd) rootCmd.AddCommand(backupSessionCmd)
backupSessionCmd.AddCommand(createBackupSessionCmd) backupSessionCmd.AddCommand(createBackupSessionCmd)
backupSessionCmd.AddCommand(startServerCmd)
createBackupSessionCmd.Flags().String("namespace", "", "The namespace of the BackupConfiguration containing the information about the backup.") createBackupSessionCmd.Flags().String("namespace", "", "The namespace of the BackupConfiguration containing the information about the backup.")
createBackupSessionCmd.Flags().String("name", "", "The name of the BackupConfiguration containing the information about the backup.") createBackupSessionCmd.Flags().String("name", "", "The name of the BackupConfiguration containing the information about the backup.")
createBackupSessionCmd.MarkFlagRequired("namespace") createBackupSessionCmd.MarkFlagRequired("namespace")