From 8c135ab556dcad2aca9c859ca12a0b21b2552249 Mon Sep 17 00:00:00 2001 From: dalcouffe Date: Wed, 8 Nov 2023 09:58:02 -0700 Subject: [PATCH] Issue 6985: Bare metal upgrade should honor the TinkerbellDatacenterConfig.skipLoadBalancerDeployment config value (#6990) Co-authored-by: doug.alcouffe --- pkg/providers/tinkerbell/stack/mocks/stack.go | 13 +++++++++---- pkg/providers/tinkerbell/stack/stack.go | 11 ++++++++--- .../tinkerbell/stack/testdata/expected_upgrade.yaml | 1 + .../stack/testdata/expected_upgrade_with_proxy.yaml | 1 + pkg/providers/tinkerbell/upgrade.go | 4 ++++ pkg/providers/tinkerbell/upgrade_test.go | 5 +++++ 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/pkg/providers/tinkerbell/stack/mocks/stack.go b/pkg/providers/tinkerbell/stack/mocks/stack.go index dfa685d9c849..4f5acc4b33fc 100644 --- a/pkg/providers/tinkerbell/stack/mocks/stack.go +++ b/pkg/providers/tinkerbell/stack/mocks/stack.go @@ -252,15 +252,20 @@ func (mr *MockStackInstallerMockRecorder) UninstallLocal(ctx interface{}) *gomoc } // Upgrade mocks base method. -func (m *MockStackInstaller) Upgrade(arg0 context.Context, arg1 v1alpha1.TinkerbellBundle, tinkerbellIP, kubeconfig, hookOverride string) error { +func (m *MockStackInstaller) Upgrade(arg0 context.Context, arg1 v1alpha1.TinkerbellBundle, tinkerbellIP, kubeconfig, hookOverride string, opts ...stack.InstallOption) error { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Upgrade", arg0, arg1, tinkerbellIP, kubeconfig, hookOverride) + varargs := []interface{}{arg0, arg1, tinkerbellIP, kubeconfig, hookOverride} + for _, a := range opts { + varargs = append(varargs, a) + } + ret := m.ctrl.Call(m, "Upgrade", varargs...) ret0, _ := ret[0].(error) return ret0 } // Upgrade indicates an expected call of Upgrade. -func (mr *MockStackInstallerMockRecorder) Upgrade(arg0, arg1, tinkerbellIP, kubeconfig, hookOverride interface{}) *gomock.Call { +func (mr *MockStackInstallerMockRecorder) Upgrade(arg0, arg1, tinkerbellIP, kubeconfig, hookOverride interface{}, opts ...interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Upgrade", reflect.TypeOf((*MockStackInstaller)(nil).Upgrade), arg0, arg1, tinkerbellIP, kubeconfig, hookOverride) + varargs := append([]interface{}{arg0, arg1, tinkerbellIP, kubeconfig, hookOverride}, opts...) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Upgrade", reflect.TypeOf((*MockStackInstaller)(nil).Upgrade), varargs...) } diff --git a/pkg/providers/tinkerbell/stack/stack.go b/pkg/providers/tinkerbell/stack/stack.go index e9b0253999d8..dd6ee017df74 100644 --- a/pkg/providers/tinkerbell/stack/stack.go +++ b/pkg/providers/tinkerbell/stack/stack.go @@ -58,7 +58,7 @@ type StackInstaller interface { CleanupLocalBoots(ctx context.Context, forceCleanup bool) error Install(ctx context.Context, bundle releasev1alpha1.TinkerbellBundle, tinkerbellIP, kubeconfig, hookOverride string, opts ...InstallOption) error UninstallLocal(ctx context.Context) error - Upgrade(_ context.Context, _ releasev1alpha1.TinkerbellBundle, tinkerbellIP, kubeconfig string, hookOverride string) error + Upgrade(_ context.Context, _ releasev1alpha1.TinkerbellBundle, tinkerbellIP, kubeconfig, hookOverride string, opts ...InstallOption) error AddNoProxyIP(IP string) GetNamespace() string } @@ -378,9 +378,13 @@ func (s *Installer) authenticateHelmRegistry(ctx context.Context) error { } // Upgrade the Tinkerbell stack using images specified in bundle. -func (s *Installer) Upgrade(ctx context.Context, bundle releasev1alpha1.TinkerbellBundle, tinkerbellIP, kubeconfig string, hookOverride string) error { +func (s *Installer) Upgrade(ctx context.Context, bundle releasev1alpha1.TinkerbellBundle, tinkerbellIP, kubeconfig string, hookOverride string, opts ...InstallOption) error { logger.V(6).Info("Upgrading Tinkerbell helm chart") + for _, option := range opts { + option(s) + } + bootEnv := s.getBootsEnv(bundle.TinkerbellStack, tinkerbellIP) osiePath, err := getURIDir(bundle.TinkerbellStack.Hook.Initramfs.Amd.URI) @@ -421,7 +425,8 @@ func (s *Installer) Upgrade(ctx context.Context, bundle releasev1alpha1.Tinkerbe image: bundle.TinkerbellStack.Rufio.URI, }, kubevip: map[string]interface{}{ - image: bundle.KubeVip.URI, + image: bundle.KubeVip.URI, + deploy: s.loadBalancer, }, envoy: map[string]interface{}{ image: bundle.Envoy.URI, diff --git a/pkg/providers/tinkerbell/stack/testdata/expected_upgrade.yaml b/pkg/providers/tinkerbell/stack/testdata/expected_upgrade.yaml index d39d505805a5..1ac5a188028d 100755 --- a/pkg/providers/tinkerbell/stack/testdata/expected_upgrade.yaml +++ b/pkg/providers/tinkerbell/stack/testdata/expected_upgrade.yaml @@ -21,6 +21,7 @@ hegel: value: 192.168.0.0/16 image: public.ecr.aws/eks-anywhere/hegel:latest kubevip: + deploy: false image: public.ecr.aws/eks-anywhere/kube-vip:latest namespace: eksa-system rufio: diff --git a/pkg/providers/tinkerbell/stack/testdata/expected_upgrade_with_proxy.yaml b/pkg/providers/tinkerbell/stack/testdata/expected_upgrade_with_proxy.yaml index b191d655fc91..e3acca1366bf 100755 --- a/pkg/providers/tinkerbell/stack/testdata/expected_upgrade_with_proxy.yaml +++ b/pkg/providers/tinkerbell/stack/testdata/expected_upgrade_with_proxy.yaml @@ -22,6 +22,7 @@ hegel: value: 192.168.0.0/16 image: public.ecr.aws/eks-anywhere/hegel:latest kubevip: + deploy: false image: public.ecr.aws/eks-anywhere/kube-vip:latest namespace: eksa-system rufio: diff --git a/pkg/providers/tinkerbell/upgrade.go b/pkg/providers/tinkerbell/upgrade.go index e6dda310cbd0..1b37b777ffaf 100644 --- a/pkg/providers/tinkerbell/upgrade.go +++ b/pkg/providers/tinkerbell/upgrade.go @@ -17,6 +17,7 @@ import ( "github.com/aws/eks-anywhere/pkg/constants" "github.com/aws/eks-anywhere/pkg/providers/tinkerbell/hardware" "github.com/aws/eks-anywhere/pkg/providers/tinkerbell/rufiounreleased" + "github.com/aws/eks-anywhere/pkg/providers/tinkerbell/stack" "github.com/aws/eks-anywhere/pkg/types" "github.com/aws/eks-anywhere/pkg/utils/yaml" ) @@ -456,6 +457,9 @@ func (p *Provider) PreCoreComponentsUpgrade( p.datacenterConfig.Spec.TinkerbellIP, cluster.KubeconfigFile, p.datacenterConfig.Spec.HookImagesURLPath, + stack.WithLoadBalancerEnabled( + len(clusterSpec.Cluster.Spec.WorkerNodeGroupConfigurations) != 0 && // load balancer is handled by kube-vip in control plane nodes + !p.datacenterConfig.Spec.SkipLoadBalancerDeployment), // configure load balancer based on datacenterConfig.Spec.SkipLoadBalancerDeployment ) if err != nil { return fmt.Errorf("upgrading stack: %v", err) diff --git a/pkg/providers/tinkerbell/upgrade_test.go b/pkg/providers/tinkerbell/upgrade_test.go index bc59edf93da8..5fe74460f4ea 100644 --- a/pkg/providers/tinkerbell/upgrade_test.go +++ b/pkg/providers/tinkerbell/upgrade_test.go @@ -82,6 +82,7 @@ func TestProviderPreCoreComponentsUpgrade_StackUpgradeError(t *testing.T) { tconfig.DatacenterConfig.Spec.TinkerbellIP, tconfig.Management.KubeconfigFile, tconfig.DatacenterConfig.Spec.HookImagesURLPath, + gomock.Any(), ). Return(errors.New(expect)) @@ -108,6 +109,7 @@ func TestProviderPreCoreComponentsUpgrade_HasBaseboardManagementCRDError(t *test tconfig.TinkerbellIP, tconfig.Management.KubeconfigFile, tconfig.DatacenterConfig.Spec.HookImagesURLPath, + gomock.Any(), ). Return(nil) @@ -143,6 +145,7 @@ func TestProviderPreCoreComponentsUpgrade_NoBaseboardManagementCRD(t *testing.T) tconfig.TinkerbellIP, tconfig.Management.KubeconfigFile, tconfig.DatacenterConfig.Spec.HookImagesURLPath, + gomock.Any(), ). Return(nil) @@ -454,6 +457,7 @@ func TestProviderPreCoreComponentsUpgrade_RufioConversions(t *testing.T) { tconfig.DatacenterConfig.Spec.TinkerbellIP, tconfig.Management.KubeconfigFile, tconfig.DatacenterConfig.Spec.HookImagesURLPath, + gomock.Any(), ). Return(nil) tconfig.KubeClient.EXPECT(). @@ -624,6 +628,7 @@ func (t *PreCoreComponentsUpgradeTestConfig) WithStackUpgrade() *PreCoreComponen t.TinkerbellIP, t.Management.KubeconfigFile, t.DatacenterConfig.Spec.HookImagesURLPath, + gomock.Any(), ). Return(nil) t.KubeClient.EXPECT().