Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/mapt/cmd/aws/services/openshift-snc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package services
import (
params "github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
sncAPI "github.com/redhat-developer/mapt/pkg/provider/api/openshift-snc"
openshiftsnc "github.com/redhat-developer/mapt/pkg/provider/aws/action/openshift-snc"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -55,9 +56,8 @@ func createSNC() *cobra.Command {
DebugLevel: viper.GetUint(params.DebugLevel),
Tags: viper.GetStringMapString(params.Tags),
},
&openshiftsnc.OpenshiftSNCArgs{
&sncAPI.OpenshiftSNCArgs{
ComputeRequest: params.ComputeRequestArgs(),
Spot: params.SpotArgs(),
Version: viper.GetString(ocpVersion),
Arch: viper.GetString(params.LinuxArch),
PullSecretFile: viper.GetString(pullSecretFile),
Expand Down
3 changes: 2 additions & 1 deletion cmd/mapt/cmd/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func GetCmd() *cobra.Command {
hosts.GetUbuntuCmd(),
hosts.GetRHELCmd(),
hosts.GetFedoraCmd(),
services.GetAKSCmd())
services.GetAKSCmd(),
services.GetOpenshiftSNCCmd())
return c
}
117 changes: 117 additions & 0 deletions cmd/mapt/cmd/azure/services/openshift-snc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package services

import (
"github.com/redhat-developer/mapt/cmd/mapt/cmd/params"
maptContext "github.com/redhat-developer/mapt/pkg/manager/context"
sncAPI "github.com/redhat-developer/mapt/pkg/provider/api/openshift-snc"
openshiftsnc "github.com/redhat-developer/mapt/pkg/provider/azure/action/openshift-snc"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

const (
cmdOpenshiftSNC = "openshift-snc"
cmdOpenshiftSNCDesc = "Manage an OpenShift Single Node Cluster based on OpenShift Local. This is not intended for production use"

ocpVersion = "version"
ocpVersionDesc = "version for Openshift. If not set it will pick latest available version"
pullSecretFile = "pull-secret-file"
pullSecretFileDesc = "file path of image pull secret (download from https://console.redhat.com/openshift/create/local)"

location = "location"
locationDesc = "If spot is passed location will be calculated based on spot results. Otherwise localtion will be used to create resources."
defaultLocation = "centralindia"
)

func GetOpenshiftSNCCmd() *cobra.Command {
c := &cobra.Command{
Use: cmdOpenshiftSNC,
Short: cmdOpenshiftSNCDesc,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}
return nil
},
}
flagSet := pflag.NewFlagSet(cmdOpenshiftSNC, pflag.ExitOnError)
params.AddCommonFlags(flagSet)
c.PersistentFlags().AddFlagSet(flagSet)
c.AddCommand(createSNC(), destroySNC())
return c

}

func createSNC() *cobra.Command {
c := &cobra.Command{
Use: params.CreateCmdName,
Short: params.CreateCmdName,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}

if err := openshiftsnc.Create(
&maptContext.ContextArgs{
ProjectName: viper.GetString(params.ProjectName),
BackedURL: viper.GetString(params.BackedURL),
ResultsOutput: viper.GetString(params.ConnectionDetailsOutput),
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
Tags: viper.GetStringMapString(params.Tags),
},
&sncAPI.OpenshiftSNCArgs{
ComputeRequest: params.ComputeRequestArgs(),
Version: viper.GetString(ocpVersion),
Arch: viper.GetString(params.LinuxArch),
PullSecretFile: viper.GetString(pullSecretFile),
Spot: params.SpotArgs(),
Location: viper.GetString(location),
Timeout: viper.GetString(params.Timeout)}); err != nil {
logging.Error(err)
}
return nil
},
}
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
flagSet.StringP(ocpVersion, "", "", ocpVersionDesc)
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
flagSet.StringP(pullSecretFile, "", "", pullSecretFileDesc)
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
flagSet.StringP(location, "", defaultLocation, locationDesc)
flagSet.StringToStringP(params.Tags, "", nil, params.TagsDesc)
params.AddComputeRequestFlags(flagSet)
params.AddSpotFlags(flagSet)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}

func destroySNC() *cobra.Command {
c := &cobra.Command{
Use: params.DestroyCmdName,
Short: params.DestroyCmdName,
RunE: func(cmd *cobra.Command, args []string) error {
if err := viper.BindPFlags(cmd.Flags()); err != nil {
return err
}

if err := openshiftsnc.Destroy(&maptContext.ContextArgs{
ProjectName: viper.GetString(params.ProjectName),
BackedURL: viper.GetString(params.BackedURL),
Debug: viper.IsSet(params.Debug),
DebugLevel: viper.GetUint(params.DebugLevel),
Serverless: viper.IsSet(params.Serverless),
}); err != nil {
logging.Error(err)
}
return nil
},
}
flagSet := pflag.NewFlagSet(params.DestroyCmdName, pflag.ExitOnError)
flagSet.Bool(params.Serverless, false, params.ServerlessDesc)
c.PersistentFlags().AddFlagSet(flagSet)
return c
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/redhat-developer/mapt/pkg/util/file"
)

type dataValues struct {
type CloudConfigDataValues struct {
// user auth information
Username string
PubKey string
Expand All @@ -17,15 +17,16 @@ type dataValues struct {
SSMPullSecretName string
SSMKubeAdminPasswordName string
SSMDeveloperPasswordName string
// Unprotected, used for azure
PullSecret string
PassDeveloper string
PassKubeadmin string
}

//go:embed cloud-config
var CloudConfig []byte
var AWSCloudConfigRequiredProfiles = []string{"arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"}

var cloudConfigRequiredProfiles = []string{"arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"}

func cloudConfig(data dataValues) (*string, error) {
templateConfig := string(CloudConfig[:])
func GenCloudConfig(data CloudConfigDataValues, cloudConfig []byte) (*string, error) {
templateConfig := string(cloudConfig[:])
cc, err := file.Template(data, templateConfig)
if err != nil {
return nil, err
Expand Down
45 changes: 45 additions & 0 deletions pkg/provider/api/openshift-snc/snc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package openshiftsnc

import (
cr "github.com/redhat-developer/mapt/pkg/provider/api/compute-request"
"github.com/redhat-developer/mapt/pkg/provider/api/spot"
)

var (
ConsoleURLRegex = "https://console-openshift-console.apps.%s.nip.io"

OutputHost = "aosHost"
OutputUsername = "aosUsername"
OutputUserPrivateKey = "aosPrivatekey"
OutputKubeconfig = "aosKubeconfig"
OutputKubeAdminPass = "aosKubeAdminPasss"
OutputDeveloperPass = "aosDeveloperPass"

CommandReadiness = "while [ ! -f /tmp/.crc-cluster-ready ]; do sleep 5; done"
CommandCaServiceRan = "sudo bash -c 'until oc get node --kubeconfig /opt/kubeconfig --context system:admin || oc get node --kubeconfig /opt/crc/kubeconfig --context system:admin; do sleep 5; done'"

// portHTTP = 80
PortHTTPS = 443
PortAPI = 6443
)

type OpenshiftSNCArgs struct {
Location string
Prefix string
ComputeRequest *cr.ComputeRequestArgs
Version string
Arch string
PullSecretFile string
Spot *spot.SpotArgs
Timeout string
}

type OpenshiftSncResultsMetadata struct {
Username string `json:"username"`
PrivateKey string `json:"private_key"`
Host string `json:"host"`
Kubeconfig string `json:"kubeconfig"`
KubeadminPass string `json:"kubeadmin_pass"`
SpotPrice *float64 `json:"spot_price,omitempty"`
ConsoleUrl string `json:"console_url,omitempty"`
}
16 changes: 0 additions & 16 deletions pkg/provider/aws/action/openshift-snc/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ var (
amiOwner = "391597328979"
// amiOriginRegion = "us-east-1"

consoleURLRegex = "https://console-openshift-console.apps.%s.nip.io"

outputHost = "aosHost"
outputUsername = "aosUsername"
outputUserPrivateKey = "aosPrivatekey"
outputKubeconfig = "aosKubeconfig"
outputKubeAdminPass = "aosKubeAdminPasss"
outputDeveloperPass = "aosDeveloperPass"

commandReadiness = "while [ ! -f /tmp/.crc-cluster-ready ]; do sleep 5; done"
commandCaServiceRan = "sudo bash -c 'until oc get node --kubeconfig /opt/kubeconfig --context system:admin || oc get node --kubeconfig /opt/crc/kubeconfig --context system:admin; do sleep 5; done'"

// portHTTP = 80
portHTTPS = 443
portAPI = 6443

// SSM
ocpPullSecretID = "ocppullsecretid"
kapass = "kapass"
Expand Down
Loading