Skip to content

Commit

Permalink
Added predicates to the controller manager with option reconcile only…
Browse files Browse the repository at this point in the history
… if annotation present.
  • Loading branch information
I308301 committed Mar 25, 2020
1 parent 5df592a commit acd3dd1
Show file tree
Hide file tree
Showing 517 changed files with 93,145 additions and 104 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/etcd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ type LastOperation struct {

// EtcdStatus defines the observed state of Etcd
type EtcdStatus struct {
// ObservedGeneration is the most recent generation observedfor this resource.
// +optional
ObserverdGeneration *int64 `json:"observedGeneration,omitempty"`
// +optional
Etcd CrossVersionObjectReference `json:"etcd,omitempty"`
// +optional
Expand Down
3 changes: 0 additions & 3 deletions charts/etcd/templates/etcd-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ spec:
matchLabels:
name: etcd
instance: {{ .Values.name }}
{{- if .Values.labels }}
{{ toYaml .Values.labels | indent 6 }}
{{- end }}
template:
metadata:
annotations:
Expand Down
36 changes: 25 additions & 11 deletions controllers/etcd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/gardener/etcd-druid/pkg/utils"

kubernetes "github.com/gardener/etcd-druid/pkg/client/kubernetes"
extensionspredicate "github.com/gardener/gardener-extensions/pkg/predicate"
"github.com/gardener/gardener/pkg/utils/imagevector"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -50,6 +51,7 @@ import (
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)

var (
Expand Down Expand Up @@ -179,6 +181,9 @@ func (r *EtcdReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
if !reflect.DeepEqual(etcd.Spec, etcdCopy.Spec) {
etcdCopy.Spec = etcd.Spec
}

etcdCopy.Status.ObserverdGeneration = &etcdCopy.Generation

logger.Infof("Reconciling etcd: %s/%s", etcd.GetNamespace(), etcd.GetName())
if !etcdCopy.DeletionTimestamp.IsZero() {
logger.Infof("Deletion timestamp set for etcd: %s", etcd.GetName())
Expand Down Expand Up @@ -268,8 +273,8 @@ func (r *EtcdReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
logger.Infof("Successfully reconciled etcd: %s", etcd.GetName())

return ctrl.Result{
Requeue: true,
RequeueAfter: time.Minute * 5,
Requeue: false,
//RequeueAfter: time.Minute * 5,
}, nil
}

Expand Down Expand Up @@ -966,6 +971,7 @@ func (r *EtcdReconciler) updateEtcdStatus(etcdCopy, etcd *druidv1alpha1.Etcd, sv
etcdCopy.Status.UpdatedReplicas = ss.Status.UpdatedReplicas
etcdCopy.Status.Ready = (ss.Status.ReadyReplicas == ss.Status.Replicas)
etcdCopy.Status.ServiceName = &svcName
etcdCopy.Status.LastError = nil

if err := r.Status().Update(context.TODO(), etcdCopy); err != nil && !errors.IsNotFound(err) {
return err
Expand All @@ -983,15 +989,6 @@ func convertConditionsToEtcd(condition *appsv1.StatefulSetCondition) druidv1alph
}
}

// SetupWithManager sets up manager with a new controller and r as the reconcile.Reconciler
func (r *EtcdReconciler) SetupWithManager(mgr ctrl.Manager, workers int) error {
return ctrl.NewControllerManagedBy(mgr).WithOptions(controller.Options{
MaxConcurrentReconciles: workers,
}).For(&druidv1alpha1.Etcd{}).
Owns(&appsv1.StatefulSet{}).
Complete(r)
}

func (r *EtcdReconciler) claimStatefulSets(etcd *druidv1alpha1.Etcd, selector labels.Selector, ss *appsv1.StatefulSetList) ([]*appsv1.StatefulSet, error) {
// If any adoptions are attempted, we should first recheck for deletion with
// an uncached quorum read sometime after listing Machines (see #42639).
Expand Down Expand Up @@ -1045,3 +1042,20 @@ func (r *EtcdReconciler) claimConfigMaps(etcd *druidv1alpha1.Etcd, selector labe
cm := NewEtcdDruidRefManager(r, etcd, selector, etcdGVK, canAdoptFunc)
return cm.ClaimConfigMaps(ss)
}

// SetupWithManager sets up manager with a new controller and r as the reconcile.Reconciler
func (r *EtcdReconciler) SetupWithManager(mgr ctrl.Manager, workers int, ignoreOperationAnnotation bool) error {
builder := ctrl.NewControllerManagedBy(mgr).WithOptions(controller.Options{
MaxConcurrentReconciles: workers,
})
if !ignoreOperationAnnotation {
builder = builder.WithEventFilter(extensionspredicate.HasOperationAnnotation())
}
return builder.
WithEventFilter(predicate.GenerationChangedPredicate{}).
For(&druidv1alpha1.Etcd{}).
Owns(&appsv1.StatefulSet{}).
Owns(&v1.Service{}).
Owns(&v1.ConfigMap{}).
Complete(r)
}
28 changes: 3 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,15 @@ module github.com/gardener/etcd-druid
go 1.12

require (
cloud.google.com/go v0.50.0 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/gardener/gardener v1.1.2
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7 // indirect
github.com/imdario/mergo v0.3.8 // indirect
github.com/json-iterator/go v1.1.9 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.5.0
github.com/prometheus/client_golang v1.3.0 // indirect
github.com/gardener/gardener-extensions v1.5.0
github.com/onsi/ginkgo v1.10.1
github.com/onsi/gomega v1.7.0
github.com/sirupsen/logrus v1.4.2
go.uber.org/atomic v1.5.1 // indirect
go.uber.org/multierr v1.4.0 // indirect
go.uber.org/zap v1.13.0 // indirect
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876 // indirect
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6 // indirect
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
golang.org/x/tools v0.0.0-20191230220329-2aa90c603ae3 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
google.golang.org/appengine v1.6.5 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
k8s.io/api v0.17.0
k8s.io/apiextensions-apiserver v0.17.0 // indirect
k8s.io/apimachinery v0.17.0
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/helm v2.16.1+incompatible
k8s.io/klog v1.0.0 // indirect
k8s.io/utils v0.0.0-20191218082557-f07c713de883 // indirect
sigs.k8s.io/controller-runtime v0.4.0
)

Expand Down
Loading

0 comments on commit acd3dd1

Please sign in to comment.