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
12 changes: 9 additions & 3 deletions cmd/mapt/cmd/aws/services/snc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const (
operatorChannelDesc = "override the OLM subscription channel for an operator (--operator-channel serverless-operator=preview,nfd=4.17)"
catalogSource = "catalog-source"
catalogSourceDesc = "override the OLM catalog source with a custom index image (--catalog-source serverless-operator=quay.io/my-org/my-index:latest)"

dnsSuffix = "dns-suffix"
dnsSuffixDesc = "DNS suffix used for the cluster endpoints instead of the nip.io default (e.g. sslip.io or a domain you control). The cluster IP is embedded in the hostname (api.<IP>.<suffix>), so the suffix must resolve wildcards of the instance public IP. Requires OpenShift >= 4.22 or 5.x (bundle support from crc-org/snc#1266)"
)

func GetOpenshiftSNCCmd() *cobra.Command {
Expand Down Expand Up @@ -97,9 +100,11 @@ func createSNC() *cobra.Command {
PullSecretFile: viper.GetString(pullSecretFile),
Timeout: viper.GetString(params.Timeout),
ServiceEndpoints: params.NetworkServiceEndpoints(),
Profiles: profiles,
OperatorChannels: viper.GetStringMapString(operatorChannel),
CatalogSources: viper.GetStringMapString(catalogSource)}); err != nil {
Profiles: profiles,
OperatorChannels: viper.GetStringMapString(operatorChannel),
CatalogSources: viper.GetStringMapString(catalogSource),
DNSuffix: viper.GetString(dnsSuffix),
}); err != nil {
return err
}
return nil
Expand All @@ -116,6 +121,7 @@ func createSNC() *cobra.Command {
flagSet.StringSliceP(sncProfile, "", []string{}, sncProfileDesc)
flagSet.StringToStringP(operatorChannel, "", nil, operatorChannelDesc)
flagSet.StringToStringP(catalogSource, "", nil, catalogSourceDesc)
flagSet.StringP(dnsSuffix, "", "", dnsSuffixDesc)
params.AddComputeRequestFlags(flagSet)
params.AddSpotFlags(flagSet)
params.AddNetworkFlags(flagSet, awsParams.ServiceEndpointsDesc)
Expand Down
4 changes: 4 additions & 0 deletions cmd/mapt/cmd/ibmcloud/services/snc.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const (
catalogSource = "catalog-source"
catalogSourceDesc = "override the OLM catalog source with a custom index image (--catalog-source serverless-operator=quay.io/my-org/my-index:latest)"

dnsSuffix = "dns-suffix"
dnsSuffixDesc = "DNS suffix used for the cluster endpoints instead of the nip.io default (e.g. sslip.io or a domain you control). The cluster IP is embedded in the hostname (api.<IP>.<suffix>), so the suffix must resolve wildcards of the instance floating IP. Requires OpenShift >= 4.22 or 5.x (bundle support from crc-org/snc#1266)"
)

func GetOpenshiftSNCCmd() *cobra.Command {
Expand Down Expand Up @@ -97,6 +99,7 @@ func createSNC() *cobra.Command {
Profiles: profiles,
OperatorChannels: viper.GetStringMapString(operatorChannel),
CatalogSources: viper.GetStringMapString(catalogSource),
DNSuffix: viper.GetString(dnsSuffix),
VpcID: viper.GetString(params.VpcID),
}); err != nil {
return err
Expand All @@ -113,6 +116,7 @@ func createSNC() *cobra.Command {
flagSet.StringSliceP(sncProfile, "", []string{}, sncProfileDesc)
flagSet.StringToStringP(operatorChannel, "", nil, operatorChannelDesc)
flagSet.StringToStringP(catalogSource, "", nil, catalogSourceDesc)
flagSet.StringP(dnsSuffix, "", "", dnsSuffixDesc)
flagSet.StringP(params.VpcID, "", "", params.VpcIDDesc)
params.AddComputeRequestFlags(flagSet)
params.AddSpotFlags(flagSet)
Expand Down
32 changes: 32 additions & 0 deletions docs/aws/openshift-snc.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,38 @@ After the AMI is published and accessible by the account, we can use the followi

After the above command succeeds the `kubeconfig` to access the deployed cluster will be available in `/tmp/snc/kubeconfig`

## Custom DNS suffix

By default the cluster endpoints use `nip.io` to map the instance public IP to
resolvable hostnames (`api.<IP>.nip.io`, `*.apps.<IP>.nip.io`). Use the
`--dns-suffix` flag to replace it with another wildcard DNS service (e.g.
`sslip.io`) or a domain you control:

```
% mapt aws openshift-snc create \
--version 4.21.0 \
--project-name mapt-snc \
--backed-url file:///home/tester/workspace \
--conn-details-output /tmp/snc \
--pull-secret-file /home/tester/Downloads/pull-secret \
--dns-suffix sslip.io
```

The suffix is written to `/opt/crc/dns-suffix` on the instance and picked up by
the `ocp-custom-domain` service, which patches the console, OAuth, API server
and image registry endpoints accordingly. The generated `kubeconfig` and the
reported console URL follow the same suffix.

> [!NOTE]
>
> - The suffix must be able to resolve the cluster hostnames: it is used as
> `api.<IP>.<suffix>` and `*.apps.<IP>.<suffix>`, where `<IP>` is the
> instance public IP.
> - This requires OpenShift >= 4.22 or 5.x: the bundle must include
> [crc-org/snc#1266](https://github.com/crc-org/snc/pull/1266) (backported
> to the 4.22 and 5.0 bundle branches). Older bundles ignore the setting
> and keep using `nip.io`, so `mapt` rejects the flag for them.

## Profiles

Profiles are optional addons that are installed on the SNC cluster after it is ready. Use the `--profile` flag to enable one or more profiles:
Expand Down
24 changes: 23 additions & 1 deletion docs/ibmcloud/openshift-snc.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ mapt ibmcloud openshift-snc create \
--pull-secret-file /path/to/pull-secret
```

With a custom DNS suffix (instead of the `nip.io` default):

```bash
mapt ibmcloud openshift-snc create \
--version 4.22.14 \
--project-name my-snc \
--backed-url file:///workspace \
--conn-details-output /tmp/snc \
--pull-secret-file /path/to/pull-secret \
--dns-suffix sslip.io
```

The suffix is written to `/opt/crc/dns-suffix` on the instance and picked up by
the `ocp-custom-domain` service, which patches the console, OAuth, API server
and image registry endpoints accordingly. The generated `kubeconfig` and the
reported console URL follow the same suffix. The suffix must resolve
`api.<IP>.<suffix>` and `*.apps.<IP>.<suffix>` — where `<IP>` is the instance
floating IP — and it requires OpenShift >= 4.22 or 5.x: the bundle must
include [crc-org/snc#1266](https://github.com/crc-org/snc/pull/1266)
(backported to the 4.22 and 5.0 bundle branches). Older bundles ignore the
setting and keep using `nip.io`, so `mapt` rejects the flag for them.

### Outputs

Files written to the path defined by `--conn-details-output`:
Expand All @@ -78,7 +100,7 @@ Files written to the path defined by `--conn-details-output`:
| `host` | Floating IP of the instance |
| `username` | SSH username (`core`) |
| `id_rsa` | Private key for the instance |
| `kubeconfig` | Kubeconfig for the cluster (API server points to the floating IP via nip.io) |
| `kubeconfig` | Kubeconfig for the cluster (API server points to the floating IP via the configured DNS suffix, `nip.io` by default) |

### Pulumi passphrase handling

Expand Down
34 changes: 21 additions & 13 deletions pkg/provider/aws/action/snc/snc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
"github.com/redhat-developer/mapt/pkg/target/service/snc/profile"
"github.com/redhat-developer/mapt/pkg/util"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/redhat-developer/mapt/pkg/util/ssh"
resourcesUtil "github.com/redhat-developer/mapt/pkg/util/resources"
"github.com/redhat-developer/mapt/pkg/util/ssh"
)

type openshiftSNCRequest struct {
Expand All @@ -46,10 +46,11 @@ type openshiftSNCRequest struct {
pullSecretFile *string
serviceEndpoints []string
allocationData *allocation.AllocationResult
profiles []string
operatorChannels map[string]string
catalogSources map[string]string
diskSize *int
profiles []string
operatorChannels map[string]string
catalogSources map[string]string
dnsSuffix string
diskSize *int
}

func (r *openshiftSNCRequest) validate() error {
Expand Down Expand Up @@ -77,6 +78,9 @@ func Create(mCtxArgs *mc.ContextArgs, args *apiSNC.SNCArgs) (_ *apiSNC.SNCResult
if err := profile.ValidateOperatorOverrides(args.OperatorChannels, args.CatalogSources); err != nil {
return nil, err
}
if err := apiSNC.ValidateDNSSuffix(args.Version, args.DNSuffix); err != nil {
return nil, err
}
// Compose request
prefix := util.If(len(args.Prefix) > 0, args.Prefix, "main")
r := openshiftSNCRequest{
Expand All @@ -88,10 +92,11 @@ func Create(mCtxArgs *mc.ContextArgs, args *apiSNC.SNCArgs) (_ *apiSNC.SNCResult
pullSecretFile: &args.PullSecretFile,
timeout: &args.Timeout,
serviceEndpoints: args.ServiceEndpoints,
profiles: args.Profiles,
operatorChannels: args.OperatorChannels,
catalogSources: args.CatalogSources,
diskSize: args.ComputeRequest.DiskSize}
profiles: args.Profiles,
operatorChannels: args.OperatorChannels,
catalogSources: args.CatalogSources,
dnsSuffix: args.DNSuffix,
diskSize: args.ComputeRequest.DiskSize}
if args.Spot != nil {
r.spot = args.Spot.Spot
}
Expand Down Expand Up @@ -162,7 +167,8 @@ func (r *openshiftSNCRequest) createCluster() (*apiSNC.SNCResults, error) {
return apiSNC.Results(sr, r.prefix,
r.mCtx.GetResultsOutputPath(),
r.allocationData.SpotPrice,
r.disableClusterReadiness)
r.disableClusterReadiness,
r.dnsSuffix)
}

func (r *openshiftSNCRequest) deploy(ctx *pulumi.Context) error {
Expand Down Expand Up @@ -276,7 +282,7 @@ func (r *openshiftSNCRequest) deploy(ctx *pulumi.Context) error {
}
}
// Use kubeconfig as the readiness for the cluster
kubeconfig, err := kubeconfig(ctx, r.prefix, c, keyResources.PrivateKey, *r.version, r.disableClusterReadiness)
kubeconfig, err := kubeconfig(ctx, r.prefix, c, keyResources.PrivateKey, *r.version, r.disableClusterReadiness, r.dnsSuffix)
if err != nil {
return err
}
Expand Down Expand Up @@ -399,7 +405,8 @@ func (r *openshiftSNCRequest) userData(ctx *pulumi.Context,
PublicIP: args[1].(string),
SSMPullSecretName: *psName,
SSMKubeAdminPasswordName: *kaPassName,
SSMDeveloperPasswordName: *devPassName})
SSMDeveloperPasswordName: *devPassName,
DNSSuffix: r.dnsSuffix})
return *ccB64, err
}).(pulumi.StringOutput)

Expand All @@ -411,6 +418,7 @@ func kubeconfig(ctx *pulumi.Context,
c *compute.Compute, mk *tls.PrivateKey,
ocpVersion string,
disableClusterReadiness bool,
dnsSuffix string,
) (pulumi.StringOutput, error) {
// Once the cluster setup is comleted we
// get the kubeconfig file from the host running the cluster
Expand Down Expand Up @@ -460,7 +468,7 @@ func kubeconfig(ctx *pulumi.Context,
func(args []interface{}) string {
return strings.ReplaceAll(args[0].(string),
"https://api.crc.testing:6443",
fmt.Sprintf("https://api.%s.nip.io:6443", args[1].(string)))
apiSNC.APIServerURL(args[1].(string), dnsSuffix))
}).(pulumi.StringOutput)
return kubeconfig, nil
}
5 changes: 5 additions & 0 deletions pkg/provider/ibmcloud/action/snc/cloud-config
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ write_files:
owner: root:root
path: /etc/sysconfig/crc-env
permissions: '0644'
{{ if .DNSSuffix }}- path: /opt/crc/dns-suffix
content: {{ .DNSSuffix }}
owner: root:root
permissions: '0644'
{{ end }}
28 changes: 19 additions & 9 deletions pkg/provider/ibmcloud/action/snc/snc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"github.com/redhat-developer/mapt/pkg/util"
"github.com/redhat-developer/mapt/pkg/util/file"
"github.com/redhat-developer/mapt/pkg/util/logging"
"github.com/redhat-developer/mapt/pkg/util/ssh"
resourcesUtil "github.com/redhat-developer/mapt/pkg/util/resources"
"github.com/redhat-developer/mapt/pkg/util/ssh"
)

var kubeconfigURLPattern = regexp.MustCompile(`https://api\.crc\.testing:\d+`)
Expand All @@ -34,12 +34,15 @@ var kubeconfigURLPattern = regexp.MustCompile(`https://api\.crc\.testing:\d+`)
var cloudConfigTemplate []byte

type dataValues struct {
Username string
PubKey string
PublicIP string
PullSecretB64 string
Username string
PubKey string
PublicIP string
PullSecretB64 string
KubeAdminPassword string
DeveloperPassword string
// DNS suffix for the cluster endpoints. When empty the SNC bundle keeps
// its own default (nip.io).
DNSSuffix string
}

type sncRequest struct {
Expand All @@ -57,6 +60,7 @@ type sncRequest struct {
profiles []string
operatorChannels map[string]string
catalogSources map[string]string
dnsSuffix string
// bareMetal is true when the request needs nested virtualization. IBM
// Cloud provides it on a bare metal server only.
bareMetal bool
Expand All @@ -77,6 +81,9 @@ func Create(mCtxArgs *mc.ContextArgs, args *apiSNC.SNCArgs) (*apiSNC.SNCResults,
if err := profile.ValidateOperatorOverrides(args.OperatorChannels, args.CatalogSources); err != nil {
return nil, err
}
if err := apiSNC.ValidateDNSSuffix(args.Version, args.DNSuffix); err != nil {
return nil, err
}
version := args.Version
var offeringCRN string
if version == "" {
Expand Down Expand Up @@ -183,6 +190,7 @@ func Create(mCtxArgs *mc.ContextArgs, args *apiSNC.SNCArgs) (*apiSNC.SNCResults,
profiles: args.Profiles,
operatorChannels: args.OperatorChannels,
catalogSources: args.CatalogSources,
dnsSuffix: args.DNSuffix,
}
cs := manager.Stack{
StackName: mCtx.StackNameByProject(apiSNC.StackName),
Expand All @@ -198,7 +206,8 @@ func Create(mCtxArgs *mc.ContextArgs, args *apiSNC.SNCArgs) (*apiSNC.SNCResults,
return apiSNC.Results(sr, &prefix,
mCtx.GetResultsOutputPath(),
nil,
r.disableClusterReadiness)
r.disableClusterReadiness,
r.dnsSuffix)
}

func Destroy(mCtxArgs *mc.ContextArgs) error {
Expand Down Expand Up @@ -296,7 +305,7 @@ func (r *sncRequest) deploy(ctx *pulumi.Context) error {
n.Floatingip.Address)

kc, err := kubeconfig(ctx, r.prefix, n.Floatingip.Address, pk,
*r.version, r.disableClusterReadiness, []pulumi.Resource{fipAssoc})
*r.version, r.disableClusterReadiness, r.dnsSuffix, []pulumi.Resource{fipAssoc})
if err != nil {
return err
}
Expand Down Expand Up @@ -518,6 +527,7 @@ func (r *sncRequest) userData(
PullSecretB64: psB64,
KubeAdminPassword: args[2].(string),
DeveloperPassword: args[3].(string),
DNSSuffix: r.dnsSuffix,
}
rawCC, err := file.Template(data, string(cloudConfigTemplate))
if err != nil {
Expand Down Expand Up @@ -548,7 +558,7 @@ func mimeWrapCloudConfig(rawCC string) string {

func kubeconfig(ctx *pulumi.Context, prefix *string, ip pulumi.StringOutput,
mk *tls.PrivateKey, ocpVersion string, disableClusterReadiness bool,
dependencies []pulumi.Resource,
dnsSuffix string, dependencies []pulumi.Resource,
) (pulumi.StringOutput, error) {
sshReadyCmd, err := remote.NewCommand(ctx,
resourcesUtil.GetResourceName(*prefix, ibmCloudSNCID, "ssh-ready"),
Expand Down Expand Up @@ -634,7 +644,7 @@ func kubeconfig(ctx *pulumi.Context, prefix *string, ip pulumi.StringOutput,
func(args []interface{}) string {
return kubeconfigURLPattern.ReplaceAllString(
args[0].(string),
fmt.Sprintf("https://api.%s.nip.io:6443", args[1].(string)))
apiSNC.APIServerURL(args[1].(string), dnsSuffix))
}).(pulumi.StringOutput)
return kc, nil
}
45 changes: 45 additions & 0 deletions pkg/provider/ibmcloud/action/snc/snc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,48 @@ func TestCloudConfigQuotesPasswordValues(t *testing.T) {
t.Errorf("developer password was not preserved: %q", contents["/opt/crc/pass_developer"])
}
}

func TestCloudConfigDNSSuffix(t *testing.T) {
base := dataValues{
Username: "core",
PubKey: "ssh-rsa AAAATEST",
PublicIP: "192.0.2.1",
PullSecretB64: "cHJ1bGxlcnNlY3JldA==",
KubeAdminPassword: "!admin-password",
DeveloperPassword: "!developer-password",
}

render := func(t *testing.T, data dataValues) map[string]string {
t.Helper()
rendered, err := file.Template(data, string(cloudConfigTemplate))
if err != nil {
t.Fatalf("render cloud config: %v", err)
}
var config struct {
WriteFiles []struct {
Path string `yaml:"path"`
Content string `yaml:"content"`
} `yaml:"write_files"`
}
if err := yaml.Unmarshal([]byte(rendered), &config); err != nil {
t.Fatalf("parse rendered cloud config: %v", err)
}
contents := make(map[string]string)
for _, writeFile := range config.WriteFiles {
contents[writeFile.Path] = writeFile.Content
}
return contents
}

withoutSuffix := render(t, base)
if _, ok := withoutSuffix["/opt/crc/dns-suffix"]; ok {
t.Error("dns-suffix file should not be written when no suffix is set")
}

withSuffix := base
withSuffix.DNSSuffix = "sslip.io"
contents := render(t, withSuffix)
if got := contents["/opt/crc/dns-suffix"]; got != "sslip.io" {
t.Errorf("dns-suffix file content = %q, want %q", got, "sslip.io")
}
}
Loading