Skip to content

Commit

Permalink
Customize tinkerbell load balancer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sp1999 committed Sep 27, 2024
1 parent fe2dad6 commit f69414a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ spec:
description: HookImagesURLPath can be used to override the default
Hook images path to pull from a local server.
type: string
loadBalancerInterface:
description: LoadBalancerInterface can be used to configure a load
balancer interface for the Tinkerbell stack.
type: string
osImageURL:
description: OSImageURL can be used to override the default OS image
path to pull from a local server. OSImageURL is a URL to the OS
Expand Down
4 changes: 4 additions & 0 deletions config/manifest/eksa-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6791,6 +6791,10 @@ spec:
description: HookImagesURLPath can be used to override the default
Hook images path to pull from a local server.
type: string
loadBalancerInterface:
description: LoadBalancerInterface can be used to configure a load
balancer interface for the Tinkerbell stack.
type: string
osImageURL:
description: OSImageURL can be used to override the default OS image
path to pull from a local server. OSImageURL is a URL to the OS
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1alpha1/tinkerbelldatacenterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type TinkerbellDatacenterConfigSpec struct {
// SkipLoadBalancerDeployment when set to "true" can be used to skip deploying a load balancer to expose Tinkerbell stack.
// Users will need to deploy and configure a load balancer manually after the cluster is created.
SkipLoadBalancerDeployment bool `json:"skipLoadBalancerDeployment,omitempty"`
// LoadBalancerInterface can be used to configure a load balancer interface for the Tinkerbell stack.
LoadBalancerInterface string `json:"loadBalancerInterface,omitempty"`
}

// TinkerbellDatacenterConfigStatus defines the observed state of TinkerbellDatacenterConfig
Expand Down
39 changes: 23 additions & 16 deletions pkg/providers/tinkerbell/stack/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
port = "port"
addr = "addr"
enabled = "enabled"
kubevipInterface = "interface"

boots = "boots"
smee = "smee"
Expand Down Expand Up @@ -76,18 +77,19 @@ type StackInstaller interface {
}

type Installer struct {
docker Docker
filewriter filewriter.FileWriter
helm Helm
podCidrRange string
registryMirror *registrymirror.RegistryMirror
proxyConfig *v1alpha1.ProxyConfiguration
namespace string
bootsOnDocker bool
hostNetwork bool
loadBalancer bool
stackService bool
dhcpRelay bool
docker Docker
filewriter filewriter.FileWriter
helm Helm
podCidrRange string
registryMirror *registrymirror.RegistryMirror
proxyConfig *v1alpha1.ProxyConfiguration
namespace string
loadBalancerInterface string
bootsOnDocker bool
hostNetwork bool
loadBalancer bool
stackService bool
dhcpRelay bool
}

type InstallOption func(s *Installer)
Expand Down Expand Up @@ -141,7 +143,7 @@ func (s *Installer) AddNoProxyIP(IP string) {
}

// 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, podCidrRange string, registryMirror *registrymirror.RegistryMirror, proxyConfig *v1alpha1.ProxyConfiguration) StackInstaller {
func NewInstaller(docker Docker, filewriter filewriter.FileWriter, helm Helm, namespace, podCidrRange, loadBalancerInterface string, registryMirror *registrymirror.RegistryMirror, proxyConfig *v1alpha1.ProxyConfiguration) StackInstaller {
return &Installer{
docker: docker,
filewriter: filewriter,
Expand All @@ -150,6 +152,7 @@ func NewInstaller(docker Docker, filewriter filewriter.FileWriter, helm Helm, na
proxyConfig: proxyConfig,
namespace: namespace,
podCidrRange: podCidrRange,
loadBalancerInterface: loadBalancerInterface,
}
}

Expand Down Expand Up @@ -177,7 +180,7 @@ func (s *Installer) Install(ctx context.Context, bundle releasev1alpha1.Tinkerbe
return fmt.Errorf("parsing hookOverride: %v", err)
}

valuesMap := s.createValuesOverride(bundle, bootEnv, tinkerbellIP, osiePath)
valuesMap := s.createValuesOverride(bundle, bootEnv, tinkerbellIP, s.loadBalancerInterface, osiePath)

values, err := yaml.Marshal(valuesMap)
if err != nil {
Expand Down Expand Up @@ -373,7 +376,7 @@ func (s *Installer) Upgrade(ctx context.Context, bundle releasev1alpha1.Tinkerbe
return fmt.Errorf("parsing hookOverride: %v", err)
}

valuesMap := s.createValuesOverride(bundle, bootEnv, tinkerbellIP, osiePath)
valuesMap := s.createValuesOverride(bundle, bootEnv, tinkerbellIP, s.loadBalancerInterface, osiePath)

values, err := yaml.Marshal(valuesMap)
if err != nil {
Expand Down Expand Up @@ -508,7 +511,7 @@ func (s *Installer) HasLegacyChart(ctx context.Context, bundle releasev1alpha1.T
}

// createValuesOverride generates the values override file to send to helm.
func (s *Installer) createValuesOverride(bundle releasev1alpha1.TinkerbellBundle, bootEnv []string, tinkerbellIP string, osiePath *url.URL) map[string]interface{} {
func (s *Installer) createValuesOverride(bundle releasev1alpha1.TinkerbellBundle, bootEnv []string, tinkerbellIP, loadBalancerInterface string, osiePath *url.URL) map[string]interface{} {
valuesMap := map[string]interface{}{
tink: map[string]interface{}{
controller: map[string]interface{}{
Expand Down Expand Up @@ -592,5 +595,9 @@ func (s *Installer) createValuesOverride(bundle releasev1alpha1.TinkerbellBundle
},
}

if loadBalancerInterface != "" {
valuesMap[stack].(map[string]interface{})[kubevip].(map[string]interface{})[kubevipInterface] = loadBalancerInterface
}

return valuesMap
}
28 changes: 14 additions & 14 deletions pkg/providers/tinkerbell/stack/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func TestTinkerbellStackInstallWithDifferentOptions(t *testing.T) {
folder, writer := test.NewWriter(t)
cluster := &types.Cluster{Name: "test"}
ctx := context.Background()
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", stackTest.registryMirror, stackTest.proxyConfig)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", stackTest.registryMirror, stackTest.proxyConfig)

generatedOverridesPath := filepath.Join(folder, "generated", overridesFileName)
if stackTest.registryMirror != nil && stackTest.registryMirror.Auth {
Expand Down Expand Up @@ -257,7 +257,7 @@ func TestTinkerbellStackUninstallLocalSucess(t *testing.T) {
writer := filewritermocks.NewMockFileWriter(mockCtrl)
ctx := context.Background()

s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, nil)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, nil)

docker.EXPECT().ForceRemove(ctx, boots)

Expand All @@ -274,7 +274,7 @@ func TestTinkerbellStackUninstallLocalFailure(t *testing.T) {
writer := filewritermocks.NewMockFileWriter(mockCtrl)
ctx := context.Background()

s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, nil)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, nil)

dockerError := "docker error"
expectedError := fmt.Sprintf("removing local boots container: %s", dockerError)
Expand All @@ -291,7 +291,7 @@ func TestTinkerbellStackCheckLocalBootsExistenceDoesNotExist(t *testing.T) {
writer := filewritermocks.NewMockFileWriter(mockCtrl)
ctx := context.Background()

s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, nil)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, nil)

docker.EXPECT().CheckContainerExistence(ctx, "boots").Return(true, nil)
docker.EXPECT().ForceRemove(ctx, "boots")
Expand All @@ -307,7 +307,7 @@ func TestTinkerbellStackCheckLocalBootsExistenceDoesExist(t *testing.T) {
writer := filewritermocks.NewMockFileWriter(mockCtrl)
ctx := context.Background()

s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, nil)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, nil)
expectedErrorMsg := "boots container already exists, delete the container manually"

docker.EXPECT().CheckContainerExistence(ctx, "boots").Return(true, nil)
Expand All @@ -323,7 +323,7 @@ func TestTinkerbellStackCheckLocalBootsExistenceDockerError(t *testing.T) {
writer := filewritermocks.NewMockFileWriter(mockCtrl)
ctx := context.Background()

s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, nil)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, nil)

docker.EXPECT().CheckContainerExistence(ctx, "boots").Return(false, nil)

Expand All @@ -344,7 +344,7 @@ func TestUpgrade(t *testing.T) {
helm.EXPECT().
UpgradeInstallChartWithValuesFile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, nil)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, nil)

err := s.Upgrade(ctx, getTinkBundle(), testIP, cluster.KubeconfigFile, "")
assert.NoError(t, err)
Expand Down Expand Up @@ -375,7 +375,7 @@ func TestUpgradeWithRegistryMirrorAuthError(t *testing.T) {
expectedErrorMsg := "invalid registry credentials"
helm.EXPECT().RegistryLogin(ctx, "1.2.3.4:443", "username", "password").Return(fmt.Errorf(expectedErrorMsg))

s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", registryMirror, nil)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", registryMirror, nil)

err := s.Upgrade(ctx, getTinkBundle(), testIP, cluster.KubeconfigFile, "")
assert.EqualError(t, err, expectedErrorMsg, "Error should be: %v, got: %v", expectedErrorMsg, err)
Expand All @@ -397,7 +397,7 @@ func TestUpdateStackInstallerNoProxyError(t *testing.T) {
NoProxy: noProxy,
}

s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, proxyConfiguration)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, proxyConfiguration)
s.AddNoProxyIP("2.3.4.5")

noProxy = append(noProxy, "2.3.4.5")
Expand Down Expand Up @@ -428,7 +428,7 @@ func TestUpgradeWithProxy(t *testing.T) {
},
}

s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, proxyConfiguration)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, proxyConfiguration)

err := s.Upgrade(ctx, getTinkBundle(), testIP, cluster.KubeconfigFile, "https://my-local-web-server/hook")
assert.NoError(t, err)
Expand All @@ -448,7 +448,7 @@ func TestUpgradeCRDsChart(t *testing.T) {
helm.EXPECT().
UpgradeInstallChartWithValuesFile(ctx, "tinkerbellCrds", fmt.Sprintf("oci://%s", "public.ecr.aws/eks-anywhere/tinkerbell/tinkerbell-crds"), helmChartVersion,
cluster.KubeconfigFile, constants.EksaSystemNamespace, "", gomock.Any())
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, nil)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, nil)

err := s.UpgradeInstallCRDs(ctx, getTinkBundle(), cluster.KubeconfigFile)
assert.NoError(t, err)
Expand All @@ -466,7 +466,7 @@ func TestLegacyUpgrade(t *testing.T) {
helm.EXPECT().
UpgradeInstallChartWithValuesFile(ctx, "tinkerbell-chart", fmt.Sprintf("oci://%s", "public.ecr.aws/eks-anywhere/tinkerbell/tinkerbell-chart"), helmChartVersion,
cluster.KubeconfigFile, "", "", gomock.Any())
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, nil)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, nil)

err := s.UpgradeLegacy(ctx, getTinkBundle(), cluster.KubeconfigFile)
assert.NoError(t, err)
Expand All @@ -485,7 +485,7 @@ func TestUninstall(t *testing.T) {
helm.EXPECT().
Uninstall(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
gomock.Any())
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, nil)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, nil)

err := s.Upgrade(ctx, getTinkBundle(), testIP, cluster.KubeconfigFile, "")
assert.NoError(t, err)
Expand All @@ -503,7 +503,7 @@ func TestHasLegacyChart(t *testing.T) {
cluster := &types.Cluster{Name: "test"}
ctx := context.Background()

s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", nil, nil)
s := stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, "192.168.0.0/16", "", nil, nil)
helm.EXPECT().ListCharts(ctx, cluster.KubeconfigFile, "tinkerbell-chart")

_, err := s.HasLegacyChart(ctx, getTinkBundle(), cluster.KubeconfigFile)
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/tinkerbell/tinkerbell.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func NewProvider(
clusterConfig: clusterConfig,
datacenterConfig: datacenterConfig,
machineConfigs: machineConfigs,
stackInstaller: stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, clusterConfig.Spec.ClusterNetwork.Pods.CidrBlocks[0], registrymirror.FromCluster(clusterConfig), proxyConfig),
stackInstaller: stack.NewInstaller(docker, writer, helm, constants.EksaSystemNamespace, datacenterConfig.Spec.LoadBalancerInterface, clusterConfig.Spec.ClusterNetwork.Pods.CidrBlocks[0], registrymirror.FromCluster(clusterConfig), proxyConfig),
providerKubectlClient: providerKubectlClient,
templateBuilder: &TemplateBuilder{
datacenterSpec: &datacenterConfig.Spec,
Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/tinkerbell/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func (p *Provider) validateMachineCfg(ctx context.Context, cluster *types.Cluste
return nil
}

// PreCoreComponentsUpgrade staisfies the Provider interface.
// PreCoreComponentsUpgrade satisfies the Provider interface.
func (p *Provider) PreCoreComponentsUpgrade(
ctx context.Context,
cluster *types.Cluster,
Expand Down

0 comments on commit f69414a

Please sign in to comment.