Some Refactoring.

This commit is contained in:
rony5394
2026-03-22 21:16:58 +01:00
parent be06e3b87c
commit ec797025e5
9 changed files with 299 additions and 234 deletions

View File

@@ -68,7 +68,7 @@ func Run(Config cfg.Config){
stop();
});
ApiClient.NetworkCreate(context.Background(), "blazenaPohar", network.CreateOptions{
ApiClient.NetworkCreate(context.Background(), theConfig.Constants.OverlayNetworkName, network.CreateOptions{
Attachable: true,
// Internal: true,
Driver: "overlay",
@@ -96,7 +96,7 @@ func Run(Config cfg.Config){
fmt.Println("Stopping http server.");
server.Close();
ApiClient.NetworkRemove(context.Background(), "blazenaPohar");
ApiClient.NetworkRemove(context.Background(), theConfig.Constants.OverlayNetworkName);
ApiClient.ConfigRemove(context.Background(), "blazenaSSHPublicKey")
ApiClient.SecretRemove(context.Background(), "blazenaSSHHostPrivateKey");

View File

@@ -14,6 +14,8 @@ import (
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
cfg "github.com/rony5394/blazena/config"
)
func prepare(w http.ResponseWriter, r *http.Request){
@@ -49,7 +51,7 @@ func prepare(w http.ResponseWriter, r *http.Request){
labels := inspectResoults.Spec.Labels;
pullBlazenaImage();
createHelper(labels["blazena.node"], bodyDecoded.VolumeId);
createHelper(theConfig, labels["blazena.node"], bodyDecoded.VolumeId);
time.Sleep(7*time.Second);
@@ -121,7 +123,7 @@ func pullBlazenaImage(){
io.Copy(io.Discard, ipc);
}
func createHelper(targetNode string, targetVolume string){
func createHelper(Config cfg.Config, targetNode string, targetVolume string){
maxConcurrent := uint64(1);
totalCompletions := uint64(1);
stopGracePeriod := time.Second * 5;
@@ -136,7 +138,7 @@ func createHelper(targetNode string, targetVolume string){
sshHostKeySecretId, err := getSecretIDByName(ApiClient, "blazenaSSHHostPrivateKey")
_, err = ApiClient.ServiceCreate(context.Background(), swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: "BlazenaHelper",
Name: Config.Constants.HelperServiceName,
Labels: map[string]string{"blazena.helper": "true"},
},
Mode: swarm.ServiceMode{
@@ -187,7 +189,7 @@ func createHelper(targetNode string, targetVolume string){
Constraints: []string{"node.hostname=="+targetNode},
},
Networks: []swarm.NetworkAttachmentConfig{swarm.NetworkAttachmentConfig{
Target: "blazenaPohar",
Target: Config.Constants.OverlayNetworkName,
}},
},
}, swarm.ServiceCreateOptions{});