Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files Browse the repository at this point in the history
Added ability to handle unknown CLI args to allow switching between v0.22 and v0.23
Added use-etcd-wrapper cli arg for etcdbr container
unmarshall committed Oct 23, 2024
1 parent 549d4a4 commit 17f5db2
Showing 39 changed files with 765 additions and 396 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/constants.go
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@ const (
LabelPartOfKey = "app.kubernetes.io/part-of"
// LabelComponentKey is a key for a label that sets the component type on resources provisioned for an etcd cluster.
LabelComponentKey = "app.kubernetes.io/component"
// LabelEtcdClusterSizeKey is the label key used to store the size of the etcd cluster on the etcd pods.
LabelEtcdClusterSizeKey = "druid.gardener.cloud/etcd-cluster-size"
)

// Annotation keys that can be placed on an Etcd custom resource.
8 changes: 6 additions & 2 deletions api/v1alpha1/etcd.go
Original file line number Diff line number Diff line change
@@ -443,6 +443,8 @@ const (
LastOperationStateSucceeded LastOperationState = "Succeeded"
// LastOperationStateError indicates that an operation is completed with errors and will be retried.
LastOperationStateError LastOperationState = "Error"
// LastOperationStateRequeue indicates that an operation is not completed and either due to an error or unfulfilled conditions will be retried.
LastOperationStateRequeue LastOperationState = "Requeue"
)

// LastOperation holds the information on the last operation done on the Etcd resource.
@@ -486,13 +488,15 @@ func (e *Etcd) IsReconciliationInProgress() bool {
return e.Status.LastOperation != nil &&
e.Status.LastOperation.Type == LastOperationTypeReconcile &&
(e.Status.LastOperation.State == LastOperationStateProcessing ||
e.Status.LastOperation.State == LastOperationStateError)
e.Status.LastOperation.State == LastOperationStateError ||
e.Status.LastOperation.State == LastOperationStateRequeue)
}

// IsDeletionInProgress returns true if the Etcd resource is currently being reconciled, else returns false.
func (e *Etcd) IsDeletionInProgress() bool {
return e.Status.LastOperation != nil &&
e.Status.LastOperation.Type == LastOperationTypeDelete &&
(e.Status.LastOperation.State == LastOperationStateProcessing ||
e.Status.LastOperation.State == LastOperationStateError)
e.Status.LastOperation.State == LastOperationStateError ||
e.Status.LastOperation.State == LastOperationStateRequeue)
}
6 changes: 3 additions & 3 deletions internal/component/clientservice/clientservice.go
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}
return resourceNames, druiderr.WrapError(err,
ErrGetClientService,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error getting client service: %v for etcd: %v", svcObjectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
if metav1.IsControlledBy(objMeta, &etcdObjMeta) {
@@ -77,7 +77,7 @@ func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd)
if err != nil {
return druiderr.WrapError(err,
ErrSyncClientService,
"Sync",
component.OperationSync,
fmt.Sprintf("Error during create or update of client service: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)),
)
}
@@ -97,7 +97,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
return druiderr.WrapError(
err,
ErrDeleteClientService,
"TriggerDelete",
component.OperationTriggerDelete,
"Failed to delete client service",
)
}
8 changes: 4 additions & 4 deletions internal/component/clientservice/clientservice_test.go
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ func TestGetExistingResourceNames(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrGetClientService,
Cause: testutils.TestAPIInternalErr,
Operation: "GetExistingResourceNames",
Operation: component.OperationGetExistingResourceNames,
},
},
}
@@ -106,7 +106,7 @@ func TestSyncWhenNoServiceExists(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncClientService,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
@@ -159,7 +159,7 @@ func TestSyncWhenServiceExists(t *testing.T) {
expectedError: &druiderr.DruidError{
Code: ErrSyncClientService,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
@@ -211,7 +211,7 @@ func TestTriggerDelete(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrDeleteClientService,
Cause: testutils.TestAPIInternalErr,
Operation: "TriggerDelete",
Operation: component.OperationTriggerDelete,
},
deleteErr: testutils.TestAPIInternalErr,
},
12 changes: 7 additions & 5 deletions internal/component/configmap/configmap.go
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}
return nil, druiderr.WrapError(err,
ErrGetConfigMap,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error getting ConfigMap: %v for etcd: %v", objKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
if metav1.IsControlledBy(objMeta, &etcdObjMeta) {
@@ -65,7 +65,9 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}

// PreSync is a no-op for the configmap component.
func (r _resource) PreSync(_ component.OperatorContext, _ *druidv1alpha1.Etcd) error { return nil }
func (r _resource) PreSync(_ component.OperatorContext, _ *druidv1alpha1.Etcd) error {
return nil
}

// Sync creates or updates the configmap for the given Etcd.
func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd) error {
@@ -76,14 +78,14 @@ func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd)
if err != nil {
return druiderr.WrapError(err,
ErrSyncConfigMap,
"Sync",
component.OperationSync,
fmt.Sprintf("Error during create or update of configmap for etcd: %v", druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)))
}
checkSum, err := computeCheckSum(cm)
if err != nil {
return druiderr.WrapError(err,
ErrSyncConfigMap,
"Sync",
component.OperationSync,
fmt.Sprintf("Error when computing CheckSum for configmap for etcd: %v", druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)))
}
ctx.Data[common.CheckSumKeyConfigMap] = checkSum
@@ -103,7 +105,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
return druiderr.WrapError(
err,
ErrDeleteConfigMap,
"TriggerDelete",
component.OperationTriggerDelete,
"Failed to delete configmap",
)
}
8 changes: 4 additions & 4 deletions internal/component/configmap/configmap_test.go
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ func TestGetExistingResourceNames(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrGetConfigMap,
Cause: testutils.TestAPIInternalErr,
Operation: "GetExistingResourceNames",
Operation: component.OperationGetExistingResourceNames,
},
},
}
@@ -115,7 +115,7 @@ func TestSyncWhenNoConfigMapExists(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncConfigMap,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
@@ -211,7 +211,7 @@ func TestSyncWhenConfigMapExists(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncConfigMap,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
@@ -264,7 +264,7 @@ func TestTriggerDelete(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrDeleteConfigMap,
Cause: testutils.TestAPIInternalErr,
Operation: "TriggerDelete",
Operation: component.OperationTriggerDelete,
},
},
}
6 changes: 3 additions & 3 deletions internal/component/memberlease/memberlease.go
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
); err != nil {
return resourceNames, druiderr.WrapError(err,
ErrListMemberLease,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error listing member leases for etcd: %v", druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
for _, lease := range objMetaList.Items {
@@ -98,7 +98,7 @@ func (r _resource) doCreateOrUpdate(ctx component.OperatorContext, etcd *druidv1
if err != nil {
return druiderr.WrapError(err,
ErrSyncMemberLease,
"Sync",
component.OperationSync,
fmt.Sprintf("Error syncing member lease: %v for etcd: %v", objKey, druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)))
}
ctx.Logger.Info("triggered create or update of member lease", "objectKey", objKey, "operationResult", opResult)
@@ -114,7 +114,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
client.MatchingLabels(getSelectorLabelsForAllMemberLeases(etcdObjMeta))); err != nil {
return druiderr.WrapError(err,
ErrDeleteMemberLease,
"TriggerDelete",
component.OperationTriggerDelete,
fmt.Sprintf("Failed to delete member leases for etcd: %v", druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
ctx.Logger.Info("deleted", "component", "member-leases")
8 changes: 4 additions & 4 deletions internal/component/memberlease/memberlease_test.go
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ func TestGetExistingResourceNames(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrListMemberLease,
Cause: testutils.TestAPIInternalErr,
Operation: "GetExistingResourceNames",
Operation: component.OperationGetExistingResourceNames,
},
},
}
@@ -135,7 +135,7 @@ func TestSync(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncMemberLease,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
{
@@ -146,7 +146,7 @@ func TestSync(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncMemberLease,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
@@ -229,7 +229,7 @@ func TestTriggerDelete(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrDeleteMemberLease,
Cause: testutils.TestAPIInternalErr,
Operation: "TriggerDelete",
Operation: component.OperationTriggerDelete,
},
},
}
6 changes: 3 additions & 3 deletions internal/component/peerservice/peerservice.go
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}
return resourceNames, druiderr.WrapError(err,
ErrGetPeerService,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error getting peer service: %s for etcd: %v", svcObjectKey.Name, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
if metav1.IsControlledBy(objMeta, &etcdObjMeta) {
@@ -77,7 +77,7 @@ func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd)
if err != nil {
return druiderr.WrapError(err,
ErrSyncPeerService,
"Sync",
component.OperationSync,
fmt.Sprintf("Error during create or update of peer service: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)),
)
}
@@ -97,7 +97,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
return druiderr.WrapError(
err,
ErrDeletePeerService,
"TriggerDelete",
component.OperationTriggerDelete,
fmt.Sprintf("Failed to delete peer service: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)),
)
}
8 changes: 4 additions & 4 deletions internal/component/peerservice/peerservice_test.go
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ func TestGetExistingResourceNames(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrGetPeerService,
Cause: testutils.TestAPIInternalErr,
Operation: "GetExistingResourceNames",
Operation: component.OperationGetExistingResourceNames,
},
},
}
@@ -105,7 +105,7 @@ func TestSyncWhenNoServiceExists(t *testing.T) {
expectedError: &druiderr.DruidError{
Code: ErrSyncPeerService,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
@@ -155,7 +155,7 @@ func TestSyncWhenServiceExists(t *testing.T) {
expectedError: &druiderr.DruidError{
Code: ErrSyncPeerService,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
@@ -209,7 +209,7 @@ func TestPeerServiceTriggerDelete(t *testing.T) {
expectError: &druiderr.DruidError{
Code: ErrDeletePeerService,
Cause: deleteInternalErr,
Operation: "TriggerDelete",
Operation: component.OperationTriggerDelete,
},
},
}
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}
return resourceNames, druiderr.WrapError(err,
ErrGetPodDisruptionBudget,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error getting PDB: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
if metav1.IsControlledBy(objMeta, &etcdObjMeta) {
@@ -83,7 +83,7 @@ func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd)
if err != nil {
return druiderr.WrapError(err,
ErrSyncPodDisruptionBudget,
"Sync",
component.OperationSync,
fmt.Sprintf("Error during create or update of PDB: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)),
)
}
@@ -98,7 +98,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
if err := client.IgnoreNotFound(r.client.Delete(ctx, emptyPodDisruptionBudget(pdbObjectKey))); err != nil {
return druiderr.WrapError(err,
ErrDeletePodDisruptionBudget,
"TriggerDelete",
component.OperationTriggerDelete,
fmt.Sprintf("Failed to delete PDB: %v for etcd: %v", pdbObjectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
ctx.Logger.Info("deleted", "component", "pod-disruption-budget", "objectKey", pdbObjectKey)
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ func TestGetExistingResourceNames(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrGetPodDisruptionBudget,
Cause: testutils.TestAPIInternalErr,
Operation: "GetExistingResourceNames",
Operation: component.OperationGetExistingResourceNames,
},
},
}
@@ -107,7 +107,7 @@ func TestSyncWhenNoPDBExists(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncPodDisruptionBudget,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
@@ -161,7 +161,7 @@ func TestSyncWhenPDBExists(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrSyncPodDisruptionBudget,
Cause: testutils.TestAPIInternalErr,
Operation: "Sync",
Operation: component.OperationSync,
},
},
}
@@ -214,7 +214,7 @@ func TestTriggerDelete(t *testing.T) {
expectedErr: &druiderr.DruidError{
Code: ErrDeletePodDisruptionBudget,
Cause: testutils.TestAPIInternalErr,
Operation: "TriggerDelete",
Operation: component.OperationTriggerDelete,
},
},
}
6 changes: 3 additions & 3 deletions internal/component/role/role.go
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ func (r _resource) GetExistingResourceNames(ctx component.OperatorContext, etcdO
}
return resourceNames, druiderr.WrapError(err,
ErrGetRole,
"GetExistingResourceNames",
component.OperationGetExistingResourceNames,
fmt.Sprintf("Error getting role: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)))
}
if metav1.IsControlledBy(objMeta, &etcdObjMeta) {
@@ -76,7 +76,7 @@ func (r _resource) Sync(ctx component.OperatorContext, etcd *druidv1alpha1.Etcd)
if err != nil {
return druiderr.WrapError(err,
ErrSyncRole,
"Sync",
component.OperationSync,
fmt.Sprintf("Error during create or update of role %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcd.ObjectMeta)),
)
}
@@ -95,7 +95,7 @@ func (r _resource) TriggerDelete(ctx component.OperatorContext, etcdObjMeta meta
}
return druiderr.WrapError(err,
ErrDeleteRole,
"TriggerDelete",
component.OperationTriggerDelete,
fmt.Sprintf("Failed to delete role: %v for etcd: %v", objectKey, druidv1alpha1.GetNamespaceName(etcdObjMeta)),
)
}
Loading

0 comments on commit 17f5db2

Please sign in to comment.