Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/v1alpha1/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (o *EtcdCluster) ValidateUpdate(old runtime.Object) error {
// Overwrite the fields which are allowed to change
oldO.Spec.Replicas = o.Spec.Replicas
oldO.Spec.Version = o.Spec.Version
oldO.Spec.PodTemplate = o.Spec.PodTemplate

if diff := cmp.Diff(oldO.Spec, o.Spec); diff != "" {
return fmt.Errorf("Unsupported changes: (- current, + new) %s", diff)
Expand Down
14 changes: 0 additions & 14 deletions api/v1alpha1/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,6 @@ func TestEtcdCluster_ValidateUpdate(t *testing.T) {
},
err: "^Unsupported changes:",
},
{
// TODO Support pod annotation modification https://github.com/improbable-eng/etcd-cluster-operator/issues/109
name: "ModifyPodSpecAnnotation",
modifier: func(o *v1alpha1.EtcdCluster) {
o.Spec.PodTemplate = &v1alpha1.EtcdPodTemplateSpec{
Metadata: &v1alpha1.EtcdPodTemplateObjectMeta{
Annotations: map[string]string{
"new-annotation": "some-value",
},
},
}
},
err: "^Unsupported changes:",
},
{
name: "UnsupportedChange/StorageClassName",
modifier: func(o *v1alpha1.EtcdCluster) {
Expand Down
35 changes: 24 additions & 11 deletions controllers/etcdcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -404,13 +405,15 @@ func (r *EtcdClusterReconciler) reconcile(
}
}

// Upgrade Etcd.
// 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 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
// 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 {
log.Info("Waiting for EtcdPeer to report expected server version", "etcdpeer-name", peer.Name)
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return result, nil, nil
}
}
if !peer.DeletionTimestamp.IsZero() {
log.Info("Waiting for EtcdPeer be deleted", "etcdpeer-name", peer.Name)
Expand Down Expand Up @@ -473,10 +476,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this using the defaulting to infer a type of outdatedReason and a value of 0?

Copy link
Author

Choose a reason for hiding this comment

The 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 (0) doesn't accidentally signal a specific reason where there is none.

)

// 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 {
Expand All @@ -491,10 +501,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 {
Expand Down