Skip to content

Commit 23fa8e7

Browse files
committed
feat: Kind offering on Azure
This commit allows to spin a kind cluster on Azure, it contains a refactor to allow matching target on cloud providers Signed-off-by: Adrian Riobo <[email protected]>
1 parent d102d1f commit 23fa8e7

File tree

29 files changed

+708
-223
lines changed

29 files changed

+708
-223
lines changed

cmd/mapt/cmd/aws/services/kind.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
77
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
88
"github.com/redhat-developer/mapt/pkg/provider/aws/action/kind"
9-
kindCloudConfig "github.com/redhat-developer/mapt/pkg/provider/util/cloud-config/kind"
9+
kindApi "github.com/redhat-developer/mapt/pkg/targets/service/kind"
1010
"github.com/spf13/cobra"
1111
"github.com/spf13/pflag"
1212
"github.com/spf13/viper"
@@ -41,11 +41,11 @@ func createKind() *cobra.Command {
4141
}
4242

4343
// Parse extra port mappings from JSON string to PortMapping struct
44-
var extraPortMappings []kindCloudConfig.PortMapping
44+
var extraPortMappings []kindApi.PortMapping
4545
extraPortMappingsStr := viper.GetString(params.KindExtraPortMappings)
4646
if extraPortMappingsStr != "" {
4747
var err error
48-
extraPortMappings, err = kindCloudConfig.ParseExtraPortMappings(extraPortMappingsStr)
48+
extraPortMappings, err = kindApi.ParseExtraPortMappings(extraPortMappingsStr)
4949
if err != nil {
5050
return fmt.Errorf("failed to parse 'extra-port-mappings' flag: %w", err)
5151
}
@@ -60,7 +60,7 @@ func createKind() *cobra.Command {
6060
DebugLevel: viper.GetUint(params.DebugLevel),
6161
Tags: viper.GetStringMapString(params.Tags),
6262
},
63-
&kind.KindArgs{
63+
&kindApi.KindArgs{
6464
ComputeRequest: params.ComputeRequestArgs(),
6565
Spot: params.SpotArgs(),
6666
Version: viper.GetString(params.KindK8SVersion),
@@ -74,7 +74,7 @@ func createKind() *cobra.Command {
7474
}
7575
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
7676
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
77-
flagSet.StringP(params.KindK8SVersion, "", "", params.KindK8SVersionDesc)
77+
flagSet.StringP(params.KindK8SVersion, "", params.KindK8SVersionDefault, params.KindK8SVersionDesc)
7878
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
7979
flagSet.StringP(params.KindExtraPortMappings, "", "", params.KindExtraPortMappingsDesc)
8080
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)

cmd/mapt/cmd/azure/azure.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func GetCmd() *cobra.Command {
3535
hosts.GetUbuntuCmd(),
3636
hosts.GetRHELCmd(),
3737
hosts.GetFedoraCmd(),
38-
services.GetAKSCmd())
38+
services.GetAKSCmd(),
39+
services.GetKindCmd())
3940
return c
4041
}

cmd/mapt/cmd/azure/hosts/constants.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package hosts
22

33
const (
4-
paramLocation = "location"
5-
paramLocationDesc = "If spot is passed location will be calculated based on spot results. Otherwise localtion will be used to create resources."
6-
defaultLocation = "westeurope"
74
paramVMSize = "vmsize"
85
paramVMSizeDesc = "set specific size for the VM and ignore any CPUs, Memory and Arch parameters set. Type requires to allow nested virtualization"
96
paramUsername = "username"

cmd/mapt/cmd/azure/hosts/linux.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hosts
22

33
import (
4+
azureParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/azure/params"
45
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
56
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
67
azureLinux "github.com/redhat-developer/mapt/pkg/provider/azure/action/linux"
@@ -61,7 +62,7 @@ func getCreateLinux(ostype data.OSType, defaultOSVersion string) *cobra.Command
6162
&azureLinux.LinuxArgs{
6263
ComputeRequest: params.ComputeRequestArgs(),
6364
Spot: params.SpotArgs(),
64-
Location: viper.GetString(paramLocation),
65+
Location: viper.GetString(azureParams.Location),
6566
Version: viper.GetString(paramLinuxVersion),
6667
Arch: viper.GetString(params.LinuxArch),
6768
OSType: ostype,
@@ -71,7 +72,7 @@ func getCreateLinux(ostype data.OSType, defaultOSVersion string) *cobra.Command
7172
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
7273
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
7374
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
74-
flagSet.StringP(paramLocation, "", defaultLocation, paramLocationDesc)
75+
flagSet.StringP(azureParams.Location, "", azureParams.LocationDefault, azureParams.LocationDesc)
7576
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
7677
flagSet.StringP(paramLinuxVersion, "", defaultOSVersion, paramLinuxVersionDesc)
7778
flagSet.StringP(paramUsername, "", defaultUsername, paramUsernameDesc)

cmd/mapt/cmd/azure/hosts/rhel.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hosts
22

33
import (
4+
azureParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/azure/params"
45
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
56
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
67
azureRHEL "github.com/redhat-developer/mapt/pkg/provider/azure/action/rhel"
@@ -52,7 +53,7 @@ func getCreateRHEL() *cobra.Command {
5253
&azureRHEL.RhelArgs{
5354
ComputeRequest: params.ComputeRequestArgs(),
5455
Spot: params.SpotArgs(),
55-
Location: viper.GetString(paramLocation),
56+
Location: viper.GetString(azureParams.Location),
5657
Version: viper.GetString(paramLinuxVersion),
5758
Arch: viper.GetString(params.LinuxArch),
5859
SubsUsername: viper.GetString(params.SubsUsername),
@@ -64,7 +65,7 @@ func getCreateRHEL() *cobra.Command {
6465
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
6566
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
6667
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
67-
flagSet.StringP(paramLocation, "", defaultLocation, paramLocationDesc)
68+
flagSet.StringP(azureParams.Location, "", azureParams.LocationDefault, azureParams.LocationDesc)
6869
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
6970
flagSet.StringP(paramLinuxVersion, "", defaultRHELVersion, paramLinuxVersionDesc)
7071
flagSet.StringP(paramUsername, "", defaultUsername, paramUsernameDesc)

cmd/mapt/cmd/azure/hosts/windows.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package hosts
22

33
import (
4+
azureParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/azure/params"
45
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
56
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
67
azureWindows "github.com/redhat-developer/mapt/pkg/provider/azure/action/windows"
@@ -66,7 +67,7 @@ func getCreateWindowsDesktop() *cobra.Command {
6667
ComputeRequest: params.ComputeRequestArgs(),
6768
Spot: params.SpotArgs(),
6869
Prefix: viper.GetString(params.ProjectName),
69-
Location: viper.GetString(paramLocation),
70+
Location: viper.GetString(azureParams.Location),
7071
Version: viper.GetString(paramWindowsVersion),
7172
Feature: viper.GetString(paramFeature),
7273
Username: viper.GetString(paramUsername),
@@ -77,7 +78,7 @@ func getCreateWindowsDesktop() *cobra.Command {
7778
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
7879
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
7980
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
80-
flagSet.StringP(paramLocation, "", defaultLocation, paramLocationDesc)
81+
flagSet.StringP(azureParams.Location, "", azureParams.LocationDefault, azureParams.LocationDesc)
8182
flagSet.StringP(paramWindowsVersion, "", defaultWindowsVersion, paramWindowsVersionDesc)
8283
flagSet.StringP(paramFeature, "", defaultFeature, paramFeatureDesc)
8384
flagSet.StringP(paramUsername, "", defaultUsername, paramUsernameDesc)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package params
2+
3+
const (
4+
Location = "location"
5+
LocationDesc = "If spot is passed location will be calculated based on spot results. Otherwise localtion will be used to create resources."
6+
LocationDefault = "westeurope"
7+
)
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package services
2+
3+
import (
4+
"fmt"
5+
6+
azureParams "github.com/redhat-developer/mapt/cmd/mapt/cmd/azure/params"
7+
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
8+
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
9+
"github.com/redhat-developer/mapt/pkg/provider/azure/action/kind"
10+
kindApi "github.com/redhat-developer/mapt/pkg/targets/service/kind"
11+
"github.com/spf13/cobra"
12+
"github.com/spf13/pflag"
13+
"github.com/spf13/viper"
14+
)
15+
16+
func GetKindCmd() *cobra.Command {
17+
c := &cobra.Command{
18+
Use: params.KindCmd,
19+
Short: params.KindCmdDesc,
20+
RunE: func(cmd *cobra.Command, args []string) error {
21+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
22+
return err
23+
}
24+
return nil
25+
},
26+
}
27+
flagSet := pflag.NewFlagSet(params.KindCmd, pflag.ExitOnError)
28+
params.AddCommonFlags(flagSet)
29+
c.PersistentFlags().AddFlagSet(flagSet)
30+
c.AddCommand(createKind(), destroyKind())
31+
return c
32+
33+
}
34+
35+
func createKind() *cobra.Command {
36+
c := &cobra.Command{
37+
Use: params.CreateCmdName,
38+
Short: params.CreateCmdName,
39+
RunE: func(cmd *cobra.Command, args []string) error {
40+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
41+
return err
42+
}
43+
44+
// Parse extra port mappings from JSON string to PortMapping struct
45+
var extraPortMappings []kindApi.PortMapping
46+
extraPortMappingsStr := viper.GetString(params.KindExtraPortMappings)
47+
if extraPortMappingsStr != "" {
48+
var err error
49+
extraPortMappings, err = kindApi.ParseExtraPortMappings(extraPortMappingsStr)
50+
if err != nil {
51+
return fmt.Errorf("failed to parse 'extra-port-mappings' flag: %w", err)
52+
}
53+
}
54+
55+
if _, err := kind.Create(
56+
&maptContext.ContextArgs{
57+
ProjectName: viper.GetString(params.ProjectName),
58+
BackedURL: viper.GetString(params.BackedURL),
59+
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
60+
Debug: viper.IsSet(params.Debug),
61+
DebugLevel: viper.GetUint(params.DebugLevel),
62+
Tags: viper.GetStringMapString(params.Tags),
63+
},
64+
&kindApi.KindArgs{
65+
ComputeRequest: params.ComputeRequestArgs(),
66+
Spot: params.SpotArgs(),
67+
HostingPlace: viper.GetString(azureParams.Location),
68+
Version: viper.GetString(params.KindK8SVersion),
69+
Arch: viper.GetString(params.LinuxArch),
70+
ExtraPortMappings: extraPortMappings}); err != nil {
71+
return err
72+
}
73+
return nil
74+
},
75+
}
76+
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
77+
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
78+
flagSet.StringP(params.KindK8SVersion, "", params.KindK8SVersionDefault, params.KindK8SVersionDesc)
79+
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
80+
flagSet.StringP(params.KindExtraPortMappings, "", "", params.KindExtraPortMappingsDesc)
81+
flagSet.StringP(azureParams.Location, "", azureParams.LocationDefault, azureParams.LocationDesc)
82+
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
83+
params.AddComputeRequestFlags(flagSet)
84+
params.AddSpotFlags(flagSet)
85+
c.PersistentFlags().AddFlagSet(flagSet)
86+
return c
87+
}
88+
89+
func destroyKind() *cobra.Command {
90+
c := &cobra.Command{
91+
Use: params.DestroyCmdName,
92+
Short: params.DestroyCmdName,
93+
RunE: func(cmd *cobra.Command, args []string) error {
94+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
95+
return err
96+
}
97+
return kind.Destroy(&maptContext.ContextArgs{
98+
ProjectName: viper.GetString(params.ProjectName),
99+
BackedURL: viper.GetString(params.BackedURL),
100+
Debug: viper.IsSet(params.Debug),
101+
DebugLevel: viper.GetUint(params.DebugLevel),
102+
Serverless: viper.IsSet(params.Serverless),
103+
ForceDestroy: viper.IsSet(params.ForceDestroy),
104+
})
105+
},
106+
}
107+
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
108+
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
109+
flagSet.Bool(params.ForceDestroy, false, params.ForceDestroyDesc)
110+
c.PersistentFlags().AddFlagSet(flagSet)
111+
return c
112+
}

cmd/mapt/cmd/params/params.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const (
106106
KindCmdDesc = "Manage a Kind cluster. This is not intended for production use"
107107
KindK8SVersion = "version"
108108
KindK8SVersionDesc = "version for k8s offered through Kind."
109+
KindK8SVersionDefault = "v1.34"
109110
KindExtraPortMappings = "extra-port-mappings"
110111
KindExtraPortMappingsDesc = "Additional port mappings for the Kind cluster. Value should be a JSON array of objects with containerPort, hostPort, and protocol properties. Example: '[{\"containerPort\": 8080, \"hostPort\": 8080, \"protocol\": \"TCP\"}]'"
111112

docs/azure/kind.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Overview
2+
3+
TBC

0 commit comments

Comments
 (0)