@@ -5,39 +5,35 @@ import (
55
66 "github.com/go-playground/validator/v10"
77 "github.com/pulumi/pulumi-azure-native-sdk/resources/v3"
8- "github.com/pulumi/pulumi-command/sdk/go/command/remote"
9- "github.com/pulumi/pulumi-tls/sdk/v5/go/tls"
10- "github.com/pulumi/pulumi/sdk/v3/go/auto"
118 "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
129 "github.com/redhat-developer/mapt/pkg/manager"
1310 mc "github.com/redhat-developer/mapt/pkg/manager/context"
14- infra "github.com/redhat-developer/mapt/pkg/provider"
1511 userDataApi "github.com/redhat-developer/mapt/pkg/provider/api/config/userdata"
1612 "github.com/redhat-developer/mapt/pkg/provider/azure"
13+ azureLinux "github.com/redhat-developer/mapt/pkg/provider/azure/action/linux"
1714 "github.com/redhat-developer/mapt/pkg/provider/azure/data"
1815 "github.com/redhat-developer/mapt/pkg/provider/azure/modules/allocation"
1916 "github.com/redhat-developer/mapt/pkg/provider/azure/modules/network"
2017 virtualmachine "github.com/redhat-developer/mapt/pkg/provider/azure/modules/virtual-machine"
21- securityGroup "github.com/redhat-developer/mapt/pkg/provider/azure/services/network/security-group"
2218 "github.com/redhat-developer/mapt/pkg/provider/util/command"
23- "github.com/redhat-developer/mapt/pkg/provider/util/output "
19+ kindApi "github.com/redhat-developer/mapt/pkg/targets/service/kind "
2420 "github.com/redhat-developer/mapt/pkg/util"
2521 resourcesUtil "github.com/redhat-developer/mapt/pkg/util/resources"
2622)
2723
2824type kindRequest struct {
29- mCtx * mc.Context `validate:"required"`
30- prefix * string
31- arch * string
32- osType * data.OSType
33- version * string
34- allocationData * allocation.AllocationResult
35- username * string
25+ mCtx * mc.Context
26+ prefix * string
27+ version * string
28+ arch * string
29+ location * string
30+ spot bool
31+ allocationData * allocation.AllocationResult
32+ // extraPortMappings []utilKind.PortMapping
3633 cloudConfigAsUserData userDataApi.CloudConfig
37- readinessCommand * string
3834}
3935
40- func (r * linuxRequest ) validate () error {
36+ func (r * kindRequest ) validate () error {
4137 v := validator .New (validator .WithRequiredStructEnabled ())
4238 err := v .Var (r .mCtx , "required" )
4339 if err != nil {
@@ -46,67 +42,60 @@ func (r *linuxRequest) validate() error {
4642 return v .Struct (r )
4743}
4844
49- func Create (mCtxArgs * mc.ContextArgs , args * LinuxArgs ) (err error ) {
45+ func Create (mCtxArgs * mc.ContextArgs , args * kindApi. KindArgs ) (* kindApi. KindResults , error ) {
5046 // Create mapt Context
5147 mCtx , err := mc .Init (mCtxArgs , azure .Provider ())
5248 if err != nil {
53- return err
49+ return nil , err
5450 }
5551 prefix := util .If (len (args .Prefix ) > 0 , args .Prefix , "main" )
56- r := & linuxRequest {
57- mCtx : mCtx ,
58- prefix : & prefix ,
59- arch : & args .Arch ,
60- osType : & args .OSType ,
61- version : & args .Version ,
62- username : & args .Username ,
63- cloudConfigAsUserData : args .CloudConfigAsUserData ,
64- readinessCommand : & args .ReadinessCommand ,
52+ r := & kindRequest {
53+ mCtx : mCtx ,
54+ prefix : & prefix ,
55+ version : & args .Version ,
56+ arch : & args .Arch ,
6557 }
66- ir , err := data .GetImageRef (* r . osType , * r .arch , * r . version )
58+ ir , err := data .GetImageRef (data . Fedora , * r .arch , data . FedoraDefaultVersion )
6759 if err != nil {
68- return err
60+ return nil , err
6961 }
7062 r .allocationData , err = allocation .Allocation (mCtx ,
7163 & allocation.AllocationArgs {
7264 ComputeRequest : args .ComputeRequest ,
7365 OSType : "linux" ,
7466 ImageRef : ir ,
75- Location : & args .Location ,
67+ Location : & args .HostingPlace ,
7668 Spot : args .Spot })
7769 if err != nil {
78- return err
70+ return nil , err
7971 }
8072 cs := manager.Stack {
81- StackName : mCtx .StackNameByProject (stackAzureLinux ),
73+ StackName : mCtx .StackNameByProject (stackAzureKind ),
8274 ProjectName : mCtx .ProjectName (),
8375 BackedURL : mCtx .BackedURL (),
8476 ProviderCredentials : azure .DefaultCredentials ,
8577 DeployFunc : r .deployer ,
8678 }
87- sr , _ := manager .UpStack (mCtx , cs )
79+ sr , err := manager .UpStack (mCtx , cs )
80+ if err != nil {
81+ return nil , err
82+ }
8883 return r .manageResults (sr )
8984}
9085
91- func Destroy (mCtxArgs * mc.ContextArgs ) error {
92- // Create mapt Context
93- mCtx , err := mc .Init (mCtxArgs , azure .Provider ())
94- if err != nil {
95- return err
96- }
97- // destroy
98- return azure .Destroy (mCtx , stackAzureLinux )
86+ func Destroy (mCtxArgs * mc.ContextArgs ) (err error ) {
87+ return azureLinux .Destroy (mCtxArgs )
9988}
10089
10190// Main function to deploy all requried resources to azure
102- func (r * linuxRequest ) deployer (ctx * pulumi.Context ) error {
91+ func (r * kindRequest ) deployer (ctx * pulumi.Context ) error {
10392 if err := r .validate (); err != nil {
10493 return err
10594 }
10695 // Get location for creating the Resource Group
10796 rgLocation := azure .GetSuitableLocationForResourceGroup (* r .allocationData .Location )
10897 rg , err := resources .NewResourceGroup (ctx ,
109- resourcesUtil .GetResourceName (* r .prefix , azureLinuxID , "rg" ),
98+ resourcesUtil .GetResourceName (* r .prefix , azureKindID , "rg" ),
11099 & resources.ResourceGroupArgs {
111100 Location : pulumi .String (rgLocation ),
112101 ResourceGroupName : pulumi .String (r .mCtx .RunID ()),
@@ -123,7 +112,7 @@ func (r *linuxRequest) deployer(ctx *pulumi.Context) error {
123112 n , err := network .Create (ctx , r .mCtx ,
124113 & network.NetworkArgs {
125114 Prefix : * r .prefix ,
126- ComponentID : azureLinuxID ,
115+ ComponentID : azureKindID ,
127116 ResourceGroup : rg ,
128117 Location : r .allocationData .Location ,
129118 SecurityGroup : sg ,
@@ -157,20 +146,19 @@ func (r *linuxRequest) deployer(ctx *pulumi.Context) error {
157146 vm , err := virtualmachine .Create (ctx , r .mCtx ,
158147 & virtualmachine.VirtualMachineArgs {
159148 Prefix : * r .prefix ,
160- ComponentID : azureLinuxID ,
149+ ComponentID : azureKindID ,
161150 ResourceGroup : rg ,
162151 NetworkInteface : n .NetworkInterface ,
163152 // Check this
164- VMSize : r .allocationData .ComputeSizes [0 ],
165- Publisher : r .allocationData .ImageRef .Publisher ,
166- Offer : r .allocationData .ImageRef .Offer ,
167- Sku : r .allocationData .ImageRef .Sku ,
168- ImageID : r .allocationData .ImageRef .ID ,
169- AdminUsername : * r .username ,
170- PrivateKey : privateKey ,
171- SpotPrice : r .allocationData .Price ,
172- Userdata : * userDataB64 ,
173- Location : * r .allocationData .Location ,
153+ VMSize : r .allocationData .ComputeSizes [0 ],
154+ Publisher : r .allocationData .ImageRef .Publisher ,
155+ Offer : r .allocationData .ImageRef .Offer ,
156+ Sku : r .allocationData .ImageRef .Sku ,
157+ ImageID : r .allocationData .ImageRef .ID ,
158+ PrivateKey : privateKey ,
159+ SpotPrice : r .allocationData .Price ,
160+ Userdata : * userDataB64 ,
161+ Location : * r .allocationData .Location ,
174162 })
175163 if err != nil {
176164 return err
@@ -201,32 +189,3 @@ func (r *linuxRequest) deployer(ctx *pulumi.Context) error {
201189 pulumi .DependsOn ([]pulumi.Resource {vm }))
202190 return err
203191}
204-
205- // security group for mac machine with ingress rules for ssh and vnc
206- func securityGroups (ctx * pulumi.Context , mCtx * mc.Context ,
207- prefix , location * string ,
208- rg * resources.ResourceGroup ) (securityGroup.SecurityGroup , error ) {
209- // ingress for ssh access from 0.0.0.0
210- sshIngressRule := securityGroup .SSH_TCP
211- sshIngressRule .CidrBlocks = infra .NETWORKING_CIDR_ANY_IPV4
212- // Create SG with ingress rules
213- return securityGroup .Create (
214- ctx ,
215- mCtx ,
216- & securityGroup.SecurityGroupArgs {
217- Name : resourcesUtil .GetResourceName (* prefix , azureLinuxID , "sg" ),
218- RG : rg ,
219- Location : location ,
220- IngressRules : []securityGroup.IngressRules {
221- sshIngressRule },
222- })
223- }
224-
225- // Write exported values in context to files o a selected target folder
226- func (r * linuxRequest ) manageResults (stackResult auto.UpResult ) error {
227- return output .Write (stackResult , r .mCtx .GetResultsOutputPath (), map [string ]string {
228- fmt .Sprintf ("%s-%s" , * r .prefix , outputUsername ): "username" ,
229- fmt .Sprintf ("%s-%s" , * r .prefix , outputUserPrivateKey ): "id_rsa" ,
230- fmt .Sprintf ("%s-%s" , * r .prefix , outputHost ): "host" ,
231- })
232- }
0 commit comments