@@ -3,19 +3,25 @@ package macpool
33import (
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
1722const (
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
0 commit comments