diff --git a/cmd/mapt/cmd/aws/services/openshift-snc.go b/cmd/mapt/cmd/aws/services/openshift-snc.go index 266c0a1e5..7d17dc0a1 100644 --- a/cmd/mapt/cmd/aws/services/openshift-snc.go +++ b/cmd/mapt/cmd/aws/services/openshift-snc.go @@ -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 { @@ -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 @@ -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) @@ -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), }) }, } diff --git a/pkg/provider/aws/action/openshift-snc/openshift-snc.go b/pkg/provider/aws/action/openshift-snc/openshift-snc.go index b5306d333..eb51b6b71 100644 --- a/pkg/provider/aws/action/openshift-snc/openshift-snc.go +++ b/pkg/provider/aws/action/openshift-snc/openshift-snc.go @@ -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 { @@ -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 } @@ -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 @@ -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{ diff --git a/tkn/infra-aws-ocp-snc.yaml b/tkn/infra-aws-ocp-snc.yaml index a66723069..2c4e4c569 100644 --- a/tkn/infra-aws-ocp-snc.yaml +++ b/tkn/infra-aws-ocp-snc.yaml @@ -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 @@ -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 diff --git a/tkn/template/infra-aws-ocp-snc.yaml b/tkn/template/infra-aws-ocp-snc.yaml index 30a15fe66..0eb908a11 100644 --- a/tkn/template/infra-aws-ocp-snc.yaml +++ b/tkn/template/infra-aws-ocp-snc.yaml @@ -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 @@ -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