Skip to content

Commit

Permalink
enable hostPort for tink services only on bootstrap (#2395)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavmpandey08 authored Jun 13, 2022
1 parent dc30f16 commit 1484135
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ require (
github.com/stretchr/testify v1.7.0
github.com/tinkerbell/rufio v0.0.0-20220606134123-599b7401b5cc
github.com/tinkerbell/tink v0.6.1-0.20220509141453-30fe9e015575
go.uber.org/multierr v1.7.0
go.uber.org/zap v1.19.1
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
Expand Down Expand Up @@ -134,7 +135,6 @@ require (
github.com/subosito/gotenv v1.2.0 // indirect
github.com/xanzy/ssh-agent v0.3.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
Expand Down
2 changes: 2 additions & 0 deletions pkg/providers/tinkerbell/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (p *Provider) PreCAPIInstallOnBootstrap(ctx context.Context, cluster *types
cluster.KubeconfigFile,
stack.WithNamespaceCreate(false),
stack.WithBootsOnDocker(),
stack.WithHostPortEnabled(true),
)
if err != nil {
return fmt.Errorf("install Tinkerbell stack on bootstrap cluster: %v", err)
Expand Down Expand Up @@ -80,6 +81,7 @@ func (p *Provider) PostWorkloadInit(ctx context.Context, cluster *types.Cluster,
cluster.KubeconfigFile,
stack.WithNamespaceCreate(true),
stack.WithBootsOnKubernetes(),
stack.WithHostPortEnabled(false),
)
if err != nil {
return fmt.Errorf("installing stack on workload cluster: %v", err)
Expand Down
16 changes: 16 additions & 0 deletions pkg/providers/tinkerbell/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ const (
createNamespace = "createNamespace"
deploy = "deploy"
env = "env"
hostPortEnabled = "hostPortEnabled"
image = "image"
namespace = "namespace"
overridesFileName = "tinkerbell-chart-overrides.yaml"
port = "port"

boots = "boots"
hegel = "hegel"
Expand All @@ -48,6 +50,7 @@ type Installer struct {
namespace string
createNamespace bool
bootsOnDocker bool
hostPort bool
}

type InstallOption func(s *Installer)
Expand Down Expand Up @@ -79,6 +82,13 @@ func WithBootsOnKubernetes() InstallOption {
}
}

// WithHostPortEnabled is an InstallOption that allows you to enable/disable host port for Tinkerbell deployments
func WithHostPortEnabled(enabled bool) InstallOption {
return func(s *Installer) {
s.hostPort = enabled
}
}

// NewInstaller returns a Tinkerbell StackInstaller which can be used to install or uninstall the Tinkerbell stack
func NewInstaller(docker Docker, filewriter filewriter.FileWriter, helm Helm, namespace string) StackInstaller {
return &Installer{
Expand Down Expand Up @@ -121,11 +131,17 @@ func (s *Installer) Install(ctx context.Context, bundle releasev1alpha1.Tinkerbe
deploy: true,
image: bundle.Tink.TinkServer.URI,
args: []string{"--tls=false"},
port: map[string]bool{
hostPortEnabled: s.hostPort,
},
},
hegel: map[string]interface{}{
deploy: true,
image: bundle.Hegel.Image.URI,
args: []string{"--grpc-use-tls=false"},
port: map[string]bool{
hostPortEnabled: s.hostPort,
},
},
boots: map[string]interface{}{
deploy: !s.bootsOnDocker,
Expand Down
1 change: 1 addition & 0 deletions pkg/providers/tinkerbell/stack/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func TestTinkerbellStackInstallWithAllOptionsSuccess(t *testing.T) {
cluster.KubeconfigFile,
stack.WithNamespaceCreate(true),
stack.WithBootsOnKubernetes(),
stack.WithHostPortEnabled(true),
); err != nil {
t.Fatalf("failed to install Tinkerbell stack: %v", err)
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/providers/tinkerbell/tinkerbell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,11 @@ func TestPreCAPIInstallOnBootstrapSuccess(t *testing.T) {
stackInstaller.EXPECT().Install(
ctx,
releasev1alpha1.TinkerbellStackBundle{},
gomock.Any(),
testIP,
"test.kubeconfig",
gomock.Any(),
gomock.Any(),
gomock.Any(),
)

err := provider.PreCAPIInstallOnBootstrap(ctx, cluster, clusterSpec)
Expand Down Expand Up @@ -260,10 +261,11 @@ func TestPostWorkloadInitSuccess(t *testing.T) {
stackInstaller.EXPECT().Install(
ctx,
releasev1alpha1.TinkerbellStackBundle{},
gomock.Any(),
testIP,
"test.kubeconfig",
gomock.Any(),
gomock.Any(),
gomock.Any(),
)
stackInstaller.EXPECT().UninstallLocal(ctx)

Expand Down

0 comments on commit 1484135

Please sign in to comment.