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
38 changes: 21 additions & 17 deletions cmd/mapt/cmd/aws/services/openshift-snc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ 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)"
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)"
disableClusterReadiness = "disable-cluster-readiness"
disableClusterReadinessDesc = "If this flag is set it will skip the checks for the cluster readiness. In this case the kubeconfig can not be generated"
)

func GetOpenshiftSNCCmd() *cobra.Command {
Expand Down Expand Up @@ -57,12 +59,13 @@ func createSNC() *cobra.Command {
Tags: viper.GetStringMapString(params.Tags),
},
&openshiftsnc.OpenshiftSNCArgs{
ComputeRequest: params.ComputeRequestArgs(),
Spot: params.SpotArgs(),
Version: viper.GetString(ocpVersion),
Arch: viper.GetString(params.LinuxArch),
PullSecretFile: viper.GetString(pullSecretFile),
Timeout: viper.GetString(params.Timeout)}); err != nil {
ComputeRequest: params.ComputeRequestArgs(),
Spot: params.SpotArgs(),
Version: viper.GetString(ocpVersion),
DisableClusterReadiness: viper.IsSet(disableClusterReadiness),
Arch: viper.GetString(params.LinuxArch),
PullSecretFile: viper.GetString(pullSecretFile),
Timeout: viper.GetString(params.Timeout)}); err != nil {
return err
}
return nil
Expand All @@ -71,6 +74,7 @@ func createSNC() *cobra.Command {
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
flagSet.StringP(ocpVersion, "", "", ocpVersionDesc)
flagSet.Bool(disableClusterReadiness, false, disableClusterReadinessDesc)
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
flagSet.StringP(pullSecretFile, "", "", pullSecretFileDesc)
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
Expand All @@ -90,13 +94,13 @@ func destroySNC() *cobra.Command {
return err
}
return openshiftsnc.Destroy(&maptContext.ContextArgs{
Context: cmd.Context(),
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),
KeepState: viper.IsSet(params.KeepState),
Context: cmd.Context(),
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),
KeepState: viper.IsSet(params.KeepState),
})
},
}
Expand Down
76 changes: 43 additions & 33 deletions pkg/provider/aws/action/openshift-snc/openshift-snc.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,35 @@ import (
"github.com/redhat-developer/mapt/pkg/provider/aws/services/ec2/keypair"
securityGroup "github.com/redhat-developer/mapt/pkg/provider/aws/services/ec2/security-group"
"github.com/redhat-developer/mapt/pkg/provider/aws/services/ssm"
"github.com/redhat-developer/mapt/pkg/provider/util/command"
"github.com/redhat-developer/mapt/pkg/provider/util/output"
"github.com/redhat-developer/mapt/pkg/provider/util/security"
"github.com/redhat-developer/mapt/pkg/util"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/redhat-developer/mapt/pkg/provider/util/command"
resourcesUtil "github.com/redhat-developer/mapt/pkg/util/resources"
)

type OpenshiftSNCArgs struct {
Prefix string
ComputeRequest *cr.ComputeRequestArgs
Version string
Arch string
PullSecretFile string
Spot *spotTypes.SpotArgs
Timeout string
Prefix string
ComputeRequest *cr.ComputeRequestArgs
Version string
DisableClusterReadiness bool
Arch string
PullSecretFile string
Spot *spotTypes.SpotArgs
Timeout string
}

type openshiftSNCRequest struct {
mCtx *mc.Context
prefix *string
version *string
arch *string
spot bool
timeout *string
pullSecretFile *string
allocationData *allocation.AllocationResult
mCtx *mc.Context
prefix *string
version *string
disableClusterReadiness bool
arch *string
spot bool
timeout *string
pullSecretFile *string
allocationData *allocation.AllocationResult
}

func (r *openshiftSNCRequest) validate() error {
Expand Down Expand Up @@ -88,12 +90,13 @@ func Create(mCtxArgs *mc.ContextArgs, args *OpenshiftSNCArgs) (_ *OpenshiftSncRe
// Compose request
prefix := util.If(len(args.Prefix) > 0, args.Prefix, "main")
r := openshiftSNCRequest{
mCtx: mCtx,
prefix: &prefix,
version: &args.Version,
arch: &args.Arch,
pullSecretFile: &args.PullSecretFile,
timeout: &args.Timeout}
mCtx: mCtx,
prefix: &prefix,
version: &args.Version,
disableClusterReadiness: args.DisableClusterReadiness,
arch: &args.Arch,
pullSecretFile: &args.PullSecretFile,
timeout: &args.Timeout}
if args.Spot != nil {
r.spot = args.Spot.Spot
}
Expand Down Expand Up @@ -266,14 +269,18 @@ func (r *openshiftSNCRequest) deploy(ctx *pulumi.Context) error {
return err
}
}
// Use kubeconfig as the readiness for the cluster
kubeconfig, err := kubeconfig(ctx, r.prefix, c, keyResources.PrivateKey)
if err != nil {
return err
if !r.disableClusterReadiness {
// Use kubeconfig as the readiness for the cluster
kubeconfig, err := kubeconfig(ctx, r.prefix, c, keyResources.PrivateKey)
if err != nil {
return err
}
ctx.Export(fmt.Sprintf("%s-%s", *r.prefix, outputKubeconfig),
pulumi.ToSecret(kubeconfig))
return nil
}
ctx.Export(fmt.Sprintf("%s-%s", *r.prefix, outputKubeconfig),
pulumi.ToSecret(kubeconfig))
return nil
return c.Readiness(ctx, command.CommandPing, *r.prefix, awsOCPSNCID,
keyResources.PrivateKey, amiUserDefault, nil, c.Dependencies)
}

// Write exported values in context to files o a selected target folder
Expand All @@ -290,14 +297,17 @@ func (r *openshiftSNCRequest) manageResults(stackResult auto.UpResult, prefix *s
if err != nil {
return nil, err
}
kubeconfig, err := getResultOutput(outputKubeconfig, stackResult, prefix)
if err != nil {
return nil, err
}
kubeAdminPass, err := getResultOutput(outputKubeAdminPass, stackResult, prefix)
if err != nil {
return nil, err
}
kubeconfig := ""
if !r.disableClusterReadiness {
kubeconfig, err = getResultOutput(outputKubeconfig, stackResult, prefix)
if err != nil {
return nil, err
}
}

hostIPKey := fmt.Sprintf("%s-%s", *prefix, outputHost)
results := map[string]string{
Expand Down
7 changes: 7 additions & 0 deletions tkn/infra-aws-ocp-snc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ spec:
- name: version
description: Version for ocp cluster. If not version set it will pick the latest stable
default: "''"
- name: disable-cluster-readiness
description: If this flag is set it will skip the checks for the cluster readiness. In this case the kubeconfig can not be generated.
default: 'false'

# Metadata params
- name: tags
Expand Down Expand Up @@ -230,6 +233,10 @@ spec:
if [[ $(params.version) != "" ]]; then
cmd+="--version $(params.version) "
fi
if [[ $(params.disable-cluster-readiness) == "true" ]]; then
cmd+="--disable-cluster-readiness "
fi

if [[ $(params.spot) == "true" ]]; then
cmd+="--spot --spot-increase-rate $(params.spot-increase-rate) --spot-eviction-tolerance $(params.spot-eviction-tolerance) "
fi
Expand Down
7 changes: 7 additions & 0 deletions tkn/template/infra-aws-ocp-snc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ spec:
- name: version
description: Version for ocp cluster. If not version set it will pick the latest stable
default: "''"
- name: disable-cluster-readiness
description: If this flag is set it will skip the checks for the cluster readiness. In this case the kubeconfig can not be generated.
default: 'false'

# Metadata params
- name: tags
Expand Down Expand Up @@ -230,6 +233,10 @@ spec:
if [[ $(params.version) != "" ]]; then
cmd+="--version $(params.version) "
fi
if [[ $(params.disable-cluster-readiness) == "true" ]]; then
cmd+="--disable-cluster-readiness "
fi

if [[ $(params.spot) == "true" ]]; then
cmd+="--spot --spot-increase-rate $(params.spot-increase-rate) --spot-eviction-tolerance $(params.spot-eviction-tolerance) "
fi
Expand Down