Skip to content

Commit f83c4d5

Browse files
committed
feat: add support for EKS service on AWS
Fix region Fix message Add error message when price coudn't be found Address review comment about CIDR count Refactor into separate functions Add spot functionality - failing Chose instanceType by parameters Add EKS readme
1 parent a649fed commit f83c4d5

636 files changed

Lines changed: 481499 additions & 25 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Instances can also define a timeout to avoid leftovers in case destoy operation
2222

2323
Mapt offers some managed services boosted with some of the features from the instances offerings (i.e spot) and also create some ad hoc services on top the instances offerings to improve reutilization of instances when there is no easy way to do it (i.e. Mac-Pool).
2424

25-
[AKS](docs/azure/aks.md)-[Mac-Pool](docs/aws/mac-pool.md) - [OpenShift-SNC](docs/aws/openshift-snc.md) - [Kind](docs/aws/openshift-snc.md)
25+
[AKS](docs/azure/aks.md)-[EKS](docs/aws/eks.md)-[Mac-Pool](docs/aws/mac-pool.md) - [OpenShift-SNC](docs/aws/openshift-snc.md) - [Kind](docs/aws/openshift-snc.md)
2626

2727

2828
### Integrations

cmd/mapt/cmd/aws/aws.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package aws
33
import (
44
"github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/hosts"
55
"github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/services"
6+
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
67
"github.com/spf13/cobra"
8+
"github.com/spf13/pflag"
79
"github.com/spf13/viper"
810
)
911

@@ -24,13 +26,18 @@ func GetCmd() *cobra.Command {
2426
},
2527
}
2628

29+
flagSet := pflag.NewFlagSet(cmd, pflag.ExitOnError)
30+
params.AddCommonFlags(flagSet)
31+
c.PersistentFlags().AddFlagSet(flagSet)
32+
2733
c.AddCommand(
2834
hosts.GetMacCmd(),
2935
hosts.GetWindowsCmd(),
3036
hosts.GetRHELCmd(),
3137
hosts.GetFedoraCmd(),
3238
services.GetMacPoolCmd(),
3339
services.GetOpenshiftSNCCmd(),
34-
services.GetKindCmd())
40+
services.GetKindCmd(),
41+
services.GetEKSCmd())
3542
return c
3643
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const (
2323
MACDHID string = "dedicated-host-id"
2424
MACDHIDDesc string = "id for the dedicated host"
2525

26-
Spot string = "spot"
27-
SpotDesc string = "if this flag is set the host will be created only on the region set by the AWS Env (AWS_DEFAULT_REGION)"
26+
Spot string = "spot"
27+
SpotDesc string = "if spot is set the spot prices across all regions will be checked and machine will be started on best spot option (price / eviction)"
2828
)
2929

3030
func MACArchAsCirrusArch(arch string) *cirrus.Arch {

cmd/mapt/cmd/aws/services/eks.go

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package services
2+
3+
import (
4+
awsparams "github.com/redhat-developer/mapt/cmd/mapt/cmd/aws/constants"
5+
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/constants"
6+
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
7+
awsEKS "github.com/redhat-developer/mapt/pkg/provider/aws/action/eks"
8+
"github.com/redhat-developer/mapt/pkg/provider/util/instancetypes"
9+
"github.com/redhat-developer/mapt/pkg/util"
10+
"github.com/redhat-developer/mapt/pkg/util/logging"
11+
"github.com/spf13/cobra"
12+
"github.com/spf13/pflag"
13+
"github.com/spf13/viper"
14+
)
15+
16+
const (
17+
cmdEKS = "eks"
18+
cmdEKSDesc = "eks operations"
19+
20+
paramVersion = "version"
21+
paramVersionDesc = "EKS K8s cluster version"
22+
defaultVersion = "1.31"
23+
paramScalingDesiredSize = "workers-desired"
24+
paramScalingDesiredSizeDesc = "Worker nodes scaling desired size"
25+
defaultScalingDesiredSize = "1"
26+
paramScalingMaxSize = "workers-max"
27+
paramScalingMaxSizeDesc = "Worker nodes scaling maximum size"
28+
defaultScalingMaxSize = "3"
29+
paramScalingMinSize = "workers-min"
30+
paramScalingMinSizeDesc = "Worker nodes scaling minimum size"
31+
defaultScalingMinSize = "1"
32+
paramAddons = "addons"
33+
paramAddonsDesc = "List of EKS addons to be installed, separated by commas."
34+
defaultAddons = ""
35+
paramLoadBalancerController = "load-balancer-controller"
36+
paramLoadBalancerControllerDesc = "Install AWS Load Balancer Controller"
37+
)
38+
39+
func GetEKSCmd() *cobra.Command {
40+
c := &cobra.Command{
41+
Use: cmdEKS,
42+
Short: cmdEKSDesc,
43+
RunE: func(cmd *cobra.Command, args []string) error {
44+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
45+
return err
46+
}
47+
return nil
48+
},
49+
}
50+
c.AddCommand(getCreateEKS(), getDestroyEKS())
51+
return c
52+
}
53+
54+
func getCreateEKS() *cobra.Command {
55+
c := &cobra.Command{
56+
Use: params.CreateCmdName,
57+
Short: params.CreateCmdName,
58+
RunE: func(cmd *cobra.Command, args []string) error {
59+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
60+
return err
61+
}
62+
63+
if err := awsEKS.Create(
64+
&maptContext.ContextArgs{
65+
ProjectName: viper.GetString(params.ProjectName),
66+
BackedURL: viper.GetString(params.BackedURL),
67+
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
68+
Debug: viper.IsSet(params.Debug),
69+
DebugLevel: viper.GetUint(params.DebugLevel),
70+
Tags: viper.GetStringMapString(params.Tags),
71+
SpotPriceIncreaseRate: viper.GetInt(params.SpotPriceIncreaseRate),
72+
},
73+
&awsEKS.EKSRequest{
74+
Prefix: viper.GetString(params.ProjectName),
75+
InstanceRequest: &instancetypes.AwsInstanceRequest{
76+
CPUs: viper.GetInt32(params.CPUs),
77+
MemoryGib: viper.GetInt32(params.Memory),
78+
Arch: util.If(viper.GetString(params.LinuxArch) == "arm64",
79+
instancetypes.Arm64, instancetypes.Amd64),
80+
},
81+
KubernetesVersion: viper.GetString(paramVersion),
82+
ScalingDesiredSize: viper.GetInt(paramScalingDesiredSize),
83+
ScalingMaxSize: viper.GetInt(paramScalingMaxSize),
84+
ScalingMinSize: viper.GetInt(paramScalingMinSize),
85+
Spot: viper.IsSet(awsparams.Spot),
86+
Addons: viper.GetStringSlice(paramAddons),
87+
LoadBalancerController: viper.IsSet(paramLoadBalancerController),
88+
}); err != nil {
89+
logging.Error(err)
90+
}
91+
return nil
92+
},
93+
}
94+
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
95+
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
96+
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
97+
flagSet.StringP(paramVersion, "", defaultVersion, paramVersionDesc)
98+
flagSet.StringP(paramScalingDesiredSize, "", defaultScalingDesiredSize, paramScalingDesiredSizeDesc)
99+
flagSet.StringP(paramScalingMaxSize, "", defaultScalingMaxSize, paramScalingMaxSizeDesc)
100+
flagSet.StringP(paramScalingMinSize, "", defaultScalingMinSize, paramScalingMinSizeDesc)
101+
flagSet.StringSliceP(paramAddons, "", []string{}, paramAddonsDesc)
102+
flagSet.Bool(paramLoadBalancerController, false, paramLoadBalancerControllerDesc)
103+
flagSet.AddFlagSet(params.GetCpusAndMemoryFlagset())
104+
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
105+
flagSet.Bool(awsparams.Spot, false, awsparams.SpotDesc)
106+
flagSet.IntP(params.SpotPriceIncreaseRate, "", params.SpotPriceIncreaseRateDefault, params.SpotPriceIncreaseRateDesc)
107+
c.PersistentFlags().AddFlagSet(flagSet)
108+
return c
109+
}
110+
111+
func getDestroyEKS() *cobra.Command {
112+
return &cobra.Command{
113+
Use: params.DestroyCmdName,
114+
Short: params.DestroyCmdName,
115+
RunE: func(cmd *cobra.Command, args []string) error {
116+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
117+
return err
118+
}
119+
if err := awsEKS.Destroy(
120+
&maptContext.ContextArgs{
121+
ProjectName: viper.GetString(params.ProjectName),
122+
BackedURL: viper.GetString(params.BackedURL),
123+
Debug: viper.IsSet(params.Debug),
124+
DebugLevel: viper.GetUint(params.DebugLevel),
125+
}); err != nil {
126+
logging.Error(err)
127+
}
128+
return nil
129+
},
130+
}
131+
}

cmd/mapt/cmd/azure/services/aks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
paramVersion = "version"
2222
paramVersionDesc = "AKS K8s cluster version"
2323
paramVMSizeDesc = "VMSize to be used on the user pool. Typically this is used to provision spot node pools"
24-
defaultVersion = "1.30"
24+
defaultVersion = "1.31"
2525
paramOnlySystemPool = "only-system-pool"
2626
paramOnlySystemPoolDesc = "if we do not need bunch of resources we can run only the systempool. More info https://learn.microsoft.com/es-es/azure/aks/use-system-pools?tabs=azure-cli#system-and-user-node-pools"
2727
paramEnableAppRouting = "enable-app-routing"

docs/aws/eks.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Overview
2+
3+
This actions will handle provision for EKS cluster instances on AWS.
4+
5+
## EKS
6+
7+
It creates / destroy a basic EKS Cluster.
8+
9+
### Operations
10+
11+
#### Create
12+
13+
This will create K8s cluster using EKS according to params specified:
14+
15+
```bash
16+
mapt aws eks create -h
17+
create
18+
19+
Usage:
20+
mapt aws eks create [flags]
21+
22+
Flags:
23+
--addons strings List of EKS addons to be installed, separated by commas.
24+
--arch string architecture for the machine. Allowed x86_64 or arm64 (default "x86_64")
25+
--conn-details-output string path to export host connection information (host, username and privateKey)
26+
--cpus int32 Number of CPUs for the cloud instance (default 8)
27+
-h, --help help for create
28+
--load-balancer-controller Install AWS Load Balancer Controller
29+
--memory int32 Amount of RAM for the cloud instance in GiB (default 64)
30+
--nested-virt Use cloud instance that has nested virtualization support
31+
--spot if spot is set the spot prices across all regions will be checked and machine will be started on best spot option (price / eviction)
32+
--spot-increase-rate int Percentage to be added on top of the current calculated spot price to increase chances to get the machine (default 20)
33+
--tags stringToString tags to add on each resource (--tags name1=value1,name2=value2) (default [])
34+
--version string EKS K8s cluster version (default "1.31")
35+
--workers-desired string Worker nodes scaling desired size (default "1")
36+
--workers-max string Worker nodes scaling maximum size (default "3")
37+
--workers-min string Worker nodes scaling minimum size (default "1")
38+
39+
Global Flags:
40+
--backed-url string backed for stack state. (local) file:///path/subpath (s3) s3://existing-bucket, (azure) azblob://existing-blobcontainer. See more https://www.pulumi.com/docs/iac/concepts/state-and-backends/#using-a-self-managed-backend
41+
--debug Enable debug traces and set verbosity to max. Typically to get information to troubleshooting an issue.
42+
--debug-level uint Set the level of verbosity on debug. You can set from minimum 1 to max 9. (default 3)
43+
--project-name string project name to identify the instance of the stack
44+
```
45+
46+
It will crete an EKS cluster and kubeconfig file to connect will be placed at `--conn-details-output`. To use the kubeconfig file, you need to have the authentication information exported as variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_DEFAULT_REGION`).
47+
48+
When running the container image it is required to pass the authentication information as variables, following a sample snippet on how to create
49+
a instance with default values:
50+
51+
```bash
52+
podman run -d --rm \
53+
-v ${PWD}:/workspace:z \
54+
-e AWS_ACCESS_KEY_ID=XXX \
55+
-e AWS_SECRET_ACCESS_KEY=XXX \
56+
-e AWS_DEFAULT_REGION=us-east-1 \
57+
quay.io/redhat-developer/mapt:v1.0.0-dev aws eks create \
58+
--project-name "mapt-eks" \
59+
--backed-url file:///workspace \
60+
--conn-details-output /workspace
61+
```
62+
63+
It is important to notice that backed-url contains the state of the resources on AWS linked to the EKS creation, to destroy we need to reference them as so we should pass same folder as we set for creation:
64+
65+
```bash
66+
podman run -d --rm \
67+
-v ${PWD}:/workspace:z \
68+
-e AWS_ACCESS_KEY_ID=XXX \
69+
-e AWS_SECRET_ACCESS_KEY=XXX \
70+
-e AWS_DEFAULT_REGION=us-east-1 \
71+
quay.io/redhat-developer/mapt:v1.0.0-dev aws eks destroy \
72+
--project-name "mapt-eks" \
73+
--backed-url file:///workspace
74+
```

docs/azure/aks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Flags:
2828
--spot if spot is set the spot prices across all regions will be cheked and machine will be started on best spot option (price / eviction)
2929
--spot-eviction-tolerance string if spot is enable we can define the minimum tolerance level of eviction. Allowed value are: lowest, low, medium, high or highest (default "lowest")
3030
--tags stringToString tags to add on each resource (--tags name1=value1,name2=value2) (default [])
31-
--version string AKS K8s cluster version (default "1.30")
31+
--version string AKS K8s cluster version (default "1.31")
3232
--vmsize string VMSize to be used on the user pool. Typically this is used to provision spot node pools (default "Standard_D8as_v5")
3333

3434
Global Flags:

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ require (
153153
github.com/pkg/errors v0.9.1 // indirect
154154
github.com/pkg/term v1.1.0 // indirect
155155
github.com/pulumi/pulumi-azure-native-sdk/managedidentity/v2 v2.90.0
156+
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.22.2
156157
github.com/rivo/uniseg v0.4.7 // indirect
157158
github.com/rogpeppe/go-internal v1.14.1 // indirect
158159
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild v0.0.3 h1:NxCXxRvzhUJP9
294294
github.com/pulumi/pulumi-docker-build/sdk/go/dockerbuild v0.0.3/go.mod h1:jw9NcyRXjv5V2HHHJlqUBdXFCFiLfZoCChWEn38LR2A=
295295
github.com/pulumi/pulumi-docker/sdk/v4 v4.7.0 h1:EnkALSr/ikA7tve6QtPoJXvNKQjLwQBqbE9lti+eOq0=
296296
github.com/pulumi/pulumi-docker/sdk/v4 v4.7.0/go.mod h1:ax7VSzBTYLMru7+NIKrZTU2clUCGtbWpLsmoSWX5IPo=
297+
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.22.2 h1:TJ1JnD/U21SD7DV8MS525Qv4/mSCANdxrRWUWuNJZOs=
298+
github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.22.2/go.mod h1:jOdpeNeRvY4iN+W8aDP5+HyqrM7hXsxa9paPsmjQFfY=
297299
github.com/pulumi/pulumi-random/sdk/v4 v4.18.2 h1:78KvcYUlwYyFWc+VYirpg/pN5d+iwzRw7ozmmJ6MWYE=
298300
github.com/pulumi/pulumi-random/sdk/v4 v4.18.2/go.mod h1:e5V6HNKin7XkaJ73ZyDuXJ2O472TVBI0K2EyfKm9obw=
299301
github.com/pulumi/pulumi-tls/sdk/v5 v5.2.0 h1:lzcWRzw4VYfdm8mZe/3rZpLd2pNRV9ztgdXtKskl++Q=
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package eks
2+
3+
const (
4+
stackName = "stackCreateEKS"
5+
awsEKSID = "aeks"
6+
outputKubeconfig = "eksKubeconfig"
7+
)
8+
9+
var amiProduct = "Linux/UNIX"

0 commit comments

Comments
 (0)