Skip to content

Commit 29aa9a1

Browse files
committed
chore: aws mac pool allow orchestrate serverless stack, to allow several task specs
Signed-off-by: Adrian Riobo <[email protected]>
1 parent 8a66e81 commit 29aa9a1

File tree

14 files changed

+356
-246
lines changed

14 files changed

+356
-246
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ VERSION ?= 0.9.0-dev
22
CONTAINER_MANAGER ?= podman
33

44
# Image URL to use all building/pushing image targets
5-
IMG ?= quay.io/redhat-developer/mapt:v${VERSION}
6-
TKN_IMG ?= quay.io/redhat-developer/mapt:v${VERSION}-tkn
5+
IMG ?= ghcr.io/redhat-developer/mapt:pr-421
6+
TKN_IMG ?= ghcr.io/redhat-developer/mapt:pr-421-tkn
77

88
# Integrations
99
# renovate: datasource=github-releases depName=cirruslabs/cirrus-cli

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/redhat-developer/mapt
22

33
go 1.23.1
44

5-
toolchain go1.24.2
5+
toolchain go1.23.7
66

77
require (
88
github.com/coocood/freecache v1.2.4

pkg/provider/aws/action/mac-pool/housekeeper.go

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ package macpool
22

33
import (
44
"fmt"
5+
"strings"
56

7+
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
68
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
79
"github.com/redhat-developer/mapt/pkg/provider/aws"
10+
"github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac"
11+
macHost "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/host"
812
"github.com/redhat-developer/mapt/pkg/provider/aws/modules/serverless"
13+
"github.com/redhat-developer/mapt/pkg/util"
914
"github.com/redhat-developer/mapt/pkg/util/logging"
1015
)
1116

@@ -50,9 +55,11 @@ func houseKeeper(ctx *maptContext.ContextArgs, r *MacPoolRequestArgs) error {
5055
}
5156

5257
// Run serverless operation for house keeping
53-
func (r *MacPoolRequestArgs) scheduleHouseKeeper() error {
54-
return serverless.Create(
58+
func scheduleHouseKeeper(ctx *pulumi.Context, r *MacPoolRequestArgs) error {
59+
// First I need to create
60+
return serverless.Deploy(ctx,
5561
&serverless.ServerlessArgs{
62+
Prefix: houseKeepingOperation,
5663
ContainerName: fmt.Sprintf("housekeeper-%s-%s-%s",
5764
r.PoolName,
5865
r.Architecture,
@@ -66,12 +73,17 @@ func (r *MacPoolRequestArgs) scheduleHouseKeeper() error {
6673
r.FixedLocation),
6774
ScheduleType: &serverless.Repeat,
6875
Schedulexpression: houseKeepingInterval,
69-
LogGroupName: fmt.Sprintf("%s-%s-%s",
76+
LogGroupName: fmt.Sprintf("%s-%s-%s-%s",
77+
houseKeepingOperation,
7078
r.PoolName,
7179
r.Architecture,
7280
r.OSVersion)})
7381
}
7482

83+
// func destroyScheduleHouseKeeper() error {
84+
// return serverless.Destroy(&houseKeepingOperation)
85+
// }
86+
7587
func houseKeepingCommand(poolName, arch, osVersion string,
7688
offeredCapacity, maxSize int,
7789
fixedLocation bool) string {
@@ -83,3 +95,89 @@ func houseKeepingCommand(poolName, arch, osVersion string,
8395
}
8496
return cmd
8597
}
98+
99+
func (r *MacPoolRequestArgs) addMachinesToPool(n int) error {
100+
if err := validateBackedURL(); err != nil {
101+
return err
102+
}
103+
for i := 0; i < n; i++ {
104+
hr := r.fillHostRequest()
105+
dh, err := macHost.CreatePoolDedicatedHost(hr)
106+
if err != nil {
107+
return err
108+
}
109+
mr := r.fillMacRequest()
110+
if err = mr.CreateAvailableMacMachine(dh); err != nil {
111+
return err
112+
}
113+
}
114+
return nil
115+
}
116+
117+
// format for remote backed url when creating the dedicated host
118+
// the backed url from param is used as base and the ID is appended as sub path
119+
func validateBackedURL() error {
120+
if strings.Contains(maptContext.BackedURL(), "file://") {
121+
return fmt.Errorf("local backed url is not allowed for mac pool")
122+
}
123+
return nil
124+
}
125+
126+
// transform pool request to host request
127+
// need if we need to expand the pool
128+
func (r *MacPoolRequestArgs) fillHostRequest() *macHost.PoolMacDedicatedHostRequestArgs {
129+
return &macHost.PoolMacDedicatedHostRequestArgs{
130+
MacDedicatedHost: &macHost.MacDedicatedHostRequestArgs{
131+
Prefix: r.Prefix,
132+
Architecture: r.Architecture,
133+
FixedLocation: r.FixedLocation,
134+
},
135+
PoolID: &macHost.PoolID{
136+
PoolName: r.PoolName,
137+
Arch: r.Architecture,
138+
OSVersion: r.OSVersion,
139+
},
140+
BackedURL: fmt.Sprintf("%s/%s",
141+
maptContext.BackedURL(),
142+
util.RandomID("mapt")),
143+
}
144+
}
145+
146+
// If we need less or equal than the max allowed on the pool we create all of them
147+
// if need are more than allowed we can create just the allowed
148+
func (r *MacPoolRequestArgs) addCapacity(p *pool) error {
149+
allowed := p.maxSize - p.offeredCapacity
150+
needed := p.offeredCapacity - p.currentOfferedCapacity()
151+
if needed <= allowed {
152+
return r.addMachinesToPool(needed)
153+
}
154+
return r.addMachinesToPool(allowed)
155+
}
156+
157+
// If we need less or equal than the max allowed on the pool we create all of them
158+
// if need are more than allowed we can create just the allowed
159+
// TODO review allocation time is on the wrong order
160+
func (r *MacPoolRequestArgs) destroyCapacity(p *pool) error {
161+
machinesToDestroy := p.currentOfferedCapacity() - r.OfferedCapacity
162+
for i := 0; i < machinesToDestroy; i++ {
163+
m := p.destroyableMachines[i]
164+
// TODO change this
165+
maptContext.SetProjectName(*m.ProjectName)
166+
if err := aws.DestroyStack(aws.DestroyStackRequest{
167+
Stackname: mac.StackMacMachine,
168+
Region: *m.Region,
169+
BackedURL: *m.BackedURL,
170+
}); err != nil {
171+
return err
172+
}
173+
if err := aws.DestroyStack(aws.DestroyStackRequest{
174+
Stackname: mac.StackDedicatedHost,
175+
// TODO check if needed to add region for backedURL
176+
Region: *m.Region,
177+
BackedURL: *m.BackedURL,
178+
}); err != nil {
179+
return err
180+
}
181+
}
182+
return nil
183+
}

0 commit comments

Comments
 (0)