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

Feature/messages to protobuff #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ help: ## Display this help.
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

protobuff:
protoc api/v1/*.proto --go_out=. --go_opt=paths=source_relative --proto_path=.

generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

Expand Down
212 changes: 212 additions & 0 deletions api/v1/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions api/v1/messages.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
syntax = "proto3";

package messages.v1;

option go_package = "github.com/uselagoon/insights-remote/api/messages_v1";

message LagoonInsightsMessage {
map<string, string> Payload = 1;
map<string, bytes> BinaryPayload = 2;
map<string, string> Annotations = 3;
map<string, string> Labels = 4;
}
11 changes: 2 additions & 9 deletions controllers/configmap_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/json"
messages_v1 "lagoon.sh/insights-remote/api/v1"
"lagoon.sh/insights-remote/cmlib"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -36,13 +37,6 @@ const InsightsLabel = "lagoon.sh/insightsType"
const InsightsUpdatedAnnotationLabel = "lagoon.sh/insightsProcessed"
const InsightsWriteDeferred = "lagoon.sh/insightsWriteDeferred"

type LagoonInsightsMessage struct {
Payload map[string]string `json:"payload"`
BinaryPayload map[string][]byte `json:"binaryPayload"`
Annotations map[string]string `json:"annotations"`
Labels map[string]string `json:"labels"`
}

// ConfigMapReconciler reconciles a ConfigMap object
type ConfigMapReconciler struct {
client.Client
Expand All @@ -67,14 +61,13 @@ type ConfigMapReconciler struct {
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.8.3/pkg/reconcile
func (r *ConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)

var configMap corev1.ConfigMap
if err := r.Get(ctx, req.NamespacedName, &configMap); err != nil {
log.Error(err, "Unable to load configMap")
return ctrl.Result{}, client.IgnoreNotFound(err)
}

var sendData = LagoonInsightsMessage{
var sendData = messages_v1.LagoonInsightsMessage{
Payload: configMap.Data,
BinaryPayload: configMap.BinaryData,
Annotations: configMap.Annotations,
Expand Down