Skip to content

Commit 81bb868

Browse files
committed
chore: aws added tag data function to get any type ofresource tags and match with a expected set of tags
this is now used within mac-pool request operation on remote mode...to get the fargate task spec to run request through it Signed-off-by: Adrian Riobo <ariobolo@redhat.com>
1 parent 6209388 commit 81bb868

40 files changed

Lines changed: 9200 additions & 32 deletions

cmd/mapt/cmd/aws/services/mac-pool.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ func request() *cobra.Command {
175175

176176
ctx := &maptContext.ContextArgs{
177177
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
178-
Serverless: viper.IsSet(params.Serverless),
179178
Debug: viper.IsSet(params.Debug),
180179
DebugLevel: viper.GetUint(params.DebugLevel),
181-
Tags: viper.GetStringMapString(params.Tags),
180+
Serverless: viper.IsSet(params.Serverless),
181+
// Remote: viper.IsSet(params.Remote),
182+
Tags: viper.GetStringMapString(params.Tags),
182183
}
183184

184185
if viper.IsSet(params.GHActionsRunnerToken) {
@@ -223,6 +224,7 @@ func request() *cobra.Command {
223224
flagSet.StringP(awsParams.MACOSVersion, "", awsParams.MACOSVersion, awsParams.MACOSVersionDefault)
224225
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
225226
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
227+
// flagSet.Bool(params.Remote, false, params.RemoteDesc)
226228
flagSet.AddFlagSet(params.GetGHActionsFlagset())
227229
params.AddCirrusFlags(flagSet)
228230
c.PersistentFlags().AddFlagSet(flagSet)
@@ -243,6 +245,7 @@ func release() *cobra.Command {
243245
Debug: viper.IsSet(params.Debug),
244246
DebugLevel: viper.GetUint(params.DebugLevel),
245247
Serverless: viper.IsSet(params.Serverless),
248+
// Remote: viper.IsSet(params.Remote),
246249
},
247250
viper.GetString(awsParams.MACDHID)); err != nil {
248251
logging.Error(err)
@@ -253,6 +256,7 @@ func release() *cobra.Command {
253256
flagSet := pflag.NewFlagSet(awsParams.MACReleaseCmd, pflag.ExitOnError)
254257
flagSet.StringP(awsParams.MACDHID, "", "", awsParams.MACDHIDDesc)
255258
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
259+
// flagSet.Bool(params.Remote, false, params.RemoteDesc)
256260
c.PersistentFlags().AddFlagSet(flagSet)
257261
err := c.MarkPersistentFlagRequired(awsParams.MACDHID)
258262
if err != nil {

cmd/mapt/cmd/constants/constants.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ const (
7777
RhelVersionDefault string = "9.4"
7878

7979
// Serverless
80-
Timeout string = "timeout"
81-
TimeoutDesc string = "if timeout is set a serverless destroy actions will be set on the time according to the timeout. The Timeout value is a duration conforming to Go ParseDuration format."
80+
Timeout string = "timeout"
81+
TimeoutDesc string = "if timeout is set a serverless destroy actions will be set on the time according to the timeout. The Timeout value is a duration conforming to Go ParseDuration format."
82+
// TODO we should be able to know if it is being executed serverless just checking the ENVs??
8283
Serverless string = "serverless"
8384
ServerlessDesc string = "if serverless is set the command will be executed as a serverless action."
8485

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
github.com/aws/aws-sdk-go-v2 v1.36.3
2222
github.com/aws/aws-sdk-go-v2/config v1.29.14
2323
github.com/aws/aws-sdk-go-v2/service/ec2 v1.222.0
24+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3
2425
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.3
2526
github.com/pulumi/pulumi-aws-native/sdk v1.28.0
2627
github.com/pulumi/pulumi-aws/sdk/v6 v6.81.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.15 h1:moLQUoVq91Liq
7575
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.15/go.mod h1:ZH34PJUc8ApjBIfgQCFvkWcUDBtl/WTD+uiYHjd8igA=
7676
github.com/aws/aws-sdk-go-v2/service/pricing v1.34.3 h1:vAv0hi3SWcc8cotkWRP4mPkmRbp/XqWKFyPW4Nwpzv0=
7777
github.com/aws/aws-sdk-go-v2/service/pricing v1.34.3/go.mod h1:giTP9ufzBQJRB6bc7P30PO8s35hCp6au5uM70zkohU4=
78+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3 h1:P87jejqS8WvQvRWyXlHUylt99VXt0y/WUIFuU6gBU7A=
79+
github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.26.3/go.mod h1:cgPfPTC/V3JqwCKed7Q6d0FrgarV7ltz4Bz6S4Q+Dqk=
7880
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.3 h1:BRXS0U76Z8wfF+bnkilA2QwpIch6URlm++yPUt9QPmQ=
7981
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.3/go.mod h1:bNXKFFyaiVvWuR6O16h/I1724+aXe/tAkA9/QS01t5k=
8082
github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 h1:1Gw+9ajCV1jogloEv1RRnvfRFia2cL6c9cuKV2Ps+G8=

pkg/manager/context/context.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ type ContextArgs struct {
4141
Serverless bool
4242
// This forces destroy even when lock exists
4343
ForceDestroy bool
44+
// If remote is set we will run the action through the serverless task spec
45+
Remote bool
4446
// integrations
4547
GHRunnerArgs *github.GithubRunnerArgs
4648
CirrusPWArgs *cirrus.PersistentWorkerArgs
@@ -58,6 +60,7 @@ type context struct {
5860
serverless bool
5961
forceDestroy bool
6062
spotPriceIncreaseRate int
63+
remote bool
6164
tags map[string]string
6265
tagsAsPulumiStringMap pulumi.StringMap
6366
}
@@ -119,6 +122,8 @@ func IsForceDestroy() bool { return mc.forceDestroy }
119122

120123
func SpotPriceIncreaseRate() int { return mc.spotPriceIncreaseRate }
121124

125+
func IsRemote() bool { return mc.remote }
126+
122127
// It will create a runID
123128
// if context has been intialized it will set it as the runID for the context
124129
// otherwise it will return the value (one time value)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
7+
"github.com/redhat-developer/mapt/pkg/provider/aws"
78
"github.com/redhat-developer/mapt/pkg/provider/aws/modules/serverless"
89
"github.com/redhat-developer/mapt/pkg/util/logging"
910
)
@@ -14,7 +15,7 @@ import (
1415
func houseKeeper(ctx *maptContext.ContextArgs, r *MacPoolRequestArgs) error {
1516
// Create mapt Context, this is a special case where we need change the context
1617
// based on the operation
17-
if err := maptContext.Init(ctx); err != nil {
18+
if err := maptContext.Init(ctx, aws.Provider()); err != nil {
1819
return err
1920
}
2021

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func HouseKeeper(ctx *maptContext.ContextArgs, r *MacPoolRequestArgs) error {
6161

6262
func Request(ctx *maptContext.ContextArgs, r *RequestMachineArgs) error {
6363
// If remote run through serverless
64-
if r.Remote {
64+
if ctx.Remote {
6565
return requestRemote(ctx, r)
6666
}
6767
return request(ctx, r)

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

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ package macpool
22

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

67
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
8+
"github.com/redhat-developer/mapt/pkg/provider/aws"
9+
"github.com/redhat-developer/mapt/pkg/provider/aws/data"
710
macConstants "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/constants"
11+
macHost "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/host"
812
macMachine "github.com/redhat-developer/mapt/pkg/provider/aws/modules/mac/machine"
913
"github.com/redhat-developer/mapt/pkg/provider/aws/modules/serverless"
1014
"github.com/redhat-developer/mapt/pkg/provider/aws/services/tag"
1115
)
1216

1317
func request(ctx *maptContext.ContextArgs, r *RequestMachineArgs) error {
1418
// If remote run through serverless
15-
if r.Remote {
19+
if maptContext.IsRemote() {
1620
return requestRemote(ctx, r)
1721
}
1822
// First get full info on the pool and the next machine for request
@@ -28,16 +32,15 @@ func request(ctx *maptContext.ContextArgs, r *RequestMachineArgs) error {
2832
// Create mapt Context
2933
ctx.ProjectName = *hi.ProjectName
3034
ctx.BackedURL = *hi.BackedURL
31-
if err := maptContext.Init(ctx); err != nil {
35+
if err := maptContext.Init(ctx, aws.Provider()); err != nil {
3236
return err
3337
}
3438

3539
mr := macMachine.Request{
36-
Prefix: *hi.Prefix,
37-
Version: *hi.OSVersion,
38-
Architecture: *hi.Arch,
39-
SetupGHActionsRunner: r.SetupGHActionsRunner,
40-
Timeout: r.Timeout,
40+
Prefix: *hi.Prefix,
41+
Version: *hi.OSVersion,
42+
Architecture: *hi.Arch,
43+
Timeout: r.Timeout,
4144
}
4245

4346
// TODO here we would change based on the integration-mode requested
@@ -55,6 +58,24 @@ func request(ctx *maptContext.ContextArgs, r *RequestMachineArgs) error {
5558
}
5659

5760
func requestRemote(ctx *maptContext.ContextArgs, r *RequestMachineArgs) error {
61+
if err := maptContext.Init(ctx, aws.Provider()); err != nil {
62+
return err
63+
}
64+
rARNs, err := data.GetResourcesMatchingTags(
65+
data.ResourceTypeECS,
66+
requestTags(
67+
r.PoolName,
68+
r.Architecture,
69+
r.OSVersion))
70+
if err != nil {
71+
return err
72+
}
73+
if len(rARNs) > 1 {
74+
return fmt.Errorf(
75+
"should be only one task spec matching tags. Found %s",
76+
strings.Join(rARNs, ","))
77+
}
78+
// We got the arn value for the task
5879
return fmt.Errorf("not implemented yet")
5980
}
6081

@@ -72,15 +93,27 @@ func (r *MacPoolRequestArgs) createRequestTaskSpec() error {
7293
r.PoolName,
7394
r.Architecture,
7495
r.OSVersion),
75-
Tags: map[string]string{
76-
macConstants.TagKeyArch: r.Architecture,
77-
macConstants.TagKeyOSVersion: r.OSVersion,
78-
macConstants.TagKeyPoolName: r.PoolName,
79-
}})
96+
Tags: requestTags(
97+
r.PoolName,
98+
r.Architecture,
99+
r.OSVersion)})
80100
}
81101

82102
func requestCommand(poolName, arch, osVersion string) string {
83103
cmd := fmt.Sprintf(requestCommandRegex,
84104
poolName, arch, osVersion)
85105
return cmd
86106
}
107+
108+
// Return the map of tags wich should identify unique
109+
// resquest operation spec for a pool
110+
func requestTags(poolName, arch, osVersion string) (m map[string]string) {
111+
poolID := macHost.PoolID{
112+
PoolName: poolName,
113+
Arch: arch,
114+
OSVersion: osVersion,
115+
}
116+
m = poolID.AsTags()
117+
m[macConstants.TagKeyPoolOperationName] = requestOperation
118+
return
119+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const (
1010
// https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-scheduled-rule-pattern.html#eb-rate-expressions
1111
houseKeepingInterval = "27 minutes"
1212

13+
requestOperation = "request"
1314
requestCommandRegex = "aws mac-pool request --name %s --arch %s --version %s --serverless "
1415
// requestTimeoutParam = "--timeout "
1516
// itCirrusPWTokenParam = "--it-cirrus-pw-token "
@@ -44,8 +45,6 @@ type RequestMachineArgs struct {
4445
OSVersion string
4546
// If timeout is set a severless scheduled task will be created to self destroy the resources
4647
Timeout string
47-
// If remote is set we will run the action through the serverless task spec
48-
Remote bool
4948
}
5049

5150
type ReleaseMachineArgs struct {

pkg/provider/aws/data/serverless.go

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

0 commit comments

Comments
 (0)