Skip to content

Commit

Permalink
Abstracted image config. Improved setup logging. Don't requeue at the…
Browse files Browse the repository at this point in the history
… end
  • Loading branch information
as51340 committed Aug 9, 2024
1 parent 9df216a commit 1c96670
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
3 changes: 0 additions & 3 deletions config/samples/memgraph_v1_ha.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ spec:
- --log-level=TRACE
- --coordinator-hostname=memgraph-coordinator-1.default.svc.cluster.local
- --log-file=/var/log/memgraph/memgraph.log
- --nuraft-log-file=/var/log/memgraph/memgraph.log

- id: "2"
boltPort: 7687
Expand All @@ -35,7 +34,6 @@ spec:
- --log-level=TRACE
- --coordinator-hostname=memgraph-coordinator-2.default.svc.cluster.local
- --log-file=/var/log/memgraph/memgraph.log
- --nuraft-log-file=/var/log/memgraph/memgraph.log

- id: "3"
boltPort: 7687
Expand All @@ -51,7 +49,6 @@ spec:
- --log-level=TRACE
- --coordinator-hostname=memgraph-coordinator-3.default.svc.cluster.local
- --log-file=/var/log/memgraph/memgraph.log
- --nuraft-log-file=/var/log/memgraph/memgraph.log


data:
Expand Down
1 change: 1 addition & 0 deletions internal/controller/memgraphha_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ var boltPort int = 7687
var coordinatorPort int = 12000
var mgmtPort int = 10000
var replicationPort int = 12000
var image string = "memgraph/memgraph:2.18.1"
7 changes: 4 additions & 3 deletions internal/controller/memgraphha_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (r *MemgraphHAReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, err
}

logger.Info("MemgrahHA", "namespace", memgraphha.Namespace)
logger.Info("Started reconciliation MemgrahHA")

for coordId := 1; coordId <= 3; coordId++ {
// ClusterIP
Expand Down Expand Up @@ -134,11 +134,12 @@ func (r *MemgraphHAReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, setupJobErr
}

// Since it is currently the last step, we don't need to requeue
if setupJobStatus == true {
logger.Info("SetupJob has been created. Returning Result with the request for requeing with error set to nil.")
return ctrl.Result{Requeue: true}, nil
logger.Info("SetupJob has been created.")
}

logger.Info("Reconciliation of MemgraphHA finished.")
// The resource doesn't need to be reconciled anymore
return ctrl.Result{}, nil
}
Expand Down
2 changes: 0 additions & 2 deletions internal/controller/memgraphha_coord.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func (r *MemgraphHAReconciler) createStatefulSetForCoord(memgraphha *memgraphv1.
labels := createCoordLabels(coordName)
replicas := int32(1)
containerName := "memgraph-coordinator"
image := "memgraph/memgraph:2.18.1"
args := []string{
fmt.Sprintf("--coordinator-id=%d", coordId),
fmt.Sprintf("--coordinator-port=%d", coordinatorPort),
Expand All @@ -80,7 +79,6 @@ func (r *MemgraphHAReconciler) createStatefulSetForCoord(memgraphha *memgraphv1.
"--also-log-to-stderr",
"--log-level=TRACE",
"--log-file=/var/log/memgraph/memgraph.log",
"--nuraft-log-file=/var/log/memgraph/memgraph.log",
}
volumeLibName := fmt.Sprintf("%s-lib-storage", coordName)
volumeLibSize := "1Gi"
Expand Down
1 change: 0 additions & 1 deletion internal/controller/memgraphha_data_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func (r *MemgraphHAReconciler) createStatefulSetForDataInstance(memgraphha *memg
labels := createDataInstanceLabels(dataInstanceName)
replicas := int32(1)
containerName := "memgraph-data"
image := "memgraph/memgraph:2.18.1"
args := []string{
fmt.Sprintf("--management-port=%d", mgmtPort),
fmt.Sprintf("--bolt-port=%d", boltPort),
Expand Down
12 changes: 8 additions & 4 deletions internal/controller/memgraphha_setup_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func (r *MemgraphHAReconciler) reconcileSetupJob(ctx context.Context, memgraphha
}

func (r *MemgraphHAReconciler) createSetupJob(memgraphha *memgraphv1.MemgraphHA) *batchv1.Job {
image := "memgraph/memgraph:2.18.1"
containerName := "memgraph-setup"
runAsUser := int64(0)
backoffLimit := int32(4)
Expand All @@ -80,19 +79,24 @@ func (r *MemgraphHAReconciler) createSetupJob(memgraphha *memgraphv1.MemgraphHA)
Args: []string{`
echo "Installing netcat..."
apt-get update && apt-get install -y netcat-openbsd
echo "Waiting for pods to become available for Bolt connection..."
echo "Waiting for pods to become available for Bolt connection. Time: $(date +'%H:%M:%S')"
until nc -z memgraph-coordinator-1.default.svc.cluster.local 7687; do sleep 1; done
until nc -z memgraph-coordinator-2.default.svc.cluster.local 7687; do sleep 1; done
until nc -z memgraph-coordinator-3.default.svc.cluster.local 7687; do sleep 1; done
until nc -z memgraph-data-0.default.svc.cluster.local 7687; do sleep 1; done
until nc -z memgraph-data-1.default.svc.cluster.local 7687; do sleep 1; done
echo "Pods are available for Bolt connection. Running registration queries!"
echo "Pods are available for Bolt connection. Running registration queries! Time: $(date +'%H:%M:%S')"
echo 'ADD COORDINATOR 2 WITH CONFIG {"bolt_server": "memgraph-coordinator-2.default.svc.cluster.local:7687", "management_server": "memgraph-coordinator-2.default.svc.cluster.local:10000", "coordinator_server": "memgraph-coordinator-2.default.svc.cluster.local:12000"};' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687
echo "Coordinator 2 added. Time: $(date +'%H:%M:%S')"
echo 'ADD COORDINATOR 3 WITH CONFIG {"bolt_server": "memgraph-coordinator-3.default.svc.cluster.local:7687", "management_server": "memgraph-coordinator-3.default.svc.cluster.local:10000", "coordinator_server": "memgraph-coordinator-3.default.svc.cluster.local:12000"};' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687
echo "Coordinator 3 added. Time: $(date +'%H:%M:%S')"
echo 'REGISTER INSTANCE instance_1 WITH CONFIG {"bolt_server": "memgraph-data-0.default.svc.cluster.local:7687", "management_server": "memgraph-data-0.default.svc.cluster.local:10000", "replication_server": "memgraph-data-0.default.svc.cluster.local:20000"};' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687
echo "Instance 1 added. Time: $(date +'%H:%M:%S')"
echo 'REGISTER INSTANCE instance_2 WITH CONFIG {"bolt_server": "memgraph-data-1.default.svc.cluster.local:7687", "management_server": "memgraph-data-1.default.svc.cluster.local:10000", "replication_server": "memgraph-data-1.default.svc.cluster.local:20000"};' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687
echo "Instance 2 added. Time: $(date +'%H:%M:%S')"
echo 'SET INSTANCE instance_1 TO MAIN;' | mgconsole --host memgraph-coordinator-1.default.svc.cluster.local --port 7687
echo "Registration queries done!"
echo "Instance 1 set to main. Time: $(date +'%H:%M:%S')"
echo "Setup finished!"
`},
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
Expand Down

0 comments on commit 1c96670

Please sign in to comment.