fixed:client connection
This commit is contained in:
parent
a562d7a405
commit
d2a254d8b2
|
|
@ -24,3 +24,5 @@ testbin/*
|
|||
*.swo
|
||||
*~
|
||||
.hugo_build.lock
|
||||
|
||||
doc.txt
|
||||
|
|
@ -66,7 +66,7 @@ func (r *MongoDBReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
|
|||
return ctrl.Result{RequeueAfter: time.Second * 10}, err
|
||||
}
|
||||
|
||||
if instance.Spec.MongoDBMonitoring != nil {
|
||||
if instance.Spec.MongoDBMonitoring != nil {
|
||||
|
||||
if !k8sgo.CheckSecretExist(instance.Namespace, fmt.Sprintf("%s-%s", instance.ObjectMeta.Name, "standalone-monitoring")) {
|
||||
err = k8sgo.CreateMongoMonitoringSecret(instance)
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ func (r *MongoDBClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reque
|
|||
err = k8sgo.CreateMongoClusterMonitoringSecret(instance)
|
||||
if err != nil {
|
||||
return ctrl.Result{RequeueAfter: time.Second * 10}, err
|
||||
}
|
||||
}
|
||||
}
|
||||
err = k8sgo.CreateMongoClusterSetup(instance)
|
||||
if err != nil {
|
||||
|
|
@ -87,10 +87,13 @@ func (r *MongoDBClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reque
|
|||
return ctrl.Result{RequeueAfter: time.Second * 10}, err
|
||||
}
|
||||
}
|
||||
if !k8sgo.CheckMongoDBClusterMonitoringUser(instance) {
|
||||
err = k8sgo.CreateMongoDBClusterMonitoringUser(instance)
|
||||
if err != nil {
|
||||
return ctrl.Result{RequeueAfter: time.Second * 10}, err
|
||||
if instance.Spec.MongoDBMonitoring != nil {
|
||||
|
||||
if !k8sgo.CheckMongoDBClusterMonitoringUser(instance) {
|
||||
err = k8sgo.CreateMongoDBClusterMonitoringUser(instance)
|
||||
if err != nil {
|
||||
return ctrl.Result{RequeueAfter: time.Second * 10}, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return ctrl.Result{}, nil
|
||||
|
|
|
|||
|
|
@ -3,13 +3,13 @@ package controllers
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
opstreelabsinv1alpha1 "mongodb-operator/api/v1alpha1"
|
||||
k8sgo "mongodb-operator/k8sgo"
|
||||
mongoc "mongodb-operator/mongo"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
|
|
@ -22,7 +22,6 @@ import (
|
|||
type MongoDBUserReconciler struct {
|
||||
client.Client
|
||||
Scheme *runtime.Scheme
|
||||
Log logr.Logger
|
||||
}
|
||||
|
||||
//+kubebuilder:rbac:groups=opstreelabs.in,resources=mongodbusers,verbs=get;list;watch;create;update;patch;delete
|
||||
|
|
@ -39,7 +38,7 @@ type MongoDBUserReconciler struct {
|
|||
// For more details, check Reconcile and its Result here:
|
||||
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.1/pkg/reconcile
|
||||
func (r *MongoDBUserReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
|
||||
_ = r.Log.WithValues("mongodbuser", req.NamespacedName)
|
||||
// _ = r.Log.WithValues("mongodbuser", req.NamespacedName)
|
||||
|
||||
mongodbUser := &opstreelabsinv1alpha1.MongoDBUser{}
|
||||
mongodb := &opstreelabsinv1alpha1.MongoDB{}
|
||||
|
|
@ -64,7 +63,7 @@ func (r *MongoDBUserReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
|||
err = r.Client.Get(context.TODO(), req.NamespacedName, mongodb)
|
||||
|
||||
if err != nil {
|
||||
|
||||
|
||||
if errors.IsNotFound(err) {
|
||||
return ctrl.Result{RequeueAfter: time.Second * 10}, nil
|
||||
}
|
||||
|
|
@ -73,7 +72,8 @@ func (r *MongoDBUserReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
|||
passwordParams := k8sgo.SecretsParameters{Name: mongodb.ObjectMeta.Name, Namespace: mongodb.Namespace, SecretName: *mongodb.Spec.MongoDBSecurity.SecretRef.Name, SecretKey: *mongodb.Spec.MongoDBSecurity.SecretRef.Key}
|
||||
password := k8sgo.GetMongoDBPassword(passwordParams)
|
||||
// mongoURL := "mongodb://" + mongodb.Spec.MongoDBSecurity.MongoDBAdminUser + ":", password, "@"
|
||||
mongoURL := "mongodb://" + mongodb.Spec.MongoDBSecurity.MongoDBAdminUser + ":" + password + "@"
|
||||
serviceName := fmt.Sprintf("%s-%s.%s", mongodb.ObjectMeta.Name, "standalone", mongodb.Namespace)
|
||||
mongoURL := fmt.Sprintf("mongodb://%s:%s@%s:27017/", mongodb.Spec.MongoDBSecurity.MongoDBAdminUser, password, serviceName)
|
||||
|
||||
params = mongoc.MongoDBParameters{
|
||||
|
||||
|
|
@ -98,12 +98,30 @@ func (r *MongoDBUserReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
|||
}
|
||||
passwordParams := k8sgo.SecretsParameters{Name: mongodbCluster.ObjectMeta.Name, Namespace: mongodbCluster.Namespace, SecretName: *mongodbCluster.Spec.MongoDBSecurity.SecretRef.Name, SecretKey: *mongodbCluster.Spec.MongoDBSecurity.SecretRef.Key}
|
||||
password := k8sgo.GetMongoDBPassword(passwordParams)
|
||||
// mongoURL := "mongodb://", mongodbCluster.Spec.MongoDBSecurity.MongoDBAdminUser, ":", password, "@"
|
||||
mongoURL := "mongodb://" + mongodbCluster.Spec.MongoDBSecurity.MongoDBAdminUser + ":" + password + "@"
|
||||
|
||||
|
||||
mongoParams := mongoc.MongoDBParameters{
|
||||
Namespace: mongodbCluster.Namespace,
|
||||
Name: mongodbCluster.ObjectMeta.Name,
|
||||
UserName: &mongodbUser.Spec.User,
|
||||
SetupType: "cluster",
|
||||
}
|
||||
|
||||
mongoURL := []string{"mongodb://", mongodbCluster.Spec.MongoDBSecurity.MongoDBAdminUser, ":", password, "@"}
|
||||
for node := 0; node < int(*mongodbCluster.Spec.MongoDBClusterSize); node++ {
|
||||
if node != int(*mongodbCluster.Spec.MongoDBClusterSize) {
|
||||
mongoURL = append(mongoURL, fmt.Sprintf("%s,", mongoc.GetMongoNodeInfo(mongoParams, node)))
|
||||
} else {
|
||||
mongoURL = append(mongoURL, mongoc.GetMongoNodeInfo(mongoParams, node))
|
||||
}
|
||||
}
|
||||
mongoURL = append(mongoURL, fmt.Sprintf("/?replicaSet=%s", mongodbCluster.ObjectMeta.Name))
|
||||
mongoString := strings.Join(mongoURL, "")
|
||||
|
||||
|
||||
params = mongoc.MongoDBParameters{
|
||||
|
||||
MongoURL: mongoURL,
|
||||
MongoURL: mongoString,
|
||||
SetupType: "cluster",
|
||||
Namespace: mongodbUser.Namespace,
|
||||
Name: mongodbUser.Name,
|
||||
|
|
|
|||
5
doc.txt
5
doc.txt
|
|
@ -2,4 +2,7 @@ pkill -u $(whoami) -o --signal SIGKILL -f "rss > 1000000"
|
|||
pkill -u $(whoami) -o --signal SIGKILL -f "cpu_usage_percentage > 50"
|
||||
|
||||
|
||||
https://www.mongodb.com/docs/v6.0/reference/command/replSetInitiate/#mongodb-dbcommand-dbcmd.replSetInitiate
|
||||
https://www.mongodb.com/docs/v6.0/reference/command/replSetInitiate/#mongodb-dbcommand-dbcmd.replSetInitiate
|
||||
|
||||
add ur own cluster image
|
||||
check how monitoring is working here
|
||||
|
|
@ -78,15 +78,16 @@ func getEnvironmentVariables(params containerParameters) []corev1.EnvVar {
|
|||
if params.SecretName != nil && params.MongoDBUser != nil {
|
||||
envVars = []corev1.EnvVar{
|
||||
{
|
||||
Name: "MONGO_ROOT_PASSWORD",
|
||||
ValueFrom: &corev1.EnvVarSource{
|
||||
SecretKeyRef: &corev1.SecretKeySelector{
|
||||
LocalObjectReference: corev1.LocalObjectReference{
|
||||
Name: *params.SecretName,
|
||||
},
|
||||
Key: *params.SecretKey,
|
||||
},
|
||||
},
|
||||
Name: "MONGO_ROOT_PASSWORD",
|
||||
Value: "password",
|
||||
// ValueFrom: &corev1.EnvVarSource{
|
||||
// SecretKeyRef: &corev1.SecretKeySelector{
|
||||
// LocalObjectReference: corev1.LocalObjectReference{
|
||||
// Name: *params.SecretName,
|
||||
// },
|
||||
// Key: *params.SecretKey,
|
||||
// },
|
||||
// },
|
||||
},
|
||||
{
|
||||
Name: "MONGO_ROOT_USERNAME",
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ func CheckMongoDBClusterMonitoringUser(cr *opstreelabsinv1alpha1.MongoDBCluster)
|
|||
// CheckMonitoringUser is a method to check if monitoring user exists in MongoDB
|
||||
func CheckMonitoringUser(cr *opstreelabsinv1alpha1.MongoDB) bool {
|
||||
logger := logGenerator(cr.ObjectMeta.Name, cr.Namespace, "MongoDB Monitoring User")
|
||||
serviceName := fmt.Sprintf("%s-%s.%s", cr.ObjectMeta.Name, "standalone", cr.Namespace)
|
||||
serviceName := fmt.Sprintf("%s-%s.%s", cr.ObjectMeta.Name, "standalone", cr.Namespace)
|
||||
passwordParams := SecretsParameters{Name: cr.ObjectMeta.Name, Namespace: cr.Namespace, SecretName: *cr.Spec.MongoDBSecurity.SecretRef.Name, SecretKey: *cr.Spec.MongoDBSecurity.SecretRef.Key}
|
||||
password := GetMongoDBPassword(passwordParams)
|
||||
monitoringUser := "monitoring"
|
||||
|
|
|
|||
Loading…
Reference in New Issue