Skip to content

Commit 3d8b85c

Browse files
committed
fix cluster client creation, replace panics with error returns
1 parent 33d925a commit 3d8b85c

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

cmd/app/commandline.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
type Flags struct {
3131
Kubeconfig string
32+
ClusterDomain string
3233
MetricsAddress string
3334
ProbeAddress string
3435
LeaderElection bool
@@ -47,6 +48,7 @@ func ParseCmdLine() Flags {
4748
pflag.CommandLine = pflag.NewFlagSet(os.Args[0], pflag.ContinueOnError)
4849

4950
pflag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
51+
pflag.String("cluster-domain", "cluster.local", "The cluster domain configured in kube-dns")
5052
pflag.String("metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
5153
pflag.String("health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
5254
pflag.Bool("leader-elect", false, "Enable leader election for controller manager. "+
@@ -78,6 +80,7 @@ func ParseCmdLine() Flags {
7880

7981
return Flags{
8082
Kubeconfig: viper.GetString("kubeconfig"),
83+
ClusterDomain: viper.GetString("cluster-domain"),
8184
MetricsAddress: viper.GetString("metrics-bind-address"),
8285
ProbeAddress: viper.GetString("health-probe-bind-address"),
8386
LeaderElection: viper.GetBool("leader-elect"),

internal/controller/etcdcluster_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -706,23 +706,23 @@ func (r *EtcdClusterReconciler) createClusterFromScratch(ctx context.Context, st
706706
// TODO!
707707
// nolint:unused
708708
func (r *EtcdClusterReconciler) scaleUpFromZero(ctx context.Context) error {
709-
panic("not yet implemented")
709+
return fmt.Errorf("not yet implemented")
710710
}
711711

712712
// TODO!
713713
// nolint:unused
714714
func (r *EtcdClusterReconciler) createOrUpdateClusterStateConfigMap(ctx context.Context) error {
715-
panic("not yet implemented")
715+
return fmt.Errorf("not yet implemented")
716716
}
717717

718718
// TODO!
719719
// nolint:unused
720720
func (r *EtcdClusterReconciler) createOrUpdateStatefulSet(ctx context.Context) error {
721-
panic("not yet implemented")
721+
return fmt.Errorf("not yet implemented")
722722
}
723723

724724
// TODO!
725725
// nolint:unused
726726
func (r *EtcdClusterReconciler) promoteLearners(ctx context.Context) error {
727-
panic("not yet implemented")
727+
return fmt.Errorf("not yet implemented")
728728
}

internal/controller/factory/etcd_client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/aenix-io/etcd-operator/api/v1alpha1"
8+
"github.com/spf13/viper"
89
clientv3 "go.etcd.io/etcd/client/v3"
910
v1 "k8s.io/api/core/v1"
1011
"k8s.io/apimachinery/pkg/types"
@@ -56,7 +57,7 @@ func configFromCluster(ctx context.Context, cluster *v1alpha1.EtcdCluster, cli c
5657
}
5758
}
5859
for name := range names {
59-
urls = append(urls, fmt.Sprintf("%s:%s", name, "2379"))
60+
urls = append(urls, fmt.Sprintf("%s.%s.%s.svc.%s:%s", name, ep.Name, cluster.Namespace, viper.GetString("cluster-domain"), "2379"))
6061
}
6162

6263
return clientv3.Config{Endpoints: urls}, nil

internal/controller/observables.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (o *observables) setClusterID() {
5252
// Also if members have different opinions on the list of members, this is
5353
// also a splitbrain.
5454
func (o *observables) inSplitbrain() bool {
55-
return o.clusterIDsAllEqual() && o.memberListsAllEqual()
55+
return !o.clusterIDsAllEqual() || !o.memberListsAllEqual()
5656
}
5757

5858
func (o *observables) clusterIDsAllEqual() bool {
@@ -184,12 +184,22 @@ func (o *observables) statefulSetReady() bool {
184184
return o.statefulSet.Status.ReadyReplicas == *o.statefulSet.Spec.Replicas
185185
}
186186

187-
// TODO:
188187
func (o *observables) clusterHasQuorum() bool {
189-
return false
188+
size := len(o.etcdStatuses)
189+
membersInQuorum := size
190+
for i := range o.etcdStatuses {
191+
if o.etcdStatuses[i].endpointStatus == nil || o.etcdStatuses[i].endpointStatus.Leader == 0 {
192+
membersInQuorum--
193+
}
194+
}
195+
return membersInQuorum*2 > size
190196
}
191197

192-
// TODO:
193198
func (o *observables) hasLearners() bool {
199+
for i := range o.etcdStatuses {
200+
if stat := o.etcdStatuses[i].endpointStatus; stat != nil && stat.IsLearner {
201+
return true
202+
}
203+
}
194204
return false
195205
}

0 commit comments

Comments
 (0)