Skip to content
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
19 changes: 19 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "2"

issues:
max-issues-per-linter: 0
max-same-issues: 0

formatters:
enable:
- gci
settings:
gci:
sections:
- standard
- default
- localmodule
no-inline-comments: true
no-prefix-comments: true
custom-order: true
no-lex-order: true
5 changes: 3 additions & 2 deletions .mise.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[tools]
go = "1.26"
"go:github.com/daixiang0/gci" = "latest"
"ubi:golangci/golangci-lint" = "2.10"
"ubi:goreleaser/goreleaser" = "2.14"
"github:golangci/golangci-lint" = "latest"
"github:goreleaser/goreleaser" = "2.14"

[env]
CGO_ENABLED=0
LGFLAGS="-extldflags '-static'"
IMAGE="skpr/grpc-go:latest"
PB_DIR="./pb"
APISERVER_MOCK_PORT=50051

[tasks.vendor]
description = "Vendor resets the main module's vendor directory to include all packages needed to build the application"
Expand Down
7 changes: 4 additions & 3 deletions cmd/apiserver-mock/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ func main() {
o := Options{}

globalModel := model.NewModel()
globalModel.AddProject(model.NewProject("project1", "Project One", []string{"group1", "group3"}, "small"))
globalModel.AddProject(model.NewProject("project2", "Project Two", []string{}, "medium"))
globalModel.AddProject(model.NewProject("project3", "Project Three", []string{"group2", "group3"}, "large"))
globalModel.AddProject(model.NewProject("drupal", "Drupal", []string{"group1", "group3"}, "small"))
globalModel.AddProject(model.NewProject("php", "Php", []string{}, "medium"))
globalModel.AddProject(model.NewProject("basic", "Basic", []string{"group2", "group3"}, "large"))
globalModel.CreateEnvironment("dev", 1, true)
globalModel.CreateEnvironment("stg", 2, true)
globalModel.CreateEnvironment("prod", 4, false)
globalModel.CreateEnvironment("pr-123", 1, true)

cmd := &cobra.Command{
Use: "apiserver-mock",
Expand Down
13 changes: 10 additions & 3 deletions environment.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ message Environment {
Drupal = 1; // Environment is Drupal
}
Type type = 2; // Type of environment
bool Production = 3; // If this is a production environment
bool Insecure = 4; // DEPRECIATED: If the environment is insecure (no read only filesystem)
bool Production = 3 [deprecated = true]; // If this is a production environment
bool Insecure = 4 [deprecated = true]; // If the environment is insecure (no read only filesystem)
string Version = 5; // Version associated with an environment
string Size = 6; // Size of the environment
Ingress Ingress = 7; // Ingress configuration for routing
Image Image = 8; // Image respository information
Image Image = 8; // Image repository information
repeated Cron Cron = 9; // Cron configuration for an environment
repeated MySQL MySQL = 10; // MySQL configuration for an environment
SMTP SMTP = 11; // SMTP configuration for an environment
Expand All @@ -67,6 +67,13 @@ message Environment {
repeated Daemon Daemon = 19; // Daemon configuration for an environment
EnvironmentResources Resources = 20; // Resources utilised by this environment
EnvironmentMetrics Metrics = 21; // Metrics configuration for this environment
enum Tier {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose not to use a string here because it can drastically impact an environment. Figured the small updates to proto required if we need new ones would be offset the benefits of it being very defined.

TierNone = 0; // Default tier type
TierProduction = 1;
TierNonProduction = 2;
TierScratch = 3;
}
Tier tier = 22; // Tier of this environment
}

/**
Expand Down
15 changes: 11 additions & 4 deletions internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package model

import (
"fmt"
"strings"
"time"

"github.com/skpr/api/pb"
Expand Down Expand Up @@ -42,10 +43,10 @@ func (s *Model) GetEnvironments() []*Environment {

func (s *Model) CreateEnvironment(name string, size int, metrics bool) {
environment := &pb.Environment{
Name: name,
Version: "v0.0.1",
Phase: "Deployed",
Production: name == "prod",
Name: name,
Version: "v1.0.1",
Phase: "Deployed",
Tier: pb.Environment_TierNonProduction,
Ingress: &pb.Ingress{
Routes: []string{
fmt.Sprintf("%s.mock.local.skpr.dev", name),
Expand Down Expand Up @@ -95,6 +96,12 @@ func (s *Model) CreateEnvironment(name string, size int, metrics bool) {
}
if name == "prod" {
environment.Ingress.Routes = append(environment.Ingress.Routes, "example.com", "www.example.com")
environment.Tier = pb.Environment_TierProduction
environment.Version = "v1.0.0"
}
if strings.HasPrefix(name, "pr-") {
environment.Tier = pb.Environment_TierScratch
environment.Version = "v1.0.1-a3ef9c"
}

cron := make(map[string]*Cron)
Expand Down
5 changes: 5 additions & 0 deletions internal/server/mock/environment/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func (c *Server) Get(ctx context.Context, req *pb.EnvironmentGetRequest) (*pb.En
return nil, err
}

// Implement deprecated production based on tier.
if environment.Environment.Tier == pb.Environment_TierProduction {
environment.Environment.Production = true //nolint:staticcheck
}

resp := &pb.EnvironmentGetResponse{
Environment: environment.Environment,
}
Expand Down
3 changes: 2 additions & 1 deletion internal/server/mock/metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"strings"
"time"

"github.com/skpr/api/pb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/skpr/api/pb"
)

// Server implements the GRPC "events" definition.
Expand Down
3 changes: 2 additions & 1 deletion internal/server/mock/metrics/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"testing"
"time"

"github.com/skpr/api/pb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/skpr/api/pb"
)

var srv = &Server{}
Expand Down
8 changes: 4 additions & 4 deletions internal/server/mock/project/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ func buildProject(model *model.Model, id string) (*pb.Project, error) {

environments := model.GetEnvironments()
for _, env := range environments {
respProject.ResourceTotals.CPU = respProject.ResourceTotals.CPU + env.Environment.Resources.CPU.Limit
respProject.ResourceTotals.Memory = respProject.ResourceTotals.Memory + env.Environment.Resources.Memory.Limit
respProject.ResourceTotals.Replicas = respProject.ResourceTotals.Replicas + env.Environment.Resources.Replicas.Max
respProject.ResourceTotals.CPU = respProject.ResourceTotals.CPU + env.Environment.Resources.CPU.Current
respProject.ResourceTotals.Memory = respProject.ResourceTotals.Memory + env.Environment.Resources.Memory.Current
respProject.ResourceTotals.Replicas = respProject.ResourceTotals.Replicas + env.Environment.Resources.Replicas.Current

if env.Environment.Production {
if env.Environment.Tier == pb.Environment_TierProduction {
respProject.Environments.Prod = env.Environment.Name
respProject.Version = env.Environment.Version
} else {
Expand Down
Loading