-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make eco recognize podTemplate changes #196
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
"github.com/go-logr/logr" | ||
etcdclient "go.etcd.io/etcd/client" | ||
v1 "k8s.io/api/core/v1" | ||
apiequality "k8s.io/apimachinery/pkg/api/equality" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
@@ -364,7 +365,7 @@ func (r *EtcdClusterReconciler) reconcile( | |
if isAllMembersStable(*members) { | ||
// The remaining operations can now be performed. In order: | ||
// * Remove surplus EtcdPeers | ||
// * Upgrade Etcd | ||
// * Upgrade Etcd or make changes that need rolling deployment | ||
// * Scale-up | ||
// * Scale-down | ||
// | ||
|
@@ -404,13 +405,19 @@ func (r *EtcdClusterReconciler) reconcile( | |
} | ||
} | ||
|
||
// Upgrade Etcd. | ||
// Remove EtcdPeers which have a different version than EtcdCluster; in reverse name order, one-at-a-time. | ||
// The EtcdPeers will be recreated in the next reconcile, with the correct version. | ||
if peer := nextOutdatedPeer(cluster, peers); peer != nil { | ||
if peer.Spec.Version == cluster.Spec.Version { | ||
log.Info("Waiting for EtcdPeer to report expected server version", "etcdpeer-name", peer.Name) | ||
return result, nil, nil | ||
// Upgrade Etcd or incorporate changes. | ||
// Remove EtcdPeers which have a different version than EtcdCluster; in reverse name order, one-at-a-time. | ||
// The EtcdPeers will be recreated in the next reconcile, with the correct state. | ||
if peer, reason := nextOutdatedPeer(cluster, peers); peer != nil { | ||
if reason == outdatedVersion { | ||
if peer.Spec.Version == cluster.Spec.Version { | ||
// The peer returned by nextOutdatedPeer is outdated based on the status.Version but the version | ||
// in the spec is already matching the desired cluster version. This means the peer spec is | ||
// already up to date and we need to wait until the status is updated. Once the status is up to date | ||
// nextOutdatedPeer will return the next outdated peer. | ||
log.Info("Waiting for EtcdPeer to report expected server version", "etcdpeer-name", peer.Name) | ||
return result, nil, nil | ||
} | ||
} | ||
if !peer.DeletionTimestamp.IsZero() { | ||
log.Info("Waiting for EtcdPeer be deleted", "etcdpeer-name", peer.Name) | ||
|
@@ -473,10 +480,17 @@ func (r *EtcdClusterReconciler) reconcile( | |
return result, nil, nil | ||
} | ||
|
||
// nextOutdatedPeer returns an EtcdPeer which has a different version than the | ||
// EtcdCluster. | ||
type outdatedReason int | ||
|
||
const ( | ||
outdatedVersion outdatedReason = iota + 1 | ||
outdatedPodTemplate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this using the defaulting to infer a type of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure I fully understand your question. This is just to have a constant to differentiate between the different outdated reasons. The enumeration starts with 1 on purpose so that a possible use of a default value ( |
||
) | ||
|
||
// nextOutdatedPeer returns an EtcdPeer which is different to the spec of the | ||
// EtcdCluster. It also returns the reason why it's outdated. | ||
// It searches EtcdPeers in reverse name order. | ||
func nextOutdatedPeer(cluster *etcdv1alpha1.EtcdCluster, peers *etcdv1alpha1.EtcdPeerList) *etcdv1alpha1.EtcdPeer { | ||
func nextOutdatedPeer(cluster *etcdv1alpha1.EtcdCluster, peers *etcdv1alpha1.EtcdPeerList) (*etcdv1alpha1.EtcdPeer, outdatedReason) { | ||
peerNames := make([]string, len(peers.Items)) | ||
peersByName := map[string]etcdv1alpha1.EtcdPeer{} | ||
for i, peer := range peers.Items { | ||
|
@@ -491,10 +505,13 @@ func nextOutdatedPeer(cluster *etcdv1alpha1.EtcdCluster, peers *etcdv1alpha1.Etc | |
continue | ||
} | ||
if peer.Status.ServerVersion != cluster.Spec.Version { | ||
return peer.DeepCopy() | ||
return peer.DeepCopy(), outdatedVersion | ||
} | ||
if !apiequality.Semantic.DeepEqual(peer.Spec.PodTemplate, cluster.Spec.PodTemplate) { | ||
return peer.DeepCopy(), outdatedPodTemplate | ||
} | ||
} | ||
return nil | ||
return nil, 0 | ||
} | ||
|
||
func hasTooFewPeers(cluster *etcdv1alpha1.EtcdCluster, peers *etcdv1alpha1.EtcdPeerList) bool { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe put a comment here to elaborate. Just something to explain that this branch occurs when we've updated the Pod specification but the etcd peer still shows as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done