Skip to content

Commit 63e64c4

Browse files
committed
PENDING TO EXTEND executionDefaults
Signed-off-by: Adrian Riobo <[email protected]>
1 parent 29aa9a1 commit 63e64c4

File tree

10 files changed

+531
-556
lines changed

10 files changed

+531
-556
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ func houseKeeper(ctx *maptContext.ContextArgs, r *MacPoolRequestArgs) error {
5555
}
5656

5757
// Run serverless operation for house keeping
58-
func scheduleHouseKeeper(ctx *pulumi.Context, r *MacPoolRequestArgs) error {
58+
func houseKeeperTaskSpecScheduler(ctx *pulumi.Context, r *MacPoolRequestArgs,
59+
vpcID, subnetID, sgID *string) error {
5960
// First I need to create
6061
return serverless.Deploy(ctx,
6162
&serverless.ServerlessArgs{
@@ -77,7 +78,12 @@ func scheduleHouseKeeper(ctx *pulumi.Context, r *MacPoolRequestArgs) error {
7778
houseKeepingOperation,
7879
r.PoolName,
7980
r.Architecture,
80-
r.OSVersion)})
81+
r.OSVersion),
82+
ExecutionDefaults: map[string]*string{
83+
serverless.TaskExecDefaultVPCID: vpcID,
84+
serverless.TaskExecDefaultSubnetID: subnetID,
85+
serverless.TaskExecDefaultSGID: sgID,
86+
}})
8187
}
8288

8389
// func destroyScheduleHouseKeeper() error {

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

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,25 @@ package macpool
33
import (
44
"encoding/json"
55
"fmt"
6+
"os"
67

78
"github.com/pulumi/pulumi/sdk/v3/go/auto"
89
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
910
"github.com/redhat-developer/mapt/pkg/manager"
1011
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
1112
"github.com/redhat-developer/mapt/pkg/provider/aws"
13+
"github.com/redhat-developer/mapt/pkg/provider/aws/data"
1214
"github.com/redhat-developer/mapt/pkg/provider/aws/modules/iam"
1315
macUtil "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/util"
16+
"github.com/redhat-developer/mapt/pkg/provider/aws/modules/network"
17+
securityGroup "github.com/redhat-developer/mapt/pkg/provider/aws/services/ec2/security-group"
1418
"github.com/redhat-developer/mapt/pkg/util/logging"
19+
resourcesUtil "github.com/redhat-developer/mapt/pkg/util/resources"
1520
)
1621

1722
const (
18-
stackName = "stackMacPool"
23+
stackName = "stackMacPool"
24+
awsMacPoolID = "amp"
1925
)
2026

2127
// Create works as an orchestrator for create n machines based on offered capacity
@@ -84,19 +90,55 @@ func (r *MacPoolRequestArgs) deploy(ctx *pulumi.Context) error {
8490
// }
8591
// TODO create the SG and pass it to the specs
8692
// Run once the housekeeper to initialize the pool
87-
if err := scheduleHouseKeeper(ctx, r); err != nil {
93+
// Create SG with ingress rules
94+
95+
poolRegion := os.Getenv("AWS_DEFAULT_REGION")
96+
azID, err := data.GetRandomAvailabilityZone(poolRegion, nil)
97+
if err != nil {
8898
return err
8999
}
90-
if err := requestTaskSpec(ctx, r); err != nil {
100+
nr := network.NetworkRequest{
101+
Prefix: r.Prefix,
102+
ID: awsMacPoolID,
103+
Region: poolRegion,
104+
AZ: *azID,
105+
}
106+
vpc, targetSubnet, _, _, _, err := nr.Network(ctx)
107+
if err != nil {
91108
return err
92109
}
93-
if err := releaseTaskSpec(
94-
ctx,
95-
r.PoolName,
96-
r.Architecture,
97-
r.OSVersion); err != nil {
110+
sshRunnerSG, err := securityGroup.SGRequest{
111+
Name: resourcesUtil.GetResourceName(r.Prefix, awsMacPoolID, "ssh-runner-sg"),
112+
VPC: vpc,
113+
Description: fmt.Sprintf("sg for %s", awsMacPoolID),
114+
}.Create(ctx)
115+
if err != nil {
98116
return err
99117
}
118+
// We will add values for VPC, Subnet and SG as tags,
119+
// the meaning of those tags would be recommended values for running the tasks
120+
// As one step is create the task spec (which does not use those values)
121+
// And second step is set a scheduler or one time execution / direct execution
122+
// in this case those values are needed, so basically we could pick them up from the tags
123+
// on the task spec otherwise any other values can be used
124+
_ = pulumi.All(vpc.ID(), targetSubnet.ID(), sshRunnerSG.SG.ID()).ApplyT(
125+
func(args []interface{}) error {
126+
vpcID := args[0].(string)
127+
subnetID := args[1].(string)
128+
sgID := args[2].(string)
129+
if err := houseKeeperTaskSpecScheduler(ctx, r, &vpcID, &subnetID, &sgID); err != nil {
130+
return err
131+
}
132+
if err := requestTaskSpec(ctx, r, &vpcID, &subnetID, &sgID); err != nil {
133+
return err
134+
}
135+
return releaseTaskSpec(
136+
ctx,
137+
r.PoolName,
138+
r.Architecture,
139+
r.OSVersion,
140+
&vpcID, &subnetID, &sgID)
141+
}).(pulumi.StringOutput)
100142
return requestReleaserAccount(ctx, r)
101143
}
102144

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func releaseRemote(ctx *maptContext.ContextArgs, hostID string) error {
3838
&serverless.MaptServerlessClusterName, &containerName, &cmd)
3939
}
4040

41-
func releaseTaskSpec(ctx *pulumi.Context, poolName, arch, osVersion string) error {
41+
func releaseTaskSpec(ctx *pulumi.Context, poolName, arch, osVersion string, vpcID, subnetID, sgID *string) error {
4242
name := releaseTaskContainerName(poolName, arch, osVersion)
4343
return serverless.Deploy(
4444
ctx,
@@ -47,6 +47,11 @@ func releaseTaskSpec(ctx *pulumi.Context, poolName, arch, osVersion string) erro
4747
ContainerName: name,
4848
Command: releaseCommand,
4949
LogGroupName: name,
50+
ExecutionDefaults: map[string]*string{
51+
serverless.TaskExecDefaultVPCID: vpcID,
52+
serverless.TaskExecDefaultSubnetID: subnetID,
53+
serverless.TaskExecDefaultSGID: sgID,
54+
},
5055
Tags: serverlessTags(
5156
poolName,
5257
arch,

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func requestRemote(ctx *maptContext.ContextArgs, r *RequestMachineArgs) error {
7676
// Run serverless operation request
7777
// check how we will call it from the request?
7878
// may add tags and find or add arn to stack?
79-
func requestTaskSpec(ctx *pulumi.Context, r *MacPoolRequestArgs) error {
79+
func requestTaskSpec(ctx *pulumi.Context, r *MacPoolRequestArgs, vpcID, subnetID, sgID *string) error {
8080
name := requestTaskContainerName(
8181
r.PoolName,
8282
r.Architecture,
@@ -90,6 +90,11 @@ func requestTaskSpec(ctx *pulumi.Context, r *MacPoolRequestArgs) error {
9090
r.Architecture,
9191
r.OSVersion),
9292
LogGroupName: name,
93+
ExecutionDefaults: map[string]*string{
94+
serverless.TaskExecDefaultVPCID: vpcID,
95+
serverless.TaskExecDefaultSubnetID: subnetID,
96+
serverless.TaskExecDefaultSGID: sgID,
97+
},
9398
Tags: serverlessTags(
9499
r.PoolName,
95100
r.Architecture,

pkg/provider/aws/modules/serverless/run.go

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)