Skip to content

Commit

Permalink
fix: use Talos API client correctly (wrapped version)
Browse files Browse the repository at this point in the history
We should never directly use unwrapped client as it doesn't do filtering
for errors correctly. This wasn't that important in this particular
case, as client was connecting directly to the endpoint and it doesn't
set 'nodes' context, but it sets bad example.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Feb 18, 2021
1 parent aaf0e82 commit fe29dfd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
17 changes: 6 additions & 11 deletions controllers/taloscontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"time"

"github.com/go-logr/logr"
"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
cabptv1 "github.com/talos-systems/cluster-api-bootstrap-provider-talos/api/v1alpha3"
controlplanev1 "github.com/talos-systems/cluster-api-control-plane-provider-talos/api/v1alpha3"
Expand Down Expand Up @@ -432,27 +431,23 @@ func (r *TalosControlPlaneReconciler) scaleDownControlPlane(ctx context.Context,

r.Log.Info("Verifying etcd status", "machine", oldest.Name, "node", node.Name, "address", address)

svcs, err := c.MachineClient.ServiceList(ctx, &empty.Empty{})
svcs, err := c.ServiceInfo(ctx, "etcd")
if err != nil {
return ctrl.Result{RequeueAfter: 20 * time.Second}, err
}

for _, svc := range svcs.Messages[0].Services {
if svc.Id != "etcd" {
continue
}

if svc.State != "Finished" {
for _, svc := range svcs {
if svc.Service.State != "Finished" {
r.Log.Info("Forfeiting leadership", "machine", oldest.Status.NodeRef.Name)

_, err = c.MachineClient.EtcdForfeitLeadership(ctx, &machine.EtcdForfeitLeadershipRequest{})
_, err = c.EtcdForfeitLeadership(ctx, &machine.EtcdForfeitLeadershipRequest{})
if err != nil {
return ctrl.Result{RequeueAfter: 20 * time.Second}, err
}

r.Log.Info("Leaving etcd", "machine", oldest.Name, "node", node.Name, "address", address)

_, err = c.MachineClient.EtcdLeaveCluster(ctx, &machine.EtcdLeaveClusterRequest{})
err = c.EtcdLeaveCluster(ctx, &machine.EtcdLeaveClusterRequest{})
if err != nil {
return ctrl.Result{RequeueAfter: 20 * time.Second}, err
}
Expand All @@ -473,7 +468,7 @@ func (r *TalosControlPlaneReconciler) scaleDownControlPlane(ctx context.Context,
// at this point etcd has been stopped.
r.Log.Info("Shutting down node", "machine", oldest.Name, "node", node.Name, "address", address)

_, err = c.MachineClient.Shutdown(ctx, &empty.Empty{})
err = c.Shutdown(ctx)
if err != nil {
return ctrl.Result{RequeueAfter: 20 * time.Second}, err
}
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ go 1.13
require (
cloud.google.com/go v0.47.0 // indirect
github.com/go-logr/logr v0.1.0
github.com/golang/protobuf v1.4.3
github.com/onsi/ginkgo v1.12.1
github.com/onsi/gomega v1.10.1
github.com/pkg/errors v0.9.1
github.com/talos-systems/cluster-api-bootstrap-provider-talos v0.2.0-alpha.10
github.com/talos-systems/talos/pkg/machinery v0.0.0-20210216142802-8d7a36cc0cc2
github.com/talos-systems/talos/pkg/machinery v0.0.0-20210218160848-32d25885288f
k8s.io/api v0.17.9
k8s.io/apimachinery v0.17.9
k8s.io/apiserver v0.17.9
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,12 @@ github.com/talos-systems/net v0.2.1-0.20210121122956-005a94f8b36b h1:y3mBkTJdW7c
github.com/talos-systems/net v0.2.1-0.20210121122956-005a94f8b36b/go.mod h1:VreSAyRmxMtqussAHSKMKkJQa1YwBTSVfkmE4Jydam4=
github.com/talos-systems/os-runtime v0.0.0-20210126185717-734f1e1cee9e h1:HrAdgwnXhVr9LlWjpc+kejkLVUpTRKbNTAJe7H+kRXM=
github.com/talos-systems/os-runtime v0.0.0-20210126185717-734f1e1cee9e/go.mod h1:+E9CUVoYpReh0nhOEvFpy7pwLiyq0700WF03I06giyk=
github.com/talos-systems/os-runtime v0.0.0-20210216141502-28dd9aaf98d6 h1:a3QXMKocLKRDRYn8iBX02wMZGQBH2XgE3EBhYHF4xws=
github.com/talos-systems/os-runtime v0.0.0-20210216141502-28dd9aaf98d6/go.mod h1:+E9CUVoYpReh0nhOEvFpy7pwLiyq0700WF03I06giyk=
github.com/talos-systems/talos/pkg/machinery v0.0.0-20210216142802-8d7a36cc0cc2 h1:eA3i2v1ZGK59z+MZoaWu51zNRIrm4CNEY4XENOP+qYQ=
github.com/talos-systems/talos/pkg/machinery v0.0.0-20210216142802-8d7a36cc0cc2/go.mod h1:hhWsbfLrP53M03VRmJ5j92yimTHx0NBwngaXnvKkPE0=
github.com/talos-systems/talos/pkg/machinery v0.0.0-20210218160848-32d25885288f h1:tvKfcJWXxUSNeuVoHWW4qwYz4k4JuzySpFfe+Rt15mI=
github.com/talos-systems/talos/pkg/machinery v0.0.0-20210218160848-32d25885288f/go.mod h1:7xqrV27kGtf2On8mrFjhv6dlNBRvtYsr+1npSZXJDlc=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down Expand Up @@ -572,6 +576,7 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down

0 comments on commit fe29dfd

Please sign in to comment.