Skip to content

Commit 0b93493

Browse files
committed
feat: added snc flag to disable cluster readiness. Fix #631.
Signed-off-by: Adrian Riobo <[email protected]>
1 parent 703a5b0 commit 0b93493

File tree

4 files changed

+71
-46
lines changed

4 files changed

+71
-46
lines changed

cmd/mapt/cmd/aws/services/openshift-snc.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ const (
1313
cmdOpenshiftSNC = "openshift-snc"
1414
cmdOpenshiftSNCDesc = "Manage an OpenShift Single Node Cluster based on OpenShift Local. This is not intended for production use"
1515

16-
ocpVersion = "version"
17-
ocpVersionDesc = "version for Openshift. If not set it will pick latest available version"
18-
pullSecretFile = "pull-secret-file"
19-
pullSecretFileDesc = "file path of image pull secret (download from https://console.redhat.com/openshift/create/local)"
16+
ocpVersion = "version"
17+
ocpVersionDesc = "version for Openshift. If not set it will pick latest available version"
18+
pullSecretFile = "pull-secret-file"
19+
pullSecretFileDesc = "file path of image pull secret (download from https://console.redhat.com/openshift/create/local)"
20+
disableClusterReadiness = "disable-cluster-readiness"
21+
disableClusterReadinessDesc = "If this flag is set it will skip the checks for the cluster readiness. In this case the kubeconfig can not be generated"
2022
)
2123

2224
func GetOpenshiftSNCCmd() *cobra.Command {
@@ -57,12 +59,13 @@ func createSNC() *cobra.Command {
5759
Tags: viper.GetStringMapString(params.Tags),
5860
},
5961
&openshiftsnc.OpenshiftSNCArgs{
60-
ComputeRequest: params.ComputeRequestArgs(),
61-
Spot: params.SpotArgs(),
62-
Version: viper.GetString(ocpVersion),
63-
Arch: viper.GetString(params.LinuxArch),
64-
PullSecretFile: viper.GetString(pullSecretFile),
65-
Timeout: viper.GetString(params.Timeout)}); err != nil {
62+
ComputeRequest: params.ComputeRequestArgs(),
63+
Spot: params.SpotArgs(),
64+
Version: viper.GetString(ocpVersion),
65+
DisableClusterReadiness: viper.IsSet(disableClusterReadiness),
66+
Arch: viper.GetString(params.LinuxArch),
67+
PullSecretFile: viper.GetString(pullSecretFile),
68+
Timeout: viper.GetString(params.Timeout)}); err != nil {
6669
return err
6770
}
6871
return nil
@@ -71,6 +74,7 @@ func createSNC() *cobra.Command {
7174
flagSet := pflag.NewFlagSet(params.CreateCmdName, pflag.ExitOnError)
7275
flagSet.StringP(params.ConnectionDetailsOutput, "", "", params.ConnectionDetailsOutputDesc)
7376
flagSet.StringP(ocpVersion, "", "", ocpVersionDesc)
77+
flagSet.Bool(disableClusterReadiness, false, disableClusterReadinessDesc)
7478
flagSet.StringP(params.LinuxArch, "", params.LinuxArchDefault, params.LinuxArchDesc)
7579
flagSet.StringP(pullSecretFile, "", "", pullSecretFileDesc)
7680
flagSet.StringP(params.Timeout, "", "", params.TimeoutDesc)
@@ -90,13 +94,13 @@ func destroySNC() *cobra.Command {
9094
return err
9195
}
9296
return openshiftsnc.Destroy(&maptContext.ContextArgs{
93-
Context: cmd.Context(),
94-
ProjectName: viper.GetString(params.ProjectName),
95-
BackedURL: viper.GetString(params.BackedURL),
96-
Debug: viper.IsSet(params.Debug),
97-
DebugLevel: viper.GetUint(params.DebugLevel),
98-
Serverless: viper.IsSet(params.Serverless),
99-
KeepState: viper.IsSet(params.KeepState),
97+
Context: cmd.Context(),
98+
ProjectName: viper.GetString(params.ProjectName),
99+
BackedURL: viper.GetString(params.BackedURL),
100+
Debug: viper.IsSet(params.Debug),
101+
DebugLevel: viper.GetUint(params.DebugLevel),
102+
Serverless: viper.IsSet(params.Serverless),
103+
KeepState: viper.IsSet(params.KeepState),
100104
})
101105
},
102106
}

pkg/provider/aws/action/openshift-snc/openshift-snc.go

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,33 +28,35 @@ import (
2828
"github.com/redhat-developer/mapt/pkg/provider/aws/services/ec2/keypair"
2929
securityGroup "github.com/redhat-developer/mapt/pkg/provider/aws/services/ec2/security-group"
3030
"github.com/redhat-developer/mapt/pkg/provider/aws/services/ssm"
31+
"github.com/redhat-developer/mapt/pkg/provider/util/command"
3132
"github.com/redhat-developer/mapt/pkg/provider/util/output"
3233
"github.com/redhat-developer/mapt/pkg/provider/util/security"
3334
"github.com/redhat-developer/mapt/pkg/util"
3435
"github.com/redhat-developer/mapt/pkg/util/logging"
35-
"github.com/redhat-developer/mapt/pkg/provider/util/command"
3636
resourcesUtil "github.com/redhat-developer/mapt/pkg/util/resources"
3737
)
3838

3939
type OpenshiftSNCArgs struct {
40-
Prefix string
41-
ComputeRequest *cr.ComputeRequestArgs
42-
Version string
43-
Arch string
44-
PullSecretFile string
45-
Spot *spotTypes.SpotArgs
46-
Timeout string
40+
Prefix string
41+
ComputeRequest *cr.ComputeRequestArgs
42+
Version string
43+
DisableClusterReadiness bool
44+
Arch string
45+
PullSecretFile string
46+
Spot *spotTypes.SpotArgs
47+
Timeout string
4748
}
4849

4950
type openshiftSNCRequest struct {
50-
mCtx *mc.Context
51-
prefix *string
52-
version *string
53-
arch *string
54-
spot bool
55-
timeout *string
56-
pullSecretFile *string
57-
allocationData *allocation.AllocationResult
51+
mCtx *mc.Context
52+
prefix *string
53+
version *string
54+
disableClusterReadiness bool
55+
arch *string
56+
spot bool
57+
timeout *string
58+
pullSecretFile *string
59+
allocationData *allocation.AllocationResult
5860
}
5961

6062
func (r *openshiftSNCRequest) validate() error {
@@ -88,12 +90,13 @@ func Create(mCtxArgs *mc.ContextArgs, args *OpenshiftSNCArgs) (_ *OpenshiftSncRe
8890
// Compose request
8991
prefix := util.If(len(args.Prefix) > 0, args.Prefix, "main")
9092
r := openshiftSNCRequest{
91-
mCtx: mCtx,
92-
prefix: &prefix,
93-
version: &args.Version,
94-
arch: &args.Arch,
95-
pullSecretFile: &args.PullSecretFile,
96-
timeout: &args.Timeout}
93+
mCtx: mCtx,
94+
prefix: &prefix,
95+
version: &args.Version,
96+
disableClusterReadiness: args.DisableClusterReadiness,
97+
arch: &args.Arch,
98+
pullSecretFile: &args.PullSecretFile,
99+
timeout: &args.Timeout}
97100
if args.Spot != nil {
98101
r.spot = args.Spot.Spot
99102
}
@@ -266,14 +269,18 @@ func (r *openshiftSNCRequest) deploy(ctx *pulumi.Context) error {
266269
return err
267270
}
268271
}
269-
// Use kubeconfig as the readiness for the cluster
270-
kubeconfig, err := kubeconfig(ctx, r.prefix, c, keyResources.PrivateKey)
271-
if err != nil {
272-
return err
272+
if !r.disableClusterReadiness {
273+
// Use kubeconfig as the readiness for the cluster
274+
kubeconfig, err := kubeconfig(ctx, r.prefix, c, keyResources.PrivateKey)
275+
if err != nil {
276+
return err
277+
}
278+
ctx.Export(fmt.Sprintf("%s-%s", *r.prefix, outputKubeconfig),
279+
pulumi.ToSecret(kubeconfig))
280+
return nil
273281
}
274-
ctx.Export(fmt.Sprintf("%s-%s", *r.prefix, outputKubeconfig),
275-
pulumi.ToSecret(kubeconfig))
276-
return nil
282+
return c.Readiness(ctx, command.CommandPing, *r.prefix, awsOCPSNCID,
283+
keyResources.PrivateKey, amiUserDefault, nil, c.Dependencies)
277284
}
278285

279286
// Write exported values in context to files o a selected target folder

tkn/infra-aws-ocp-snc.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ spec:
122122
- name: version
123123
description: Version for ocp cluster. If not version set it will pick the latest stable
124124
default: "''"
125+
- name: disable-cluster-readiness
126+
description: If this flag is set it will skip the checks for the cluster readiness. In this case the kubeconfig can not be generated.
127+
default: 'false'
125128

126129
# Metadata params
127130
- name: tags
@@ -230,6 +233,10 @@ spec:
230233
if [[ $(params.version) != "" ]]; then
231234
cmd+="--version $(params.version) "
232235
fi
236+
if [[ $(params.disable-cluster-readiness) == "true" ]]; then
237+
cmd+="--disable-cluster-readiness "
238+
fi
239+
233240
if [[ $(params.spot) == "true" ]]; then
234241
cmd+="--spot --spot-increase-rate $(params.spot-increase-rate) --spot-eviction-tolerance $(params.spot-eviction-tolerance) "
235242
fi

tkn/template/infra-aws-ocp-snc.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ spec:
122122
- name: version
123123
description: Version for ocp cluster. If not version set it will pick the latest stable
124124
default: "''"
125+
- name: disable-cluster-readiness
126+
description: If this flag is set it will skip the checks for the cluster readiness. In this case the kubeconfig can not be generated.
127+
default: 'false'
125128

126129
# Metadata params
127130
- name: tags
@@ -230,6 +233,10 @@ spec:
230233
if [[ $(params.version) != "" ]]; then
231234
cmd+="--version $(params.version) "
232235
fi
236+
if [[ $(params.disable-cluster-readiness) == "true" ]]; then
237+
cmd+="--disable-cluster-readiness "
238+
fi
239+
233240
if [[ $(params.spot) == "true" ]]; then
234241
cmd+="--spot --spot-increase-rate $(params.spot-increase-rate) --spot-eviction-tolerance $(params.spot-eviction-tolerance) "
235242
fi

0 commit comments

Comments
 (0)