From 9a479062aaf3b61116e529817be9fcf28c4fbce3 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Fri, 24 Jul 2026 17:33:14 +0200 Subject: [PATCH 1/2] docs: print deprecated Load Balancer Type information if present --- go.mod | 2 ++ go.sum | 4 ++-- internal/cmd/loadbalancer/change_type.go | 2 ++ internal/cmd/loadbalancer/create.go | 20 ++++++++++++++------ internal/cmd/loadbalancer/texts.go | 22 ++++++++++++++++++++++ 5 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 internal/cmd/loadbalancer/texts.go diff --git a/go.mod b/go.mod index fc106a9d8..e9562fdfa 100644 --- a/go.mod +++ b/go.mod @@ -63,3 +63,5 @@ require ( google.golang.org/protobuf v1.36.8 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) + +replace github.com/hetznercloud/hcloud-go/v2 => github.com/hetznercloud/hcloud-go/v2 v2.46.1-0.20260724152100-ac1f8a155a9c diff --git a/go.sum b/go.sum index 70ff27003..cedc74835 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/guptarohit/asciigraph v0.10.0 h1:LmbFXSHZOhaQxjJYexdRk7TzoC5sJ7vDTEjP1YUbKgY= github.com/guptarohit/asciigraph v0.10.0/go.mod h1:dYl5wwK4gNsnFf9Zp+l06rFiDZ5YtXM6x7SRWZ3KGag= -github.com/hetznercloud/hcloud-go/v2 v2.45.0 h1:0TnAwVUK/DJzEacOcY6IcbISJOIqldUjvaFpuVz8Mbk= -github.com/hetznercloud/hcloud-go/v2 v2.45.0/go.mod h1:pdG7fFGlYsCAaJ9r0QOIF0O6wQcpbJxT2VT8aP6XlIc= +github.com/hetznercloud/hcloud-go/v2 v2.46.1-0.20260724152100-ac1f8a155a9c h1:ZaU1c/ZwuML55mUaiCLaAN5dQli/Tbm/O6WrVcQFDxw= +github.com/hetznercloud/hcloud-go/v2 v2.46.1-0.20260724152100-ac1f8a155a9c/go.mod h1:pdG7fFGlYsCAaJ9r0QOIF0O6wQcpbJxT2VT8aP6XlIc= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= diff --git a/internal/cmd/loadbalancer/change_type.go b/internal/cmd/loadbalancer/change_type.go index 8c81a6361..6fb638227 100644 --- a/internal/cmd/loadbalancer/change_type.go +++ b/internal/cmd/loadbalancer/change_type.go @@ -44,6 +44,8 @@ var ChangeTypeCmd = base.Cmd{ return fmt.Errorf("Load Balancer Type not found: %s", loadBalancerTypeIDOrName) } + cmd.Print(deprecatedLoadBalancerTypeWarning(loadBalancerType)) + opts := hcloud.LoadBalancerChangeTypeOpts{ LoadBalancerType: loadBalancerType, } diff --git a/internal/cmd/loadbalancer/create.go b/internal/cmd/loadbalancer/create.go index 0c5f73daa..bbf35a1c9 100644 --- a/internal/cmd/loadbalancer/create.go +++ b/internal/cmd/loadbalancer/create.go @@ -52,7 +52,7 @@ var CreateCmd = base.CreateCmd[*hcloud.LoadBalancer]{ }, Run: func(s state.State, cmd *cobra.Command, _ []string) (*hcloud.LoadBalancer, any, error) { name, _ := cmd.Flags().GetString("name") - serverType, _ := cmd.Flags().GetString("type") + loadBalancerTypeName, _ := cmd.Flags().GetString("type") algorithmType, _ := cmd.Flags().GetString("algorithm-type") location, _ := cmd.Flags().GetString("location") networkZone, _ := cmd.Flags().GetString("network-zone") @@ -65,12 +65,20 @@ var CreateCmd = base.CreateCmd[*hcloud.LoadBalancer]{ return nil, nil, err } + loadBalancerType, _, err := s.Client().LoadBalancerType().Get(s, loadBalancerTypeName) + if err != nil { + return nil, nil, err + } + if loadBalancerType == nil { + return nil, nil, fmt.Errorf("Load Balancer Type not found: %s", loadBalancerTypeName) + } + + cmd.Print(deprecatedLoadBalancerTypeWarning(loadBalancerType)) + createOpts := hcloud.LoadBalancerCreateOpts{ - Name: name, - LoadBalancerType: &hcloud.LoadBalancerType{ - Name: serverType, - }, - Labels: labels, + Name: name, + LoadBalancerType: loadBalancerType, + Labels: labels, } if algorithmType != "" { createOpts.Algorithm = &hcloud.LoadBalancerAlgorithm{Type: hcloud.LoadBalancerAlgorithmType(algorithmType)} diff --git a/internal/cmd/loadbalancer/texts.go b/internal/cmd/loadbalancer/texts.go new file mode 100644 index 000000000..901242ec9 --- /dev/null +++ b/internal/cmd/loadbalancer/texts.go @@ -0,0 +1,22 @@ +package loadbalancer + +import ( + "fmt" + + "github.com/hetznercloud/hcloud-go/v2/hcloud" + "github.com/hetznercloud/hcloud-go/v2/hcloud/exp/deprecationutil" +) + +const ChangeDeprecatedLoadBalancerTypeMessage = `Existing Load Balancers of that plan will ` + + `continue to work as before and no action is required on your part. ` + + `It is possible to migrate this Load Balancer to another Load Balancer Type by using ` + + `the "hcloud load-balancer change-type" command.` + +func deprecatedLoadBalancerTypeWarning(loadBalancerType *hcloud.LoadBalancerType) string { + message, _ := deprecationutil.LoadBalancerTypeMessage(loadBalancerType) + if message == "" { + return "" + } + + return fmt.Sprintf("Attention: %s. %s\n\n", message, ChangeDeprecatedLoadBalancerTypeMessage) +} From b32a33db00ec7e4fc6474c102344ee7eba3796cb Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Fri, 24 Jul 2026 17:48:55 +0200 Subject: [PATCH 2/2] fix test --- internal/cmd/loadbalancer/create_test.go | 9 +++++++++ internal/cmd/loadbalancer/testdata/create_response.json | 1 + 2 files changed, 10 insertions(+) diff --git a/internal/cmd/loadbalancer/create_test.go b/internal/cmd/loadbalancer/create_test.go index 7be4a8c05..4c37b6b09 100644 --- a/internal/cmd/loadbalancer/create_test.go +++ b/internal/cmd/loadbalancer/create_test.go @@ -25,6 +25,9 @@ func TestCreate(t *testing.T) { cmd := loadbalancer.CreateCmd.CobraCommand(fx.State()) fx.ExpectEnsureToken() + fx.Client.LoadBalancerTypeClient.EXPECT(). + Get(gomock.Any(), "lb11"). + Return(&hcloud.LoadBalancerType{Name: "lb11"}, nil, nil) fx.Client.LoadBalancerClient.EXPECT(). Create(gomock.Any(), hcloud.LoadBalancerCreateOpts{ Name: "myLoadBalancer", @@ -88,6 +91,9 @@ func TestCreateJSON(t *testing.T) { Targets: []hcloud.LoadBalancerTarget{}, } + fx.Client.LoadBalancerTypeClient.EXPECT(). + Get(gomock.Any(), "lb11"). + Return(&hcloud.LoadBalancerType{Name: "lb11"}, nil, nil) fx.Client.LoadBalancerClient.EXPECT(). Create(gomock.Any(), hcloud.LoadBalancerCreateOpts{ Name: "myLoadBalancer", @@ -132,6 +138,9 @@ func TestCreateProtection(t *testing.T) { }, } + fx.Client.LoadBalancerTypeClient.EXPECT(). + Get(gomock.Any(), "lb11"). + Return(&hcloud.LoadBalancerType{Name: "lb11"}, nil, nil) fx.Client.LoadBalancerClient.EXPECT(). Create(gomock.Any(), hcloud.LoadBalancerCreateOpts{ Name: "myLoadBalancer", diff --git a/internal/cmd/loadbalancer/testdata/create_response.json b/internal/cmd/loadbalancer/testdata/create_response.json index 3027880d9..1f30b7130 100644 --- a/internal/cmd/loadbalancer/testdata/create_response.json +++ b/internal/cmd/loadbalancer/testdata/create_response.json @@ -10,6 +10,7 @@ "labels": {}, "load_balancer_type": { "deprecated": null, + "deprecation": null, "description": "", "id": 0, "max_assigned_certificates": 0,