Skip to content
Merged
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
7 changes: 7 additions & 0 deletions app/pipeline/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ func (a *Agent) Start(ctx context.Context) error {
return
}
}()

go func() {
if err := a.runStatusMonitor(rCtx, *config); err != nil {
log.Ctx(ctx).Error().Err(err).Msg("agent: error running metrics scrapper")
return
}
}()
// }
}
}
Expand Down
36 changes: 36 additions & 0 deletions app/pipeline/agent/monitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package agent

import (
"context"
"time"

"github.com/cloudness-io/cloudness/types"

"github.com/rs/zerolog/log"
)

func (a *Agent) runStatusMonitor(ctx context.Context, config types.RunnerConfig) error {
ticker := time.NewTicker(time.Duration(5) * time.Second)
for {
select {
case <-ctx.Done():
return nil
case <-ticker.C:
status, err := a.serverManager.ListApplicationStatuses(ctx, nil)
if err != nil {
continue
}

if len(status) == 0 {
log.Debug().Msg("agent: no application status found")
continue
}

err = a.client.UploadAppStatus(ctx, status)
if err != nil {
log.Ctx(ctx).Error().Err(err).Msg("agent: error updating application status in monitor")
continue
}
}
}
}
21 changes: 11 additions & 10 deletions app/pipeline/convert/deploy_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,17 @@ func deployCommand(

func getTemplateInput(image string, input *pipeline.RunnerContextInput, spec *types.ApplicationSpec, vars map[string]string) (*templates.TemplateIn, error) {
in := &templates.TemplateIn{
Namespace: input.Application.ParentSlug,
Identifier: input.Application.GetIdentifierStr(),
CloudnessIdentifier: fmt.Sprintf("%d", input.Application.UID),
Image: image,
MaxReplicas: spec.Deploy.MaxReplicas,
CPU: spec.Deploy.CPU,
Memory: spec.Deploy.Memory,
Volumes: make([]*templates.Volume, 0),
Variables: make(map[string]string),
Secrets: make(map[string]string),
Namespace: input.Application.ParentSlug,
Identifier: input.Application.GetIdentifierStr(),
CloudnessAppIdentifier: input.Application.UID,
CloudnessProjectID: input.Application.ProjectID,
Image: image,
MaxReplicas: spec.Deploy.MaxReplicas,
CPU: spec.Deploy.CPU,
Memory: spec.Deploy.Memory,
Volumes: make([]*templates.Volume, 0),
Variables: make(map[string]string),
Secrets: make(map[string]string),
//networking
ServicePorts: make([]int, 0),
HasState: input.Application.Type == enum.ApplicationTypeStateful,
Expand Down
6 changes: 4 additions & 2 deletions app/pipeline/convert/templates/static/3-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ spec:
labels:
app.kubernetes.io/name: {{ .Identifier }}
app.kubernetes.io/instance: {{ .Identifier }}
app.kubernetes.io/cloudness-identifier: "{{ .CloudnessIdentifier }}"
app.kubernetes.io/cloudness-app: "{{ .CloudnessAppIdentifier }}"
app.kubernetes.io/cloudness-project-identifier: "{{ .CloudnessProjectID }}"
app.kubernetes.io/component: app
app.kubernetes.io/managed-by: cloudness
spec:
Expand Down Expand Up @@ -148,7 +149,8 @@ spec:
labels:
app.kubernetes.io/name: {{ .Identifier }}
app.kubernetes.io/instance: {{ .Identifier }}
app.kubernetes.io/cloudness-identifier: "{{ .CloudnessIdentifier }}"
app.kubernetes.io/cloudness-app: "{{ .CloudnessAppIdentifier }}"
app.kubernetes.io/cloudness-project-identifier: "{{ .CloudnessProjectID }}"
app.kubernetes.io/component: app
app.kubernetes.io/managed-by: cloudness
spec:
Expand Down
35 changes: 18 additions & 17 deletions app/pipeline/convert/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,24 @@ func getTemplate(fileName string) *template.Template {

type (
TemplateIn struct {
Identifier string
CloudnessIdentifier string
Namespace string
HasState bool
Image string
Command []string
Args []string
ServicePorts []int
PrivateDomain string
ServiceDomain *ServiceDomain
Volumes []*Volume
MaxReplicas int64
CPU int64
Memory float64
Variables map[string]string
Secrets map[string]string
UpdatedAt string
Identifier string
CloudnessAppIdentifier int64
CloudnessProjectID int64
Namespace string
HasState bool
Image string
Command []string
Args []string
ServicePorts []int
PrivateDomain string
ServiceDomain *ServiceDomain
Volumes []*Volume
MaxReplicas int64
CPU int64
Memory float64
Variables map[string]string
Secrets map[string]string
UpdatedAt string
}

ServiceDomain struct {
Expand Down
3 changes: 3 additions & 0 deletions app/pipeline/manager/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ type RunnerClient interface {
//Metrics
// UploadMetrics uploads the full metrics to server
UploadMetrics(ctx context.Context, metrics []*types.AppMetrics) error

// UploadAppStatus Uploads the application status
UploadAppStatus(ctx context.Context, status []*types.AppStatus) error
}
4 changes: 4 additions & 0 deletions app/pipeline/manager/client/embedded_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ func (e *embeddedClient) Upload(ctx context.Context, deploymentID int64, logs []
func (e *embeddedClient) UploadMetrics(ctx context.Context, metrics []*types.AppMetrics) error {
return e.manager.UploadMetrics(ctx, metrics)
}

func (e *embeddedClient) UploadAppStatus(ctx context.Context, status []*types.AppStatus) error {
return e.manager.UploadAppStatus(ctx, status)
}
2 changes: 1 addition & 1 deletion app/pipeline/manager/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (m *runnerManager) down(ctx context.Context, deployment *types.Deployment)
log.Warn().Err(err).Msg("manager: could not publish deployment updated event")
}

if err := m.sseStreamer.Publish(ctx, app.ProjectID, enum.SSETypeApplicationUpdated, app); err != nil {
if err := m.sseStreamer.Publish(ctx, app.ProjectID, enum.SSETypeApplicationDeploymentUpdated, app); err != nil {
log.Warn().Err(err).Msg("manager: could not publish application updated event")
}

Expand Down
17 changes: 17 additions & 0 deletions app/pipeline/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ type (
//Metrics
// UploadMetrics uploads the full metrics to server
UploadMetrics(ctx context.Context, metrics []*types.AppMetrics) error

// UploadAppStatus Uploads the application status
UploadAppStatus(ctx context.Context, status []*types.AppStatus) error
}
)

Expand Down Expand Up @@ -347,3 +350,17 @@ func (m *runnerManager) UploadMetrics(ctx context.Context, metrics []*types.AppM
}
return nil
}

func (m *runnerManager) UploadAppStatus(ctx context.Context, statuses []*types.AppStatus) error {
for _, status := range statuses {
if _, err := m.applicationStore.UpdateStatus(ctx, status.ApplicationUID, status.Status); err != nil {
log.Ctx(ctx).Error().Err(err).Msg("manager: error updating application status")
continue
}

if err := m.sseStreamer.Publish(ctx, status.ProjectID, enum.SSETypeApplicationStatusUpdated, status.ToEvent()); err != nil {
log.Warn().Err(err).Msg("manager: could not publish application updated event")
}
}
return nil
}
2 changes: 1 addition & 1 deletion app/pipeline/manager/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (m *runnerManager) up(ctx context.Context, deployment *types.Deployment) er
log.Warn().Err(err).Msg("manager: could not publish deployment updated event")
}

if err := m.sseStreamer.Publish(ctx, app.ProjectID, enum.SSETypeApplicationUpdated, app); err != nil {
if err := m.sseStreamer.Publish(ctx, app.ProjectID, enum.SSETypeApplicationDeploymentUpdated, app); err != nil {
log.Warn().Err(err).Msg("manager: could not publish application updated event")
}

Expand Down
13 changes: 12 additions & 1 deletion app/services/manager/kube/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (m *K8sManager) getKubeKeyForDomain(subdomain, hostname string) (string, er
}

func (m *K8sManager) getApplicationUIDFromPodLabels(labels map[string]string) int64 {
appIdentifier := labels["app.kubernetes.io/cloudness-identifier"] //will be of type app-123123123
appIdentifier := labels["app.kubernetes.io/cloudness-app"] //will be of type 123123123

if appIdentifier != "" {
appUID, _ := strconv.ParseInt(appIdentifier, 10, 64)
Expand All @@ -52,6 +52,17 @@ func (m *K8sManager) getApplicationUIDFromPodLabels(labels map[string]string) in
return 0
}

func (m *K8sManager) getProjectIDFromPodLabels(labels map[string]string) int64 {
projectIdentifier := labels["app.kubernetes.io/cloudness-project-identifier"] //will be of type 123123123

if projectIdentifier != "" {
projectID, _ := strconv.ParseInt(projectIdentifier, 10, 64)
return projectID
}

return 0
}

func (m *K8sManager) getUpdateTimeFromPodAnnotations(labels map[string]string) int64 {
updateTimeStr, found := labels["cloudness.io/deployment-time"]
if !found {
Expand Down
Loading
Loading