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

Deploy statefulset as component. #365

Merged
merged 15 commits into from
Aug 3, 2022
9 changes: 4 additions & 5 deletions controllers/compaction_lease_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (
druidv1alpha1 "github.com/gardener/etcd-druid/api/v1alpha1"
controllersconfig "github.com/gardener/etcd-druid/controllers/config"
"github.com/gardener/etcd-druid/pkg/common"
componentlease "github.com/gardener/etcd-druid/pkg/component/etcd/lease"
druidpredicates "github.com/gardener/etcd-druid/pkg/predicate"
"github.com/gardener/etcd-druid/pkg/utils"
"github.com/gardener/gardener/pkg/utils/imagevector"
Expand Down Expand Up @@ -119,7 +118,7 @@ func (lc *CompactionLeaseController) Reconcile(ctx context.Context, req ctrl.Req

// Get full and delta snapshot lease to check the HolderIdentity value to take decision on compaction job
fullLease := &coordinationv1.Lease{}
if err := lc.Get(ctx, kutil.Key(etcd.Namespace, componentlease.GetFullSnapshotLeaseName(etcd)), fullLease); err != nil {
if err := lc.Get(ctx, kutil.Key(etcd.Namespace, utils.GetFullSnapshotLeaseName(etcd)), fullLease); err != nil {
logger.Info("Couldn't fetch full snap lease because: " + err.Error())

return ctrl.Result{
Expand All @@ -128,7 +127,7 @@ func (lc *CompactionLeaseController) Reconcile(ctx context.Context, req ctrl.Req
}

deltaLease := &coordinationv1.Lease{}
if err := lc.Get(ctx, kutil.Key(etcd.Namespace, componentlease.GetDeltaSnapshotLeaseName(etcd)), deltaLease); err != nil {
if err := lc.Get(ctx, kutil.Key(etcd.Namespace, utils.GetDeltaSnapshotLeaseName(etcd)), deltaLease); err != nil {
logger.Info("Couldn't fetch delta snap lease because: " + err.Error())

return ctrl.Result{
Expand Down Expand Up @@ -491,8 +490,8 @@ func getCompactJobCommands(etcd *druidv1alpha1.Etcd) []string {
command = append(command, "--data-dir=/var/etcd/data")
command = append(command, "--snapstore-temp-directory=/var/etcd/data/tmp")
command = append(command, "--enable-snapshot-lease-renewal=true")
command = append(command, "--full-snapshot-lease-name="+componentlease.GetFullSnapshotLeaseName(etcd))
command = append(command, "--delta-snapshot-lease-name="+componentlease.GetDeltaSnapshotLeaseName(etcd))
command = append(command, "--full-snapshot-lease-name="+utils.GetFullSnapshotLeaseName(etcd))
command = append(command, "--delta-snapshot-lease-name="+utils.GetDeltaSnapshotLeaseName(etcd))

var quota int64 = DefaultETCDQuota
if etcd.Spec.Etcd.Quota != nil {
Expand Down
9 changes: 4 additions & 5 deletions controllers/compaction_lease_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"time"

druidv1alpha1 "github.com/gardener/etcd-druid/api/v1alpha1"
componentlease "github.com/gardener/etcd-druid/pkg/component/etcd/lease"
"github.com/gardener/etcd-druid/pkg/utils"
"github.com/gardener/gardener/pkg/controllerutils"
"github.com/gardener/gardener/pkg/utils/test/matchers"
Expand Down Expand Up @@ -406,8 +405,8 @@ func validateEtcdForCmpctJob(instance *druidv1alpha1.Etcd, j *batchv1.Job) {
"--data-dir=/var/etcd/data": Equal("--data-dir=/var/etcd/data"),
"--snapstore-temp-directory=/var/etcd/data/tmp": Equal("--snapstore-temp-directory=/var/etcd/data/tmp"),
"--enable-snapshot-lease-renewal=true": Equal("--enable-snapshot-lease-renewal=true"),
fmt.Sprintf("%s=%s", "--full-snapshot-lease-name", componentlease.GetFullSnapshotLeaseName(instance)): Equal(fmt.Sprintf("%s=%s", "--full-snapshot-lease-name", componentlease.GetFullSnapshotLeaseName(instance))),
fmt.Sprintf("%s=%s", "--delta-snapshot-lease-name", componentlease.GetDeltaSnapshotLeaseName(instance)): Equal(fmt.Sprintf("%s=%s", "--delta-snapshot-lease-name", componentlease.GetDeltaSnapshotLeaseName(instance))),
fmt.Sprintf("%s=%s", "--full-snapshot-lease-name", utils.GetFullSnapshotLeaseName(instance)): Equal(fmt.Sprintf("%s=%s", "--full-snapshot-lease-name", utils.GetFullSnapshotLeaseName(instance))),
fmt.Sprintf("%s=%s", "--delta-snapshot-lease-name", utils.GetDeltaSnapshotLeaseName(instance)): Equal(fmt.Sprintf("%s=%s", "--delta-snapshot-lease-name", utils.GetDeltaSnapshotLeaseName(instance))),
fmt.Sprintf("%s=%s", "--store-prefix", instance.Spec.Backup.Store.Prefix): Equal(fmt.Sprintf("%s=%s", "--store-prefix", instance.Spec.Backup.Store.Prefix)),
fmt.Sprintf("%s=%s", "--storage-provider", store): Equal(fmt.Sprintf("%s=%s", "--storage-provider", store)),
fmt.Sprintf("%s=%s", "--store-container", *instance.Spec.Backup.Store.Container): Equal(fmt.Sprintf("%s=%s", "--store-container", *instance.Spec.Backup.Store.Container)),
Expand Down Expand Up @@ -757,7 +756,7 @@ func fullLeaseIsCorrectlyReconciled(c client.Client, instance *druidv1alpha1.Etc
ctx, cancel := context.WithTimeout(context.TODO(), timeout)
defer cancel()
req := types.NamespacedName{
Name: componentlease.GetFullSnapshotLeaseName(instance),
Name: utils.GetFullSnapshotLeaseName(instance),
Namespace: instance.Namespace,
}

Expand All @@ -775,7 +774,7 @@ func deltaLeaseIsCorrectlyReconciled(c client.Client, instance *druidv1alpha1.Et
ctx, cancel := context.WithTimeout(context.TODO(), timeout)
defer cancel()
req := types.NamespacedName{
Name: componentlease.GetDeltaSnapshotLeaseName(instance),
Name: utils.GetDeltaSnapshotLeaseName(instance),
Namespace: instance.Namespace,
}

Expand Down
72 changes: 0 additions & 72 deletions controllers/controller_ref_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,56 +210,6 @@ func (m *EtcdDruidRefManager) FetchStatefulSet(ctx context.Context, etcd *druidv
return statefulSets, err
}

// ClaimStatefulsets tries to take ownership of a list of Statefulsets.
//
// It will reconcile the following:
// * Adopt orphans if the selector matches.
// * Release owned objects if the selector no longer matches.
// * Remove ownerReferences from the statefulsets and use annotations
//
// Optional: If one or more filters are specified, a Statefulset will only be claimed if
// all filters return true.
//
// A non-nil error is returned if some form of reconciliation was attempted and
// failed. Usually, controllers should try again later in case reconciliation
// is still needed.
//
// If the error is nil, either the reconciliation succeeded, or no
// reconciliation was necessary. The list of statefulsets that you now own is returned.
func (m *EtcdDruidRefManager) ClaimStatefulsets(ctx context.Context, statefulSetList *appsv1.StatefulSetList, filters ...func(*appsv1.StatefulSet) bool) ([]*appsv1.StatefulSet, error) {
abdasgupta marked this conversation as resolved.
Show resolved Hide resolved
unmarshall marked this conversation as resolved.
Show resolved Hide resolved
var (
claimed []*appsv1.StatefulSet
errlist []error
)

match := func(obj metav1.Object) bool {
ss := obj.(*appsv1.StatefulSet)
// Check selector first so filters only run on potentially matching statefulsets.
if !m.Selector.Matches(labels.Set(ss.Labels)) {
return false
}
for _, filter := range filters {
if !filter(ss) {
return false
}
}
return true
}

for k := range statefulSetList.Items {
sts := &statefulSetList.Items[k]
ok, err := m.claimObject(ctx, sts, match, m.AdoptResource, m.ReleaseResource)
if err != nil {
errlist = append(errlist, err)
continue
}
if ok {
claimed = append(claimed, sts)
}
}
return claimed, utilerrors.NewAggregate(errlist)
}

func (m *EtcdDruidRefManager) ClaimPodDisruptionBudget(ctx context.Context, pdb *policyv1beta1.PodDisruptionBudget, filters ...func(*policyv1beta1.PodDisruptionBudget) bool) (*policyv1beta1.PodDisruptionBudget, error) {
var errlist []error

Expand Down Expand Up @@ -425,25 +375,3 @@ func RecheckDeletionTimestamp(getObject func() (metav1.Object, error)) func() er
return nil
}
}

// CheckStatefulSet checks whether the given StatefulSet is healthy.
// A StatefulSet is considered healthy if its controller observed its current revision,
// it is not in an update (i.e. UpdateRevision is empty) and if its current replicas are equal to
// desired replicas specified in ETCD specs.
func CheckStatefulSet(etcd *druidv1alpha1.Etcd, statefulSet *appsv1.StatefulSet) error {
if statefulSet.Status.ObservedGeneration < statefulSet.Generation {
return fmt.Errorf("observed generation outdated (%d/%d)", statefulSet.Status.ObservedGeneration, statefulSet.Generation)
}

replicas := int32(1)

if etcd != nil {
replicas = etcd.Spec.Replicas
}

if statefulSet.Status.ReadyReplicas < replicas {
return fmt.Errorf("not enough ready replicas (%d/%d)", statefulSet.Status.ReadyReplicas, replicas)
}

return nil
}
8 changes: 4 additions & 4 deletions controllers/controllers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ var _ = BeforeSuite(func(done Done) {
er, err := NewEtcdReconcilerWithImageVector(mgr, false)
Expect(err).NotTo(HaveOccurred())

err = er.SetupWithManager(mgr, 1, true)
err = er.SetupWithManager(mgr, 5, true)
Expect(err).NotTo(HaveOccurred())

secret := NewSecret(mgr)

err = secret.SetupWithManager(mgr, 1)
err = secret.SetupWithManager(mgr, 5)
Expect(err).NotTo(HaveOccurred())

custodian := NewEtcdCustodian(mgr, controllersconfig.EtcdCustodianController{
Expand All @@ -119,13 +119,13 @@ var _ = BeforeSuite(func(done Done) {
},
})

err = custodian.SetupWithManager(mgrCtx, mgr, 1, true)
err = custodian.SetupWithManager(mgrCtx, mgr, 5, true)
Expect(err).NotTo(HaveOccurred())

etcdCopyBackupsTaskReconciler, err := NewEtcdCopyBackupsTaskReconcilerWithImageVector(mgr)
Expect(err).NotTo(HaveOccurred())

err = etcdCopyBackupsTaskReconciler.SetupWithManager(mgr, 1)
err = etcdCopyBackupsTaskReconciler.SetupWithManager(mgr, 5)
Expect(err).NotTo(HaveOccurred())

activeDeadlineDuration, err = time.ParseDuration("2m")
Expand Down
Loading