Skip to content

Commit 1d0b2e1

Browse files
committed
snc: implement openshift-snc for azure
1 parent 6085c9b commit 1d0b2e1

File tree

12 files changed

+564
-22
lines changed

12 files changed

+564
-22
lines changed

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.GetOpenshiftSNCCmd())
3940
return c
4041
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package services
2+
3+
import (
4+
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
5+
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
6+
sncAPI "github.com/redhat-developer/mapt/pkg/provider/api/openshift-snc"
7+
openshiftsnc "github.com/redhat-developer/mapt/pkg/provider/azure/action/openshift-snc"
8+
"github.com/redhat-developer/mapt/pkg/util/logging"
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/pflag"
11+
"github.com/spf13/viper"
12+
)
13+
14+
const (
15+
cmdOpenshiftSNC = "openshift-snc"
16+
cmdOpenshiftSNCDesc = "Manage an OpenShift Single Node Cluster based on OpenShift Local. This is not intended for production use"
17+
18+
ocpVersion = "version"
19+
ocpVersionDesc = "version for Openshift. If not set it will pick latest available version"
20+
pullSecretFile = "pull-secret-file"
21+
pullSecretFileDesc = "file path of image pull secret (download from https://console.redhat.com/openshift/create/local)"
22+
23+
location = "location"
24+
locationDesc = "If spot is passed location will be calculated based on spot results. Otherwise localtion will be used to create resources."
25+
defaultLocation = "centralindia"
26+
)
27+
28+
func GetOpenshiftSNCCmd() *cobra.Command {
29+
c := &cobra.Command{
30+
Use: cmdOpenshiftSNC,
31+
Short: cmdOpenshiftSNCDesc,
32+
RunE: func(cmd *cobra.Command, args []string) error {
33+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
34+
return err
35+
}
36+
return nil
37+
},
38+
}
39+
flagSet := pflag.NewFlagSet(cmdOpenshiftSNC, pflag.ExitOnError)
40+
params.AddCommonFlags(flagSet)
41+
c.PersistentFlags().AddFlagSet(flagSet)
42+
c.AddCommand(createSNC(), destroySNC())
43+
return c
44+
45+
}
46+
47+
func createSNC() *cobra.Command {
48+
c := &cobra.Command{
49+
Use: params.CreateCmdName,
50+
Short: params.CreateCmdName,
51+
RunE: func(cmd *cobra.Command, args []string) error {
52+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
53+
return err
54+
}
55+
56+
if err := openshiftsnc.Create(
57+
&maptContext.ContextArgs{
58+
ProjectName: viper.GetString(params.ProjectName),
59+
BackedURL: viper.GetString(params.BackedURL),
60+
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
61+
Debug: viper.IsSet(params.Debug),
62+
DebugLevel: viper.GetUint(params.DebugLevel),
63+
Tags: viper.GetStringMapString(params.Tags),
64+
},
65+
&sncAPI.OpenshiftSNCArgs{
66+
ComputeRequest: params.ComputeRequestArgs(),
67+
Version: viper.GetString(ocpVersion),
68+
Arch: viper.GetString(params.LinuxArch),
69+
PullSecretFile: viper.GetString(pullSecretFile),
70+
Spot: params.SpotArgs(),
71+
Location: viper.GetString(location),
72+
Timeout: viper.GetString(params.Timeout)}); err != nil {
73+
logging.Error(err)
74+
}
75+
return nil
76+
},
77+
}
78+
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
79+
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
80+
flagSet.StringP(ocpVersion, "", "", ocpVersionDesc)
81+
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
82+
flagSet.StringP(pullSecretFile, "", "", pullSecretFileDesc)
83+
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
84+
flagSet.StringP(location, "", defaultLocation, locationDesc)
85+
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
86+
params.AddComputeRequestFlags(flagSet)
87+
params.AddSpotFlags(flagSet)
88+
c.PersistentFlags().AddFlagSet(flagSet)
89+
return c
90+
}
91+
92+
func destroySNC() *cobra.Command {
93+
c := &cobra.Command{
94+
Use: params.DestroyCmdName,
95+
Short: params.DestroyCmdName,
96+
RunE: func(cmd *cobra.Command, args []string) error {
97+
if err := viper.BindPFlags(cmd.Flags()); err != nil {
98+
return err
99+
}
100+
101+
if err := openshiftsnc.Destroy(&maptContext.ContextArgs{
102+
ProjectName: viper.GetString(params.ProjectName),
103+
BackedURL: viper.GetString(params.BackedURL),
104+
Debug: viper.IsSet(params.Debug),
105+
DebugLevel: viper.GetUint(params.DebugLevel),
106+
Serverless: viper.IsSet(params.Serverless),
107+
}); err != nil {
108+
logging.Error(err)
109+
}
110+
return nil
111+
},
112+
}
113+
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
114+
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
115+
c.PersistentFlags().AddFlagSet(flagSet)
116+
return c
117+
}

pkg/provider/api/openshift-snc/snc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var (
2424
)
2525

2626
type OpenshiftSNCArgs struct {
27+
Location string
2728
Prefix string
2829
ComputeRequest *cr.ComputeRequestArgs
2930
Version string

pkg/provider/azure/action/linux/linux.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ func (r *linuxRequest) deployer(ctx *pulumi.Context) error {
178178
return fmt.Errorf("error creating RHEL Server on Azure: %v", err)
179179
}
180180
}
181-
182181
vm, err := virtualmachine.Create(ctx, r.mCtx,
183182
&virtualmachine.VirtualMachineArgs{
184183
Prefix: *r.prefix,
@@ -194,7 +193,7 @@ func (r *linuxRequest) deployer(ctx *pulumi.Context) error {
194193
AdminUsername: *r.username,
195194
PrivateKey: privateKey,
196195
SpotPrice: r.allocationData.Price,
197-
Userdata: userDataB64,
196+
Userdata: pulumi.String(userDataB64),
198197
Location: *r.allocationData.Location,
199198
})
200199
if err != nil {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#cloud-config
2+
runcmd:
3+
- systemctl enable --now kubelet
4+
write_files:
5+
- path: /home/core/.ssh/authorized_keys
6+
content: {{ .PubKey }}
7+
owner: {{ .Username }}
8+
permissions: '0600'
9+
- path: /opt/crc/id_rsa.pub
10+
content: {{ .PubKey }}
11+
owner: root:root
12+
permissions: '0644'
13+
- content: |
14+
CRC_CLOUD=1
15+
CRC_NETWORK_MODE_USER=0
16+
owner: root:root
17+
path: /etc/sysconfig/crc-env
18+
permissions: '0644'
19+
- path: /opt/crc/pull-secret
20+
content: |
21+
{{ .PullSecret }}
22+
owner: root:root
23+
permissions: '0644'
24+
- path: /opt/crc/pass_developer
25+
content: '{{ .PassDeveloper }}'
26+
owner: root:root
27+
permissions: '0644'
28+
- path: /opt/crc/pass_kubeadmin
29+
content: '{{ .PassKubeadmin }}'
30+
owner: root:root
31+
permissions: '0644'
32+
- path: /opt/crc/eip
33+
content: '{{ .PublicIP }}'
34+
owner: root:root
35+
permissions: '0644'

0 commit comments

Comments
 (0)