Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dockerfile to use uppercase 'AS' for builder stage #359

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.23 as builder
FROM golang:1.23 AS builder
ARG GIT_VERSION
ARG GIT_COMMITSHA

Expand Down
123 changes: 111 additions & 12 deletions meshsync/handlers.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package meshsync

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"time"
"encoding/json"

"github.com/layer5io/meshkit/broker"
"github.com/layer5io/meshkit/utils"
Expand Down Expand Up @@ -68,6 +70,95 @@ func (h *Handler) UpdateInformer() error {
return nil
}

// func (h *Handler) ListenToRequests() {
// listenerConfigs := make(map[string]config.ListenerConfig, 10)
// err := h.Config.GetObject(config.ListenersKey, &listenerConfigs)
// if err != nil {
// h.Log.Error(ErrGetObject(err))
// }

// h.Log.Info("Listening for requests in: ", listenerConfigs[config.RequestStream].SubscribeTo)
// reqChan := make(chan *broker.Message)
// err = h.Broker.SubscribeWithChannel(listenerConfigs[config.RequestStream].SubscribeTo, listenerConfigs[config.RequestStream].ConnectionName, reqChan)
// if err != nil {
// h.Log.Error(ErrSubscribeRequest(err))
// }

// for request := range reqChan {
// if request.Request == nil {
// h.Log.Error(ErrInvalidRequest)
// continue
// }

// switch request.Request.Entity {
// case broker.LogRequestEntity:
// h.Log.Info("Starting log session")
// err := h.processLogRequest(request.Request.Payload, listenerConfigs[config.LogStream])
// if err != nil {
// h.Log.Error(err)
// continue
// }

// // TODO: Add this to the broker pkg
// case "informer-store":
// d, err := json.Marshal(request.Request.Payload)
// // TODO: Update broker pkg in Meshkit to include Reply types
// var payload struct{ Reply string }
// if err != nil {
// h.Log.Error(err)
// continue
// }
// err = json.Unmarshal(d, &payload)
// if err != nil {
// h.Log.Error(err)
// continue
// }
// replySubject := payload.Reply
// storeObjects := h.listStoreObjects()
// splitSlices := splitIntoMultipleSlices(storeObjects, 5) // performance of NATS is bound to degrade if huge messages are sent

// h.Log.Info("Publishing the data from informer stores to the subject: ", replySubject)
// for _, val := range splitSlices {
// err = h.Broker.Publish(replySubject, &broker.Message{
// Object: val,
// })
// if err != nil {
// h.Log.Error(err)
// continue
// }
// }

// case broker.ReSyncDiscoveryEntity:
// h.Log.Info("Resyncing")
// h.channelPool[channels.ReSync].(channels.ReSyncChannel) <- struct{}{}
// case broker.ExecRequestEntity:
// h.Log.Info("Starting interactive session")
// err := h.processExecRequest(request.Request.Payload, listenerConfigs[config.ExecShell])
// if err != nil {
// h.Log.Error(err)
// continue
// }
// case broker.ActiveExecEntity:
// h.Log.Info("Connecting to channel pool")
// err := h.processActiveExecRequest()
// if err != nil {
// h.Log.Error(err)
// continue
// }
// case "meshsync-meta":
// h.Log.Info("Publishing MeshSync metadata to the subject")
// err := h.Broker.Publish("meshsync-meta", &broker.Message{
// Object: config.Server["version"],
// })
// if err != nil {
// h.Log.Error(err)
// continue
// }
// }
// }
// }

// Update the ListenToRequests function
func (h *Handler) ListenToRequests() {
listenerConfigs := make(map[string]config.ListenerConfig, 10)
err := h.Config.GetObject(config.ListenersKey, &listenerConfigs)
Expand Down Expand Up @@ -97,10 +188,8 @@ func (h *Handler) ListenToRequests() {
continue
}

// TODO: Add this to the broker pkg
case "informer-store":
d, err := json.Marshal(request.Request.Payload)
// TODO: Update broker pkg in Meshkit to include Reply types
var payload struct{ Reply string }
if err != nil {
h.Log.Error(err)
Expand All @@ -113,13 +202,11 @@ func (h *Handler) ListenToRequests() {
}
replySubject := payload.Reply
storeObjects := h.listStoreObjects()
splitSlices := splitIntoMultipleSlices(storeObjects, 5) // performance of NATS is bound to degrade if huge messages are sent
splitSlices := splitIntoMultipleSlices(storeObjects, 5)

h.Log.Info("Publishing the data from informer stores to the subject: ", replySubject)
h.Log.Info("Writing the data from informer stores to the file")
for _, val := range splitSlices {
err = h.Broker.Publish(replySubject, &broker.Message{
Object: val,
})
err = writeToFile(replySubject, val) // Call the new function to write to file
if err != nil {
h.Log.Error(err)
continue
Expand All @@ -144,10 +231,8 @@ func (h *Handler) ListenToRequests() {
continue
}
case "meshsync-meta":
h.Log.Info("Publishing MeshSync metadata to the subject")
err := h.Broker.Publish("meshsync-meta", &broker.Message{
Object: config.Server["version"],
})
h.Log.Info("Writing MeshSync metadata to the file")
err := writeToFile("meshsync-meta", config.Server["version"]) // Call the new function to write to file
if err != nil {
h.Log.Error(err)
continue
Expand All @@ -156,6 +241,20 @@ func (h *Handler) ListenToRequests() {
}
}

// Function to write data to a file
func writeToFile(filename string, data interface{}) error {
filePath := filepath.Join("data", filename+".json") // Define the file path and name
file, err := os.Create(filePath)
if err != nil {
return err
}
defer file.Close()

enc := json.NewEncoder(file)
enc.SetIndent("", " ")
return enc.Encode(data)
}

func (h *Handler) listStoreObjects() []model.KubernetesResource {
objects := make([]interface{}, 0)
for _, v := range h.stores {
Expand Down