Skip to content

Commit 8770d46

Browse files
authored
feat(api): adds support for API creating deployment resource (#159)
1 parent 59b4a45 commit 8770d46

File tree

14 files changed

+447
-66
lines changed

14 files changed

+447
-66
lines changed

foundry/api/cmd/api/main.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@ import (
1313
"github.com/input-output-hk/catalyst-forge/foundry/api/internal/models"
1414
"github.com/input-output-hk/catalyst-forge/foundry/api/internal/repository"
1515
"github.com/input-output-hk/catalyst-forge/foundry/api/internal/service"
16+
"github.com/input-output-hk/catalyst-forge/foundry/api/pkg/k8s"
17+
"github.com/input-output-hk/catalyst-forge/foundry/api/pkg/k8s/mocks"
1618
"gorm.io/driver/postgres"
1719
"gorm.io/gorm"
1820
)
1921

22+
var mockK8sClient = mocks.ClientMock{
23+
CreateDeploymentFunc: func(ctx context.Context, deployment *models.ReleaseDeployment) error {
24+
return nil
25+
},
26+
}
27+
2028
func main() {
2129
// Load configuration
2230
cfg, err := config.Load()
@@ -51,6 +59,20 @@ func main() {
5159
os.Exit(1)
5260
}
5361

62+
// Initialize Kubernetes client if enabled
63+
var k8sClient k8s.Client
64+
if cfg.Kubernetes.Enabled {
65+
logger.Info("Initializing Kubernetes client", "namespace", cfg.Kubernetes.Namespace)
66+
k8sClient, err = k8s.New(cfg.Kubernetes.Namespace, logger)
67+
if err != nil {
68+
logger.Error("Failed to initialize Kubernetes client", "error", err)
69+
os.Exit(1)
70+
}
71+
} else {
72+
k8sClient = &mockK8sClient
73+
logger.Info("Kubernetes integration is disabled")
74+
}
75+
5476
// Initialize repositories
5577
releaseRepo := repository.NewReleaseRepository(db)
5678
deploymentRepo := repository.NewDeploymentRepository(db)
@@ -60,7 +82,7 @@ func main() {
6082

6183
// Initialize services
6284
releaseService := service.NewReleaseService(releaseRepo, aliasRepo, counterRepo, deploymentRepo)
63-
deploymentService := service.NewDeploymentService(deploymentRepo, releaseRepo, eventRepo)
85+
deploymentService := service.NewDeploymentService(deploymentRepo, releaseRepo, eventRepo, k8sClient, db, logger)
6486

6587
// Setup router
6688
router := api.SetupRouter(releaseService, deploymentService, db, logger)

foundry/api/docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.8'
2-
31
services:
42
api:
53
image: foundry-api:latest
@@ -16,6 +14,7 @@ services:
1614
DB_PASSWORD: changeme
1715
DB_NAME: foundry
1816
DB_SSLMODE: disable
17+
K8S_ENABLED: "false"
1918
LOG_LEVEL: debug
2019
LOG_FORMAT: text
2120
ports:

foundry/api/go.mod

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@ require (
88
github.com/stretchr/testify v1.9.0
99
gorm.io/driver/postgres v1.5.11
1010
gorm.io/gorm v1.25.12
11+
k8s.io/apimachinery v0.32.3
12+
k8s.io/client-go v0.32.3
1113
)
1214

1315
require (
1416
github.com/bytedance/sonic v1.11.6 // indirect
1517
github.com/bytedance/sonic/loader v0.1.1 // indirect
1618
github.com/cloudwego/base64x v0.1.4 // indirect
1719
github.com/cloudwego/iasm v0.2.0 // indirect
18-
github.com/davecgh/go-spew v1.1.1 // indirect
20+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
21+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
1922
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
2023
github.com/gin-contrib/sse v0.1.0 // indirect
24+
github.com/go-logr/logr v1.4.2 // indirect
2125
github.com/go-playground/locales v0.14.1 // indirect
2226
github.com/go-playground/universal-translator v0.18.1 // indirect
2327
github.com/go-playground/validator/v10 v10.20.0 // indirect
2428
github.com/goccy/go-json v0.10.2 // indirect
29+
github.com/gogo/protobuf v1.3.2 // indirect
30+
github.com/google/go-cmp v0.6.0 // indirect
31+
github.com/google/gofuzz v1.2.0 // indirect
2532
github.com/jackc/pgpassfile v1.0.0 // indirect
2633
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
2734
github.com/jackc/pgx/v5 v5.5.5 // indirect
@@ -30,22 +37,34 @@ require (
3037
github.com/jinzhu/now v1.1.5 // indirect
3138
github.com/json-iterator/go v1.1.12 // indirect
3239
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
33-
github.com/kr/text v0.2.0 // indirect
40+
github.com/kr/pretty v0.3.1 // indirect
3441
github.com/leodido/go-urn v1.4.0 // indirect
3542
github.com/mattn/go-isatty v0.0.20 // indirect
3643
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3744
github.com/modern-go/reflect2 v1.0.2 // indirect
45+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
3846
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
39-
github.com/pmezard/go-difflib v1.0.0 // indirect
47+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
4048
github.com/rogpeppe/go-internal v1.14.1 // indirect
49+
github.com/spf13/pflag v1.0.5 // indirect
4150
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
4251
github.com/ugorji/go/codec v1.2.12 // indirect
52+
github.com/x448/float16 v0.8.4 // indirect
4353
golang.org/x/arch v0.8.0 // indirect
44-
golang.org/x/crypto v0.23.0 // indirect
45-
golang.org/x/net v0.25.0 // indirect
46-
golang.org/x/sync v0.1.0 // indirect
54+
golang.org/x/crypto v0.28.0 // indirect
55+
golang.org/x/net v0.30.0 // indirect
56+
golang.org/x/oauth2 v0.23.0 // indirect
57+
golang.org/x/sync v0.8.0 // indirect
4758
golang.org/x/sys v0.26.0 // indirect
48-
golang.org/x/text v0.15.0 // indirect
49-
google.golang.org/protobuf v1.34.1 // indirect
59+
golang.org/x/term v0.25.0 // indirect
60+
golang.org/x/text v0.19.0 // indirect
61+
golang.org/x/time v0.7.0 // indirect
62+
google.golang.org/protobuf v1.35.1 // indirect
63+
gopkg.in/inf.v0 v0.9.1 // indirect
5064
gopkg.in/yaml.v3 v3.0.1 // indirect
65+
k8s.io/klog/v2 v2.130.1 // indirect
66+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
67+
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
68+
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
69+
sigs.k8s.io/yaml v1.4.0 // indirect
5170
)

0 commit comments

Comments
 (0)